Implementation of Embedded OS Lab1 Linux Kernel Compilation
Goal Learn how to build Linux kernel image for PXA270. / 18 2015/03/31
Environment Host System Build System Target System Software Windows XP VirtualBox + Ubuntu 8.04 Target System Creator XScale PXA270 Software Toolchain Linux for PXA270 linux-2.6.15.3-creator-pxa270.patch mkimage utility Bootloader image Root filesystem image (20M) You can download them from RSWiki IEOS Course Software / 18 2015/03/31
Setting up Environment Install VirtualBox, Ubuntu 8.04, and development tools. Please refer to the slides of lab1 from the course Computer System Laboratory (CSL). Check the evaluation board. Please refer to the slides of lab2 from CSL. / 18 2015/03/31
Installing Toolchain Install the toolchain (cross compiler) for PXA270. Step1: download the toolchain. % wget http://eraser.csie.ntu.edu.tw/courses/ieos/10202/lab 2/arm-linux-toolchain-bin.4.0.2.tar.gz Step2: extract the tar.gz file to home directory. % tar zxvf arm-linux-toolchain-bin.4.0.2.tar.gz -C $HOME Step3: append installation directory (bin) to PATH. By adding “export PATH=$PATH:$HOME/arm-unknown-linux- gnu/bin” to $HOME/.bashrc Don’t forget to logout and login again to make the change effective. Test the newly installed cross-compiler. % arm-unknown-linux-gnu-gcc –v You will see the version number (4.0.2) in the output. / 18 2015/03/31
Compiling Linux Kernel (1/3) Step1: download Linux source codes (mt-linux- 2.6.15.3.tar.gz) for PXA270. Step2: extract the source codes. Step3: apply the patch. % cd pxa270/create-pxa270 % wget http://eraser.csie.ntu.edu.tw/courses/ieos/10202 /lab2/linux-2.6.15.3-creator-pxa270.patch % patch -p0 < linux-2.6.15.3-creator- pxa270.patch / 18 2015/03/31
Compiling Linux Kernel (2/3) Step4: configure the Linux kernel. Please make sure the toolchain path has been specified in PATH and the C development library (libc6-dev) has been installed. % cd ../linux % make mrproper % make creator_pxa270_defconfig The “make <platform>_defconfig” command will create .config by the default symbol values from arch/<architecture>/configs/<platform>_defconfig To customize the configuration, please refer to page 9 of this slides. Step5: compile Linux kernel. % make –j4 / 18 2015/03/31
Compiling Linux Kernel (3/3) There are three output files in the source tree. ./vmlinux: uncompressed image in ELF format ./arch/arm/boot/compressed/vmlinux: compressed image in ELF format ./arch/arm/boot/zImage: compressed image in raw format Decompression Function Compressed Kernel (c) ELF Header (b) Uncompressed Kernel (a) / 18 2015/03/31
Configuring Linux Kernel (1/2) The Linux kernel build system (Kbuild) supports a variety of configuration methods, and the most commonly used method is: % make menuconfig Please install libncurses5-dev package in Ubuntu. / 18 2015/03/31
Configuring Linux Kernel (2/2) Many features and drivers are available as modules, and it is possible to choose whether to build them into the kernel. Please always build modules into the kernel, i.e., <*>, in our Labs. You need to add the NIC driver into the kernel as follows. Once the kernel has been configured, you can quit the kernel configuration menu via Esc key or the Exit menu item. Choose “Yes” to save the new configuration. built-in / 18 2015/03/31
Memory Layout of PXA270 (1/3) The Creator XScale PXA270 board has 32MB flash and 64MB SDRAM. Flash memory ranges from 0x00000000 to 0x02000000. SDRAM ranges from 0xa0000000 to 0xa4000000. The locations and sizes of kernel image and root filesystem are specified in Linux kernel (in arch/arm/mach- pxa/mach-creator-pxa270.c). The structure of creator_pxa270_partitions[] is at line 248. / 18 2015/03/31
Memory Layout of PXA270 (2/3) U-Boot 0x00080000 Linux kernel 0x00480000 0xa1080000 U-Boot (TFTP) Root Filesystem 0x01880000 0xa3f80000 U-Boot (domingo) 0x02000000 0xa4000000 Flash RAM / 18 2015/03/31
Memory Layout of PXA270 (3/3) Based on the memory layout, we can configure the partition of the flash in Linux kernel as follows. static struct mtd_partition creator_pxa270_partitions[] = { ... },{ name: "Kernel", offset: 0x00080000, size: 0x00400000, // 4M mask_flags: MTD_WRITEABLE name: "Filesystem", offset: 0x00480000, size: 0x01400000, // 20M } / 18 2015/03/31
Converting to U-Boot Bootable Image (1/2) Since U-Boot has its own format for kernel images, we need to convert the Linux kernel image (vmlinux) to U-Boot bootable image (uImage). Step1: get the raw binary file. % arm-unknown-linux-gnu-objcopy -O binary -R .note - R .comment -S arch/arm/boot/compressed/vmlinux linux.bin Step2: compress the raw binary. % gzip -9 linux.bin / 18 2015/03/31
Converting to U-Boot Bootable Image (2/2) Step3: add the header of U-Boot bootable image. % chmod +x mkimage % ./mkimage -A arm -O linux -T kernel -C gzip -a 0xa0008000 -e 0xa0008000 -n "IEOS Lab1 Kernel" - d linux.bin.gz uImage mkimage can be downloaded from our course website (mkimage). You can see the mkimage usage by executing without arguments. The resulting uImage is the U-Boot image we want. / 18 2015/03/31
Flashing Please refer to the slides of lab2 from CSL for the steps of copying bootloader, kernel, and filesystem. Use the following files instead. Bootloader: u-boot.bin Linux kernel: the one you just compiled (uImage). Filesystem: rootfs_20M / 18 2015/03/31
Testing Your Kernel Image (1/2) After resetting PXA270, you will see your own Linux kernel is booted. U-Boot will display the image name “IEOS Lab1 Kernel” when loading the kernel image. After Linux is booted, use df -h to check the size of filesystem. You will see the size of root filesystem (/dev/mtdblock3). / 18 2015/03/31
Testing Your Kernel Image (2/2) Check the NIC driver has been compiled into the kernel. Please use ifconfig eth0 to check your network card. / 18 2015/03/31