Porting Linux on embedded platforms

30
Porting Linux on Embedded Platforms By Meghanad Shingate Electrical Engineering Department IIT Bombay

description

Porting Linux to ARM embedded platforms

Transcript of Porting Linux on embedded platforms

Page 1: Porting Linux on embedded platforms

Porting Linux on Embedded Platforms

ByMeghanad ShingateElectrical Engineering DepartmentIIT Bombay

Page 2: Porting Linux on embedded platforms

Outline

● How processor (ARM9) boots?● AT91Bootstrap overview and configuration● UBoot-1.3.4 overview and configuration● Configuring the kernel – for x86 and ARM systems● Make uImage – build kernel image● Dep, clean, mrproper● Installing kernel image - x86 systems● Porting Linux on ARM board● Editing existing drivers to adapt to your application – e.g.

SMI/MII driver

Page 3: Porting Linux on embedded platforms

How Processor Boots (ARM9)?

● Power on● processor always boots at address 0x0● On reset processor samples jumper configuration:

○ REMAP = 0, BMS = 0 : Boot on External Memory■ Boots on slow clock (on-chip RC or 32,768 Hz)■ bootstrap (customer-programmed) does config■ To speed-up

● program PMC (main oscillator enable or bypass mode)

● program and start PLL● Reprogram SMC setup, cycle, hold, mode

timings register for CS0 for new clock● switch main clock to new value

Page 4: Porting Linux on embedded platforms

How Processor Boots (ARM9)?

● Initialization of DBGU setial port

Internal Memories

...

...

EBI Chip select 3/ NAND Flash

...

Internal Peripherals

0x0000 0000

0x0FFF FFFF

0x4000 0000

0x4FFF FFFF

0xF000 0000

0xFFFF FFFF

Boot Memory*

ROM

...

...

0x0000 0000

0x0010 0000

0x0FFF FFFF

AT91SAM9G20EK Memory Mapping

Page 5: Porting Linux on embedded platforms

How Processor Boots (ARM9)?

● Boot Sequence - ○ Serial (SPI) Flash Boot○ Data Flash Boot○ NAND Flash Boot○ SDCard Boot○ SAM-BA Boot - if no valid application found (waits for

USB/USART traasaction)E.g. NAND Boot

● Jump to NAND Flash Boot sequence● searches for valid application in NAND Flash - seven

valid ARM exception vectors (B-branch or LDR inst. except 6th)

Page 6: Porting Linux on embedded platforms

How Processor Boots (ARM9)?

● If valid application found, load it into internal SRAM, perform remap and jump to 0x0 and start execution.

● Bootstrap copies uboot to RAM and start executing● UBoot gets control● UBoot initializes minimum necessory hardware● Uboot runs boot cmd and loads kernel and passes

configuration to kernel● Kernel knows hardware initialized● Kernel extracts rootfs● Kernel runs init● Init gets user space up and running

Page 7: Porting Linux on embedded platforms

ARM Board Memory - overview

Bootstrap*

UBoot

Linux (Kernel)

rootfs.jffs2

NAND FLASH (1GB)

Maxim

Memory (Virtual)0x00000000

0x00020000

0x000A0000

0x00400000

0x22000000 (Load Addr)

0x23F00000 (Bootstrap Jump)

0x10000000 (Maxim Base)

0x11000000

} 32MB (Maxim)

SDRAM (Maxim)

SDRAM (Maxim Use)

0x113000003MB (Maxim Use)}

0x12000000} 32MB

(RAM 32+32 MB)

Page 8: Porting Linux on embedded platforms

AT91Bootstrap

● Source and compile

$ wget ftp://www.at91.com/pub/at91bootstrap/AT91Bootstrap1.16.zip

$ unzip downloads/AT91Bootstrap1.16.zip

// Configure as per your need - see next slide

$ cd Bootstrap-v1.16$ cd board/at91sam9g20ek/nandflash$ make// Binary generated - nandflash.bin

Page 9: Porting Linux on embedded platforms

Configuring - AT91Bootstrap

● Configure PLL, GPIO, USART, SPI○ board/at91sam9g20ek/nandflash/at91sam9g20ek.h○ board/at91sam9g20ek/at91sam9g20ek.c

#define MASTER_CLOCK 101376000 //clock (101MHz)#define PLLA_SETTINGS 0x20203F01 //PLLA#define PLLB_SETTINGS 0x10193F05 //PLLB#define IMG_ADDRESS 0x20000 //Uboot Img address in nandflash#defin IMG_SIZE 0x50000 //Img size on nand flash#define JUMP_ADDR 0x23F00000 //Final jump address(See datasheet of at91sam9g20ek for details)

