[yocto] [meta-raspberrypi][PATCH] u-boot: Simplify boot script

Jonathan Liu net147 at gmail.com
Fri Nov 4 05:13:55 PDT 2016


Hi Paul,

On 4 November 2016 at 09:14, Paul Barker <paul at paulbarker.me.uk> wrote:
> On Fri, 4 Nov 2016 08:55:05 +1100
> Jonathan Liu <net147 at gmail.com> wrote:
>
>> Hi Paul,
>>
>> On 4 November 2016 at 07:57, Paul Barker <paul at paulbarker.me.uk> wrote:
>> > On Wed,  2 Nov 2016 00:49:11 +1100
>> > Jonathan Liu <net147 at gmail.com> wrote:
>> >
>> >> device_tree_address=0x100 is set in config.txt so the firmware will
>> >> load a patched device tree blob to 0x100 before passing control to
>> >> U-Boot. The U-Boot script will then read the command line arguments
>> >> generated by the firmware from the device tree and boot the kernel
>> >> with the command line arguments and the loaded device tree.
>> >>
>> >> This allows things like MAC address, board revision and serial number
>> >> to be correctly configured and options in config.txt to be used.
>> >>
>> >> Signed-off-by: Jonathan Liu <net147 at gmail.com>
>> >> ---
>> >>  recipes-bsp/bootfiles/rpi-config_git.bb                | 5 +++++
>> >>  recipes-bsp/rpi-u-boot-scr/files/boot.cmd              | 3 +++
>> >>  recipes-bsp/rpi-u-boot-scr/files/raspberrypi/boot.cmd  | 6 ------
>> >>  recipes-bsp/rpi-u-boot-scr/files/raspberrypi0/boot.cmd | 6 ------
>> >>  recipes-bsp/rpi-u-boot-scr/files/raspberrypi2/boot.cmd | 6 ------
>> >>  recipes-bsp/rpi-u-boot-scr/files/raspberrypi3/boot.cmd | 6 ------
>> >>  6 files changed, 8 insertions(+), 24 deletions(-)
>> >>  create mode 100644 recipes-bsp/rpi-u-boot-scr/files/boot.cmd
>> >>  delete mode 100644 recipes-bsp/rpi-u-boot-scr/files/raspberrypi/boot.cmd
>> >>  delete mode 100644 recipes-bsp/rpi-u-boot-scr/files/raspberrypi0/boot.cmd
>> >>  delete mode 100644 recipes-bsp/rpi-u-boot-scr/files/raspberrypi2/boot.cmd
>> >>  delete mode 100644 recipes-bsp/rpi-u-boot-scr/files/raspberrypi3/boot.cmd
>> >>
>> >> diff --git a/recipes-bsp/bootfiles/rpi-config_git.bb b/recipes-bsp/bootfiles/rpi-config_git.bb
>> >> index f610718..2f4d25c 100644
>> >> --- a/recipes-bsp/bootfiles/rpi-config_git.bb
>> >> +++ b/recipes-bsp/bootfiles/rpi-config_git.bb
>> >> @@ -76,6 +76,11 @@ do_deploy() {
>> >>          echo "dispmanx_offline=1" >>${DEPLOYDIR}/bcm2835-bootfiles/config.txt
>> >>      fi
>> >>
>> >> +    # U-Boot Device Tree support
>> >> +    if [ "${KERNEL_IMAGETYPE}" = "uImage" ]; then
>> >> +        sed -i '/#device_tree_address/ c\device_tree_address=0x100' ${DEPLOYDIR}/bcm2835-bootfiles/config.txt
>> >> +    fi
>> >> +
>> >>      # SPI bus support
>> >>      if [ -n "${ENABLE_SPI_BUS}" ] || [ "${PITFT}" = "1" ]; then
>> >>          echo "# Enable SPI bus" >>${DEPLOYDIR}/bcm2835-bootfiles/config.txt
>> >> diff --git a/recipes-bsp/rpi-u-boot-scr/files/boot.cmd b/recipes-bsp/rpi-u-boot-scr/files/boot.cmd
>> >> new file mode 100644
>> >> index 0000000..3f7e3b6
>> >> --- /dev/null
>> >> +++ b/recipes-bsp/rpi-u-boot-scr/files/boot.cmd
>> >> @@ -0,0 +1,3 @@
>> >> +fdt addr ${fdt_addr_r} && fdt get value bootargs /chosen bootargs
>> >> +fatload mmc 0:1 ${kernel_addr_r} uImage
>> >> +bootm ${kernel_addr_r} - ${fdt_addr_r}
>> >>
>> >> <snip deleted files>
>> >
>> > This doesn't work for me.
>> >
>> > On RaspberryPi B+ I get no kernel messages during the boot. I do get a
>> > login prompt though and the boot is successful.
>> >
>> > On RaspberryPi 3 I don't get anything after "Starting kernel ...".
>> >
>> > https://www.raspberrypi.org/documentation/configuration/device-tree.md
>> > says:
>> >
>> >     The base Device Trees are located alongside start.elf in the FAT
>> >     partition (/boot from Linux), named bcm2708-rpi-b.dtb,
>> >     bcm2708-rpi-b-plus.dtb, bcm2708-rpi-cm.dtb, and
>> >     bcm2709-rpi-2-b.dtb.
>> >
>> > In /boot I have:
>> >
>> >     bcm2708-rpi-b.dtb
>> >     bcm2708-rpi-b-plus.dtb
>> >     bcm2709-rpi-2-b.dtb
>> >     bcm2710-rpi-3-b.dtb
>> >
>> > So my guess is that the RaspberryPi 3 isn't loading the right device
>> > tree.
>> >
>> > Is this a problem with start.elf (which we need to report upstream) or
>> > a problem with our DTB file names?
>> >
>> > I'd also say we probably have a problem with bootargs as it doesn't
>> > print out kernel messages during boot.
>> >
>> > What's the benefit of using the device tree cobbled together by
>> > start.elf instead of loading the DTB file ourselves?
>>
>> As I mentioned in the commit:
>> "This allows things like MAC address, board revision and serial number
>> to be correctly configured and options in config.txt to be used."
>>
>> So:
>> - MAC address of ethernet shown by ifconfig
>> - Output of cat /proc/cpuinfo
>>
>> Looks like the config.txt option disables the board model auto
>> detection so the device_tree= config.txt isn't automatically set
>> properly. Probably the U-Boot binary needs to modified by mkknlimg
>> --dtok instead of explicitly setting the device tree address in
>> config.txt. Will look into this later if I have time.
>>
>
> Ah ok, that makes sense.
>
> I'll have a look if there's any way to check which DTB file start.elf is
> picking up.
>
> I thought mkknlimg wasn't required any more though
> (https://github.com/raspberrypi/tools/issues/58). I'm probably just
> hitting up against the not-well-documented bits of the RaspberryPi boot
> process.

You're right. It seems the firmware from 4.4 release onward will
enable device tree by default if there is no trailer present.

Running "vcdbg log msg" shows:
002761.625: Read command line from file 'cmdline.txt'
dwc_otg.lpm_enable=0 console=serial0,115200 root=/dev/mmcblk0p2
rootfstype=ext4 rootwait
002785.056: Loading 'kernel7.img' to 0x8000 size 0x52690
002788.710: No kernel trailer (run mkknlimg to fix) - assuming DT-capable
002791.303: Loading 'bcm2709-rpi-2-b.dtb' to 0x5a690 size 0x3bfc
002869.679: dtparam: pwr_led_gpio=35
002879.048: dtparam: uart0_clkrate=48000000
002969.703: dtparam: arm_freq=900000000
003011.816: dtparam: core_freq=250000000
003022.927: dtparam: cache_line_size=64
003044.337: Device tree loaded to 0x2effbf00 (size 0x40f8)
003047.568: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined
100942.791: vchiq_core: vchiq_init_state: slot_zero = 0xf6c80000, is_master = 1
100947.180: hdmi: HDMI:hdmi_get_state is deprecated, use
hdmi_get_display_state instead
100952.267: TV service:host side not connected, dropping notification
0x00000002, 0x00000002, 0x00000027

I just copied downloaded
https://github.com/raspberrypi/firmware/blob/master/hardfp/opt/vc/bin/vcdbg
and https://github.com/raspberrypi/firmware/blob/master/hardfp/opt/vc/lib/libelftoolchain.so
to my Raspberry Pi and ran "LD_LIBRARY_PATH=. ./vcdbg log msg".

Note the line "002788.710: No kernel trailer (run mkknlimg to fix) -
assuming DT-capable".
Sometime ago the firmware used to load the patched device tree blobs
to 0x100 (which is the default value of fdt_addr_r in newer versions
of U-Boot for Raspberry Pi). It seems to have changed though as can be
seen by the line "003044.337: Device tree loaded to 0x2effbf00 (size
0x40f8)".

Something like this would fix it for Raspberry Pi 2:

diff --git a/recipes-bsp/bootfiles/rpi-config_git.bb
b/recipes-bsp/bootfiles/rpi-config_git.bb
index 2f4d25c..f610718 100644
--- a/recipes-bsp/bootfiles/rpi-config_git.bb
+++ b/recipes-bsp/bootfiles/rpi-config_git.bb
@@ -76,11 +76,6 @@ do_deploy() {
         echo "dispmanx_offline=1" >>${DEPLOYDIR}/bcm2835-bootfiles/config.txt
     fi

-    # U-Boot Device Tree support
-    if [ "${KERNEL_IMAGETYPE}" = "uImage" ]; then
-        sed -i '/#device_tree_address/ c\device_tree_address=0x100'
${DEPLOYDIR}/bcm2835-bootfiles/config.txt
-    fi
-
     # SPI bus support
     if [ -n "${ENABLE_SPI_BUS}" ] || [ "${PITFT}" = "1" ]; then
         echo "# Enable SPI bus" >>${DEPLOYDIR}/bcm2835-bootfiles/config.txt
diff --git a/recipes-bsp/rpi-u-boot-scr/files/boot.cmd
b/recipes-bsp/rpi-u-boot-scr/files/boot.cmd
index 3f7e3b6..201272a 100644
--- a/recipes-bsp/rpi-u-boot-scr/files/boot.cmd
+++ b/recipes-bsp/rpi-u-boot-scr/files/boot.cmd
@@ -1,3 +1,4 @@
+setenv fdt_addr_r 0x2effbf00
 fdt addr ${fdt_addr_r} && fdt get value bootargs /chosen bootargs
 fatload mmc 0:1 ${kernel_addr_r} uImage
 bootm ${kernel_addr_r} - ${fdt_addr_r}

But the device tree address may change in the future and might be
different for each Raspberry Pi model.
I only have Raspberry Pi 2 for development.

Here are some ways to solve this:
- Find out the memory address the blob is loaded to for each model and
use the fdt addr command to try each one until it can parse it
successfully. Likely to break in the future.
- Modify U-Boot to save the device tree address from CPU register r2
in the entry point, then the U-Boot script can try reading the device
tree from that address.
- Get upstream Raspberry Pi firmware to support auto-detection of
board and loading of associated device tree, even when
device_tree_address is set in config.txt

Regards,
Jonathan



More information about the yocto mailing list