epoch1970
Posts: 1646
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Overlays and A/B rootfs?

Fri Jun 08, 2018 2:02 pm

I would like to setup a system with A/B OTA updating, using u-Boot.
I'm aiming to have only a few invariant files in the FAT partition, and most files in /boot on partitions A or B, so that an update can include kernel and overlays.
Eg. in mmcblk0p1 (FAT, /)

Code: Select all

bootcode.bin config.txt (minimal config) cmdline.txt fixup.dat start.elf kernel7.img (is really u-boot.bin)
and in mmcblk0p2 (ext4, /boot):

Code: Select all

bcm2710-rpi-3-b.dtb config.txt (full config) boot.scr uImage overlays/
I'm fairly unclear about the way DT files/config.txt work and when they are used (system start, kernel launch, ...)
Is it possible to override an initial config.txt with another one?
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1733
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Overlays and A/B rootfs?

Fri Jun 08, 2018 2:17 pm

Although there are multiple boot methods, they all(*) boil down to:
1) Locate and load bootcode.bin
2) Load config.txt
3) Load start*.elf
4) Load config.txt (yes, start.elf effectively starts from scratch w.r.t. config.txt)
5) Load the kernel (which can be U-boot) and cmdline.txt
6) Load the DTB and any overlays
7) Launch the kernel

The firmware only understands FAT16/32/VFAT, so loading data from other file systems, including ext4, will have to be done by the kernel/U-boot.
If you want to support overlays in the environment you propose then either U-boot has to be extended to support them OR you have to apply the overlays offline and boot using the combined DTB.

(*) NOOBS has one other (weird) trick - after 7 it can force a reboot, which takes you back to step 1 having first changed the number of the boot partition.

feelslikeautumn
Posts: 224
Joined: Wed Aug 09, 2017 9:51 pm

Re: Overlays and A/B rootfs?

Fri Jun 08, 2018 8:06 pm

Uboot can apply overlays.

As I understand it uboot can use the dtb passed to it by the pi firmware, or it can load its own.


epoch1970
Posts: 1646
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Overlays and A/B rootfs?

Fri Jun 08, 2018 8:35 pm

Thanks!

I found this: viewtopic.php?f=107&t=134018#p1167030
and it looks like what I want is to undo that nice feature of automatic DTB passing from start.elf to u-boot...

I don't think I can 'include' because only u-boot knows what is to be included -the A/B thing-, and /boot is on ext4. The way I understand it, start.elf handles config.txt, having it read A/boot/moreconfig.txt would be too far, too early.

So yes, have u-boot apply overlays itself (having parsed config.txt on the side, probably at update packaging time)... If someone had an example related to loading base dtb + overlays on a Pi, that would be great.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

feelslikeautumn
Posts: 224
Joined: Wed Aug 09, 2017 9:51 pm

Re: Overlays and A/B rootfs?

Fri Jun 08, 2018 10:08 pm

A lot of config.txt seems to me to be just converted to kernel command line boot parameters. I wonder if the boot parameters could be just used on their own, without the config.txt entries? Also is the config.txt really going to be different between A/B? Could the A/B boot contents be copied to different directories on the FAT partition?


epoch1970
Posts: 1646
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Overlays and A/B rootfs?

Sat Jun 09, 2018 9:25 am

Thanks for the link. That looks manageable.
As to copying stuff to VFAT or only changing command-line, this might well be a practical way of doing what I want; but I fear adding parameters to command-line could not be enough in some cases, and copying to VFAT would be very adverse to system reliability.

By how much A and B could differ? By one text file or by the complete OS. Ideally you could add or replace a HAT on the Pi, and pull a new system that would make use of it. U-boot + swupdate + Hawkbit, that is the grandiose plan. And now I will try to find out why my u-boot compile conks out suddenly...
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

epoch1970
Posts: 1646
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Status = "okay"?

Tue Jun 12, 2018 2:48 pm

