Embedded Linux Exercises Version - 2019.10
Total Page:16
File Type:pdf, Size:1020Kb
Embedded Linux Exercises Version - 2019.10 Hands-On Exercises for Embedded Linux v. 2019.10 WARNING: The order of the exercises does not always follow the same order of the explanations in the slides. When carrying out the exercises, carefully follow the exercise requirements. Do NOT blindly type the commands or code as found in the slides. Read every exercise in its entirety before carrying out the instructions. © OPERSYS INC. 1/10 Embedded Linux Exercises Version - 2019.10 These exercises are made available to you under a Creative Commons hare- "li#e 3.0 license. The full terms of this license are here: https://creativecommons.org/licenses/by!sa/3.0/ "ttribution requirements and misc.: • This page must remain as!is in this specific location (page #2,, (almost) everything else you are free to change. • -ou are forbidden from removing our name or logo. • .se of figures in other documents must feature the below /Originals at” .RL immediately under that figure and the below copyright notice where appropriate. • -ou are free to fill in the space in the below “Delivered and/or customi3ed by” section as you see fit. )C, Copyright 2003!+%45, Opersys inc. These exercises created by: Karim Yaghmour Originals at: www.opersys.com/training/ Delivered and/or customized by& © OPERSYS INC. 2/10 Embedded Linux Exercises Version - 2019.10 Software components versions Hard"are: BeagleBone White 8 has serial integrated into . 7 $%ass &rive: 2ocation to be provided in class 'i%es: Prebuilt SD card image& el-image-bb!454%%:.img.xz Wor#space& bbone-white!$.%.%!454%4;.tar.b3+ Linux (erne%: <ersion& =.$.+ 9atch& >0>? Configuration for target& multi@v7@defconfig 6ernel image& arch'arm/boot'3Amage Device tree blob& arch'arm/boot'dts'am3$=x-bone.dtb )ootloader: 9ac#age& .-Boot <ersion& u-boot!+%45.%: 9atch& >0>? Configuration for target& am$$=x_evm_defconfig Amages to use on target& u-boot.img and B20 Too%c*ain: Prefix ).buntu ARM toolchain,& arm-linux-gnueabi! Prefix )7uildroot uClibc toolchain,& arm-linux- TARGET SERIAL N+,)ER: © OPERSYS INC. 3/10 Embedded Linux Exercises Version - 2019.10 “Linux” basics: 4) .se the following commands to install the following packages: $ sudo apt-get install libc6-armel-cross libc6-dev-armel-cross \ > binutils-arm-linux-gnueabi libncurses5-dev $ sudo apt-get install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi $ sudo apt install bison flex $ sudo apt install gnupg2 $ sudo apt install libssl-dev +, Configure your PC to connect to beaglebone. -ouCll need to ma#e sure you are part of the “dialout” group and that you can see 'dev/ttyU 7% on your host. $, Download prebuilt SD card image and use the “dd1 command to put it on the SD card and boot with it. ;) .se “picocom” to shell into the Beagle7one. =, Create a local!2"> configuration for your Ethernet card to allow connection to the target using a cross-over ?thernet cable (host& 45+.4DE.+%+.4%%F target& 45+.4DE.+%+.:5). Example Ethernet card configuration& A9"DDRG45+.4DE.+%+.4%% H"T?W"-G45+.4DE.+%+.:5 >?TW0R6G45+.4DE.+%+.% >?TB" 6G+==.+==.+==.% 7R0"DC" TG45+.4DE.+%+.+== &eve%o#ment Wor/s#ace: 4) Download the development wor#space image and put it in your home directory. +) Extract the development wor#space $, Ma#e sure you are able to run the “devenv” setup script to set up your environment variables. ;) Repartition the SD card using the fdisk command for booting the beaglebone =) Put the images in “images/boot-part” on your bootable partition. D, Boot with the newly reformatted card 8 the #ernel should panic because it doesnCt have a root filesystem. ThatCs expected. (erne% )asics: %) Apply any necessary #ernel patch 4, Configure the #ernel for the target. Ma#e sure that support for config.g3 in 'proc is enabled © OPERSYS INC. 4/10 Embedded Linux Exercises Version - 2019.10 )/6ernel .config support1,. +) Build the #ernel $) Anstall the #ernel ;) Build the #ernel modules =) Anstall the #ernel modules D) Build the device trees :) Anstall the beaglebone device tree E) 0verwrite the default #ernel and DT7 on the SD card with the one you have Iust built and boot with them. 5) Check that the #ernel booting is your own in its early messages. )ootloader: %) Apply any necessary .!7oot patch 4) Build .-Boot using this command& $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j8 am335x_evm_defconfig $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j8 +) Anstall .-Boot& J cp B20 JKPRLR00TM'images J cp u-boot.img JKPRJR00TM'images $) Copy the u-boot images to the <N"T partition& J cd JKPRJR00TM'images J cp B20 'media'karim/…. J cp u-boot.img 'media'karim/…. J cp uEnv.txt 'media'karim/…. ;) Boot with .-Boot and try out the online help =) Print .-Boot's environment variables D) Configure your host for serving DQCP requests :) .se “bootp” in .-Boot to get config from DQCP server E) Configure your host for serving TNT9 requests 5) .se TNTP to download image to target 4%) Boot with image 44) Create environment variables in .!7ootCs environment to automate the loading of the #ernel and the DT7 to boot from them using tftp. © OPERSYS INC. 5/10 Embedded Linux Exercises Version - 2019.10 Root 0%es stem: 4) Create essential rootfs directories +, Copy glibc libraries to target's rootfs and strip them. >0T?& contrary to the slides, the libraries are in /usr/arm-linux-gnueabi/lib/ $) Copy #ernel modules to target's rootfs ;) Ma#e sure you have 'dev, 'proc and 'sys in your rootfs =) Configure BusyBox using the “ma#e menuconfig” command D) Build and install 7usyBox :, Create initialization scripts for BusyBox init. Don't forget to set 'etc/init.d'rcS to allow for it to execute (chmod :== 'etc/init.d'rcS). Contrary to the examples in the slides, do not put an entry in 'etc/fstab for >NS, and do not put an entry for “custom-app” in 'etc/inittab. E, Copy your rootfs into the ext; partition on the device 8 youCll have to see what directory itCs mounted to. J cd JKPRJR00TM'rootfs J cp -a JKPRJR00TM'rootfs'R 'media'karim/O 5) Boot the new SD card, you should now have a fully-functional embedded 2inux system 'i%es stem T #es: %) Anstall the MTD utilities for your host 4) Build and install the cramfs utilities +) Create a CR"BN image of your target's root filesystem $) Anstall the romfs utilities $) Create a R0BN image of your target's root filesystem ;) Anstall the squashfs utilities =) Create a squashfs image of your target's root filesystem D) Create a .7ANS image of your target's root filesystem :) Create a LNN + image of your target's root filesystem E) Create a RAM disk image of your target's root filesystem 5) Create an initramfs images of your target's root filesystem 4%) Compare the filesystem image sizes 44, Configure your host and your target so that the target's configuration is obtained at boot time via DQCP and the rootfs is mounted on >NS. © OPERSYS INC. 6/10 Embedded Linux Exercises Version - 2019.10 &evice &rivers 1 Set 23: Write a dynamically loadable device driver for the target that& a, Amplements a character device with the open(), release(), read(), and write), functions. b) .ses the misc_register() functionality to register itself as a character device. c) Provides circular buSer functionality wherein a call to write), causes the input bytes to be written to a buSer and upon a read), causes the bytes in the buSer to be consumed and returned to the caller. .se a “read” pointer and a “write1 pointer to walk around the buSer. A buSer of ;%%bytes is more than sufficient. d) Provides a sysfs interface to print the number of bytes in the buSer. 0'Reilly's /2inux Device Drivers, $rd ed.1 is a useful reference for this exercise. At is found online at& http&''lwn.net'6ernel'2DD$'. There is a copy of a ma#efile to use for building your driver in 2DD$. .sing that ma#efile, you can use a command that has /ARCQG...1 and “CR0 @C0B9A2?G...” to build your module. Nor information regarding misc_register(), see& http&''www.linuxjournal.com/article'+5+% 0nce implemented, you should be able to test your driver by doing& * echo foobar U 'dev/circchar * cat 'dev/circchar foobar Tracin4 "it* ftrace: 4. Reconfigure the #ernel to support ftrace, if it's not already enable& a. The “function1 and “function@graph1 tracers. Ma#e sure you enable C0>NAH@D->"BAC@NTR"CE. b. Modules and module unloading. -ou don't need to enable forced module unloading. +. Rebuild your #ernel, reflash the SD card and reboot. 0r use network booting if you want. $. tart ftrace using the “function” tracer and monitor its output. Careful& once you start ftrace by echoing /4” into tracing@on, it'll stay on until you stop it (i.e. echo /%” into same file). © OPERSYS INC. 7/10 Embedded Linux Exercises Version - 2019.10 ;. .se ftrace to monitor the following& • Scheduling change events • C9. frequency scaling events • Calls to @@kmalloc • Calls to the “brk” system call • Calls to both @@kmalloc and the /brk” system call • All events occurring while the “system@server” process is scheduled • All mcount calls occurring while the “system_server” process is scheduled =. Modify your driver to add a static tracepoint to monitor each read), and write), operation to it. .se trace@print#), to achieve that, remember that youPll have to use B0D.2?@2AC?> ?)/H921, in order to have access to this symbol. Rebuild your driver and reload it on the device. tart ftrace tracing and ma#e sure you can see the output in the ftrace output at runtime when you do a “cat1 or “echo” as above.