contents

23
1 1 Porting Embedded Linux and Android to your Hardware Marcel Ziswiler Noser Engineering AG 2 2 Contents Contents Get to know your Hardware Development Environment Porting Boot Loader Porting Linux Kernel Introducing Android Porting Android Get to know your hardware Tools making up your development environment Porting embedded Linux Porting the boot loader Porting the embedded Linux kernel Introducing Android Porting Android Porting the Android Linux kernel Porting the file system with the Android framework and its applications

Upload: peterbuck

Post on 20-May-2015

1.329 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Contents

1 1

Porting Embedded Linux and Android to your Hardware

Marcel ZiswilerNoser Engineering AG

2 2

ContentsContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

● Get to know your hardware

● Tools making up your development environment

● Porting embedded Linux● Porting the boot loader● Porting the embedded Linux kernel

● Introducing Android

● Porting Android● Porting the Android Linux kernel● Porting the file system with the Android framework

and its applications

Page 2: Contents

3

Get to Know your Hardware

What are the key components?Where to get more information?

4

● Most embedded HW centred around System On Chip (SoC)

● Important to understand bus/chip mapping● What chips hooked up to what buses:

AC97, I2C, PCI, peripheral, SDRAM controller, SPI, USB bus● Bus width vs. chip width● Address pin used for command/data FIFO switching● Bus timing: SRAM vs. VLIO modes● Specialities like address offsets (shifts) or latches/multiplexing

● GPIO/interrupt routing● Most SoCs have at least partially re-configurable pins● Usually completely board specific

● Displays: number of colour data lines vs. bits per pixel (bpp)

What are the Key Components?Contents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

Page 3: Contents

5

● 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

Colibri XScale PXA320

6

● 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

Limestone PDA Design Kit

Page 4: Contents

7

● Study Data Sheets and User Guides● From some vendors freely available on-line● Other vendors including Marvell and Samsung require you to

sign an NDA

● Source-code of other similar HW might be of help as well

● Ask questions on relevant mailing lists● U-Boot: [email protected]● Linux kernel: [email protected]● Subsystem specific ones for e.g. MTD, YAFFS2, USB, ...

● Lots of experience of course

Where to get more Information?Contents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

8

Tools making up your Development Environment

How to low-level control your hardware?

Page 5: Contents

9

● Most SoCs feature some low-level HW debugger interface● Background debug mode (BDM) found on ColdFire/PowerPC● Different joint test action group (JTAG) IEEE 1149.1 variants● Nexus IEEE-ISTO 5001-2003

● XScale feature standard ARM EJTAG interface● Interfacing usually requires special pod called a HW JTAG

debugger

How to low-level control your HardwareContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

10

● 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

Hardware JTAG Debugger

Page 6: Contents

11

● 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!

Hardware JTAG Debugger (cont.)

12

Porting Embedded Linux

Porting the boot loaderPorting the embedded Linux kernel

Page 7: Contents

13

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?

14

● U-Boot boot loader● Clone git repository● Configurations in include/configs show various PXA variants

like PXA250 and PXA27X to be supported● No mentioning of PXA3xx● cpu/pxa/cpu.c shows Monahans (code name for PXA3xx)

support● Two supported boards: Delta and Zylonite● Zylonite being Marvell's development board

● Pick existing board close to your HW and go from there● I took zylonite as base of my porting efforts

What is supported by Open-Source?Contents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

Page 8: Contents

15

● What features should be supported?● Primary task: boot board● Serial debug console a must● Image loading via Ethernet/USB is convenient

● What about the boot concept?● What is the boot media? My HW only features NAND flash

● First get booting from initialised SDRAM via debugger working● BDI initialises SDRAM● Load special run-from-RAM U-Boot image to SDRAM● Directly execute re-located U-Boot from there● Allows for quick development cycle and easy debugging

PortingContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

16

● Booting from NAND flash is not as trivial as booting from NOR● NOR

● Supports eXecute in place (XIP)● NAND

● Usually no XIP support● Requires special provisions for NAND booting built into SoC

● PXA3xx features mask programmed initial program loader (IPL)● Fetches first NAND block containing your secondary program

loader (SPL) into internal SRAM to be executed● SPL to initialise enough from boards memories (e.g. SDRAM)

plus NAND controller to continue booting● U-Boot NAND boot framework called nand_spl only for PowerPC

based SoCs

Booting from NAND FlashContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

Page 9: Contents

17

● lowlevel_init.S● Written in assembly● Called by generic PXA SoC boot code cpu/pxa/start.S● Configure minimal set of GPIO pins mainly for serial console● Your board might use completely different mapping● Initialise chip select registers● Initialise static memory controler● Initialise dynamic memory controler

● Calibrate DDR memory timing

Low-level InitialisationContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

18

● Skip DDR RAM initialisation● Already done by BDI start-up script

● Skip relocation to RAM● Already running from RAM