So I'm trying to see what should be done to apply a supplemental config.txt or overlays residing outside partition 1 to the rpi3 device tree.

I had hopes the stock device tree would show signs of distress when an overlay is not found in /overlays, but overall it always feels okay: if start.elf finds an option it seems to generate nodes with status = "okay" even when there is an obvious problem.

So I can't really start by looking at the tree and patching it. (= configs in partition 1, overlays mostly elsewhere)
I could load bcm2710-rpi-3.dtb and start from scratch. But parsing (my)config.txt doesn't sound like a lot of fun.
Is there a way to reuse existing code?

Thanks in advance.

PS: some test results.
Comparing Device Trees on a Pi3 without HAT with another wearing a HAT (a justboom amp FWIW)
config.txt includes "dtoverlay=justboom-dac,24db_digital_gain"

With overlay present in FAT, without the HAT.
HAT node not created, but everything else is "okay":

Code: Select all

U-Boot> fdt print /hat
libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND
U-Boot> fdt print sound
sound {
        i2s-controller = <0x00000021>;
        compatible = "justboom,justboom-dac";
        justboom,24db_digital_gain;
        status = "okay";
        phandle = <0x00000072>;
};
U-Boot> fdt print i2c
i2c@7e804000 {
        compatible = "brcm,bcm2835-i2c";
        reg = <0x7e804000 0x00001000>;
        interrupts = <0x00000002 0x00000015>;
        clocks = <0x00000008 0x00000014>;
        #address-cells = <0x00000001>;
        #size-cells = <0x00000000>;
        status = "okay";
        pinctrl-names = "default";
        pinctrl-0 = <0x00000014>;
        clock-frequency = <0x000186a0>;
        phandle = <0x00000024>;
        pcm5122@4d {
                status = "okay";
                CPVDD-supply = <0x00000075>;
                DVDD-supply = <0x00000075>;
                AVDD-supply = <0x00000075>;
                reg = <0x0000004d>;
                compatible = "ti,pcm5122";
                #sound-dai-cells = <0x00000000>;
        };
};
With the HAT and overlay in FAT.
Same same except for the HAT:

Code: Select all

U-Boot> fdt print /hat
hat {
        uuid = "f4519dd2-c591-4708-b135-000000xxxxxx";
        product_ver = "0x0101";
        product_id = "0x0003";
        product = "JustBoom Amp HAT v1.1";
        vendor = "JustBoom";
};
With the HAT but overlay missing from FAT.
Still "okay" but the parameter 24bit_gain is missing, and so are entries related to power suppy in pcm5122@4d:

Code: Select all