● Loads Uboot in RAM and jumps to JUMP_ADDR

Page 10: Porting Linux on embedded platforms

Uboot - 1.3.4

● Source and compile$ wget ftp://ftp.denx.de/pub/u-boot/u-boot-1.3.4.tar.bz2$ tar xjvf u-boot-1.3.4.tar.bz2$ cd u-boot-1.3.4/

// Patch$ wget ftp://www.at91.com/pub/uboot/u-boot-1.3.4-exp.5/u-boot-1.3.4-exp.5.diff$ cat u-boot-1.3.4-exp.5.diff | patch -p1

// Configure as per your need - see next sile

$ make at91sam9g20ek_dataflash_cs1_config

$ export CROSS_COMPILE=/opt/crossTools/CodeSourcery/bin/arm-none-eabi-

$ make

// Binary generated - uboot.bin

Page 11: Porting Linux on embedded platforms

Configuring - UBoot

● Initialization - MACB, ASICs,USART etc.○ board/atmel/at91sam9g20ek/at91sam9g20ek.c

● Configuration - ○ include/configs/at91sam9g20ek.h

#include PHYS_SDRAM 0x20000000 //SDRAM

#include PHYS_SDRAM_SIZE 0x04000000 //SIZE#include CFG_NAND_BASE 0x40000000 // FLASH BASE#include CFG_LOAD_ADDR 0x22000000 // Load addr#define CONFIG_BOOTCMD "nand read 0x22000000 0xA0000 0x200000; bootm"#define CONFIG_BOOTARGS "root=1f01 rootfstype=jffs2"

Page 12: Porting Linux on embedded platforms

Overview - Kernel Compilation

● Compiling kernel composed of configuring, building and installing

● Latest stable kernel version available is 3.3.2● We will go step-by-step over configuring, building and

installing kernel version 2.6.30● Presentation mostly will be embedded system oriented -

ARM9● Downloading kernel

$ wget http://www.kernel.org/pub/linux/kernel/v2.0/linux-2.6.30.tar.bz2

$ tar -zxvf linux-2.6.30.tar.gz

Page 13: Porting Linux on embedded platforms

Configuration – x86 System

● Configuration can be non trivial, since you have to include support for your hardware for proper working

● If already configured – old configuration will be in .config, then do “make oldconfig”

● For new configuration do “make menuconfig”, based on your hardware go through the options and select configuration e.g. sound support, networking

● “make defconfig”, It will automatically copy your distribution's .config, that should fit almost everything

Page 14: Porting Linux on embedded platforms

Configuration – ARM● For ARM(at91sam9) – download patch (if any, for your

architecture. Here the example is for Atmel ARM9) from $ wget ftp://www.linux4sam.org/pub/linux/2.6.30-at91-exp.patch.gz

$ zcat 2.6.30-at91-exp.patch.gz | patch -d linux-2.6.30 -p1

● For embedded system we need toolchain for cross-compilation of kernel, I have added references for the same.

$ export ARCH=arm

$ export CROSS_COMPILE=<path_to_cross-compiler/cross-compiler-prefix->

e.g.

$ CROSS_COMPILE=/opt/crossTools/arm-2007q1/bin/arm-none-linux-gnueabi-

● Then for configuration -$ make oldconfig //OR

$ make menuconfig

Page 15: Porting Linux on embedded platforms

Menuconfig

● Select options using spacebar● Use Enter key to see sub-menus● Save and exit

Page 16: Porting Linux on embedded platforms

Configuring - Linux

● Board Init - I2C, SPI, USB etc.○ arch/arm/mach-at91/board-sam9g20ek.c

at91sam9260_initialize(18432000) //18.432 MHz

● Nand flash partitions

Page 17: Porting Linux on embedded platforms

Building - Linux

● For x86 system-$make dep – creates dependencies$make bzImage – creates kernel image$make modules – builds components chosen to build as

modules● It will generate kernel image - /arch/i386/boot/bzImage● For ARM building kernel image-

○ If has Uboot - $make uImage○ If do not have Uboot - $make zImage

It will generate kernel image - /arch/arm/boot/u(z)Image

Page 18: Porting Linux on embedded platforms

dep, clean, mrproper

● Make dep – generates dependency information which then used for building the kernel

● Sometimes you might need to clean up the source and build all again, make clean will remove all object files.