● Skip clock configuration● Changing it mid-ways completely screws the game

● Configure working environment area● NVRAM variant pointing to some arbitrary location in RAM

works just fine for now● Should give you the first U-Boot prompt!

Run-from-RAM VariantContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

Page 10: Contents

19

● Working NAND flash driver as pre-requisite● Zylonite board support contained bare bones NAND driver● Only supports SW ECC generation● PXA3xx NAND controller features HW ECC generation● Marvell's IPL requires HW ECC algorithm and OOB placement● Adding HW ECC glue logic showed timing issues on write● Short delay in write routine did the trick

NAND BootingContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

20

● Symbolic links to a few vital source files scattered throughout U-Boot

● Starts with cpu/pxa/start.S● Continues with our board's lowlevel_init.S● Ends up in generic nand_spl/nand_boot.c● Paired with our NAND driver● As few as possible other files

● cpu/pxa/interrupts.c featuring delay implementation● drivers/nand/nand_ecc.c for ECC glue● lib_arm/interrupts.c for exception handling● _udivsi3.S for division implementation

nand_spl FrameworkContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

Page 11: Contents

21

● Tricky part: trimming to fit into 16 KB of first NAND block● Just define away bloated stuff

● E.g. printf as SPL anyway won't be able to output anything● Generic nand_boot.c required significant modifications

● Supported only directly bus/pin controlled NAND chips● PXA3xx feature intelligent NAND controller

● Some rather tricky debugging of the different boot stages● Finally booting from NAND!● Ethernet similar to existing PXA270 HW just on 16 bit rather than

32 bit peripheral bus● Unfortunately final HW features different components

● Large block rather than small block NAND chip● New Ethernet controller

nand_spl Framework (cont.)Contents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

22

● New NAND chip● Bigger page size of 2 KB rather than 512 bytes● Large blocks of 128 KB rather than 16 KB

● Attempts to play nice with existing U-Boot NAND driver and MTD infrastructure failed!

● Somebody ported later Linux MTD subsystem to U-Boot● Paved the way for large block NAND support

● Ported Linux' latest PXA3xx NAND driver pxa3xx_nand.c to U-Boot● Implementing polling operation

Getting Production HW to workContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

Page 12: Contents

23

● New Ethernet chip● Still NE2000 compatible● Hooked up differently

● Switching between command and data FIFO by address 11 rather than 2

● Required different VLIO bus timing● Chineese blog outlined integration into ancient U-Boot version

● Could not read a single comment of this blog● But managed to port code snippets to latest U-Boot

Getting Production HW to work (cont.)Contents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

24

Porting the Linux Kernel

What is supported by open-source?

Page 13: Contents

25

● Embedded Linux kernel● Clone git repository● Configurations in arch/arm/configs show various PXA variants

including PXA3xx to be supported● PXA support can be found in arch/arm/mach-pxa● Multiple supported boards: CM-X300, Littleton and Zylonite● Littleton and Zylonite being Marvell's development kits/boards

What is supported by Open-Source?Contents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

26

● At first no mainline PXA3xx support● Had to go with NDAed Marvell kernel being slightly out-dated

● Got it built for Zylonite development platform● Did not boot or rather at least not output anything

● Had to modify pin configuration for console UART again● Board specific code in arch/arm/mach-pxa/zylonite.c

● U-Boot still without Ethernet TFTP capabilities● Pre-load it all by BDI

● U-Boot to address 0x83008000● Linux kernel to address 0x81000000● 16 MB RAM disk to address 0x87000000

● First Linux shell!

The early AttemptsContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

Page 14: Contents

27

● While working on U-Boot PXA3xx support hit mainline● New XScale multi function pin (MFP) framework● GPIOlib

● PXA support located at arch/arm/mach-pxa● Zylonite support split into multiple files

● zylonite.c for generics● zylonite_pxa300.c zylonite_pxa320.c

for SoC specific configuration/initialisation● Similar to our HW coming in two flavours

● High-end PXA320 with audio and touch● Low-cost PXA300 without audio and touch

● Different pin numbering and peripheral support

Porting Linux KernelContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

28

● MFC configuration table● Outlining exact use of each pin

● Particular peripheral block● General purpose IO (GPIO)

● Macros from mach/mfp-pxa300.h resp. mfp-pxa320.h● By no means comprehensive● For all possible combinations consult Marvell's user guide

● Possible to tri-state pins● Configure as GPIO input or null alternate function● Required on Colibri due to multiple SoC pins being routed to

identical module pin

SoC specific CodeContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

Page 15: Contents

29

● SoC specific peripherals● AC97 audio● Touch screen controller● NAND flash partitioning due to different sized chips

● Main initialisation functions● Check whether running on respective SoC● Configure pins according to our MFP configuration tables● Register SoC specific peripherals● Assign GPIO pins and NAND flash partitions used in generic

code

Porting Linux Kernel (cont.)Contents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

