Difference between revisions of "RPi Upstreaming"

From eLinux.org
Jump to: navigation, search
(Initial release)
 
m (Fixed Stephen's name (I insist to miswrite it), minor corrections and enhancements.)
Line 9: Line 9:
 
As of 20140211, all of UART (serial), SD card, HDMI (via simple-framebuffer), and USB should work. Not all SD cards will work (it may depend on the transfer modes the card supports, and timing tolerances). Not all USB devices will work (it may depend on the type of transfer, interrupt/control/bulk, the device uses, etc.)
 
As of 20140211, all of UART (serial), SD card, HDMI (via simple-framebuffer), and USB should work. Not all SD cards will work (it may depend on the transfer modes the card supports, and timing tolerances). Not all USB devices will work (it may depend on the type of transfer, interrupt/control/bulk, the device uses, etc.)
  
This page is kept deliberately terse, so as not to duplicate [[RPi_Kernel_Compilation]], which describes how to compile the Raspberry Pi Foundation's downstream kernel. Read that page for some background if this page doesn't make sense to you.
+
If something in this page doesn't make sense to you, pay a visit to [[RPi_Kernel_Compilation]], [[RPi_Upstream_Kernel_Compilation]] and [[RPi_U-Boot]] articles.
  
 
As a quickstart, this procedure will build a monolithic kernel, without modules, and good for a start. Build a sucessful image first, and then start your adventures with your crafted kernel.
 
As a quickstart, this procedure will build a monolithic kernel, without modules, and good for a start. Build a sucessful image first, and then start your adventures with your crafted kernel.
Line 19: Line 19:
 
  $ git clone git://github.com/raspberrypi/tools.git --depth=1
 
  $ git clone git://github.com/raspberrypi/tools.git --depth=1
  
Also, fetch Steven Warren's u-boot branch (we will need it, because the default bootloader won't be of help):
+
Also, fetch Stephen Warren's u-boot branch (we will need it, because the default bootloader won't be of help):
  
 
  $ git clone git://github.com/swarren/u-boot.git --depth=1
 
  $ git clone git://github.com/swarren/u-boot.git --depth=1
Line 32: Line 32:
  
 
=== Building your kernel ===
 
=== Building your kernel ===
'''A word of advice''': Don't forget to prefix the make commands with the <tt>ARCH</tt> and <tt>CROSS_COMPILE</tt> prefixes. If you forget to use it and start a make command, it will probably result on a build failure. If you forgot and ran a make, do a make clean and start over.
+
'''Pro tip:''' Don't forget to prefix the make commands with the <tt>ARCH</tt> and <tt>CROSS_COMPILE</tt> prefixes. If you forget to use it and start a make command, it will probably result on a build failure. If you forgot and ran a make, do a make clean and start over.
 
And now, let's prepare the Linux build recipe:
 
And now, let's prepare the Linux build recipe:
  
Line 51: Line 51:
  
 
=== Building your bootloader ===
 
=== Building your bootloader ===
As of 20140918, a upstream kernel image can't be booted using the default bootloader. And that's why we need the Steven Warren's das u-Boot. Let's build it:
+
As of 20140918, a upstream kernel image can't be booted using the default bootloader. And that's why we need the Stephen Warren's das u-Boot. Let's build it:
  
 
  $ cd ../u-boot
 
  $ cd ../u-boot
Line 80: Line 80:
 
And now, it's time to set up your SD card. This procedure assumes that your SD card is at <tt>/media/boot</tt>.
 
And now, it's time to set up your SD card. This procedure assumes that your SD card is at <tt>/media/boot</tt>.
  
First, move your current SD card to a backup directory:
+
First, let's save the current content to a backup directory (and empty the root directory):
  
 
  $ export SD=/media/boot
 
  $ export SD=/media/boot

Revision as of 11:45, 18 September 2014

Back to the Hub.


Software & Distributions:

Software - an overview.

Distributions - operating systems and development environments for the Raspberry Pi.

Kernel Compilation - advice on compiling a kernel.

Performance - measures of the Raspberry Pi's performance.

Programming - programming languages that might be used on the Raspberry Pi.

Building an Upstream Kernel for you Raspberry Pi

First word of advice: Have you visited the RPi_Kernel_Compilation page? If you did not, read at least the Roadmap section.

