Linux Porting 
& 
Linux Support Package 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 
All Rights Reserved.
What to Expect? 
Kernel Basics for Linux Porting 
W's of Linux Porting 
W's of Linux Support Package (LSP) 
Architecture of LSPs 
Browse & Understand the LSPs 
LSP & Board Bringup Connections 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 2 
All Rights Reserved.
Some Basics 
For 
Understanding Linux Porting 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 3 
All Rights Reserved.
Kernel Items to Consider 
Version 
Major 
Minor 
Sequence 
Extra version 
/proc/version 
Source Repositories & Mailing Lists 
Architecture Specific 
Architecture Merging Efforts 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 4 
All Rights Reserved.
Kernel Configuration (Detailed) 
Changing the .config by hand 
Preparing & Using a default config 
Example: arch/arm/configs/omap3evm 
Other Configs: rand, allmod, allyes, allno 
Adding an Entry 
Change in Kconfig 
Change in Makefile 
Let's have a demonstration 
The autoconf.h 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 5 
All Rights Reserved.
Kernel Image Components 
Observe the Makefile &/or vmlinux build with V=1 
Objects 
arch/<arch>/kernel/head.o 
Kernel Architecture specific startup code 
arch/<arch>/kernel/init-task.o 
Initial thread & task structs required by Kernel 
init/built-in.o 
Main kernel initialization code 
… 
Linker script 
arch/<arch>/kernel/vmlinux.lds 
Kernel Bootstrap Loader 
Initialize Processor's internal caches and C runtime environment (head*.o) 
Decompression & re-location (misc.o) 
Processor-specific initialization, e.g. endian related (*endian.o) 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 6 
All Rights Reserved.
Kernel Initialization (Detailed) 
Kernel Entry Point 
arch/<arch>/kernel/head*.o 
Kernel Startup 
init/main.c → start_kernel(); 
Browse the code 
Architecture Setup 
Command Line Processing & __setup macro(arg, f) 
Subsystem Initializations & Initcalls (for memory free up) 
Kernel init Thread → init process 
Idle Process 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 7 
All Rights Reserved.
Let's get down to the Source Code 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 8 
All Rights Reserved.
Let's Check 
Where are the following things done? 
MMU switching ON 
Starting of kernel 
Mounting of init ramdisk and root filesystem 
board_init invocation 
Where is the default command line setup? 
'Booting Kernel' message 
Machine Id verification 
Command Line parsing 
start_kernel location 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 9 
All Rights Reserved.
Linux Porting 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 10 
All Rights Reserved.
What is Porting? 
“To Port” is “To Carry” 
Adapting to the Environment 
That it was not Designed for 
And by “(Embedded) Linux Porting” we mean 
Adapting Linux to work on an Embedded Platform 
So, what does it take to port Linux 
At high level, the 5's of Embedded Systems 
And at kernel level, the 5 M's of OS 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 11 
All Rights Reserved.
5 M's of OS (Revisited) 
Architecture Porting 
Processor Management 
Memory Management 
Board Porting 
I/O Management 
Storage Management 
Network Management 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 12 
All Rights Reserved.
Linux Porting 
Architecture Porting is a subject in itself 
Would talk in a separate session 
Board Porting 
Board-specific Initialization Code 
And majorly Drivers Porting 
So, part of the Kernel Space 
Two categories of Drivers 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 13 
All Rights Reserved. 
Standard Device Drivers 
Part of the Kernel 
Or, Needs to be done as for writing the standard Linux Drivers 
At the standard directory locations 
Custom Device / Interface Drivers 
Board-specific Custom Code required 
Needs to be specifically brought-in with the Kernel
What is Linux Support Package? 
Collection of this board specific 
Initialization & Custom Code is referred as 
Board Support Package (BSP) – normal 
language 
Or, Linux Support Package (LSP) – Linux 
language 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 14 
All Rights Reserved.
Sources of LSPs 
Board Vendor 
For a reference board, Or 
For a board based on the reference design 
Develop your Own for a Custom Board 
developed In-House 
First, search the kernel source for existing code 
If found, use it 
Else, if found something close, modify & use it 
Otherwise, following material would provide 
further guidelines 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 15 
All Rights Reserved.
Architecture of Linux Support Packages 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 16 
All Rights Reserved.
Components of LSP 
As LSP is very specific to a board. It consists 
of code for things hard-wired on the board 
A Usual List 
Interrupt Request Numbers 
Audio Codecs 
Keypad Interfaces 
Switch Interfaces 
LED Interfaces 
... 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 17 
All Rights Reserved.
LSP Placement 
With these in mind, and a board being tied to an architecture, the 
natural place for an LSP becomes under the kernel's “arch” sub-tree 
To be more specific, under the specific <arch> of the arch/ 
Architecture Specific Code resides under 
arch/<arch> → Sources 
include/asm-<arch> → Headers 
So, Board Specific Code resides under 
arch/<arch>/mach-<board_name> → Sources 
include/asm/mach-<board_name> → Headers 
mach stands for Machine, lingo for Board in Linux community 
Many LSP vendors, violate these norms, and 
Place headers with sources 
Place the LSP at other inappropriate locations 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 18 
All Rights Reserved.
Design & Layout of LSPs 
Where does a keypad driver go? 
Under drivers, Or 
Linux Support Package 
What about code for Audio chip, when the controller doesn't have 
built-in audio support (say I2S)? 
Such gray areas create confusion 
People place the code as per their judgment 
Hence, we follow some thumb rules 
Design & Layout Rules of Thumb 
Look for something similar, already in kernel source 
Follow the norm 
If not there, start from the LSP 
Over time, if it becomes generic enough, move to drivers 
For all the above, appropriately update Kconfig & Makefile 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 19 
All Rights Reserved.
Initialization Code LSP 
Board specific Code 
UART Configuration – UART Pins, UART vs 
Device mapping, ... 
Ethernet Configuration – Interrupt Pin, ... 
… (the various device configurations) 
Let's browse the code 
mach-omap2/board-omap3evm.c 
plat-omap/... 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 20 
All Rights Reserved.
Custom Code LSP 
Interrupts 
Input / Output Management 
Audio 
Video 
Embedded Storage Management 
Flash Partitioning 
NB Separate sessions needed for each 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 21 
All Rights Reserved.
Let's Browse some LSPs 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 22 
All Rights Reserved.
LSP & Board Bringup Connections 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 23 
All Rights Reserved.
BSP in Bootloader 
Bootloader does some of the Board-specific 
tasks, which are done in kernel 
Device Initialization 
Some Device Access 
This could be taken advantage from 
Could serve as the reference for the LSP 
Many a times, it becomes other way round 
Code developed for LSP may help enhance 
Bootloader 
Improving a better Board Bringup Experience 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 24 
All Rights Reserved.
Board Id 
Unique Number designated to every 
Board Type 
Part of the LSP and exposed to Bootloader 
Populated by Bootloader 
Verified by LSP 
Let's browse to view it 
arch/arm/tools/mach-types 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 25 
All Rights Reserved.
Hacking the LSP 
Very often, we have initial boot, test & 
board bringup programs, written to run 
on the bare board 
They may be really useful to hack the LSP 
When it is not working as expected 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 26 
All Rights Reserved.
Steps in Porting 
Register the machine and get the machine id for board 
Create a board specific file 'board-<board_name>' at 
arch/arm/mach-<soc> 
Define the MACHINE_START for the board 
Update the Kconfig file at arch/arm/mach-<soc> 
Update the corresponding makefile 
Create the default configuration for the board and place the 
working .config file at arch/arm/configs/ 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 27 
All Rights Reserved.
What all have we learnt? 
Kernel Basics for Linux Porting 
W's of Linux Porting 
W's of Linux Support Package (LSP) 
Architecture of LSPs 
Browse & Understand the LSPs 
LSP & Board Bringup Connections 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 28 
All Rights Reserved.
Any Queries? 
© 2010-14 SysPlay Workshops <workshop@sysplay.in> 29 
All Rights Reserved.

