Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Porting Embedded Linux and Android to your Hardware Marcel Ziswiler Noser Engineering AG 1 1 Contents Contents ● Get to know your hardware Get to know your Hardware ● Tools making up your development environment Development Environment ● Porting embedded Linux ● Porting the boot loader Porting Boot Loader ● Porting the embedded Linux kernel Porting Linux Kernel ● Introducing Android ● Porting Android Introducing Android ● Porting the Android Linux kernel Porting Android ● Porting the file system with the Android framework and its applications 2 2
  2. 2. Get to Know your Hardware What are the key components? Where to get more information? 3 What are the Key Components? Contents ● Most embedded HW centred around System On Chip (SoC) Get to know your Hardware ● Important to understand bus/chip mapping ● What chips hooked up to what buses: Development Environment AC97, I2C, PCI, peripheral, SDRAM controller, SPI, USB bus ● Bus width vs. chip width Porting Boot Loader ● Address pin used for command/data FIFO switching ● Bus timing: SRAM vs. VLIO modes Porting Linux Kernel ● Specialities like address offsets (shifts) or latches/multiplexing Introducing Android ● GPIO/interrupt routing ● Most SoCs have at least partially re-configurable pins Porting Android ● Usually completely board specific ● Displays: number of colour data lines vs. bits per pixel (bpp) 4
  3. 3. Colibri XScale PXA320 ● SoC: Marvell XScale PXA320 at 806 MHz ● Memories ● Volatile: 128 MB Hynix, Micron or Qimonda Mobile DDR RAM on 32 bit (2 x 16 bit chip) EMPI SDCS0 ● Non-volatile: 1 GB Hynix or Samsung NAND Flash on 8 bit ND_CS0 ● Ethernet: Asix AX88796BLF on 16 bit SRAM CS2, FIFO on ADDR11, address shifted by 1, interrupt GPIO36 ● Audio codec/touch: NXP UCB1400E on AC97, interrupt GPIO4_2 ● Power management: Maxim MAX8660 on power I2C addr 0x34 ● Display/touch: Sharp LQ043T3DX02 4.3” WQVGA, 480 x 272, 16 or 18 bpp 5 Limestone PDA Design Kit ● Marvell XScale PXA320 at 806 MHz ● Memories ● Volatile: 128 MB Hynix, Micron or Qimonda Mobile DDR RAM on 32 bit (2 x 16 bit chip) EMPI SDCS0 ● Non-volatile: 1 GB Hynix or Samsung NAND Flash on 8 bit ND_CS0 ● Unfortunately no Ethernet ● Audio codec/touch: Wolfson WM9713L on AC97, interrupt GPIO36 ● Power management: Maxim MAX8660 on power I2C addr 0x34 ● Fuel gauge: Ti Bq27210 on I2C addr 0x55 ● Display/touch: Hitachi TX09D40VM3CAA, 240 x 320, 16 bpp 6
  4. 4. Where to get more Information? Contents ● Study Data Sheets and User Guides ● From some vendors freely available on-line Get to know your Hardware ● Other vendors including Marvell and Samsung require you to Development Environment sign an NDA ● Source-code of other similar HW might be of help as well Porting Boot Loader ● Ask questions on relevant mailing lists ● U-Boot: Porting Linux Kernel ● Linux kernel: Introducing Android ● Subsystem specific ones for e.g. MTD, YAFFS2, USB, ... Porting Android ● Lots of experience of course 7 Tools making up your Development Environment How to low-level control your hardware? 8
  5. 5. How to low-level control your Hardware Contents ● Most SoCs feature some low-level HW debugger interface ● Background debug mode (BDM) found on ColdFire/PowerPC Get to know your Hardware ● Different joint test action group (JTAG) IEEE 1149.1 variants ● Nexus IEEE-ISTO 5001-2003 Development Environment ● XScale feature standard ARM EJTAG interface Porting Boot Loader ● Interfacing usually requires special pod called a HW JTAG debugger Porting Linux Kernel Introducing Android Porting Android 9 Hardware JTAG Debugger ● Abatron BDI2000/BDI3000 ● The one used by the pros ● Dependable technology even if in doubt about your HW/SW ● Ethernet interface ● Telnet command line interface ● Direct GDB remote debug interface (RDI) support ● Directly burn NOR flashes ● No direct NAND flash support ● Start-up script loaded by TFTP ● Low-level memory read/write operations ● Set SDRAM controler registers to initialise and calibrate DDR ● Image loading by TFTP 10
  6. 6. Hardware JTAG Debugger (cont.) ● OpenOCD with e.g. Amontec JTAGkey-Tiny ● The one used by the diys ● Open-source JTAG debugger solution ● No support for latest PXA3xx chips, but works for PXA270 ● Slightly sluggish, but hey, costs 100 times less! 11 Porting Embedded Linux Porting the boot loader Porting the embedded Linux kernel 12
  7. 7. Porting the Boot Loader What is supported by open-source? How to boot from NAND flash? How does the low-level initialisation work? Is there a run-from-RAM U-Boot variant? How to use U-Boot's nand_spl framework? 13 What is supported by Open-Source? Contents ● U-Boot boot loader ● Clone git repository Get to know your Hardware ● Configurations in include/configs show various PXA variants Development Environment like PXA250 and PXA27X to be supported ● No mentioning of PXA3xx ● cpu/pxa/cpu.c shows Monahans (code name for PXA3xx) Porting Boot Loader support Porting Linux Kernel ● Two supported boards: Delta and Zylonite ● Zylonite being Marvell's development board Introducing Android ● Pick existing board close to your HW and go from there ● I took zylonite as base of my porting efforts Porting Android 14
  8. 8. Porting Contents ● What features should be supported? ● Primary task: boot board Get to know your Hardware ● Serial debug console a must ● Image loading via Ethernet/USB is convenient Development Environment ● What about the boot concept? Porting Boot Loader ● What is the boot media? My HW only features NAND flash Porting Linux Kernel ● First get booting from initialised SDRAM via debugger working ● BDI initialises SDRAM Introducing Android ● Load special run-from-RAM U-Boot image to SDRAM ● Directly execute re-located U-Boot from there Porting Android ● Allows for quick development cycle and easy debugging 15 Booting from NAND Flash Contents ● Booting from NAND flash is not as trivial as booting from NOR ● NOR Get to know your Hardware ● Supports eXecute in place (XIP) ● NAND Development Environment ● Usually no XIP support Porting Boot Loader ● Requires special provisions for NAND booting built into SoC ● PXA3xx features mask programmed initial program loader (IPL) Porting Linux Kernel ● Fetches first NAND block containing your secondary program loader (SPL) into internal SRAM to be executed Introducing Android ● SPL to initialise enough from boards memories (e.g. SDRAM) plus NAND controller to continue booting Porting Android ● U-Boot NAND boot framework called nand_spl only for PowerPC based SoCs 16
  9. 9. Low-level Initialisation Contents ● lowlevel_init.S ● Written in assembly Get to know your Hardware ● Called by generic PXA SoC boot code cpu/pxa/start.S ● Configure minimal set of GPIO pins mainly for serial console Development Environment ● Your board might use completely different mapping Porting Boot Loader ● Initialise chip select registers ● Initialise static memory controler Porting Linux Kernel ● Initialise dynamic memory controler ● Calibrate DDR memory timing Introducing Android Porting Android 17 Run-from-RAM Variant Contents ● Skip DDR RAM initialisation ● Already done by BDI start-up script Get to know your Hardware ● Skip relocation to RAM Development Environment ● Already running from RAM ● Skip clock configuration Porting Boot Loader ● Changing it mid-ways completely screws the game Porting Linux Kernel ● Configure working environment area ● NVRAM variant pointing to some arbitrary location in RAM Introducing Android works just fine for now ● Should give you the first U-Boot prompt! Porting Android 18
  10. 10. NAND Booting Contents ● Working NAND flash driver as pre-requisite ● Zylonite board support contained bare bones NAND driver Get to know your Hardware ● Only supports SW ECC generation ● PXA3xx NAND controller features HW ECC generation Development Environment ● Marvell's IPL requires HW ECC algorithm and OOB placement Porting Boot Loader ● Adding HW ECC glue logic showed timing issues on write ● Short delay in write routine did the trick Porting Linux Kernel Introducing Android Porting Android 19 nand_spl Framework Contents ● Symbolic links to a few vital source files scattered throughout U-Boot Get to know your Hardware ● Starts with cpu/pxa/start.S ● Continues with our board's lowlevel_init.S Development Environment ● Ends up in generic nand_spl/nand_boot.c ● Paired with our NAND driver Porting Boot Loader ● As few as possible other files ● cpu/pxa/interrupts.c featuring delay implementation Porting Linux Kernel ● drivers/nand/nand_ecc.c for ECC glue Introducing Android ● lib_arm/interrupts.c for exception handling ● _udivsi3.S for division implementation Porting Android 20
  11. 11. nand_spl Framework (cont.) Contents ● Tricky part: trimming to fit into 16 KB of first NAND block ● Just define away bloated stuff Get to know your Hardware ● E.g. printf as SPL anyway won't be able to output anything ● Generic nand_boot.c required significant modifications Development Environment ● Supported only directly bus/pin controlled NAND chips ● PXA3xx feature intelligent NAND controller Porting Boot Loader ● Some rather tricky debugging of the different boot stages Porting Linux Kernel ● Finally booting from NAND! ● Ethernet similar to existing PXA270 HW just on 16 bit rather than Introducing Android 32 bit peripheral bus ● Unfortunately final HW features different components Porting Android ● Large block rather than small block NAND chip ● New Ethernet controller 21 Getting Production HW to work Contents ● New NAND chip ● Bigger page size of 2 KB rather than 512 bytes Get to know your Hardware ● Large blocks of 128 KB rather than 16 KB ● Attempts to play nice with existing U-Boot NAND driver and MTD Development Environment infrastructure failed! Porting Boot Loader ● Somebody ported later Linux MTD subsystem to U-Boot ● Paved the way for large block NAND support Porting Linux Kernel ● Ported Linux' latest PXA3xx NAND driver pxa3xx_nand.c to U- Boot Introducing Android ● Implementing polling operation Porting Android 22
  12. 12. Getting Production HW to work (cont.) Contents ● New Ethernet chip ● Still NE2000 compatible Get to know your Hardware ● Hooked up differently ● Switching between command and data FIFO by address 11 Development Environment rather than 2 ● Required different VLIO bus timing Porting Boot Loader ● Chineese blog outlined integration into ancient U-Boot version ● Could not read a single comment of this blog Porting Linux Kernel ● But managed to port code snippets to latest U-Boot Introducing Android Porting Android 23 Porting the Linux Kernel What is supported by open-source? 24
  13. 13. What is supported by Open-Source? Contents ● Embedded Linux kernel ● Clone git repository Get to know your Hardware ● Configurations in arch/arm/configs show various PXA variants Development Environment including PXA3xx to be supported ● PXA support can be found in arch/arm/mach-pxa ● Multiple supported boards: CM-X300, Littleton and Zylonite Porting Boot Loader ● Littleton and Zylonite being Marvell's development kits/boards Porting Linux Kernel Introducing Android Porting Android 25 The early Attempts Contents ● At first no mainline PXA3xx support ● Had to go with NDAed Marvell kernel being slightly out-dated Get to know your Hardware ● Got it built for Zylonite development platform ● Did not boot or rather at least not output anything Development Environment ● Had to modify pin configuration for console UART again Porting Boot Loader ● Board specific code in arch/arm/mach-pxa/zylonite.c ● U-Boot still without Ethernet TFTP capabilities Porting Linux Kernel ● Pre-load it all by BDI ● U-Boot to address 0x83008000 Introducing Android ● Linux kernel to address 0x81000000 Porting Android ● 16 MB RAM disk to address 0x87000000 ● First Linux shell! 26
  14. 14. Porting Linux Kernel Contents ● While working on U-Boot PXA3xx support hit mainline ● New XScale multi function pin (MFP) framework Get to know your Hardware ● GPIOlib Development Environment ● PXA support located at arch/arm/mach-pxa ● Zylonite support split into multiple files Porting Boot Loader ● zylonite.c for generics ● zylonite_pxa300.c zylonite_pxa320.c Porting Linux Kernel for SoC specific configuration/initialisation ● Similar to our HW coming in two flavours Introducing Android ● High-end PXA320 with audio and touch ● Low-cost PXA300 without audio and touch Porting Android ● Different pin numbering and peripheral support 27 SoC specific Code Contents ● MFC configuration table ● Outlining exact use of each pin Get to know your Hardware ● Particular peripheral block ● General purpose IO (GPIO) Development Environment ● Macros from mach/mfp-pxa300.h resp. mfp-pxa320.h Porting Boot Loader ● By no means comprehensive ● For all possible combinations consult Marvell's user guide Porting Linux Kernel ● Possible to tri-state pins ● Configure as GPIO input or null alternate function Introducing Android ● Required on Colibri due to multiple SoC pins being routed to identical module pin Porting Android 28
  15. 15. Porting Linux Kernel (cont.) Contents ● SoC specific peripherals ● AC97 audio Get to know your Hardware ● Touch screen controller ● NAND flash partitioning due to different sized chips Development Environment ● Main initialisation functions Porting Boot Loader ● Check whether running on respective SoC ● Configure pins according to our MFP configuration tables Porting Linux Kernel ● Register SoC specific peripherals ● Assign GPIO pins and NAND flash partitions used in generic Introducing Android code Porting Android 29 Generic Code Contents ● Handle chip select address mapping Get to know your Hardware ● Utilises CPLD for flexibility reason ● Configure peripherals available on all module types ● Ethernet Development Environment ● Frame buffer with display configurations Porting Boot Loader ● MMC/SD card controller ● NAND flash controller Porting Linux Kernel ● RTC chip ● SPI controller Introducing Android ● USB controller Porting Android 30
  16. 16. Porting Linux Kernel (cont.) Contents ● Generic initialisation function first calls specific ones Get to know your Hardware ● Enable chip select address decoder Development Environment ● Configure and register generic peripherals ● Defines actual machine structure Porting Boot Loader Porting Linux Kernel Introducing Android Porting Android 31 Introducing Android What is Android? How about its Architecture? 32
  17. 17. Contents Get to know your Hardware Open-source mobile phone platform initiated by Google ● ● Building a better phone for consumers Development Environment ● Porting Boot Loader Open handset alliance ● ● Several companies innovate in the open Porting Linux Kernel ● …Increased openness will enable everyone in our industry to Introducing Android innovate more rapidly and respond better to consumer's demands. … ● Porting Android Noser Engineering AG works on core functionality ● 33 Android Architecture Contents Get to know your Hardware Development Environment Porting Boot Loader Porting Linux Kernel Introducing Android Porting Android 34
  18. 18. Porting Android What are the system requirements? How to port the Android Linux kernel? How to port the file system with the Android framework and its applications? 35 System Requirements Contents ● Recent Linux kernel running on your target HW Get to know your Hardware ● ARM based SoC ● Low-level assembly optimisation Development Environment ● Code generation in graphics subsystem Porting Boot Loader ● 128 MB SDRAM ● 256 MB flash favourably of the NAND kind Porting Linux Kernel ● Optimised for 16 bpp QVGA LCD with capacitive touch screen Introducing Android ● At least 5 button navigation keypad Porting Android 36
  19. 19. Porting Android Linux Kernel Contents ● What we got so far ● Android 1.0 kernel based on vanilla Linux 2.6.25 Get to know your Hardware ● Colibri BSP kernel based on vanilla Linux 2.6.26 Development Environment ● Two possibilities ● Port Android modifications into our BSP kernel Porting Boot Loader ● Or vice versa Porting Linux Kernel ● Depending on who did your BSP that code might be better understood by you speaking for second approach Introducing Android ● Android modifications rather well integrated/understood Porting Android ● Analyse Android kernel modifications and integrate them into our BSP kernel 37 Android Kernel Extensions Contents ● Ashmem ● mm/ashmem.c Get to know your Hardware ● Anonymous shared memory subsystem ● Allow processes to share named blocks of memory Development Environment ● Kernel may reclaim them if not in use Porting Boot Loader ● Binder IPC ● drivers/android/binder.c Porting Linux Kernel ● System oriented component architecture ● Providing object-oriented operating system environment Introducing Android ● Inter-process communication (IPC) between processes and Porting Android thread pools ● Memory management and clean-up functionality 38
  20. 20. Android Kernel Extensions (cont.) Contents ● Logger ● drivers/android/ram_console.c Get to know your Hardware ● Store kernel log messages in RAM buffer ● drivers/android/logger.c Development Environment ● Logging mechanism for user processes to read and write Porting Boot Loader system log messages ● Low Memory Killer Porting Linux Kernel ● drivers/misc/lowmemorykiller.c ● Scans list of running processes and kills one Introducing Android ● Optional component not required for basic bring-up Porting Android 39 Android Kernel Extensions (cont.) Contents ● Power management ● drivers/android/power.c Get to know your Hardware ● At its core uses regular Linux power management subsystem ● Does not poll for power related changes Development Environment ● Uses iNotify interface via fs/inotify_user.c Porting Boot Loader ● Subscribe to power related updates Porting Linux Kernel ● YAFFS2 ● Yet another flash file system 2nd edition Introducing Android ● fs/yaffs2/* ● Primary file system for low-cost high density NAND flash based Porting Android storage ● Not part of any mainline kernel yet 40
  21. 21. Android Kernel Configuration Contents ● Requires one to enable previously discussed features Get to know your Hardware ● Standard Android kernel configuration (emulator) arch/arm/configs/goldfish_defconfig Development Environment Porting Boot Loader Porting Linux Kernel Introducing Android Porting Android 41 Special Considerations Contents ● Frame buffer ● Requires double buffering aka panning functionality Get to know your Hardware ● Allocate twice the memory required for actual frame size ● Pan function selects which part is actually output to screen Development Environment ● Touch screen Porting Boot Loader ● Android uses standard Linux input subsystem ● Driver that not only reports pressure but button touch as well Porting Linux Kernel ● BTN_TOUCH upon detecting pen down event Introducing Android ● Many mainline touch drivers do not implement it that way ● drivers/input/touchscreen/ucb1400_ts.c Porting Android ● drivers/input/touchscreen/wm97xx-core.c 42
  22. 22. Porting the File System with the Android Framework and its Applications Contents ● Initial RAM file system to boot-strap Android ● Regular gziped cpio archive as initramfs Get to know your Hardware ● Contains just Android proprietary init process Development Environment ● 3 different flash partitions ● Each 64 MB in size Porting Boot Loader ● YAFFS2 NAND flash file system ● System partition required to be pre-loaded Porting Linux Kernel ● User data partition Image File MTD Partition Mount Point ● Cache partition Introducing Android ramdisk.img N/A / system.img /dev/mtdblock0 /system Porting Android userdata.img /dev/mtdblock1 /data N/A /dev/mtdblock2 /cache 43 Touch Screen Calibration Contents ● No support for calibration as required by resistive touch screens Get to know your Hardware ● Only capacitive touch screens not requiring any calibration Development Environment ● Traditionally touch screen calibration handled by tslib ● Special ts_calibrate application ● Generates /etc/pointercal file containing calibration constants Porting Boot Loader ● Integrated calibration calculation into Android Porting Linux Kernel ● Did not bother to port actual calibration application to Android ● Just integrate correct calibration file into Android file system Introducing Android ● /system/etc/pointercal Porting Android 44
  23. 23. Continuing Information ● Visit us at our booth at the Embedded World 2009 11-115 ● Attend one of our next trainings Embedded Linux Seminar - June 4 & 5, 2009 ● Visit our website ● Or contact us for more information 45