This page describes how to compile an upstream or mainline kernel for the Raspberry Pi. It is mainly useful for upstream kernel maintainers/developers, or distribution kernel package maintainers.

As of 20140211, all of UART (serial), SD card, HDMI (via simple-framebuffer), and USB should work. Not all SD cards will work (it may depend on the transfer modes the card supports, and timing tolerances). Not all USB devices will work (it may depend on the type of transfer, interrupt/control/bulk, the device uses, etc.)

If something in this page doesn't make sense to you, pay a visit to RPi_Kernel_Compilation, RPi_Upstream_Kernel_Compilation and RPi_U-Boot articles.

As a quickstart, this procedure will build a monolithic kernel, without modules, and good for a start. Build a sucessful image first, and then start your adventures with your crafted kernel.

Preparing the environment

First of all, get the toolchain for cross compile your kernel:

$ cd /usr/src
$ git clone git://github.com/raspberrypi/tools.git --depth=1

Also, fetch Stephen Warren's u-boot branch (we will need it, because the default bootloader won't be of help):

$ git clone git://github.com/swarren/u-boot.git --depth=1

And now, get the mainline source:

$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git --depth=1

Define the following environment variable:

$ export KERNEL_SRC=/usr/src/linux ; export CCPREFIX=/usr/src/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-

Building your kernel

Pro tip: Don't forget to prefix the make commands with the ARCH and CROSS_COMPILE prefixes. If you forget to use it and start a make command, it will probably result on a build failure. If you forgot and ran a make, do a make clean and start over. And now, let's prepare the Linux build recipe:

$ cd linux
$ ARCH=arm CROSS_COMPILE=${CCPREFIX} make bcm2835_defconfig

If you are building a Linux version which does not contains this patch (which is true at least up to 3.17), then you will have to manually select the USB controller, otherwise the USB ports (and networking!) will not work. Here is how to fix it. Enter the menuconfig

$ ARCH=arm CROSS_COMPILE=${CCPREFIX} make menuconfig

And then navigate to Device Drivers ---> USB support ---> DesignWare USB2 DRD Core Support and check both Host only mode and DWC2 Platform.

Leave the menuconfig, save the new .config and then build the kernel:

$ ARCH=arm CROSS_COMPILE=${CCPREFIX} chrt -i 0 make -j 8

Your build was sucessful? Great. Leve it alone for a while.

Building your bootloader

As of 20140918, a upstream kernel image can't be booted using the default bootloader. And that's why we need the Stephen Warren's das u-Boot. Let's build it:

$ cd ../u-boot
$ git checkout -b rpi_dev origin/rpi_dev
$ ARCH=arm CROSS_COMPILE=${CCPREFIX} chrt -i 0 make rpi_b_config
$ ARCH=arm CROSS_COMPILE=${CCPREFIX} chrt -i 0 make -j 8

Right, leave it alone. And now, let's setup the cmdline boot.

$ cd tools

And create the file boot.scr with the following content:

mmc dev 0
fatload mmc 0:1 ${kernel_addr_r} zImage
fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}
setenv fdtfile bcm2835-rpi-b.dtb
setenv bootargs earlyprintk console=tty0 console=ttyAMA0 root=/dev/mmcblk0p2 rootwait
bootz ${kernel_addr_r} - ${fdt_addr_r}

Pro tip: I've found that u-boot doesn't play nicely with long cmdlines. Avoid cluttering it. Otherwise it will print a quick setenv failure and your boot will fail.

And now, compile your cmdline:

$ ./mkimage -A arm -O linux -T script -C none -n boot.scr -d boot.scr boot.scr.uimg

Putting it all together

And now, it's time to set up your SD card. This procedure assumes that your SD card is at /media/boot.

First, let's save the current content to a backup directory (and empty the root directory):

$ export SD=/media/boot
$ mkdir $SD/backup
$ mv $SD/* $SD/backup

That's right, keep it empty. And now, let's populate with the fresh stuff.

Fetch a new firmware set from https://github.com/raspberrypi/firmware/tree/master/boot and save it to your $SD

And finally:

$ cd /usr/src
$ cp u-boot/u-boot.bin $SD/kernel.img
$ cp kernel/arch/arm/boot/zImage kernel/arch/arm/boot/dts/bcm2835-rpi-b.dtb u-boot/tools/boot.scr.uimg $SD

And you are done. Good luck!