# README-linux_kernel.ronetix # Building the Linux kernel # for AT91SAM9G45/AT91SAM9263/AT91SAM9261 based boards: # PM9G45, PM9263 and PM9261. # # Ronetix GmbH # www.ronetix.at # February, 2012 # Table of Contents: 1. Download and install the GNU toolchain 2. Getting and unpacking the Linux kernel 3. Kernel config 4. Kernel build 5. Cooking uImage(for PM9263 with linux 2.6.23.14 only) 6. Modules build 7. Install the Linux Kernel modules in the rootfs image file 8. Installation of the Kernel modules 9. Make rootfs image for NAND flash 10. Programming/Writing 11. Debugging 12. Tip and tricks 1. Download and install the GNU toolchain See the toolchain README 2. Getting and unpacking the Linux kernel 2.1. Getting and unpacking the Linux kernel for PM9G45 For Linux kernel 2.6.30 $ wget http://download.ronetix.info/boards/linux/kernel/2.6.30/linux-2.6.30.tar.bz2 $ wget http://download.ronetix.info/boards/linux/kernel/2.6.30/patches/2.6.30-at91.patch.gz $ wget http://download.ronetix.info/boards/linux/kernel/2.6.30/patches/2.6.30-at91-exp.5.tar.gz $ wget http://download.ronetix.info/boards/linux/kernel/2.6.30/patches/2.6.30-at91-exp.5-patches-pm9g45-091220/11.tar.bz2 $ tar xjf linux-2.6.30.tar.bz2 $ gunzip 2.6.30-at91.patch.gz $ tar xzf 2.6.30-at91-exp.5.tar.gz $ tar xjf 2.6.30-at91-exp.5-patches-pm9g45-09122011.tar.bz2 $ cd linux-2.6.30 $ git init $ git add * $ git add .gitignore .mailmap $ git commit -m "Initial commit after linux-2.6.30.tar.bz2 extraction" $ git checkout -b 2.6.30-at91.patch $ patch -p1 < ../2.6.30-at91.patch $ git add -u $ git add * $ git commit -m "patching with 2.6.30-at91.patch" $ git checkout -b 2.6.30-at91-exp.5 $ for N in ../2.6.30-at91-exp.5/*.patch; do git am $N ; done $ git checkout -b pm9g45 $ for P in ../2.6.30-at91-exp.5-patches-pm9g45-09122011/*.patch ;do git am $P ; done 2.2. Getting and unpacking the Linux kernel for PM9263 A. For Linux kernel 2.6.28 $ wget http://download.ronetix.info/boards/linux/kernel/2.6.28/linux-2.6.28.tar.bz2 $ wget http://download.ronetix.info/boards/linux/kernel/2.6.28/001_linux-2.6.28-at91.patch $ wget http://download.ronetix.info/boards/linux/kernel/2.6.28/002_linux-2.6.28-exp.patch $ wget http://download.ronetix.info/boards/linux/kernel/2.6.28/003_linux-2.6.28-at91-ronetix-20112009.patch $ tar xjf linux-2.6.28.tar.bz2 $ cd linux-2.6.28 $ patch -p1 < ../001_linux-2.6.28-at91.patch $ patch -p1 < ../002_linux-2.6.28-exp.patch $ patch -p1 < ../003_linux-2.6.28-at91-ronetix-20112009.patch B. For Linux kernel 2.6.23.14 $ wget http://download.ronetix.info/boards/linux/kernel/2.6.23/linux-2.6.23.14.tar.bz2 $ wget http://download.ronetix.info/boards/linux/kernel/2.6.23/2.6.23-at91.patch $ wget http://download.ronetix.info/boards/linux/kernel/2.6.23/linux-2.6.23.14-ronetix-08-04-29.2136.patch $ tar xvfj linux-2.6.23.tar.bz2 $ cd linux-2.6.23.14 $ patch -p1 < ../2.6.23-at91.patch $ patch -p1 < ../linux-2.6.23.14-ronetix-08-04-29.2136.patch 2.3. Getting and unpacking the Linux kernel for PM9261 For Linux kernel 2.6.25.4 $ wget http://download.ronetix.info/boards/linux/kernel/2.6.25/linux-2.6.25.4.tar.bz2 $ wget http://download.ronetix.info/boards/linux/kernel/2.6.25/2.6.25-at91.patch $ wget http://download.ronetix.info/boards/linux/kernel/2.6.25/linux-2.6.25.4-ronetix-08-11-02.2228.patch $ wget http://download.ronetix.info/boards/linux/kernel/2.6.25/socketcan-driver-at91.patch $ tar xjf linux-2.6.25.4.tar.bz2 $ cd linux-2.6.25.4 $ patch -p1 < ../2.6.25-at91.patch $ patch -p1 < ../linux-2.6.25.4-ronetix-08-11-02.2228.patch $ patch -p1 < ../socketcan-driver-at91.patch 3. Kernel config To carry into effect the default kernel configuration you have to do the following. A. For PM9G45 on BB9G45 $ export ARCH=arm $ make make pm9g45_v1.3-bb9g45_v1.1_defconfig B. For PM9263 $ export ARCH=arm $ make pm9263_defconfig C. For PM9261 $ export ARCH=arm $ make pm9261_defconfig # SPI support for MMC/SD or $ export ARCH=arm $ make pm9261_mci_defconfig # MCI support for MMC/SD If you want to change something in the kernel do the following: $ export ARCH=arm $ make menuconfig If you have a 16-bit NAND Flash, select: System type -> Atmel AT91 System-on-Chip -> Enable 16-bit data bus interface to NAND flash To determine what kind of NAND Flash chip do you have, look at the bottom side of the CPU board: U5 - MT29F2G16 - 16-bit NAND Flash U9 - MT29F2G08 - 8-bit NAND Flash On exit save the changes. 4. Kernel build uImage is the Linux kernel packed(U-Boot wrapped zImage) in format for loading by U-Boot. The "mkimage" utility which is part of U-Boot is required to be in the executable search path(environment variable PATH). The "mkimage" can be aken from http://download.ronetix.info/boards/tools/linux/mkimage or obtained after building U-Boot for an ARM board. $ echo Make sure "mkimage" is in the executable search path! $ export CROSS_COMPILE=arm-oe-linux-gnueabi- $ make uImage The binary file for programming is arch/arm/boot/uImage. 5. Cooking uImage(for PM9263 with linux 2.6.23.14 only) The uImage is Linux kernel executable packed in a file usable for U-Boot. The uImage file format is made when you run "make uImage" from Linux source base tree, but it is recommended for PM9263 with 2.6.23.14 to do it manually, in other cases use the uImage from the Linux build process. $ mkdir image $ cd image $ arm-linux-objcopy -O binary -S ../vmlinux vmlinux.bin $ gzip -f9 vmlinux.bin $ mkimage -A arm -O linux -T kernel -C gzip -a 0x20008000 -e 0x20008000 -n "PM9263 Linux Kernel Only Image" -d vmlinux.bin.gz vmImage $ rm vmlinux.bin.gz The binary file for programming is vmImage. The "mkimage" is part from the U-Boot. You can have from http://download.ronetix.info/boards/linux/tools/mkimage or make it from U-Boot source code. Recommended to make mkimage from the U-Boot, to be sure that the mkimake will run on your build machine. 6. Modules build In the Linux Kernel source base directory, and after building the kernel, execute the following command to build the modules, if any. $ make modules 7. Install the Linux Kernel modules in the rootfs image file. If you have selected some Linux kernel stuff as a modules, you should put them in the rootfs image. 7.1. Matching Linux Kernel and the rootfs The Linux kernel and the file system binary files must use the same (E)ABI version in order to work. This can be achieved by using one toolchain for building Linux kernel and the rootfs binaries. The second issue could come from the different Linux kernels sources used for building the kernel and the rootfs. This comes form the slightly change of the drivers API, leading to programs managing devices to misbehave also and the devices. To avoid this issues use OpenEmbedded, Buildroot or LTIB(Linux Target Image Builder) which will build Kernel, rootfs, toolchains and in some cases bootloader(s). Then you can make SDK(Software Development Kit) or toolchain(the same with the SDK) and build modified Linux Kernel for your case. Remember that the toolchain (containing GCC, binutils, gdb, libs, headers) require and are based on some Linux Kernel version and vice versa! For set of a matching kernel and modules take a look at README-pre-built_images.ronetix. 7.2. Get a rootfs as tar.bz2 package. More often the rootfs will be in a JFFS2 image file. A. /dev file system with Udev In this case the /dev directory in the rootfs image will be empty and will be populated when the udev is run for the first(second times check and create new dev files) time. So when you, not being root, unpack the rootfs archive ignore the messages containing " ... can not create node ..." B. device nodes generated statically You can choose to preserve the /dev directory contents or create a new one. The choice depend if you can obtain root privileges or have a device description file. You can get a basic device description file from Ronetix web site. If you can be root use the device description file. $ su - # tar xvjf rootfs-pm9x-*.tar.bz2 package 7.3. Get a rootfs as a JFFS2 image. You have to have a root privileges to mount a filesytem or to has a rights to mount it, and also a modules are needed, and installed mtd-tools. Mount through loopback # export loop=$(losetup -f) # losetup $loop rootfs.jffs2 # modprobe block2mtd block2mtd=$loop,131072 # modprobe jffs2 # modprobe mtdblock # mkdir -p mountpoint # sleep 2 # if these commands are in a script, here a delay is needed # export loopA=`echo $loop | sed -n 's/\/dev\/// p'` # export N=`sed -n ' s/mtd\([0-9]*\): .*\"block2mtd: \/dev\/'$loopA'\"/\1/ p' /proc/mtd` # mount -t jffs2 -o ro /dev/mtdblock$N mountpoint # mkdir pint # cp -rp mountpoint/* point/ Do what it have to be done in the "point/" directory. # mkfs.jffs2 -v -n -d point/ --little-endian --pad --eraseblock=131072 --pagesize=2048 -o mrootfs.jffs2 # rm -rf point/ # umount mountpoint # rmmod jffs2 # rmmod block2mtd # rmmod mtdblock # rmmod mtd_blkdevs # rmmod mtd # losetup -d $loop # export loop= # export loopA= # export N= 8. Installation of the Kernel modules In the Linux Kernel source base directory, and after building the kernel and modules, execute the following command to install the modules, if any. $ make INSTALL_MOD_PATH= modules_install Note: If you get errors, perhaps you have to update your module-tools from here http://kernel.org/pub/linux/utils/kernel/module-init-tools If in the target root file system /lib/modules/ exist overwrite the modules.* files, they will be updated with the available modules on the next boot. 9. Make rootfs image for NAND flash: If static device nodes are to be created, use "--devtable=FILE" option after the mkfs.jffs2 command. Use the named FILE as a device table file. $ mkfs.jffs2 -v -n -d --little-endian --pad --eraseblock=131072 --pagesize=2048 -o rootfs.jffs2 10. Programming/Writing After successful building the file for programming/writing is uImage. On how to program it see the README for programming. 11. Debugging Take a look at the README-develop.ronetix file. 12. Tip and tricks 12.1. To see the current state of a LED: cat /sys/class/leds/led<0|1|2>/trigger 12.2. To change the state of a LED: echo > /sys/class/leds/led<0|1|2>/trigger 12.3. Specifying calculation of floating point numbers. $ export KCFLAGS='-mfloat-abi=soft -mfpu=vfp' $ export KAFLAGS='-mfloat-abi=soft -mfpu=vfp' 12.4. Updating Linux kernel ARM machines numbers $ wget http://www.arm.linux.org.uk/developer/machines/download.php -O arch/arm/tools/mach-types $ git add arch/arm/tools/mach-types $ git commit -m "update ARM mach-types"