Linux Porting

  • 1.
    Linux Porting & Linux Support Package © 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved.
  • 2.
    What to Expect? Kernel Basics for Linux Porting W's of Linux Porting W's of Linux Support Package (LSP) Architecture of LSPs Browse & Understand the LSPs LSP & Board Bringup Connections © 2010-14 SysPlay Workshops <workshop@sysplay.in> 2 All Rights Reserved.
  • 3.
    Some Basics For Understanding Linux Porting © 2010-14 SysPlay Workshops <workshop@sysplay.in> 3 All Rights Reserved.
  • 4.
    Kernel Items toConsider Version Major Minor Sequence Extra version /proc/version Source Repositories & Mailing Lists Architecture Specific Architecture Merging Efforts © 2010-14 SysPlay Workshops <workshop@sysplay.in> 4 All Rights Reserved.
  • 5.
    Kernel Configuration (Detailed) Changing the .config by hand Preparing & Using a default config Example: arch/arm/configs/omap3evm Other Configs: rand, allmod, allyes, allno Adding an Entry Change in Kconfig Change in Makefile Let's have a demonstration The autoconf.h © 2010-14 SysPlay Workshops <workshop@sysplay.in> 5 All Rights Reserved.
  • 6.
    Kernel Image Components Observe the Makefile &/or vmlinux build with V=1 Objects arch/<arch>/kernel/head.o Kernel Architecture specific startup code arch/<arch>/kernel/init-task.o Initial thread & task structs required by Kernel init/built-in.o Main kernel initialization code … Linker script arch/<arch>/kernel/vmlinux.lds Kernel Bootstrap Loader Initialize Processor's internal caches and C runtime environment (head*.o) Decompression & re-location (misc.o) Processor-specific initialization, e.g. endian related (*endian.o) © 2010-14 SysPlay Workshops <workshop@sysplay.in> 6 All Rights Reserved.
  • 7.
    Kernel Initialization (Detailed) Kernel Entry Point arch/<arch>/kernel/head*.o Kernel Startup init/main.c → start_kernel(); Browse the code Architecture Setup Command Line Processing & __setup macro(arg, f) Subsystem Initializations & Initcalls (for memory free up) Kernel init Thread → init process Idle Process © 2010-14 SysPlay Workshops <workshop@sysplay.in> 7 All Rights Reserved.
  • 8.
    Let's get downto the Source Code © 2010-14 SysPlay Workshops <workshop@sysplay.in> 8 All Rights Reserved.
  • 9.
    Let's Check Whereare the following things done? MMU switching ON Starting of kernel Mounting of init ramdisk and root filesystem board_init invocation Where is the default command line setup? 'Booting Kernel' message Machine Id verification Command Line parsing start_kernel location © 2010-14 SysPlay Workshops <workshop@sysplay.in> 9 All Rights Reserved.
  • 10.
    Linux Porting ©2010-14 SysPlay Workshops <workshop@sysplay.in> 10 All Rights Reserved.
  • 11.
    What is Porting? “To Port” is “To Carry” Adapting to the Environment That it was not Designed for And by “(Embedded) Linux Porting” we mean Adapting Linux to work on an Embedded Platform So, what does it take to port Linux At high level, the 5's of Embedded Systems And at kernel level, the 5 M's of OS © 2010-14 SysPlay Workshops <workshop@sysplay.in> 11 All Rights Reserved.
  • 12.
    5 M's ofOS (Revisited) Architecture Porting Processor Management Memory Management Board Porting I/O Management Storage Management Network Management © 2010-14 SysPlay Workshops <workshop@sysplay.in> 12 All Rights Reserved.
  • 13.
    Linux Porting ArchitecturePorting is a subject in itself Would talk in a separate session Board Porting Board-specific Initialization Code And majorly Drivers Porting So, part of the Kernel Space Two categories of Drivers © 2010-14 SysPlay Workshops <workshop@sysplay.in> 13 All Rights Reserved. Standard Device Drivers Part of the Kernel Or, Needs to be done as for writing the standard Linux Drivers At the standard directory locations Custom Device / Interface Drivers Board-specific Custom Code required Needs to be specifically brought-in with the Kernel
  • 14.
    What is LinuxSupport Package? Collection of this board specific Initialization & Custom Code is referred as Board Support Package (BSP) – normal language Or, Linux Support Package (LSP) – Linux language © 2010-14 SysPlay Workshops <workshop@sysplay.in> 14 All Rights Reserved.
  • 15.
    Sources of LSPs Board Vendor For a reference board, Or For a board based on the reference design Develop your Own for a Custom Board developed In-House First, search the kernel source for existing code If found, use it Else, if found something close, modify & use it Otherwise, following material would provide further guidelines © 2010-14 SysPlay Workshops <workshop@sysplay.in> 15 All Rights Reserved.
  • 16.
    Architecture of LinuxSupport Packages © 2010-14 SysPlay Workshops <workshop@sysplay.in> 16 All Rights Reserved.
  • 17.
    Components of LSP As LSP is very specific to a board. It consists of code for things hard-wired on the board A Usual List Interrupt Request Numbers Audio Codecs Keypad Interfaces Switch Interfaces LED Interfaces ... © 2010-14 SysPlay Workshops <workshop@sysplay.in> 17 All Rights Reserved.
  • 18.
    LSP Placement Withthese in mind, and a board being tied to an architecture, the natural place for an LSP becomes under the kernel's “arch” sub-tree To be more specific, under the specific <arch> of the arch/ Architecture Specific Code resides under arch/<arch> → Sources include/asm-<arch> → Headers So, Board Specific Code resides under arch/<arch>/mach-<board_name> → Sources include/asm/mach-<board_name> → Headers mach stands for Machine, lingo for Board in Linux community Many LSP vendors, violate these norms, and Place headers with sources Place the LSP at other inappropriate locations © 2010-14 SysPlay Workshops <workshop@sysplay.in> 18 All Rights Reserved.
  • 19.
    Design & Layoutof LSPs Where does a keypad driver go? Under drivers, Or Linux Support Package What about code for Audio chip, when the controller doesn't have built-in audio support (say I2S)? Such gray areas create confusion People place the code as per their judgment Hence, we follow some thumb rules Design & Layout Rules of Thumb Look for something similar, already in kernel source Follow the norm If not there, start from the LSP Over time, if it becomes generic enough, move to drivers For all the above, appropriately update Kconfig & Makefile © 2010-14 SysPlay Workshops <workshop@sysplay.in> 19 All Rights Reserved.
  • 20.
    Initialization Code LSP Board specific Code UART Configuration – UART Pins, UART vs Device mapping, ... Ethernet Configuration – Interrupt Pin, ... … (the various device configurations) Let's browse the code mach-omap2/board-omap3evm.c plat-omap/... © 2010-14 SysPlay Workshops <workshop@sysplay.in> 20 All Rights Reserved.
  • 21.
    Custom Code LSP Interrupts Input / Output Management Audio Video Embedded Storage Management Flash Partitioning NB Separate sessions needed for each © 2010-14 SysPlay Workshops <workshop@sysplay.in> 21 All Rights Reserved.
  • 22.
    Let's Browse someLSPs © 2010-14 SysPlay Workshops <workshop@sysplay.in> 22 All Rights Reserved.
  • 23.
    LSP & BoardBringup Connections © 2010-14 SysPlay Workshops <workshop@sysplay.in> 23 All Rights Reserved.
  • 24.
    BSP in Bootloader Bootloader does some of the Board-specific tasks, which are done in kernel Device Initialization Some Device Access This could be taken advantage from Could serve as the reference for the LSP Many a times, it becomes other way round Code developed for LSP may help enhance Bootloader Improving a better Board Bringup Experience © 2010-14 SysPlay Workshops <workshop@sysplay.in> 24 All Rights Reserved.
  • 25.
    Board Id UniqueNumber designated to every Board Type Part of the LSP and exposed to Bootloader Populated by Bootloader Verified by LSP Let's browse to view it arch/arm/tools/mach-types © 2010-14 SysPlay Workshops <workshop@sysplay.in> 25 All Rights Reserved.
  • 26.
    Hacking the LSP Very often, we have initial boot, test & board bringup programs, written to run on the bare board They may be really useful to hack the LSP When it is not working as expected © 2010-14 SysPlay Workshops <workshop@sysplay.in> 26 All Rights Reserved.
  • 27.
    Steps in Porting Register the machine and get the machine id for board Create a board specific file 'board-<board_name>' at arch/arm/mach-<soc> Define the MACHINE_START for the board Update the Kconfig file at arch/arm/mach-<soc> Update the corresponding makefile Create the default configuration for the board and place the working .config file at arch/arm/configs/ © 2010-14 SysPlay Workshops <workshop@sysplay.in> 27 All Rights Reserved.
  • 28.
    What all havewe learnt? Kernel Basics for Linux Porting W's of Linux Porting W's of Linux Support Package (LSP) Architecture of LSPs Browse & Understand the LSPs LSP & Board Bringup Connections © 2010-14 SysPlay Workshops <workshop@sysplay.in> 28 All Rights Reserved.
  • 29.
    Any Queries? ©2010-14 SysPlay Workshops <workshop@sysplay.in> 29 All Rights Reserved.