● Make mrproper removes everything except source, it will also remove .config* files, so be sure to save configuration elsewhere.

● For building first time you only need make dep, make clean and make mrproper not needed.

Page 19: Porting Linux on embedded platforms

Installing new kernel - x86

● $sudo make modules_install – installs modules in /lib/modules/2.6.30

● $sudo make install – installs kernel in /boot/● $ sudo update-initramfs -c -k 2.6.30 – temporary file

system used in boot process.● $ sudo update-grub – lets bootloader know new kernel● Verify new kernel installation

○ See kernel image in /boot (here vmlinux-2.6.30)○ See whole new directory of loadable modules under

/lib/modules (here 2.6.30)● Reboot ! (and pray!)

Page 20: Porting Linux on embedded platforms

Porting Linux - ARM board

● Porting of new kernel on ARM board differs from board-to-board.

● We have - bootstrap, uboot, linux kernel, rootfs● Atmel SAM-ICE (JTAG) - used to put bootstrap and uboot

on flash (see reference for HowTo)● JTAG software tool - SAM-BA● Bootstrap - initialize access, copy uboot to RAM● Uboot - (0x20000)

○ Read/write flash memory○ Use the network: IP config, telnet, ping, tftp○ Probe hardware or perform dignostic○ Boots kernel

(reboot board and use serial terminal for next steps)

Page 21: Porting Linux on embedded platforms

Porting Linux - ARM board

● Rootfs - use tftp (0x400000)○ Stored rootfs on flash and used as root filesystem -

JFFS2● Linux kernel - use tftp (0xA0000)

○ loads rootfs○ runs Init

UBoot> set ipaddr 10.107.48.61

UBoot> set serverip 10.107.48.120

UBoot> set bootfile <binary_name_on_server>

UBoot> tftp // this will transfer file to board RAM and shows load_addr

UBoot> nand write <load_addr> <write_addr> <size_of_file>

// reboot board

Page 22: Porting Linux on embedded platforms

Edit drivers to adapt to your application

● For each time you need not to write new driver for your application. You can adapt existing driver to meet your application requirement.

● Ioctl – I/O control library call – interaction with device drivers.

● Ioctl call - int ioctl(int, int, ...) - first arg is file discriptor to device file, second argument is Identification number of specific request to ioctl.

● Additional arguments are optional – usually ioctl has 3 arguments, third is pointer to structure.

● See references for more information on ioctl

Page 23: Porting Linux on embedded platforms

Edit drivers to adapt to your application● Example SMI/MII driver

○ For user to implement own ioctl Linux provides identification numbers – SIOCDEVPRIVATE you can use it to implement your desired functionality.

○ smi/mii driver can be fount in drivers/net/phy/phy.c, you can add new switch statement in phy_mii_ioctl() function and do what you want.

Page 24: Porting Linux on embedded platforms

Edit drivers to adapt to your application

● Calling ioctl from application program.

Page 25: Porting Linux on embedded platforms

Thank You !

Page 26: Porting Linux on embedded platforms

References

● Cross-compilation toolchain:○ http://wiki.debian.

org/BuildingCrossCompilers#Installing_a_Cross_Compiler○ http://askubuntu.com/questions/65630/installing-gnu-arm-

toolchain○ http://maxim.org.za/links.html○ https://sourcery.mentor.com/sgpp/lite/arm/portal/subscription?

@template=lite○ http://www.ibm.com/developerworks/linux/library/l-arm-

toolchain/#resources○ http://ferryzhou.wordpress.com/2011/06/30/e-couldnt-find-

package-gcc-arm-linux-gnueabi/○ http://www.gnuarm.com/○ http://www.gnuarm.com/files.html

Page 28: Porting Linux on embedded platforms

References

● Uboot○ include/autoconf.mk - contains all configs.

● AT91Bootstrap○ http://www.at91.

com/linux4sam/bin/view/Linux4SAM/AT91Bootstrap

● Complete references○ http://howto.homelinux.com/wiki/Linux4SAM○ http://www.cmtekchina.com/doc/9260-boot.html

Page 29: Porting Linux on embedded platforms

Backup Slides

Page 30: Porting Linux on embedded platforms

Embedded boot process - brief

● Power on● Bootstrap copies uboot to RAM and start executing● UBoot gets control● UBoot initializes minimum necessory hardware● Uboot runs boot cmd and loads kernel and passes

configuration to kernel● Kernel knows hardware initialized● Kernel extracts rootfs● Kernel runs init● Init gets user space up and running