30

● Handle chip select address mapping● Utilises CPLD for flexibility reason● Configure peripherals available on all module types

● Ethernet● Frame buffer with display configurations● MMC/SD card controller● NAND flash controller● RTC chip● SPI controller● USB controller

Generic CodeContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

Page 16: Contents

31

● Generic initialisation function first calls specific ones

● Enable chip select address decoder

● Configure and register generic peripherals

● Defines actual machine structure

Porting Linux Kernel (cont.)Contents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

32

Introducing Android

What is Android?How about its Architecture?

Page 17: Contents

33

●Open-source mobile phone platform initiated by Google● Building a better phone for consumers● source.android.com

●Open handset alliance● Several companies innovate in the open● …Increased openness will enable everyone in our industry to

innovate more rapidly and respond better to consumer's demands. …

● openhandsetalliance.com

●Noser Engineering AG works on core functionality

Contents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

34

Android ArchitectureContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

Page 18: Contents

35

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?

36

● Recent Linux kernel running on your target HW

● ARM based SoC● Low-level assembly optimisation● Code generation in graphics subsystem

● 128 MB SDRAM

● 256 MB flash favourably of the NAND kind

● Optimised for 16 bpp QVGA LCD with capacitive touch screen

● At least 5 button navigation keypad

System RequirementsContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

Page 19: Contents

37

● What we got so far● Android 1.0 kernel based on vanilla Linux 2.6.25● Colibri BSP kernel based on vanilla Linux 2.6.26

● Two possibilities● Port Android modifications into our BSP kernel● Or vice versa

● Depending on who did your BSP that code might be better

understood by you speaking for second approach

● Android modifications rather well integrated/understood

● Analyse Android kernel modifications and integrate them into our

BSP kernel

Porting Android Linux KernelContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

38

● Ashmem● mm/ashmem.c● Anonymous shared memory subsystem● Allow processes to share named blocks of memory● Kernel may reclaim them if not in use

● Binder IPC● drivers/android/binder.c● System oriented component architecture● Providing object-oriented operating system environment● Inter-process communication (IPC) between processes and

thread pools● Memory management and clean-up functionality

Android Kernel ExtensionsContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

Page 20: Contents

39

● Logger● drivers/android/ram_console.c

● Store kernel log messages in RAM buffer● drivers/android/logger.c

● Logging mechanism for user processes to read and write system log messages

● Low Memory Killer● drivers/misc/lowmemorykiller.c● Scans list of running processes and kills one● Optional component not required for basic bring-up

Android Kernel Extensions (cont.)Contents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

40

● Power management● drivers/android/power.c● At its core uses regular Linux power management subsystem● Does not poll for power related changes● Uses iNotify interface via fs/inotify_user.c● Subscribe to power related updates

● YAFFS2● Yet another flash file system 2nd edition● fs/yaffs2/*● Primary file system for low-cost high density NAND flash based

storage● Not part of any mainline kernel yet

Android Kernel Extensions (cont.)Contents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

Page 21: Contents

41

Android Kernel ConfigurationContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

● Requires one to enable previously discussed features

● Standard Android kernel configuration (emulator)

arch/arm/configs/goldfish_defconfig

42

Special ConsiderationsContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

● Frame buffer● Requires double buffering aka panning functionality● Allocate twice the memory required for actual frame size● Pan function selects which part is actually output to screen

● Touch screen● Android uses standard Linux input subsystem● Driver that not only reports pressure but button touch as well

● BTN_TOUCH upon detecting pen down event● Many mainline touch drivers do not implement it that way

● drivers/input/touchscreen/ucb1400_ts.c● drivers/input/touchscreen/wm97xx-core.c

Page 22: Contents

43

Porting the File System with the

Android Framework and its ApplicationsContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

● Initial RAM file system to boot-strap Android● Regular gziped cpio archive as initramfs● Contains just Android proprietary init process

● 3 different flash partitions● Each 64 MB in size● YAFFS2 NAND flash file system● System partition required to be pre-loaded● User data partition● Cache partition

Image File MTD Partition Mount Point

ramdisk.img N/A /

system.img /dev/mtdblock0 /system

userdata.img /dev/mtdblock1 /data

N/A /dev/mtdblock2 /cache

44

Touch Screen CalibrationContents

Get to know your Hardware

Development Environment

Porting Boot Loader

Porting Linux Kernel

Introducing Android

Porting Android

● No support for calibration as required by resistive touch screens

● Only capacitive touch screens not requiring any calibration

● Traditionally touch screen calibration handled by tslib● Special ts_calibrate application● Generates /etc/pointercal file containing calibration constants

● Integrated calibration calculation into Android● Did not bother to port actual calibration application to Android● Just integrate correct calibration file into Android file system

● /system/etc/pointercal

Page 23: Contents

45

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

www.noser.com/linux

● Or contact us for more information

[email protected]