linux porting
DESCRIPTION
linux porting to a new arm-based platformTRANSCRIPT
![Page 2: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/2.jpg)
OutLine
GNU Toolchain
Linux Kernel Prerequisites and Assumptions
Images
Boot Sequence
Kernel Configuration & Compilation
Kernel Porting
Device Drivers
Boot Options
initramfs vs initrd
References
![Page 3: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/3.jpg)
GNU Toolchains
CodeSourcery gnu toolchainhttp://www.codesourcery.com/sgpp/lite/arm/download.html
Buildroothttp://buildroot.uclibc.org/
Scratchboxhttp://www.scratchbox.org/
OpenEmbeddedhttp://wiki.openembedded.net/index.php/Main_Page
Ptxdisthttp://www.pengutronix.de/software/ptxdist/index_en.html
![Page 4: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/4.jpg)
GNU Toolchains - buildroot
linux kernel like configuration interface
ncurse UI, .config file uClibc generate linux 2.6 compatible small footprint
applications for most platform remember to enable software float output: toolchain/uClibc/busybox/rootfs
![Page 5: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/5.jpg)
Linux Kernel Prerequisites and Assumptions
DRAM is initialized Hardware-related initialization tasks are done MMU/Cache is disabled specific values should be saved in registers
r1: Machine ID, r2: pointer of ATAG list (optional)
![Page 6: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/6.jpg)
Images and intermediate files
vmlinuz(ELF object)
kernel proper
objcopyimage(binary object)
stripped image binary kernel
gzip piggy.gz
compressedbinary kernel
asm
piggy.o
misc.o
head.o
bootablekernel image
(zImage)
![Page 7: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/7.jpg)
Boot Sequence
arch/arm/boot/compressed/
head.S
bootstrap loader(uncompress)
start
arch/arm/kernel/head.S
start
ARM-specifickernel code
init/main.c
start_kernel
kernel code
detail boot sequence is listed in [9]
![Page 8: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/8.jpg)
Kernel Porting – Kernel Memory Map
CPU vector page/copy_user_page(),clear_user_page()
DMA memory mapping
free for platform use
vmalloc()/ioremap() space
kernel direct-mapped RAM region
kernel module space
user space mapping
CPU vector page/null pointer trap0x0000_0000
0xFF00_0000
TASK_SIZE
PAGE_OFFSET
VMALLOC_START
VMALLOC_END
0x0000_1000
0xFFFF_0000
0xFFFF_FFFF
![Page 9: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/9.jpg)
Kernel Porting – Directories
mm/memory-handling related code
boot/bootstrap loader code
kernel/ARM architecture dependent code
mach-XXXXXX/specific machine dependent code
configs/each machine’s default kernel configurations
![Page 10: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/10.jpg)
Kernel Porting – new machine items
refer to other machine to create or modify items(ex: foo, fxx) register the new machine
arch/arm/tools/mach-types
Create machine folderarch/arm/mach-fxx
arch/arm/mach-fxx/include/mach
Modify or Create Kconfig & Makefilearch/arm/Kconfig (usually add config ARCH_FXX for architecture)
arch/arm/Makefile
arch/arm/mm/Kconfig
arch/arm/mach-fxx/Kconfig (config MACH_FOO for machine)
arch/arm/mach-fxx/Makefile
arch/arm/mach-fxx/Makefile.boot (set zreladdr-y for image location)
![Page 11: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/11.jpg)
Kernel Porting – new machine itemsregister the new machine
Add an entry in arch/arm/tools/mach-types
ex: foo MACH_FOO FOO 65535 For official registration, should register here, also.
http://www.arm.linux.org.uk/developer/machines/
![Page 12: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/12.jpg)
Kernel Porting – new machine itemscreate machine folders
arm/arch/mach-fxx
for machine dependent source code arm/arm/mach-fxx/include/mach
for machine dependent headers/assembly
debug-macro.S: adduart, senduart, busyuart, waituartdma.hentry-macro.S: macro get_irqnr_and_basehardware.hio.hirqs.h: NR_IRQSmemory.h: PHYS_OFFSET
system.h: arch_idle(), arch_reset()timex.h: CLOCK_TICK_RATEuncompress.h: putc()vmalloc.h: VMALLOC_END
![Page 13: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/13.jpg)
Kernel Porting – new machine itemsmodify or create Kconfig & Makefile
arch/arm/Kconfigconfig ARCH_FXX
bool “FXX family processors“
help
This enables support for systems based on the fxx processors.
………
source "arch/arm/mach-fxx/Kconfig"
arch/arm/Makefile machine-$(CONFIG_ARCH_FXX) := fxx
arch/arm/mm/Kconfig (ex: ARM926-based)config CPU_ARM926T
bool "Support ARM926T processor"
depends on ARCH_INTEGRATOR || ARCH_VERSATILE_PB || \
… || ARCH_FXX
default y if ARCH_VERSATILE_PB || ARCH_VERSATILE_AB || \
… || ARCH_FXX
![Page 14: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/14.jpg)
Kernel Porting – new machine itemsmodify or create Kconfig & Makefile
arch/arm/mach-fxx/Kconfigmenu "FXX platform type“
depends on ARCH_FXX
config MACH_FOO
bool "Support FOO platform"
default y
help
Include support for the FOO platform.
endmenu
arch/arm/mach-fxx/Makefile# Common support (must be linked before board specific support)
obj-y :=
# Specific board support
obj-$(CONFIG_MACH_FOO) += core.o
arch/arm/mach-fxx/Makefile.bootzreladdr-y := 0x01008000
architecture depend code
machine depend code
![Page 15: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/15.jpg)
Kernel Porting – description structure
MACHINE_START(FOO, "FOO processor") /* Maintainer: Champ Yen */ .map_io = foo_map_io, .init_irq = foo_init_irq, .init_machine = foo_init, .timer = &foo_timer, /* for ATAG list is optional */ .boot_params = 0x01000100,MACHINE_END
![Page 16: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/16.jpg)
Kernel Porting – Initialization code
I/O Memory Mapping Table IRQ Timer
struct sys_timer
Initial order: .map_io .initrq .timer .init_machine
![Page 17: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/17.jpg)
Kernel Porting – I/O Memory Map
static struct map_desc foo_io_desc[] __initdata =
{
{
/* address after mapping */
.virtual = IO_ADDRESS(CPU_DEV_PHY_BASE),
/* page index of physical address */
.pfn = __phys_to_pfn(CPU_DEV_PHY_BASE),
.length = CPU_DEV_IO_LEN, /* address mapping range */
.type = MT_DEVICE /* I/O type */
},
……
};
….
static void __init foo_map_io(void)
{
iotable_init(foo_io_desc, ARRAY_SIZE(foo_io_desc));
}
![Page 18: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/18.jpg)
Kernel Porting – IRQ
arch/arm/mach-fxx/include/mach/entry-macro.Sget_irqnr_and_base: after calling irqnr: irq number, not equal condition should be set.
arch/arm/mach-fxx/include/mach/irqs.hNR_IRQS (number of irq types) should be defined
struct irq_chip, irqactionset_irq_chip(), set_irq_flags(), set_irq_handler(), setup_irq()
static struct irq_chip foo_irq_chip = { .ack = foo_int_ack, .mask = foo_int_mask, .unmask = foo_int_unmask,};
………for(i = o; i < NR_IRQS; i++){
set_irq_handler(i, handle_level_irq);set_irq_chip(i, &foo_irq_chip);set_irq_flags(i, IRQF_VALID);
}………
![Page 19: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/19.jpg)
Kernel Porting - Timer
struct sys_timer foo_timer = {
.init = foo_timer_init,
.offset = foo_gettimeoffset,
};
![Page 20: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/20.jpg)
Kernel Porting – DMA memory (optional)
Influence to dma_alloc_coherent() usage In arch/arm/mach-fxx/include/mach/dma.h
MAX_DMA_ADDRESS In arch/arm/mach-fxx/include/mach/memory.h
CONSISTENT_DMA_SIZE ISA_DMA_THRESHOLD
![Page 21: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/21.jpg)
Boot Options – static string
Boot options -> Default kernel command stringex: mem=8M@0x01000000 initrd=0x01180000,145762
![Page 22: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/22.jpg)
Boot Options – ATAG lists
ATAG provides dynamic boot option passing There are two way to pass pointer of ATAG lists
r2 value passed by bootloader, .boot_params in machine descriptor
refer to arch/arm/include/asm/setup.h
……
ATAG_CORE
ATAG_NONE
struct tag_header { __u32 size; __u32 tag;};
struct tag { struct tag_header hdr; union { struct tag_core core; struct tag_mem32 mem;
… } u;};
![Page 23: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/23.jpg)
Device Drivers
platform_device_register(), platform_driver_register()for some on-chip devices(ex: clock/power control)
UART subsystem in driver/serialfor startup message, console ,and shell
Framebuffer subsystem in driver/video
![Page 24: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/24.jpg)
initramfs vs initrd
initrd initramfs
image ext2 image + gzip cpio + gzip
implementation block device tmpfs
first execution /linuxrc /init
mount rootfs pivot_root switch_root
initrd requires ext2 and block devices support. It adds 150KB+to kernel size.
![Page 25: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/25.jpg)
initramfs
create an initramfs image by command: find . | cpio -o -H newc | gzip > ../initramfs.cpio.gz
take care of the distance between image and kernel, otherwise image will be overwritten by kernel.
/init
ex:#!/bin/busybox sh
#/bin/busybox --install
mount -t proc proc /proc
exec /bin/busybox sh
initramfs
![Page 26: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/26.jpg)
Debug
decompression: putc() definiition in include/mach/uncompress.h
kernel debugging features in kernel hacking of kernel options (and CONFIG_DEBUG_LL option for low level debugging)
early debug: printascii/printhex(2,4,8) make use of uart macros in include/mach/debug-macro.S
printk()
CONNFIG_KGDB
![Page 27: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/27.jpg)
References
Embedded Linux Primer, Christopher Hallinan, Prentice Hall Building Embedded Linux Systems 2/e, Karim Yaghmour, Oreilly linux-2.6.2x-xx/Documentation/arm http://heaven.branda.to/~thinker/GinGin_CGI.py/get_afile/166/porting_to_arm.pdf http://www.glomationinc.com/PortingLinuxKernel.pdf http://www.ens-lyon.fr/LIP/Pub/Rapports/RR/RR2006/RR2006-08.pdf http://glt08.linuxtage.at/slides/glt08-kvas_linuxonarm.pdf http://www.linux-arm.org/LinuxKernel/LinuxNewPlatformPort http://gicl.cs.drexel.edu/people/sevy/linux/ARM_Linux_boot_sequence.html http://www.simtec.co.uk/products/SWLINUX/files/booting_article.html http://www.ibm.com/developerworks/linux/library/l-initrd.html http://blog.linux.org.tw/~jserv/archives/001954.html
![Page 28: Linux Porting](https://reader033.vdocuments.net/reader033/viewer/2022052217/555c456fd8b42a0b038b515a/html5/thumbnails/28.jpg)
Q & A