A second stage bootloader for the Raspberry Pi
Switch branches/tags
Nothing to show
Clone or download
Permalink
Failed to load latest commit information.
libdtc @ 6c07352 Updated libdtc tracking Jan 19, 2017
rpi-boot-tools Added clipLog.py to help interpret nofs partitions Jun 1, 2013
test_kernel Fix compiler options for test_kernel Mar 1, 2013
.gitignore Added .gitignore Jan 19, 2017
.gitmodules Removed link to dtc (use our own fork instead) Aug 31, 2016
.travis.yml Move to CROSS_COMPILE env variable Jan 9, 2017
LICENCE.GPL Added support for device trees using the libftd library. Aug 31, 2016
LICENCE.broadcom Added support for device trees using the libftd library. Aug 31, 2016
LICENCE.musl Added support for device trees using the libftd library. Aug 31, 2016
MULTIBOOT-ARM Added support for the (framebuffer_*) fields at the end of multiboot.h May 29, 2017
Makefile Some makefile fixes Apr 17, 2017
Makefile.rpi-boot.in Added gcc flags to prevent -O3 causing memset to call itself Apr 17, 2017
README Added support for device trees using the libftd library. Aug 31, 2016
assert.c Added support for device trees using the libftd library. Aug 31, 2016
assert.h Added support for device trees using the libftd library. Aug 31, 2016
atag.c Use uintptr_t where we can Jan 9, 2017
atag.h Use uintptr_t where we can Jan 9, 2017
bcm2709-rpi-2-b.dtb Added support for device trees using the libftd library. Aug 31, 2016
block.c Rewrote ext2/fat fread functions to use fs_fread Jun 1, 2013
block.h Rewrote ext2/fat fread functions to use fs_fread Jun 1, 2013
block_cache.c Added support for device trees using the libftd library. Aug 31, 2016
boot.s Bug fix in quick_memcpy Feb 26, 2013
boot64.s Add support for aarch64 Jan 10, 2017
config.h Added full support for obtaining the addresses of uart, timer, gpio, Sep 1, 2016
config_parse.c Add deliminator to split and config parse functions Jan 10, 2017
config_parse.h Add deliminator to split and config parse functions Jan 10, 2017
console.c Merge branch 'master' of github.com:jncronin/rpi-boot Jun 26, 2013
console.h Added support for enabling and disabling framebuffer and uart output … Apr 5, 2013
crc32.c Initial commit of raspbootin support functions. Apr 7, 2013
crc32.h Initial commit of raspbootin support functions. Apr 7, 2013
ctype.c Added support for device trees using the libftd library. Aug 31, 2016
ctype.h Added support for device trees using the libftd library. Aug 31, 2016
dirent.h Added README and licence statements. Feb 9, 2013
dwc_usb.c Continued work on dwc_usb driver. Mar 4, 2013
dwc_usb.h Continued work on dwc_usb driver. Mar 4, 2013
elf.c Use uintptr_t where we can Jan 9, 2017
elf.h Added README and licence statements. Feb 9, 2013
emmc.c Use uintptr_t where we can Jan 9, 2017
errno.h Rewrote ext2/fat fread functions to use fs_fread Jun 1, 2013
ext2.c Fixed error where block numbers in ext_fread were not being converted… Apr 17, 2017
fat.c Use uintptr_t where we can Jan 9, 2017
fb.c Use uintptr_t where we can Jan 9, 2017
fb.h Added README and licence statements. Feb 9, 2013
font.c Added README and licence statements. Feb 9, 2013
fs.h Added a host of new functions to multiboot_arm_functions Jun 1, 2013
heap.c Add qemufw target Jan 10, 2017
libfs.c Rewrote ext2/fat fread functions to use fs_fread Jun 1, 2013
linker-qemu.ld Added .ARM.exidx* sections to qemu build Dec 26, 2015
linker.ld Fixed a bug in fat.c where the fs struct was not being zeroed Jun 17, 2013
log.c Fixed bug in log.c where null pointer was sometimes dereferenced on c… Sep 1, 2016
log.h Added support for device trees using the libftd library. Aug 31, 2016
main.c Moved first printf statement in main.c to after initialization of uart Jun 15, 2017
malloc.c Fixed licence statements. Feb 9, 2013
mbox.c Added full support for obtaining the addresses of uart, timer, gpio, Sep 1, 2016
mbox.h Added README and licence statements. Feb 9, 2013
mbr.c Added some debugging support to nofs Jun 1, 2013
memchunk.c Added README and licence statements. Feb 9, 2013
memchunk.h Added README and licence statements. Feb 9, 2013
mkknlimg Added mkknlimg from the official rpi repository. Aug 31, 2016
mksdimg.sh Added generic block driver support (and implemented it in emmc) Feb 2, 2013
mmio.c Use uintptr_t where we can Jan 9, 2017
mmio.h Use uintptr_t where we can Jan 9, 2017
multiboot.c Added support for the (framebuffer_*) fields at the end of multiboot.h May 29, 2017
multiboot.h Added support for the (framebuffer_*) fields at the end of multiboot.h May 29, 2017
nofs.c Added support for device trees using the libftd library. Aug 31, 2016
output.c Added log.c (based upon an idea from https://github.com/JamesC1) whic… Jun 1, 2013
output.h Added a host of new functions to multiboot_arm_functions Jun 1, 2013
printf.c Added sprintf May 27, 2013
qemufw.c Add qemufw target Jan 10, 2017
qemufw.ld Abort read on broken ext2 fs Jan 10, 2017
ramdisk.c Added support for device trees using the libftd library. Aug 31, 2016
raspbootin-server.c Added config.h file as the main way of configuring (and enabling comp… May 27, 2013
raspbootin.c Added config.h file as the main way of configuring (and enabling comp… May 27, 2013
raspbootin.h Added config.h file as the main way of configuring (and enabling comp… May 27, 2013
rpifdt.c Use uintptr_t where we can Jan 9, 2017
rpifdt.h Added support for device trees using the libftd library. Aug 31, 2016
stdio.c Added support for enabling and disabling framebuffer and uart output … Apr 5, 2013
stdio.h Added README and licence statements. Feb 9, 2013
stdlib.c Added support for device trees using the libftd library. Aug 31, 2016
stdlib.h Added log.c (based upon an idea from https://github.com/JamesC1) whic… Jun 1, 2013
stream.c Added README and licence statements. Feb 9, 2013
string.h Added support for device trees using the libftd library. Aug 31, 2016
strstr.c Added support for device trees using the libftd library. Aug 31, 2016
strtol.c Added further patches from https://github.com/JamesC1 May 28, 2013
strtoll.c Added support for device trees using the libftd library. Aug 31, 2016
timer.c Added full support for obtaining the addresses of uart, timer, gpio, Sep 1, 2016
timer.h Fixed a bug in fat.c where the fs struct was not being zeroed Jun 17, 2013
uart.c Use uintptr_t where we can Jan 9, 2017
uart.h Added support for enabling and disabling framebuffer and uart output … Apr 5, 2013
usb.h Started working on DWC USB host controller driver. Mar 2, 2013
util.h Added support for device trees using the libftd library. Aug 31, 2016
vfs.c Fixed dome bugs in register_log_file and fwrite Jun 2, 2013
vfs.h Added log.c (based upon an idea from https://github.com/JamesC1) whic… Jun 1, 2013

README

rpi-boot
--------

A simple second stage boot loader for the Raspberry Pi to assist in the
development of hobby kernels.


Features
--------

* Supports booting flat binary files, ELF executables and ELF and a.out
executables with a Multiboot header.  Linux kernels are currently not
supported (but support is planned for a future version).

* Supports FAT(16/32) and ext2 filesystems.

* Supports loading additional modules when in Multiboot mode.

* Proviedes functions to the loaded kernel to allow it to easily
access the framebuffer (via a printf() interface) and the filesystem
(via fopen/fread/fclose/opendir/readdir/closedir).


Installation
------------

Edit config.h to your needs to enable/disable certain functionality.

Run make in the source directory and copy the kernel.img file to the SD card
containing your Raspian distribution.  You are recommended to backup your
original kernel.img file first.


Usage
-----

The rpi-boot bootloader will initially search for files called
/boot/rpi_boot.cfg, /boot/rpi-boot.cfg and /boot/grub/grub.cfg (in that order)
on the first partition of the SD card.  If one is not found, it searches for
those files on each filesystem known to the system.

It understands the following commands:

multiboot <kernel> [cmdline]
	- Load a multiboot compliant kernel

module <file> [name]
	- Load an additional Multiboot module

kernel <kernel>
	- Load a non-multiboot compliant kernel

boot
	- Boot the kernel

binary_load_addr <address>
	- Set the load address for a flat binary file subsequently loaded by the
		'kernel' command

entry_addr <address>
	- Set the entry point that is jumped to by a subsequent 'boot' command

console_log <file>[+] [buffer_size]
	- Copy the console log to a file.  If '+' is specified after the file name
		then append to the file instead of overwriting it.  If 'buffer_size'
		is specified then it is the number of bytes to buffer before writing
		to the file.  This prevents the log quickly using up all the write
		cycles on solid state media, but runs the risk of some messages being
		lost on a kernel crash.  Call fflush(get_log_file()) from the guest
		OS to manually flush the buffer.  Support for console_log requires
		that ENABLE_CONSOLE_LOGFILE be enabled in config.h


System state on kernel start
----------------------------

For Multiboot kernels, the system state is defined in MULTIBOOT-ARM, otherwise:

r0 will be 0
r1 will be the ARM machine type
r2 will be the address of the ATAGs

(the above 3 are identical to the ARM Linux boot protocol)

r3 will be the address of the multiboot_arm_functions structure as defined in
MULTIBOOT-ARM.

See the test-kernel directory for an example.


Caveats
-------

rpi-boot occupies the first 1 MiB of memory for itself.  If you wish to make
use of the multiboot_arm_functions functions you need to preserve this.  If
not you can overwrite it from within your kernel.  If you do overwrite it,
you should make sure you have already obtained all the information you need
from the various Multiboot structures (or copied them elsewhere).

Because of this, rpi-boot will not boot kernels which are linked below 1 MiB.


Licence
-------

rpi-boot is released under a MIT licence (see main.c for an example).

mkknlimg is released under the GPL (see LICENCE.GPL)
The rpi device tree dtb files are Copyright Broadcom (see LICENCE.broadcom)

The contents of the libdtc directory are the Device Tree Compiler.  See
libdtc/libfdt/libfdt.h for conditions.

strstr.c is taken from the musl C library (see LICENCE.musl)