Booting the ELF kernel without ubldr on Raspberry Pi

Sylvain Garrigues sylgar at gmail.com
Thu Dec 24 10:51:12 UTC 2015


If I look at what gonzo did for VERSATILEPB, I think it can be done easily by writing a tiny assembly code that does something like what he did:

# set r0..r3 to zero
    /usr/bin/printf "\0\0\240\343" > ${WORKDIR}/first_commands
    /usr/bin/printf "\0\020\240\343" >> ${WORKDIR}/first_commands
    /usr/bin/printf "\0\040\240\343" >> ${WORKDIR}/first_commands
    /usr/bin/printf "\0\060\240\343" >> ${WORKDIR}/first_commands
    
# jump to kernel entry point
    /usr/bin/printf "\001\366\240\343" >> ${WORKDIR}/first_commands
    
# install kernel
    [ ! -d ${WORKDIR}/_.kernel.bin ] && mkdir ${WORKDIR}/_.kernel.bin
    board_default_installkernel ${WORKDIR}/_.kernel.bin

    dd of=$VERSATILEPB_FLASH bs=1M count=4 if=/dev/zero
    dd of=$VERSATILEPB_FLASH bs=1 conv=notrunc if=${WORKDIR}/first_commands
    dd of=$VERSATILEPB_FLASH bs=64k oseek=15 conv=notrunc if=${WORKDIR}/_.kernel.bin/boot/kernel/kernel.bin

The only problem for the Raspberry pi is that, if I am correct, the DTB is modified by the firmware (bootcode.bin) so I can’t statically compile the DTB in the kernel like for VERSATILEPB :( I would need to mimic what loader does and create a kernel environment variable which contains the address to the DTB.

This is a good exercice, but it doesn’t solve my project which is to:

1/ have a self-extracting kernel or have a loader which uncompress the kernel, so that it takes much less time to start (my benchmark is raspbian or openelec). 
==> I compiled ubldr with LOADER_GZIP_SUPPORT and compressed kernel to kernel.gz, reducing the size by 2. The loader does manage to load, uncompress and boot the kernel.gz, but the loading time is worse than when uncompressed, so I’m stuck I don’t know what’s wrong?

2/ have the bootloader / kernel display a nice splash screen while the kernel boots
==> for that I looked at u-boot splash screen but the quality of the rendering is too poor (8-bit bitmap). I looked at the VT frame buffer but the slash screen feature is also limited. So I might now look into the misc/raspberrypi-userland port and understand how the hello_jpeg sample code does that with the GPU, then I plan to port it in the kernel initialization code, not sure it’s going to work) 

Have a good day

> Le 24 déc. 2015 à 07:18, Tim Kientzle <tim at kientzle.com> a écrit :
> 
> Actually, it would be more interesting to go a step further and boot the FreeBSD kernel directly from the firmware, bypassing both U-Boot and ubldr.
> 
> Warner did some work long ago to allow the FreeBSD kernel to boot from a Linux boot loader, which should make this possible.  You might try looking at that code and seeing if you can get it to work.
> 
> Cheers,
> 
> Tim
> 
> 
>> On Dec 21, 2015, at 7:48 PM, Sylvain Garrigues <sylgar at gmail.com <mailto:sylgar at gmail.com>> wrote:
>> 
>> Hello,
>> 
>> I’d like to boot FreeBSD directly with u-boot, without ubldr, using an image provided by the u-boot mkimage tool. The reason is simple: mkimage can deal with compressed kernels and will therefore speed my boot time. And I want to try it anyway, as it seems possible reading http://bsdcan.org/2008/schedule/attachments/49_2008_uboot_freebsd.pdf <http://bsdcan.org/2008/schedule/attachments/49_2008_uboot_freebsd.pdf><http://bsdcan.org/2008/schedule/attachments/49_2008_uboot_freebsd.pdf <http://bsdcan.org/2008/schedule/attachments/49_2008_uboot_freebsd.pdf>> and various other 
>> 
>> Before going there and using an mkimage, I’d like to boot the kernel image just with the same bootelf version provided by the sysutils/u-boot-rpi2 port. It doesn’t display anything and crashes (I think I can see « illegal instruction » just before the board reboots). I don’t understand why, and this is my first question.
>> 
>> Then I looked at the mkimage utility, although we can specify and freebsd kernel type through the -O flag, the bootm command only understands linux and NetBSD. I guess I should use linux there?
>> 
>> Thanks for your help,
>> Sylvain
>> 
>> 
>> PS: FYI, below is:
>> 
>> 1/ info about my kernel (I can see the entry point is at 0xc0100100), copied into the fat partition
>> 
>> # readelf -h /root/crochet/work/obj/arm.armv6/root/crochet/src/sys/RPI2/kernel                          
>> ELF Header:
>> Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
>> Class:                             ELF32
>> Data:                              2's complement, little endian
>> Version:                           1 (current)
>> OS/ABI:                            UNIX - System V
>> ABI Version:                       0
>> Type:                              EXEC (Executable file)
>> Machine:                           ARM
>> Version:                           0x1
>> Entry point address:               0xc0100100
>> Start of program headers:          52 (bytes into file)
>> Start of section headers:          6235080 (bytes into file)
>> Flags:                             0x5000202, has entry point, Version5 EABI, <unknown>
>> Size of this header:               52 (bytes)
>> Size of program headers:           32 (bytes)
>> Number of program headers:         6
>> Size of section headers:           40 (bytes)
>> Number of section headers:         38
>> Section header string table index: 35
>> [root at clad /usr/ports/sysutils/u-boot-rpi2]#  
>> 
>> 2/ the interesting part of my include/configs/rpi-common.h from u-boot:
>> 
>> #define CONFIG_EXTRA_ENV_SETTINGS \
>>       ENV_DEVICE_SETTINGS \
>>       "loadaddr=0x02000000\0" \
>>       "Fatboot=" \
>>         "env exists loaderdev || env set loaderdev ${fatdev}; " \
>>         "echo Booting from: ${fatdev} ${bootfile}; " \
>>         "fatload ${fatdev} ${loadaddr} ${bootfile} && bootelf ${loadaddr}; " \
>>       "\0" \
>>       "preboot=" \
>>         "fdt addr 0x100; " \
>>         "env set bootfile kernel; " \  
>>         "env set fatdev 'mmc 0'; " \
>>       "\0"
>> #undef  CONFIG_BOOTCOMMAND
>> #define CONFIG_BOOTCOMMAND     "run Fatboot"
>> #undef  CONFIG_PREBOOT
>> #define CONFIG_PREBOOT         "run preboot"
>> _______________________________________________
>> freebsd-arm at freebsd.org <mailto:freebsd-arm at freebsd.org> mailing list
>> https://lists.freebsd.org/mailman/listinfo/freebsd-arm <https://lists.freebsd.org/mailman/listinfo/freebsd-arm>
>> To unsubscribe, send any mail to "freebsd-arm-unsubscribe at freebsd.org <mailto:freebsd-arm-unsubscribe at freebsd.org>"



More information about the freebsd-arm mailing list