SlideShare a Scribd company logo
1 of 48
Download to read offline
Porting Linux
Embedded Linux Conference (Europe)
Porting Linux
About Jon Masters
●

●

●

●

●

Been playing with Linux for 14 years (and the
kernel for 13 of those), since the age of 13.
Built embedded NMR scientific instruments,
worked with Montavista UK, now at Red Hat.
Author of the LKML Summary Podcast and the
kernel column in Linux User & Developer.
Co-author of Building Embedded Linux
Systems (second edition) – O'Reilly (2008)
My car still has an empeg :)
Porting Linux
Overview
●

Why port Linux anyway?

●

Background pre-requisities

●

Early board work

●

Bootloader bringup

●

Initial kernel bringup

●

Debugging

●

Working with Upstream

●

Trends
Porting Linux
Why port Linux anyway?
●

Linux is very portable
●

●

●

Supports 23 architectures in the upstream
“mainline” kernel tree of Linus Torvalds.
Kernel is mostly written in C, with some assembly
(most architectures only need a dozen such files)
Split between high-level generic functions and lowlevel functions to abstract architectural differences.
Porting Linux
Why port Linux anyway?
●

Linux is competitive
●

●

●

●

The number of Linux kernel developers contributing
to the official kernel has tripled since 2005.
Feature growth continues with an average of 10K
new lines of source code added every day.
In the hour you spend here 5.45 patches will on
average be added to the upstream Linux kernel.

Source: Linux Foundation analysis
Porting Linux
Why port Linux anyway?
●

Linux is cost effective.
●

A large amount of code to build upon.

●

Large (growing) community of developers.

●

I think we all know the rest.
Porting Linux
Background pre-requisities
●

Hardware
●

Development board or simulator
–
–
–
–
–

Optional debugger, some kind of UART
Boards range in value from $200-$crazy
Implement the same architecture and platform as the
final design but maybe with a number of hacks.
Simulator can be cheap and flexible (e.g.
Android/OpenMoko/OLPC using QEMU).
See Pierre's talk on QEMU for more.
Porting Linux
Background pre-requisities
●

Software
●

Toolchain (GCC, binutils, etc.)
–
–

●

Some kind of IDE
–

●

PTXdist/crosstool/project specific
See Robert Schwebel's PTXdist talk.
Likely to be Eclipse based, e.g. all the vendors.

You can get all of this from a vendor.
Porting Linux
Background pre-requisities
●

Experience
●

Kernel development experience
–

●

Hardware reference documentation
–

●

Don't forget to check the errata (first!)

Books and resources
–

●

Maybe not arch level, but at least driver work. Need to
understand and study architectural issues.

Some links later, also forums such as CELF.

Sign up to the Linux Kernel Mailing List
–

At least keep an eye on discussion. Don't miss topics like
the ongoing generic-asm work by Arnd Bergmann.
Porting Linux
Early board work
●

Test the board actually works
●

●

●

Write a simple LED flasher, print messages to the
UART, have an idea that it does something.
If examples have been supplied by a board vendor,
run them to make sure the board isn't defective.

Test the debugger actually works
●

I've had hardware debuggers that would lose
breakpoints, and other weirdness.
Porting Linux
Bootloader bringup
●

Many Open Source friendly projects use U-Boot
●

●
●

●

Das U-Boot written by Wolfgang Denk, and
maintained by many “custodians”.
http://www.denx.de/wiki/U-Boot
Supports ARM, AVR32, Blackfin, Microblaze, MIPS,
NIOS, PowerPC, SH, and more.
Typically stored in on-board NOR or NAND.
–

Relocates itself into RAM, loads a kernel (and root
filesystem in an initramfs).
Porting Linux
Bootloader bringup
●

U-Boot Design Principles
●

“Keep it small”
–

●

“Keep it simple”
–

●

U-Boot should only do what is necessary to boot

“Keep it fast”
–

●

A build of U-Boot with network support (if applicable)
should fit in 256KiB.

Get things running and then get out of the way.

“Keep it portable”
–

U-Boot is (like Linux) mostly written in C, with some
assembly for unavoidable reset/CPU init/RAM setup/C
stack environment setup.
Porting Linux
Bootloader bringup
●

U-Boot is highly configurable
●

●

Many if (CONFIG_) conditionals

Implementation split between “board” and “cpu”
●

Platform stuff under “board”, arch under “cpu”
Porting Linux
Bootloader bringup
●

U-Boot “board” support
●

Linker script defining U-Boot image

●

boardname.c file with basic functions

●

(optional) assembly helper code if needed

●

Various functions the CPU code will call into
–
–
–
–
–
–

lowlevel_init
board_pre_init, board_init
checkboard
initdram
Testdram
get_sys_info, get_PCI_freq
Porting Linux
Bootloader bringup
●

U-Boot “board” support
●
●

●

Board provided functions may be empty
The possible functions vary by supported
architecture, documented in the source
Flash functions that end in _f
–

●

Callable before relocation into RAM is complete.

Relocated functions that end in _r
–

Callable only once relocation into RAM is complete.
Porting Linux
Bootloader bringup
●

Implementing a new U-Boot “board” port
●

Use a similar board as a reference guide.

●

Start by bringing up the U-Boot prompt

●

●

Add some testing functions to exercise specific
board features (another common use)
Later add drivers for additional devices
–

●

Ethernet, disk, flash parts, etc.

Become a custodian of your port
–

Custodians maintain their piece of U-Boot (usually in their
own “git” tree) on the Denx git server.
Porting Linux
Bootloader bringup
●

U-Boot “cpu” support
●

●

Much less common that you would need to port to
an entirely new architecture
Typical system entry is in start.S
–
–
–
–
–
–
–

e.g. start440 for a PowerPC 440 system.
Initialize CPU cacheing asap (e.g. iccci/dccci)
Initialize CPU mode/context (e.g. SPRs)
Initialize MMU (e.g. no virtual/clear TLBs)
Provide interrupt and exception vectors
Setup minimal C stack environment
Finally end up in cpu_init/board_init
Porting Linux
Bootloader bringup
●

Passing System Information
●

●

Historically, embedded Linux didn't have a direct
equivalent of EFI/ACPI/Open Firmware.
Kernels were heavily bound to the specific board in
question
–

