Download - exercises-20120203

Transcript
  • Embedded Linux Exercises Version - 2012.02

    Exercisesfor

    EmbeddedLinux

    v2012.02

    WARNING:Theorder of the exercises does not alwaysfollowthesameorderof theexplanations intheslides. Whencarryingouttheexercises,carefullyfollowtheexerciserequirements.DoNOT blindlytypethecommandsasfound intheslides.Readeveryexerciseinitsentiretybeforecarryingouttheinstructions.

    OPERSYS INC. 1

  • Embedded Linux Exercises Version - 2012.02

    TheseexercisesaremadeavailabletoyouunderaCreativeCommonsShareAlike3.0license.Thefulltermsofthislicensearehere:

    https://creativecommons.org/licenses/bysa/3.0/

    Attributionrequirementsandmisc.:

    Thispagemustremainasisinthisspecificlocation(page#2),everythingelseyouarefreetochange;includingthelogo:)

    UseoffiguresinotherdocumentsmustfeaturethebelowOriginalsatURLimmediatelyunderthatfigureandthebelowcopyrightnoticewhereappropriate.

    YouarefreetofillinthespaceinthebelowDeliveredand/orcustomizedbysectionasyouseefit.

    (C)Copyright20032012,Opersysinc.

    Theseexercisescreatedby:KarimYaghmour

    Originalsat:www.opersys.com/community/docs

    Deliveredand/orcustomizedby:

    OPERSYS INC. 2

  • Embedded Linux Exercises Version - 2012.02

    Softwarecomponentsversions

    Workspace:Downloadlocation: http://opersys.com/downloads/lite5200workspace.tar.bz2Downloadlocation: http://opersys.com/downloads/tqm860workspace.tar.bz2

    LinuxKernel:Downloadlocation: http://www.kernel.orgVersion: 2.6.37PatchforEVB5200: NONEPatchforTQM860L: NONEConfigurationforEVB5200: 52xx/lite5200b_defconfigConfigurationforTQM860L: tqm8xx_defconfigImagetouseforEVB5200: arch/powerpc/boot/images/cuImage.lite5200ImagetouseforTQM860L: arch/powerpc/boot/images/cuImage

    Bootloader:Package: UBootDownloadlocation: http://www.denx.de/wiki/UBootVersion: 2010.12PatchforEVB5200: uboot2010.12fixlite5200.patchPatchforTQM860L: NONEMakefiletargetforTQM860L: TQM860L_configMakefiletargetforEVB5200: icecube_5200_LOWBOOT_config

    TARGETSERIALNUMBER:

    OPERSYS INC. 3

  • Embedded Linux Exercises Version - 2012.02

    Chapter2:1)Usedsudoaddusertocreateastageuser.Followtheinstructionstoaddthenewuserandsetitspassword.2)Usingthestageaccount,downloadandextracttheworkspaceforyourtarget. Havingselectedandcopiedto/home/stageoneof lite5200workspace.tar.bz2or tqm860workspace.tar.bz2,usethetarxjfcommandtoextracttheworkspace.3)Maketheproperchangessothatyourareabletoaccessyourserialportfromthestageuseraccount. Youwillneedtologoutcompletely(closeallwindowsandlogout),andlogbackininorderforthechangestotakeeffect. Youmightbeabletoreuseexistinggroupsettingsfortherelevantfilesinsteadofthosedescribedintheslide,havealookatthecurrent groupsettingsfor/dev/ttyS0. Inordertoconfigureminicom,youwillneedtologinasrootandusetheminicomscommand.4)VerifythatthereisanexistingconfigurationforyourEthernetcardallowingconnectiontotheInternet. ExplorethedoublearrowiconontheUbuntutoolbarbyclickingandrightclickingit.5)CreatealocalLANconfiguration foryourEthernetcardtoallowconnectiontothetargetusingacrossoverEthernetcable(host:192.168.202.100;target:192.168.202.79).

    ExampleEthernetcardconfiguration:IPADDR=192.168.202.100GATEWAY=192.168.202.79NETWORK=192.168.202.0NETMASK=255.255.255.0BROADCAST=192.168.202.255

    Chapter3:0)Applyanynecessarykernelpatch1) Configure the kernel for the target. Use the configuration listed on the Softwarecomponentsversionssheetoftheexercisesetasthebasisofyourconfiguration.Inadditiontothevaluesalreadypreset,addsupportforconfig.gzin/proc(Kernel.configsupport).2)Buildthekernel3)Installthekernel4)Buildthekernelmodules5)Installthekernelmodules

    Chapter4:0)ApplyanynecessaryUBootpatch1)BuildUBoot2)BootwithUBootandtryouttheonlinehelp3)PrintUBoot'senvironmentvariables

    OPERSYS INC. 4

  • Embedded Linux Exercises Version - 2012.02

    4)Settheenvironmentvariablesaslistedonthebottomofp.79andsavethem. FortheTQM860L,youmightneedtoreplacetheoffstringinthenfscmdenvironmentvariablewitheth0.Therootpathwillhavetomatchyourowndevelopmentenvironment.5)CreateaUBootimageofthekernelbuiltearlier6)ConfigureyourhostforservingTFTPrequests7)UseTFTPtodownloadimagetotarget.FortheEVB5200,youwillneedtodownloadtheimageto0x00200000insteadof0x00100000becauseofitssize.8)Bootwithimage(fortheEVB5200,youwillneedtosetthebootargsenvironmentvariabletoconsole=ttyS0,115200.)

    Chapter5:1)Createessentialrootfsdirectories2)Copyglibc librariesto target'srootfsandstrip them.NOTE:contraryto theslides,thelibrariesarein${TARGET_PREFIX}/${TARGET}/sysroot/lib.3)Copykernelmodulestotarget'srootfs4)Createnodesontarget'srootfs5)ConfigureBusyBoxusingthemakemenuconfigcommand6)BuildandinstallBusyBox7)CreateinitializationscriptsforBusyBoxinit.Don'tforgettoset/etc/init.d/rcStoallowforit toexecute(chmod755/etc/init.d/rcS).Contrarytotheexamplesintheslides,donotputanentryin/etc/fstabforNFS,anddonotputanentryforcustomappin/etc/inittab.

    Chapter6:1)BuildandinstalltheMTDutilitiesforyourhost(p.149).NOTE:

    Forzlib,youmustedittheconfigurefileandchangelines268and269forthese:CFLAGS="${CFLAGS}"SFLAGS="${SFLAGS}"

    Againforzlib,usethislinefortheinstallinsteadoftheoneontheslide:$makeprefix=${TARGET_PREFIX}/${TARGET}/sysroot/install

    Forlzo,usetheseconfigureandinstallinstructionsinsteadofthoseontheslide:$CC=${TARGET}gcc./configureenablesharedhost=${TARGET}$makeprefix=${TARGET_PREFIX}/${TARGET}/sysroot/install

    2)ReconfigurethetargetkernelwebuiltearliertoaddsupportfortheMTDsubsystem(usemenuconfig,lookunderDeviceDrivers).Seep.152fortheoptionstoset.Setalloptionsasbuiltin (*) not asmodules (M). Ignore the mappingdrivers. Also, in the DeviceDrivers>Blockdevicessubmenu,andmakesureRAMblockdevicesupportisbuiltin(notasmodules.)3)RebuildthekernelandupdatethekernelforUBootimageintheimages/directory.4)BuildtheMTDtoolsforthetargetandinstalltheminyourtarget'srootfilesystem:

    $cpa${TARGET_PREFIX}/${TARGET}/sysroot/include/*include/$makeCROSS="${TARGET}"$cppowerpcunknownlinuxgnu/flash*${PRJROOT}/rootfs/sbin/

    OPERSYS INC. 5

  • Embedded Linux Exercises Version - 2012.02

    5)Createtheappropriate/deventriesfortheMTDpartitionsasshownonp.154.

    Chapter7:1)Buildandinstallthecramfsutilities(p.166)2)CreateaCRAMFSimageofyourtarget'srootfilesystem(p.167)3)Buildandinstalltheromfsutilities(p.168)3)CreateaROMFSimageofyourtarget'srootfilesystem(p.168)4)Buildandinstallthesquashfsutilities(p.169)5)Createasquashfsimageofyourtarget'srootfilesystem(p.169)6)CreateaUBIFSimageofyourtarget'srootfilesystem(p.170)7)CreateaJFFS2imageofyourtarget'srootfilesystem(p.171)8)CreateaRAMdiskimageofyourtarget'srootfilesystem(p.172174)9)Createaninitramfsimagesofyourtarget'srootfilesystem(175)10)Comparethefilesystemimagesizes11)Configureyourhostandyourtargetsothatthetarget'sconfigurationisobtainedatboot timeviaDHCPandtherootfsismountedonNFS.

    Chapter8:1)Addafilecalledmy_panic.cinthekernel'skernel/directory.Thatfileshouldcontainthe codeonpages217and218.Youwillneedtoreplacethecalltonotifier_chain_registerwitha call to atomic_notifier_chain_register. In the write_raw_user_screen(void), put thefollowing:

    printk(Thisboxhasjustpanicked...\n);2)Modifykernel/Makefiletoreflectthechangesin#13)Crosscompilethemodifiedkernelaswedidinchapter34) Boot this newkernel directly using the bootm command. Given that there is no rootfilesystem,thekernelshouldpanicandtheabovemessageshouldbedisplayed.

    Chapter10:3hoursWriteadynamicallyloadabledevicedriverforthetargetthat:

    a)Implementsacharacterdevicewiththeopen(),release(),read(),andwrite()functions.b)Hasafixedsizearray(~20entries)whereitrecordsforeachcalltoread():

    a)thePIDoftheprocessthatcalledread()b)theexacttimeatwhichthatcallwasmade

    c)Uponawrite(),thedrivershouldprintouttotheconsolethecontentofitsarray.O'Reilly'sLinuxDeviceDrivers,3rd ed.isausefulreferenceforthisexercise. Itisfoundonlineat:http://lwn.net/Kernel/LDD3/.Thereisacopyofamakefiletouseforbuildingyourdriver in LDD3. Using that makefile, youcanusea command that has ARCH=... andCROSS_COMPILE=...tobuildyourmodule.

    OPERSYS INC. 6

  • Embedded Linux Exercises Version - 2012.02

    mmap:NOTE:ReadALLtheseexercisesoncebeforestarting.Theyarealllinkedtogether.1)Createacharacterdriverthatallocatesalarge(X*MB)bufferandexportsthemmap()fileoptherebyallowinguserspaceprocessestommap()thebuffertouserspace.Makesureallbytes in the buffer are zeroed out before returning from mmap(). Have a look atvmalloc_user()andremap_vmalloc_range().2)Createauserspaceapplicationthatopensthedevicecorrespondingtoyourcharacterdriverandcallsonmmaptomapthedriver'sbufferinitsaddressspace.3)Addanioctl()calltoyourdriverallowingauserspaceprocesstosettozeroallbytesinthebuffer,andwriteaseparateapplicationthatopensyourdeviceandusessaidioctl()callto clearallbytesinthebuffer.4)Modifythekernelmoduleimplementingyourcharacterdrivertolaunchakernelthreadinitsinitializationfunction.Havethethreadwritea0xAAbyteatthefirstunusedaddressofthe bufferandperiodicallycheckwhetherthenextbyteis0x55and,ifso,thenwrites0xAAright after0x55.Makesuretoimplementacircularbuffer.5)Modifytheapplicationcodedin#2toperiodicallymonitorthebuffer'sfirstunusedaddressforthe0xAAvalueandiffound,write0x55valueinthenextbyte. Again,makesureyoucirclearoundtothefirstbytewhenyougettotheendofthebuffer.

    Chapter13:1)Createasmallprogram,compileitwiththedebuggingflags,andinstallitonyourtarget's rootfilesystem.Usethegdbservertoremotelystepthroughyourprogram,asisexplainedon page 276. You will find the gdbserver binary in: ${TARGET_PREFIX}/${TARGET}/debugroot/usr/bin2)Usestraceonthetargettoobservethebehaviorofafewprocesses(p.279and280.)Thestracebinaryisinthesamelocationasthegdbserver.

    Chapter16:1)Buildandinstallcrosstoolng(p.383).Makesureyouhavealltheprerequisitepackagesinstalled.2)Configureatoolchainforthetargetandbuildit(p.383384).3)Rebuildthekernelandregeneratetherootfsusingthenewtoolchain. Recreatealltheappropriateimagesandrestartthetargetusingthoseimagesinordertovalidatethenewtoolchain.

    OPERSYS INC. 7


Top Related