U-Boot> fdt print sound
sound {
        i2s-controller = <0x00000021>;
        compatible = "justboom,justboom-dac";
        status = "okay";
        phandle = <0x00000072>;
};
U-Boot> fdt print i2c     
i2c@7e804000 {
        compatible = "brcm,bcm2835-i2c";
        reg = <0x7e804000 0x00001000>;
        interrupts = <0x00000002 0x00000015>;
        clocks = <0x00000008 0x00000014>;
        #address-cells = <0x00000001>;
        #size-cells = <0x00000000>;
        status = "okay";
        pinctrl-names = "default";
        pinctrl-0 = <0x00000014>;
        clock-frequency = <0x000186a0>;
        phandle = <0x00000024>;
        pcm5122@4d {
                status = "okay";
                reg = <0x0000004d>;
                compatible = "ti,pcm5122";
                #sound-dai-cells = <0x00000000>;
        };
};
Loading the missing overlay separately.
Pcm5122@4d gets populated but the 24db_digital_gain option is missing (haven't tried passing it):

Code: Select all

U-Boot> fdt print sound
sound {
        i2s-controller = <0x00000021>;
        compatible = "justboom,justboom-dac";
        status = "okay";
        phandle = <0x00000077>;
};
U-Boot> fdt print i2c  
i2c@7e804000 {
        compatible = "brcm,bcm2835-i2c";
        reg = <0x7e804000 0x00001000>;
        interrupts = <0x00000002 0x00000015>;
        clocks = <0x00000008 0x00000014>;
        #address-cells = <0x00000001>;
        #size-cells = <0x00000000>;
        status = "okay";
        pinctrl-names = "default";
        pinctrl-0 = <0x00000014>;
        clock-frequency = <0x000186a0>;
        phandle = <0x00000024>;
        pcm5122@4d {
                CPVDD-supply = <0x00000075>;
                DVDD-supply = <0x00000075>;
                AVDD-supply = <0x00000075>;
                status = "okay";
                reg = <0x0000004d>;
                compatible = "ti,pcm5122";
                #sound-dai-cells = <0x00000000>;
        };
};
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1733
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Overlays and A/B rootfs?

Tue Jun 12, 2018 2:57 pm

I had hopes the stock device tree would show signs of distress when an overlay is not found in /overlays, but overall it always feels okay: if start.elf finds an option it seems to generate nodes with status = "okay" even when there is an obvious problem.

So I can't really start by looking at the tree and patching it. (= configs in partition 1, overlays mostly elsewhere)
I could load bcm2710-rpi-3.dtb and start from scratch. But parsing (my)config.txt doesn't sound like a lot of fun.
Is there a way to reuse existing code?
I understand all the words and your English is good, but I'm not sure I understand what you are really asking. Please tell me what you would like to happen, then I might understand.
Comparing Device Trees on a Pi3 without HAT with another wearing a HAT [...]
The HAT EEPROM for the JustBoom DAC includes a copy of the overlay, albeit a slightly older one without the 24bit_gain parameter, so the firmware doesn't try to load it from the FAT partition. Does this explain your findings?

epoch1970
Posts: 1646
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Overlays and A/B rootfs?

Tue Jun 12, 2018 5:06 pm

Ha. I was at the conclusion of a long reply, "In my previous post I was ..." and then I finally understood what I was :)

So in summary, in u-boot I can do this:

Code: Select all

fatload mmc 0:1 0x02008000 /bcm2710-rpi-3-b.dtb
fdt resize 0x7000
ext4load mmc 0:2 0x0100 /boot/jb-dac.dtbo
fdt apply 0x100
boot
and it works fine. I have to see how to inject a parameter like the 24db_gain thing, but I don't expect a problem there (...)

Then what I need then is an uboot script that will read a list of overlays and options, and apply them.
No need to parse the existing config.txt format indeed, I can come up with my own format/setup.

I hope this makes more sense. (You can be rude, I'm French.)
Thanks again!
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1733
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Overlays and A/B rootfs?

Tue Jun 12, 2018 7:19 pm

I have to see how to inject a parameter like the 24db_gain thing, but I don't expect a problem there (...)
I think that may prove to be more of a problem. The parameters are a Pi-specific extension, so I doubt U-boot will support them (but I've been wrong about U-boot before so who knows?).

epoch1970
Posts: 1646
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Overlays and A/B rootfs?

Tue Jun 12, 2018 8:09 pm

I can "ftd set sound justboom,24db_digital_gain" and get something like that:

Code: Select all

sound {
        justboom,24db_digital_gain;
        i2s-controller = <0x00000021>;
        compatible = "justboom,justboom-dac";
        status = "okay";
        phandle = <0x00000072>;
};
So at least it looks like what would come from start.elf... I'll compare start.elf-built DTs with and without this parameter and see where the changes are.
(24db gain, who invented that anyway!)
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1733
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Overlays and A/B rootfs?

Tue Jun 12, 2018 8:19 pm

Yes, that works - you can just do "manually" what the overlay parameters would have done once applied.

epoch1970
Posts: 1646
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Overlays and A/B rootfs?

Tue Jun 12, 2018 8:26 pm

Excellent. A bespoke hush shell script will implement that, uboot will call it at boot. Problem solved. I think.
Thanks again.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Return to “Device Tree”

Who is online

Users browsing this forum: No registered users and 4 guests