recompile needed to set options

●

Kernel command line option passing was added

●

bdinfo structure on PowerPC

●

Recent work focuses on Flattened Device Tree.
Porting Linux
Bootloader bringup
●

Flattened Device Tree
●

Expresses system information in the form of an
Open Firmware style device tree
–
–
–

●

Stored in a binary BLOB and passed to the kernel
–

●

Location of system resources in physical memory map
Model and serial number
Installed and optional devices
Special utilities to convert text file OF-style trees

Linux can decode the fdt to figure out board info
Porting Linux
Initial kernel bringup
●

Kernel Overview
●

●

Linux supports 32 and 64-bit systems of Little
and/or Big Endian in nature.
Macros, wrappers, function pointers and common
function names abstract away such differences.

●

The kernel is split into arch and platform code.

●

All stored under the “arch/” directory.
–

Each arch has flexibility into handling its own platforms
Porting Linux
Initial kernel bringup
●

Kernel Overview
●

The “core kernel” includes the low-level arch
support and high level functions
–

●

●

e.g. those in the top-level “kernel/” and “mm/” directories.

Other stuff (filesystems, networking, drivers) are not
considered to be “core kernel”.
Source code overview
–
–

Use a tool such as LXR (lxr.linux.no) to browse.
Use a tool such as cscope (invoke it with cscope -kR) to
search specific symbols.
Porting Linux
Initial kernel bringup
●

Architectures
●

Live in “arch/”
–

●

New architectures are rare
–
–

●

Formerly also include/asm-archname
But several added this year alone (microblaze, S+Core).
Total in the official kernel is 23 today.

Typical mistake is to copy an existing architecture
–

Especially something wildly inappropriate, such as x86
for an ARM-like new architecture, complete with all of its
(deprecated) system calls.
Porting Linux
Initial kernel bringup
●

Architectures
●

The kernel tree has been known to have too much
duplication (e.g. i386 vs. x86_64)
–

●

But it's being worked on, e.g. x86 unification.

Arnd Bergmann introduced generic-asm
–
–
–

A generic “ABI” that provides all of the core header
functions needed by the higher level kernel code.
e.g. <asm-generic/atomic.h> provides atomicity functions
such as atomic_add, including a generic version.
Also implementations of low-level mmu.h, mutex.h, pci.h,
page.h and 121 other header files right now.
Porting Linux
Initial kernel bringup
●

Architectures
●

Asm-generic used by several architectures already.
–
–

●

Especially the new S+Core architecture
Microblaze is the process of migrating

S+Core
–
–

–

Liqin Chen appeared on LKML several months ago with
patches for a new (ARM-like) arch from Sunplus.
The architecture is a low power 32-bit RISC SoC, with a
32/16-bit hybrid instruction mode (Thumbish), optional
MMU, optional DSP-like functions, user defined coprocessors, 63 prioritized interrupts, SJTAG, etc.
Targeting: Home and Entertainment
Porting Linux
Initial kernel bringup
●

Architectures
●

Arnd Bergmann reviewed the initial S+Core port

●

Sent many suggestions that Liqin dutifully followed.
–
–

●

Both gained from the experience.
Now a good reference architecture in S+Core

Only proposed a few months ago and already
upstream due to good community interaction.
–

A success story and a role model.
Porting Linux
Initial kernel bringup
●

Architectures
●

The S+Core tree:
–
–
–

–

boot/
- Target location for vmlinux.bin
configs/ - A defconfig example
Include/ - The “asm” directory. Many of the 89 files in
here simply include their <asm-generic> counterpart.
Some e.g. cache/VM bits, register specifics (threadinfo),
etc. following the standard asm-generic ABI.
Kconfig - Standard kernel configuration data. There is
also a debug verion of this file called Kconfig.debug.
Porting Linux
Initial kernel bringup
●

Architectures
●

The S+Core tree:
–

–
–
–

kernel/ - The “head.S” low-level assembly entry point,
irq.c interrupt bits, module.c ELF module loader bits,
process.c bits specific to clone(), setup.c low-level bits for
bootmem, sys_call_table, sys_core, and time.c.
lib/
- Various low-level implemenations of things
like strlen written in fast assembly.
Makefile
mm/
- pgtable.c, init.c (paging_init and mem_init),
tlb-miss.c, tlb-score.c, etc.
Porting Linux
Initial kernel bringup
●

Porting to a new architecture
●

Get to know the kernel tree first.
–

●

●
●

●

LXR, cscope, and others are your friends.

Pick an existing similar (endianness, bit size,
behavior, etc.) arch and look at its implementation.
Don't copy an existing architecture.
Create your new one and pull in the asm-generic
bits. Look to S+Core (“score”) and eventually to
Microblaze for good example code.
See also: Nina Wilner's PowerPC presentation
Porting Linux
Initial kernel bringup
●

Typical init process
●

●

Read through the code beginning with the head.S
entry for your favorite reference architecture.
head.S
–
–
–

Conventional name for lowest level entry (usually at
“start”, “_start”, “start_here”, or similar)
Entered directly after U-Boot exec.
Responsible for early configuring the CPU
●

–

Cacheing, initial stack sufficient for C code, enbale (SW/HW)
MMU, jump to core kernel start_kernel

And providing exception vectors
●

Errors, Faults (page faults), etc.
Porting Linux
Initial kernel bringup
●

Typical init process
●

start_kernel
–
–
–
–

Sequentially initialize the kernel.
Initialize lockdep/stack canary
boot_cpu_init. Activate the first processor using hotplug.
setup_arch. Architectural specifics. For example:
●
●
●
●

●

Low-level CPU and platform init
Paging (VM) enabled
Data passed in from the bootloader (device tree)
On S+Core: cpu_cache_init, tlb_init, bootmem_init, paging_init,
and resource_init.
On PowerPC: enabling xmon debugger and debug output.
Porting Linux
Initial kernel bringup
●

Typical init process
●

start_kernel
–
–

–
–

