epoch1970
Posts: 2994
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: 2219
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: 307
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: 2994
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: 307
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: 2994
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: 2994
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
[email protected] {
        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>;
        [email protected] {
                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 [email protected]:

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     
[email protected] {
        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>;
        [email protected] {
                status = "okay";
                reg = <0x0000004d>;
                compatible = "ti,pcm5122";
                #sound-dai-cells = <0x00000000>;
        };
};
Loading the missing overlay separately.
[email protected] 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  
[email protected] {
        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>;
        [email protected] {
                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: 2219
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: 2994
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: 2219
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: 2994
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: 2219
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: 2994
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

openJeremy
Posts: 1
Joined: Sat Sep 01, 2018 8:52 am

Re: Overlays and A/B rootfs?

Mon Sep 03, 2018 1:55 pm

Hi Epoch1970:

I just wanted to thank you for your answer to my post about OpenVPN and dnsmasq / Great firewall of China.

The original post is gone (it's unclear why it was deleted but it's gone and I have to thank you someplace else) but I had the time to get the link you shared. Merci!

openJeremy - now getting back to work

ahb
Posts: 1
Joined: Thu Dec 27, 2018 4:07 pm

Re: Overlays and A/B rootfs?

Thu Dec 27, 2018 5:01 pm

epoch1970 wrote:
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.
Hi Epoch1970,

I'm currently going down the same rabbit hole, in my case to combine RAUC in A/B mode with the Raspberry Pi. Would you mind to share your u-boot script / setup?

The hints in this thread were already very helpful.

However, I'm still having several issues, e.g. working around the dtparam mechanism to enable I2C and SPI.
Update: The following simple overlay can substitute dtparam=i2c_arm=on (unfortunately, the aliases are not available, thus i2c1 is hardcoded):

Code: Select all

/dts-v1/;

/plugin/;
/{
        compatible = "brcm,bcm2708";
        [email protected] {
                target = <&i2c1>;
                __overlay__ {
                        status = "okay";
                };
        };
};
It would still be great, if you could share your u-boot script :)

Best regards,
Andreas

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

Re: Overlays and A/B rootfs?

Tue Jan 01, 2019 11:31 am

There is nothing to share, just the idea (if it is one)

If you know how the Debian utility “run-parts” works, you can have a good idea of the solution I implemented: a bunch of scriptlet files that are read in order, the last one being called something like “99-boot” and this one has the uboot boot command in it.
The other ones have “fdt” commands in them.

How to find the right commands? I run a base config.txt and print the dt in uboot, then modify config.txt, compare the dt. For what I have seen, a single “fdt set something somewhere” is enough to replicate the effect obtained from the target config.txt.
So it is purely manual hunt and peck style, but it works fine for me.

(I don’t know RAUC and the version of Hush it packs, but the limiting factor in doing a “run-parts” equivalent is indeed the shell’s capabilities.)
"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”