setup_command_line. Use the bootmem allocator to
stash away the kernel command line.
sort_main_extable. Sort the kernel symbol table for later
use by the module loader (recent speedup work here by
Alan Jenkins and also Carmelo's LKM fast loader later).
mm_init. Calls arch-specific mem_init, sets up various
kernel caches and enables vmalloc.
sched_init. Does the heavy lifting to prep the scheduler
(allocating using bootmem the runqueus and CFS bits).
Porting Linux
Initial kernel bringup
●

Typical init process
●

start_kernel
–
–
–
–
–
–

early_irq_init. Allocate the IRQ structs.
init_IRQ. Architectural counterpart to early_irq_init,
providing platform specific stuff.
timekeeping_init. Generic function that determines which
clocksources to use and configures them.
time_init. Corresponding architectural specifics.
console_init. Enables the console to that we can begin to
output the various kernel boot messages.
kmemleak_init. Initialize Catalin's nifty leak detector.
Porting Linux
Initial kernel bringup
●

Typical init process
●

start_kernel
–
–

●

calibrate_delay. Determine the “bogomips”.
fork_init. Prepare to be able to fork (clone) new tasks.
Calls down into the arch code to complete this.

rest_init
–
–
–
–

Prepare the scheduler (including RCU)
Start the master kernel thread (kthreadd)
Setup the idle task and schedule into init
After that heading toward userspace
Porting Linux
Initial kernel bringup
●

Platforms
●

As with U-Boot, platforms build upon architectures.
–
–
–
–

PowerPC implements a clean “platforms” directory.
ARM mixes things around under the CPU type.
Others (such as x86) don't really handle many different
(non-PC) platforms all that well (yet).
Some platforms use structs of function pointers
●

●

PowerPC uses a define_machine macro, including a probe
function that can selectively utilize the device tree.
ARM uses a MACHINE_STARTS macro, but is not yet as
flexible. For example, board-n8x0.c registers n8x0_init_machine
to be called for the Nokia N8xx tablet initialization.
Porting Linux
Initial kernel bringup
●

Platforms
●

Platform devices
–

–

Many platforms are built using standard parts such as
PCI (or PCI like) devices that can be registers and
managed generically.
Some “devices” are connected to legacy buses or aren't
really on a traditional bus at all
●

–

As is the case for many mapped SoC devices.

The Linux driver model documentation (in the
“Documentation/” kernel directory) will show you how to
register and manage platform devices
●

Needed for power management.
Porting Linux
Initial kernel bringup
●

Porting to a new platform
●

●

●

●

This is far easier than porting to a new arch, since
it's just a variant.
Typically, you can base your platform port on an
existing platform for the arch in question and more
legitimately copy/paste where not generalizable.
Make sure you educate the kernel about system
geometry (RAM size, etc.) and location of PCI.
Use the platform abstraction for any generic
mapped devices not managed elsewhere.
Porting Linux
Device Drivers
●

●

●

Basic architecture and platform support have
little meaning without drivers for peripherals.
Fortunately, Linux already supports a large
(growing) number of existing devices that may
already cover the majority of your design.
rd

Refer to Linux Device Drivers (3 edition) for
more information about writing drivers.
Porting Linux
Debugging
●

Many debugging and diagnostic options.
●

●

●

●
●

gdb. Can be used to attach to a remote hardware
(or virtual machine) gdbstub and issue instructions.
ftrace. An in-kernel function tracing framework,
originally used to measure kernel latencies.
kexec/crash/kdump. Can be used to boot an aux.
kernel if the main one crashes, to capture state. A
recent enhancement allows “flight recorder” mode.
Ksplice. Dynamically patch your running kernel.
Performance Events (“perf”). Capture system
performance metrics (and almost anything else).
Porting Linux
Working with upstream
●

Why you need upstream
●

●

●

●

Less “bitrot” due to constantly evolving upstream
kernel. Reduces “rebasing vs. retaining” tradeoff.
More influence on future development. People will
care about your project if it has code upstream.
70% of total contributions to the kernel come from
developers working at corporations that consider
such participation a competitive edge.
Source: Linux Foundation analysis.
Porting Linux
Working with upstream
●

Development Trees
●

●

The official kernel lives in Linus Torvald's “git” tree
on git.kernel.org
There are countless other “git” trees available.
–

linux-next is a stepping stone
●
●

–

staging is for immature code
●
●

●

Stephen Rothwell posts a new tree each day
Made from 140 “git” trees that are merged
Lives in a special kernel directory (harder for arches)
Greg Kroah-Hartman periodically updates it

Please read Documentation/development-process
Porting Linux
Working with upstream
●

Where do I go from here?
●

Check the MAINTAINERS file to see who owns the
architecture or other kernel subsystem concerned.
–

Reach out to the community for advice if unsure.

●

Learn to use “git”, “quilt”, and the git email features.

●

Consider the “staging” tree for immature code.

●

Prepare your work for linux-next.
–
–

Track Stephen Rothwell's tree regularly and post a “git”
tree of your patches.
Code that passes review and is in linux-next has a very
good chance of being merged upstream in the next
“merge window” by the relevant maintainer.
Porting Linux
Working with upstream
●

Mailing Lists
●

http://vger.kernel.org

●

LKML – Linux Kernel Mailing List

●

Linux-next Mailing List

●

Architectural Maintainer Lists

●

Greg Kroah-Hartman's Driver Development List

●

etc.
Porting Linux
Trends
●

Boot time
●

●

Dynamic Power Management
●

●

Work is going on in boot time reduction. See the
talk today and upstream “bootchart”/“timechart”.
Rafael J. Wysocki implemented dynamic suspend
of individual buses in a recent rework.

Flattened Device Tree
●

Continued work is happening here. Thanks to Grant
Likely and others for their efforts.
Porting Linux
Links
●

LWN - http://www.lwn.net/

●

LKML - http://vger.kernel.org/

●

Understanding the Linux Kernel

●

Linux Kernel Development

●

Linux Device Drivers (LDD3)

●

Building Embedded Linux Systems

●

Linux Kernel in a nutshell
Porting Linux
Disclaimer
●

I do not speak for my employer.

●

Web: http://www.jonmasters.org/

●

Email: jcm@jonmasters.org
Questions?
Porting Linux
Trends
●

Devtmpfs
●

●

IO Bandwidth Limiting
●

●

Devfs v2.0? Not quite.
Several proposals (dm-ioband, IO scheduler) but
nothing agreed on just yet.

Swap
●

Compcache. Compressed RAM alternative to swap.
Porting Linux
Trends
●

Virtualization
●

●

Various work to implement low-overhead (even lowlatency “Real Time”) enhancements in KVM.
KSM. Kernel Shared Memory allows dynamic
sharing of identical pages and is just one cool
technology recently pulled into KVM.

More Related Content

What's hot

IncludeOS for ics 2018
IncludeOS for ics 2018IncludeOS for ics 2018
IncludeOS for ics 2018Per Buer
 
Embedded Linux Basics
Embedded Linux BasicsEmbedded Linux Basics
Embedded Linux BasicsMarc Leeman
 
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSD
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSDLAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSD
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSDLinaro
 
Embedded Os [Linux & Co.]
Embedded Os [Linux & Co.]Embedded Os [Linux & Co.]
Embedded Os [Linux & Co.]Ionela
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesBUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesLinaro
 
Building Embedded Linux
Building Embedded LinuxBuilding Embedded Linux
Building Embedded LinuxSherif Mousa
 
LAS16-500: The Rise and Fall of Assembler and the VGIC from Hell
LAS16-500: The Rise and Fall of Assembler and the VGIC from HellLAS16-500: The Rise and Fall of Assembler and the VGIC from Hell
LAS16-500: The Rise and Fall of Assembler and the VGIC from HellLinaro
 
Kernel Proc Connector and Containers
Kernel Proc Connector and ContainersKernel Proc Connector and Containers
Kernel Proc Connector and ContainersKernel TLV
 
LAS16-305: Smart City Big Data Visualization on 96Boards
LAS16-305: Smart City Big Data Visualization on 96BoardsLAS16-305: Smart City Big Data Visualization on 96Boards
LAS16-305: Smart City Big Data Visualization on 96BoardsLinaro
 
LAS16-209: Finished and Upcoming Projects in LMG
LAS16-209: Finished and Upcoming Projects in LMGLAS16-209: Finished and Upcoming Projects in LMG
LAS16-209: Finished and Upcoming Projects in LMGLinaro
 
A low cost, real-time algorithm for embedded devices based on freertos kernel
A low cost, real-time algorithm for embedded devices based on freertos kernelA low cost, real-time algorithm for embedded devices based on freertos kernel
A low cost, real-time algorithm for embedded devices based on freertos kerneleSAT Journals
 
linux minimal os tutorial - by shatrix
linux minimal os tutorial - by shatrixlinux minimal os tutorial - by shatrix
linux minimal os tutorial - by shatrixSherif Mousa
 
Linux Kernel and Driver Development Training
Linux Kernel and Driver Development TrainingLinux Kernel and Driver Development Training
Linux Kernel and Driver Development TrainingStephan Cadene
 
Porting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeot
Porting the drm/kms graphic drivers to DragonFlyBSD by Francois TigeotPorting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeot
Porting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeoteurobsdcon
 
BKK16-105 HALs for LITE
BKK16-105 HALs for LITEBKK16-105 HALs for LITE
BKK16-105 HALs for LITELinaro
 
BKK16-103 OpenCSD - Open for Business!
BKK16-103 OpenCSD - Open for Business!BKK16-103 OpenCSD - Open for Business!
BKK16-103 OpenCSD - Open for Business!Linaro
 

What's hot (20)

IncludeOS for ics 2018
IncludeOS for ics 2018IncludeOS for ics 2018
IncludeOS for ics 2018
 
Embedded Linux Basics
Embedded Linux BasicsEmbedded Linux Basics
Embedded Linux Basics
 
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSD
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSDLAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSD
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSD
 
Embedded Os [Linux & Co.]
Embedded Os [Linux & Co.]Embedded Os [Linux & Co.]
Embedded Os [Linux & Co.]
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesBUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
 
Building Embedded Linux
Building Embedded LinuxBuilding Embedded Linux
Building Embedded Linux
 
LAS16-500: The Rise and Fall of Assembler and the VGIC from Hell
LAS16-500: The Rise and Fall of Assembler and the VGIC from HellLAS16-500: The Rise and Fall of Assembler and the VGIC from Hell
LAS16-500: The Rise and Fall of Assembler and the VGIC from Hell
 
Kernel Proc Connector and Containers
Kernel Proc Connector and ContainersKernel Proc Connector and Containers
Kernel Proc Connector and Containers
 
LAS16-305: Smart City Big Data Visualization on 96Boards
LAS16-305: Smart City Big Data Visualization on 96BoardsLAS16-305: Smart City Big Data Visualization on 96Boards
LAS16-305: Smart City Big Data Visualization on 96Boards
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
LAS16-209: Finished and Upcoming Projects in LMG
LAS16-209: Finished and Upcoming Projects in LMGLAS16-209: Finished and Upcoming Projects in LMG
LAS16-209: Finished and Upcoming Projects in LMG
 
A low cost, real-time algorithm for embedded devices based on freertos kernel
A low cost, real-time algorithm for embedded devices based on freertos kernelA low cost, real-time algorithm for embedded devices based on freertos kernel
A low cost, real-time algorithm for embedded devices based on freertos kernel
 
Eclipse - Installation and quick start guide
Eclipse - Installation and quick start guideEclipse - Installation and quick start guide
Eclipse - Installation and quick start guide
 
linux minimal os tutorial - by shatrix
linux minimal os tutorial - by shatrixlinux minimal os tutorial - by shatrix
linux minimal os tutorial - by shatrix
 
Linux Kernel and Driver Development Training
Linux Kernel and Driver Development TrainingLinux Kernel and Driver Development Training
Linux Kernel and Driver Development Training
 
Porting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeot
Porting the drm/kms graphic drivers to DragonFlyBSD by Francois TigeotPorting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeot
Porting the drm/kms graphic drivers to DragonFlyBSD by Francois Tigeot
 
BKK16-105 HALs for LITE
BKK16-105 HALs for LITEBKK16-105 HALs for LITE
BKK16-105 HALs for LITE
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
BKK16-103 OpenCSD - Open for Business!
BKK16-103 OpenCSD - Open for Business!BKK16-103 OpenCSD - Open for Business!
BKK16-103 OpenCSD - Open for Business!
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 

Viewers also liked (8)

Tutorial Embedded System
Tutorial Embedded System Tutorial Embedded System
Tutorial Embedded System
 
Embedded Technology
Embedded TechnologyEmbedded Technology
Embedded Technology
 
如何靠自學成為工程師
如何靠自學成為工程師如何靠自學成為工程師
如何靠自學成為工程師
 
Linux firewall-201503
Linux firewall-201503Linux firewall-201503
Linux firewall-201503
 
嵌入式平台移植技巧概說
嵌入式平台移植技巧概說嵌入式平台移植技巧概說
嵌入式平台移植技巧概說
 
Embedded C
Embedded CEmbedded C
Embedded C
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
 
Board Bringup
Board BringupBoard Bringup
Board Bringup
 

Similar to Masters porting linux

01 linux-quick-start
01 linux-quick-start01 linux-quick-start
01 linux-quick-startNguyen Vinh
 
Embedded platform choices
Embedded platform choicesEmbedded platform choices
Embedded platform choicesTavish Naruka
 
Module 4 Embedded Linux
Module 4 Embedded LinuxModule 4 Embedded Linux
Module 4 Embedded LinuxTushar B Kute
 
Embedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoEmbedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoSherif Mousa
 
Building Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMBuilding Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMSherif Mousa
 
Lec 10-linux-review
Lec 10-linux-reviewLec 10-linux-review
Lec 10-linux-reviewabinaya m
 
Introduction to Docker (and a bit more) at LSPE meetup Sunnyvale
Introduction to Docker (and a bit more) at LSPE meetup SunnyvaleIntroduction to Docker (and a bit more) at LSPE meetup Sunnyvale
Introduction to Docker (and a bit more) at LSPE meetup SunnyvaleJérôme Petazzoni
 
Embedded Linux primer
Embedded Linux primerEmbedded Linux primer
Embedded Linux primerDrew Fustini
 
Workshop : 45 minutes pour comprendre Docker avec Jérôme Petazzoni
Workshop : 45 minutes pour comprendre Docker avec Jérôme PetazzoniWorkshop : 45 minutes pour comprendre Docker avec Jérôme Petazzoni
Workshop : 45 minutes pour comprendre Docker avec Jérôme PetazzoniTheFamily
 
Introduction to Docker, December 2014 "Tour de France" Edition
Introduction to Docker, December 2014 "Tour de France" EditionIntroduction to Docker, December 2014 "Tour de France" Edition
Introduction to Docker, December 2014 "Tour de France" EditionJérôme Petazzoni
 
Working with Shared Libraries in Perl
Working with Shared Libraries in PerlWorking with Shared Libraries in Perl
Working with Shared Libraries in PerlIdo Kanner
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modulesdibyajyotig
 

Similar to Masters porting linux (20)

01 linux-quick-start
01 linux-quick-start01 linux-quick-start
01 linux-quick-start
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 
Embedded platform choices
Embedded platform choicesEmbedded platform choices
Embedded platform choices
 
Module 4 Embedded Linux
Module 4 Embedded LinuxModule 4 Embedded Linux
Module 4 Embedded Linux
 
Linux Kernel
Linux KernelLinux Kernel
Linux Kernel
 
Embedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoEmbedded Linux from Scratch to Yocto
Embedded Linux from Scratch to Yocto
 
Building Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMBuilding Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARM
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
Intro to linux
Intro to linux Intro to linux
Intro to linux
 
Portin g
Portin gPortin g
Portin g
 
Embedded Linux - Building toolchain
Embedded Linux - Building toolchainEmbedded Linux - Building toolchain
Embedded Linux - Building toolchain
 
Docker_AGH_v0.1.3
Docker_AGH_v0.1.3Docker_AGH_v0.1.3
Docker_AGH_v0.1.3
 
Lec 10-linux-review
Lec 10-linux-reviewLec 10-linux-review
Lec 10-linux-review
 
Introduction to Docker (and a bit more) at LSPE meetup Sunnyvale
Introduction to Docker (and a bit more) at LSPE meetup SunnyvaleIntroduction to Docker (and a bit more) at LSPE meetup Sunnyvale
Introduction to Docker (and a bit more) at LSPE meetup Sunnyvale
 
Introduction and course Details of Embedded Linux Platform Developer Training
Introduction and course Details of Embedded Linux Platform Developer TrainingIntroduction and course Details of Embedded Linux Platform Developer Training
Introduction and course Details of Embedded Linux Platform Developer Training
 
Embedded Linux primer
Embedded Linux primerEmbedded Linux primer
Embedded Linux primer
 
Workshop : 45 minutes pour comprendre Docker avec Jérôme Petazzoni
Workshop : 45 minutes pour comprendre Docker avec Jérôme PetazzoniWorkshop : 45 minutes pour comprendre Docker avec Jérôme Petazzoni
Workshop : 45 minutes pour comprendre Docker avec Jérôme Petazzoni
 
Introduction to Docker, December 2014 "Tour de France" Edition
Introduction to Docker, December 2014 "Tour de France" EditionIntroduction to Docker, December 2014 "Tour de France" Edition
Introduction to Docker, December 2014 "Tour de France" Edition
 
Working with Shared Libraries in Perl
Working with Shared Libraries in PerlWorking with Shared Libraries in Perl
Working with Shared Libraries in Perl
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 

More from Shashank Asthana

Operating system Memory management
Operating system Memory management Operating system Memory management
Operating system Memory management Shashank Asthana
 
GSM Cell planning and frequency reuse
GSM Cell planning and frequency reuseGSM Cell planning and frequency reuse
GSM Cell planning and frequency reuseShashank Asthana
 
IPv4 addressing and subnetting
IPv4 addressing and subnettingIPv4 addressing and subnetting
IPv4 addressing and subnettingShashank Asthana
 
Call flow and MS attach in LTE
Call flow and MS attach in LTECall flow and MS attach in LTE
Call flow and MS attach in LTEShashank Asthana
 

More from Shashank Asthana (6)

Operating system Memory management
Operating system Memory management Operating system Memory management
Operating system Memory management
 
Border Gatway Protocol
Border Gatway ProtocolBorder Gatway Protocol
Border Gatway Protocol
 
GSM Cell planning and frequency reuse
GSM Cell planning and frequency reuseGSM Cell planning and frequency reuse
GSM Cell planning and frequency reuse
 
IPv4 addressing and subnetting
IPv4 addressing and subnettingIPv4 addressing and subnetting
IPv4 addressing and subnetting
 
Call flow and MS attach in LTE
Call flow and MS attach in LTECall flow and MS attach in LTE
Call flow and MS attach in LTE
 
LTE 3GPP
LTE 3GPPLTE 3GPP
LTE 3GPP
 

Recently uploaded

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 

Masters porting linux

  • 1. Porting Linux Embedded Linux Conference (Europe)
  • 2. Porting Linux About Jon Masters ● ● ● ● ● Been playing with Linux for 14 years (and the kernel for 13 of those), since the age of 13. Built embedded NMR scientific instruments, worked with Montavista UK, now at Red Hat. Author of the LKML Summary Podcast and the kernel column in Linux User & Developer. Co-author of Building Embedded Linux Systems (second edition) – O'Reilly (2008) My car still has an empeg :)
  • 3. Porting Linux Overview ● Why port Linux anyway? ● Background pre-requisities ● Early board work ● Bootloader bringup ● Initial kernel bringup ● Debugging ● Working with Upstream ● Trends
  • 4. Porting Linux Why port Linux anyway? ● Linux is very portable ● ● ● Supports 23 architectures in the upstream “mainline” kernel tree of Linus Torvalds. Kernel is mostly written in C, with some assembly (most architectures only need a dozen such files) Split between high-level generic functions and lowlevel functions to abstract architectural differences.
  • 5. Porting Linux Why port Linux anyway? ● Linux is competitive ● ● ● ● The number of Linux kernel developers contributing to the official kernel has tripled since 2005. Feature growth continues with an average of 10K new lines of source code added every day. In the hour you spend here 5.45 patches will on average be added to the upstream Linux kernel. Source: Linux Foundation analysis
  • 6. Porting Linux Why port Linux anyway? ● Linux is cost effective. ● A large amount of code to build upon. ● Large (growing) community of developers. ● I think we all know the rest.
  • 7. Porting Linux Background pre-requisities ● Hardware ● Development board or simulator – – – – – Optional debugger, some kind of UART Boards range in value from $200-$crazy Implement the same architecture and platform as the final design but maybe with a number of hacks. Simulator can be cheap and flexible (e.g. Android/OpenMoko/OLPC using QEMU). See Pierre's talk on QEMU for more.
  • 8. Porting Linux Background pre-requisities ● Software ● Toolchain (GCC, binutils, etc.) – – ● Some kind of IDE – ● PTXdist/crosstool/project specific See Robert Schwebel's PTXdist talk. Likely to be Eclipse based, e.g. all the vendors. You can get all of this from a vendor.
  • 9. Porting Linux Background pre-requisities ● Experience ● Kernel development experience – ● Hardware reference documentation – ● Don't forget to check the errata (first!) Books and resources – ● Maybe not arch level, but at least driver work. Need to understand and study architectural issues. Some links later, also forums such as CELF. Sign up to the Linux Kernel Mailing List – At least keep an eye on discussion. Don't miss topics like the ongoing generic-asm work by Arnd Bergmann.
  • 10. Porting Linux Early board work ● Test the board actually works ● ● ● Write a simple LED flasher, print messages to the UART, have an idea that it does something. If examples have been supplied by a board vendor, run them to make sure the board isn't defective. Test the debugger actually works ● I've had hardware debuggers that would lose breakpoints, and other weirdness.
  • 11. Porting Linux Bootloader bringup ● Many Open Source friendly projects use U-Boot ● ● ● ● Das U-Boot written by Wolfgang Denk, and maintained by many “custodians”. http://www.denx.de/wiki/U-Boot Supports ARM, AVR32, Blackfin, Microblaze, MIPS, NIOS, PowerPC, SH, and more. Typically stored in on-board NOR or NAND. – Relocates itself into RAM, loads a kernel (and root filesystem in an initramfs).
  • 12. Porting Linux Bootloader bringup ● U-Boot Design Principles ● “Keep it small” – ● “Keep it simple” – ● U-Boot should only do what is necessary to boot “Keep it fast” – ● A build of U-Boot with network support (if applicable) should fit in 256KiB. Get things running and then get out of the way. “Keep it portable” – U-Boot is (like Linux) mostly written in C, with some assembly for unavoidable reset/CPU init/RAM setup/C stack environment setup.
  • 13. Porting Linux Bootloader bringup ● U-Boot is highly configurable ● ● Many if (CONFIG_) conditionals Implementation split between “board” and “cpu” ● Platform stuff under “board”, arch under “cpu”
  • 14. Porting Linux Bootloader bringup ● U-Boot “board” support ● Linker script defining U-Boot image ● boardname.c file with basic functions ● (optional) assembly helper code if needed ● Various functions the CPU code will call into – – – – – – lowlevel_init board_pre_init, board_init checkboard initdram Testdram get_sys_info, get_PCI_freq
  • 15. Porting Linux Bootloader bringup ● U-Boot “board” support ● ● ● Board provided functions may be empty The possible functions vary by supported architecture, documented in the source Flash functions that end in _f – ● Callable before relocation into RAM is complete. Relocated functions that end in _r – Callable only once relocation into RAM is complete.
  • 16. Porting Linux Bootloader bringup ● Implementing a new U-Boot “board” port ● Use a similar board as a reference guide. ● Start by bringing up the U-Boot prompt ● ● Add some testing functions to exercise specific board features (another common use) Later add drivers for additional devices – ● Ethernet, disk, flash parts, etc. Become a custodian of your port – Custodians maintain their piece of U-Boot (usually in their own “git” tree) on the Denx git server.
  • 17. Porting Linux Bootloader bringup ● U-Boot “cpu” support ● ● Much less common that you would need to port to an entirely new architecture Typical system entry is in start.S – – – – – – – e.g. start440 for a PowerPC 440 system. Initialize CPU cacheing asap (e.g. iccci/dccci) Initialize CPU mode/context (e.g. SPRs) Initialize MMU (e.g. no virtual/clear TLBs) Provide interrupt and exception vectors Setup minimal C stack environment Finally end up in cpu_init/board_init
  • 18. Porting Linux Bootloader bringup ● Passing System Information ● ● Historically, embedded Linux didn't have a direct equivalent of EFI/ACPI/Open Firmware. Kernels were heavily bound to the specific board in question – recompile needed to set options ● Kernel command line option passing was added ● bdinfo structure on PowerPC ● Recent work focuses on Flattened Device Tree.
  • 19. Porting Linux Bootloader bringup ● Flattened Device Tree ● Expresses system information in the form of an Open Firmware style device tree – – – ● Stored in a binary BLOB and passed to the kernel – ● Location of system resources in physical memory map Model and serial number Installed and optional devices Special utilities to convert text file OF-style trees Linux can decode the fdt to figure out board info
  • 20. Porting Linux Initial kernel bringup ● Kernel Overview ● ● Linux supports 32 and 64-bit systems of Little and/or Big Endian in nature. Macros, wrappers, function pointers and common function names abstract away such differences. ● The kernel is split into arch and platform code. ● All stored under the “arch/” directory. – Each arch has flexibility into handling its own platforms
  • 21. Porting Linux Initial kernel bringup ● Kernel Overview ● The “core kernel” includes the low-level arch support and high level functions – ● ● e.g. those in the top-level “kernel/” and “mm/” directories. Other stuff (filesystems, networking, drivers) are not considered to be “core kernel”. Source code overview – – Use a tool such as LXR (lxr.linux.no) to browse. Use a tool such as cscope (invoke it with cscope -kR) to search specific symbols.
  • 22. Porting Linux Initial kernel bringup ● Architectures ● Live in “arch/” – ● New architectures are rare – – ● Formerly also include/asm-archname But several added this year alone (microblaze, S+Core). Total in the official kernel is 23 today. Typical mistake is to copy an existing architecture – Especially something wildly inappropriate, such as x86 for an ARM-like new architecture, complete with all of its (deprecated) system calls.
  • 23. Porting Linux Initial kernel bringup ● Architectures ● The kernel tree has been known to have too much duplication (e.g. i386 vs. x86_64) – ● But it's being worked on, e.g. x86 unification. Arnd Bergmann introduced generic-asm – – – A generic “ABI” that provides all of the core header functions needed by the higher level kernel code. e.g. <asm-generic/atomic.h> provides atomicity functions such as atomic_add, including a generic version. Also implementations of low-level mmu.h, mutex.h, pci.h, page.h and 121 other header files right now.
  • 24. Porting Linux Initial kernel bringup ● Architectures ● Asm-generic used by several architectures already. – – ● Especially the new S+Core architecture Microblaze is the process of migrating S+Core – – – Liqin Chen appeared on LKML several months ago with patches for a new (ARM-like) arch from Sunplus. The architecture is a low power 32-bit RISC SoC, with a 32/16-bit hybrid instruction mode (Thumbish), optional MMU, optional DSP-like functions, user defined coprocessors, 63 prioritized interrupts, SJTAG, etc. Targeting: Home and Entertainment
  • 25. Porting Linux Initial kernel bringup ● Architectures ● Arnd Bergmann reviewed the initial S+Core port ● Sent many suggestions that Liqin dutifully followed. – – ● Both gained from the experience. Now a good reference architecture in S+Core Only proposed a few months ago and already upstream due to good community interaction. – A success story and a role model.
  • 26. Porting Linux Initial kernel bringup ● Architectures ● The S+Core tree: – – – – boot/ - Target location for vmlinux.bin configs/ - A defconfig example Include/ - The “asm” directory. Many of the 89 files in here simply include their <asm-generic> counterpart. Some e.g. cache/VM bits, register specifics (threadinfo), etc. following the standard asm-generic ABI. Kconfig - Standard kernel configuration data. There is also a debug verion of this file called Kconfig.debug.
  • 27. Porting Linux Initial kernel bringup ● Architectures ● The S+Core tree: – – – – kernel/ - The “head.S” low-level assembly entry point, irq.c interrupt bits, module.c ELF module loader bits, process.c bits specific to clone(), setup.c low-level bits for bootmem, sys_call_table, sys_core, and time.c. lib/ - Various low-level implemenations of things like strlen written in fast assembly. Makefile mm/ - pgtable.c, init.c (paging_init and mem_init), tlb-miss.c, tlb-score.c, etc.
  • 28. Porting Linux Initial kernel bringup ● Porting to a new architecture ● Get to know the kernel tree first. – ● ● ● ● LXR, cscope, and others are your friends. Pick an existing similar (endianness, bit size, behavior, etc.) arch and look at its implementation. Don't copy an existing architecture. Create your new one and pull in the asm-generic bits. Look to S+Core (“score”) and eventually to Microblaze for good example code. See also: Nina Wilner's PowerPC presentation
  • 29. Porting Linux Initial kernel bringup ● Typical init process ● ● Read through the code beginning with the head.S entry for your favorite reference architecture. head.S – – – Conventional name for lowest level entry (usually at “start”, “_start”, “start_here”, or similar) Entered directly after U-Boot exec. Responsible for early configuring the CPU ● – Cacheing, initial stack sufficient for C code, enbale (SW/HW) MMU, jump to core kernel start_kernel And providing exception vectors ● Errors, Faults (page faults), etc.
  • 30. Porting Linux Initial kernel bringup ● Typical init process ● start_kernel – – – – Sequentially initialize the kernel. Initialize lockdep/stack canary boot_cpu_init. Activate the first processor using hotplug. setup_arch. Architectural specifics. For example: ● ● ● ● ● Low-level CPU and platform init Paging (VM) enabled Data passed in from the bootloader (device tree) On S+Core: cpu_cache_init, tlb_init, bootmem_init, paging_init, and resource_init. On PowerPC: enabling xmon debugger and debug output.
  • 31. Porting Linux Initial kernel bringup ● Typical init process ● start_kernel – – – – setup_command_line. Use the bootmem allocator to stash away the kernel command line. sort_main_extable. Sort the kernel symbol table for later use by the module loader (recent speedup work here by Alan Jenkins and also Carmelo's LKM fast loader later). mm_init. Calls arch-specific mem_init, sets up various kernel caches and enables vmalloc. sched_init. Does the heavy lifting to prep the scheduler (allocating using bootmem the runqueus and CFS bits).
  • 32. Porting Linux Initial kernel bringup ● Typical init process ● start_kernel – – – – – – early_irq_init. Allocate the IRQ structs. init_IRQ. Architectural counterpart to early_irq_init, providing platform specific stuff. timekeeping_init. Generic function that determines which clocksources to use and configures them. time_init. Corresponding architectural specifics. console_init. Enables the console to that we can begin to output the various kernel boot messages. kmemleak_init. Initialize Catalin's nifty leak detector.
  • 33. Porting Linux Initial kernel bringup ● Typical init process ● start_kernel – – ● calibrate_delay. Determine the “bogomips”. fork_init. Prepare to be able to fork (clone) new tasks. Calls down into the arch code to complete this. rest_init – – – – Prepare the scheduler (including RCU) Start the master kernel thread (kthreadd) Setup the idle task and schedule into init After that heading toward userspace
  • 34. Porting Linux Initial kernel bringup ● Platforms ● As with U-Boot, platforms build upon architectures. – – – – PowerPC implements a clean “platforms” directory. ARM mixes things around under the CPU type. Others (such as x86) don't really handle many different (non-PC) platforms all that well (yet). Some platforms use structs of function pointers ● ● PowerPC uses a define_machine macro, including a probe function that can selectively utilize the device tree. ARM uses a MACHINE_STARTS macro, but is not yet as flexible. For example, board-n8x0.c registers n8x0_init_machine to be called for the Nokia N8xx tablet initialization.
  • 35. Porting Linux Initial kernel bringup ● Platforms ● Platform devices – – Many platforms are built using standard parts such as PCI (or PCI like) devices that can be registers and managed generically. Some “devices” are connected to legacy buses or aren't really on a traditional bus at all ● – As is the case for many mapped SoC devices. The Linux driver model documentation (in the “Documentation/” kernel directory) will show you how to register and manage platform devices ● Needed for power management.
  • 36. Porting Linux Initial kernel bringup ● Porting to a new platform ● ● ● ● This is far easier than porting to a new arch, since it's just a variant. Typically, you can base your platform port on an existing platform for the arch in question and more legitimately copy/paste where not generalizable. Make sure you educate the kernel about system geometry (RAM size, etc.) and location of PCI. Use the platform abstraction for any generic mapped devices not managed elsewhere.
  • 37. Porting Linux Device Drivers ● ● ● Basic architecture and platform support have little meaning without drivers for peripherals. Fortunately, Linux already supports a large (growing) number of existing devices that may already cover the majority of your design. rd Refer to Linux Device Drivers (3 edition) for more information about writing drivers.
  • 38. Porting Linux Debugging ● Many debugging and diagnostic options. ● ● ● ● ● gdb. Can be used to attach to a remote hardware (or virtual machine) gdbstub and issue instructions. ftrace. An in-kernel function tracing framework, originally used to measure kernel latencies. kexec/crash/kdump. Can be used to boot an aux. kernel if the main one crashes, to capture state. A recent enhancement allows “flight recorder” mode. Ksplice. Dynamically patch your running kernel. Performance Events (“perf”). Capture system performance metrics (and almost anything else).
  • 39. Porting Linux Working with upstream ● Why you need upstream ● ● ● ● Less “bitrot” due to constantly evolving upstream kernel. Reduces “rebasing vs. retaining” tradeoff. More influence on future development. People will care about your project if it has code upstream. 70% of total contributions to the kernel come from developers working at corporations that consider such participation a competitive edge. Source: Linux Foundation analysis.
  • 40. Porting Linux Working with upstream ● Development Trees ● ● The official kernel lives in Linus Torvald's “git” tree on git.kernel.org There are countless other “git” trees available. – linux-next is a stepping stone ● ● – staging is for immature code ● ● ● Stephen Rothwell posts a new tree each day Made from 140 “git” trees that are merged Lives in a special kernel directory (harder for arches) Greg Kroah-Hartman periodically updates it Please read Documentation/development-process
  • 41. Porting Linux Working with upstream ● Where do I go from here? ● Check the MAINTAINERS file to see who owns the architecture or other kernel subsystem concerned. – Reach out to the community for advice if unsure. ● Learn to use “git”, “quilt”, and the git email features. ● Consider the “staging” tree for immature code. ● Prepare your work for linux-next. – – Track Stephen Rothwell's tree regularly and post a “git” tree of your patches. Code that passes review and is in linux-next has a very good chance of being merged upstream in the next “merge window” by the relevant maintainer.
  • 42. Porting Linux Working with upstream ● Mailing Lists ● http://vger.kernel.org ● LKML – Linux Kernel Mailing List ● Linux-next Mailing List ● Architectural Maintainer Lists ● Greg Kroah-Hartman's Driver Development List ● etc.
  • 43. Porting Linux Trends ● Boot time ● ● Dynamic Power Management ● ● Work is going on in boot time reduction. See the talk today and upstream “bootchart”/“timechart”. Rafael J. Wysocki implemented dynamic suspend of individual buses in a recent rework. Flattened Device Tree ● Continued work is happening here. Thanks to Grant Likely and others for their efforts.
  • 44. Porting Linux Links ● LWN - http://www.lwn.net/ ● LKML - http://vger.kernel.org/ ● Understanding the Linux Kernel ● Linux Kernel Development ● Linux Device Drivers (LDD3) ● Building Embedded Linux Systems ● Linux Kernel in a nutshell
  • 45. Porting Linux Disclaimer ● I do not speak for my employer. ● Web: http://www.jonmasters.org/ ● Email: jcm@jonmasters.org
  • 47. Porting Linux Trends ● Devtmpfs ● ● IO Bandwidth Limiting ● ● Devfs v2.0? Not quite. Several proposals (dm-ioband, IO scheduler) but nothing agreed on just yet. Swap ● Compcache. Compressed RAM alternative to swap.
  • 48. Porting Linux Trends ● Virtualization ● ● Various work to implement low-overhead (even lowlatency “Real Time”) enhancements in KVM. KSM. Kernel Shared Memory allows dynamic sharing of identical pages and is just one cool technology recently pulled into KVM.