mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Konstantin Kletschke <konstantin.kletschke@inside-m2m.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: Howto implement bootchooser <-> rauc interaction
Date: Wed, 22 Dec 2021 15:05:07 +0100	[thread overview]
Message-ID: <YcMwk6mncQ8fSwTJ@Hephaistos> (raw)
In-Reply-To: <YbyczaAWK6juc0VO@Hephaistos>

I switched from doing the state in the onboard EEPROM (as said, it
is write protected in production use) to save the state in a dead space
in the onboard eMMC chip between MBR and first partition:

/ {
	aliases {
		state = &state_eeprom;
	};

	state_eeprom: state_eeprom {
		#address-cells = <1>;
		#size-cells = <1>;
		compatible = "barebox,state";
		magic = <0xcafebabe>;
		backend-type = "raw";
		backend = <&backend_state_mmc2>;
		backend-storage-type = "direct";
		backend-stridesize = <54>;
		last_chosen {
			reg = <0x0 0x4>;
			type = "uint32";
		};
		system0 {
			#address-cells = <1>;
			#size-cells = <1>;
			remaining_attempts {
				reg = <0x4 0x4>;
				type = "uint32";
				default = <3>;
			};
			priority {
				reg = <0x8 0x4>;
				type = "uint32";
				default = <21>;
			};
			ok {
				reg = <0xc 0x4>;
				type = "uint32";
				default = <0>;
			};
		};
		system1 {
			#address-cells = <1>;
			#size-cells = <1>;
			remaining_attempts {
				reg = <0x10 0x4>;
				type = "uint32";
				default = <3>;
			};
			priority {
				reg = <0x14 0x4>;
				type = "uint32";
				default = <20>;
			};
			ok {
				reg = <0x18 0x4>;
				type = "uint32";
				default = <0>;
			};
		};
	};
};

&mmc2 {
	backend_state_mmc2: part@1000 {
		label = "state";
		reg = <0x1000 0x1000>;
	};
};

This looks good so far:

barebox boot-up excerpt:

mmc1: detected MMC card version 5.1
mmc1: registered mmc1
state: New state registered 'state'
state: Using bucket 0@0x00000000

devinfo state:

Parameters:
  dirty: 0 (type: bool)
  init_from_defaults: 0 (type: bool)
  last_chosen: 2 (type: uint32)
  save_on_shutdown: 1 (type: bool)
  system0.ok: 0 (type: uint32)
  system0.priority: 21 (type: uint32)
  system0.remaining_attempts: 0 (type: uint32)
  system1.ok: 0 (type: uint32)
  system1.priority: 20 (type: uint32)
  system1.remaining_attempts: 1 (type: uint32)

bootchooser -i:

Good targets (first will be booted next):
system1
    id: 2
    priority: 20
    default_priority: 1
    remaining attempts: 1
    default attempts: 3
    boot: 'system1'

Disabled targets:
system0
    id: 1
    priority: 21
    default_priority: 1
    remaining attempts: 0
    default attempts: 3
    boot: 'system0'
    disabled due to remaining attempts = 0

last booted target: system1

Compiled in (relevant) variables:

* boot.default: bootchooser insidem2m_1 insidem2m_2
  boot.watchdog_timeout: 0
  bootchooser.default_attempts: 3
  bootchooser.default_priority: 1
  bootchooser.disable_on_zero_attempts: 0
  bootchooser.reset_attempts:  (list: "power-on", "all-zero")
  bootchooser.reset_priorities: 
  bootchooser.retry: 0
* bootchooser.state_prefix: state
* bootchooser.targets: system0 system1

devinfo excerpt:

            `-- 481d82fc.target-module@d8000.of
               `-- 481d8000.mmc@0.of
                  `-- mmc1
                     `-- 0x00000000-0xe3ffffff (   3.6 GiB): /dev/mmc1
                     `-- 0x00100000-0x010fffff (    16 MiB): /dev/mmc1.0
                     `-- 0x01100000-0x4ddfffff (   1.2 GiB): /dev/mmc1.1
                     `-- 0x4de00000-0x9aafffff (   1.2 GiB): /dev/mmc1.2
                     `-- 0x9ab00000-0xe3ffffff (   1.1 GiB): /dev/mmc1.3
                     `-- 0x00001000-0x00001fff (     4 KiB): /dev/mmc1.state
                     `-- fat0

boot:

Booting entry 'bootchooser'
Booting entry 'system1'
ext4 ext40: EXT2 rev 1, inode_size 256, descriptor size 64
mounted /dev/mmc1.2 on /mnt/mmc1.2
[...]


The userspace is no amused, however:

rauc status output:

(rauc:583): rauc-WARNING **: 18:51:57.389: Failed getting primary slot: Failed getting primary slot: No content to read

=== System Info ===
Compatible:  insidem2m-s
Variant:
Booted from: rootfs.1 (system1)

=== Bootloader ===
Activated: (null) ((null))

=== Slot States ===
o [rootfs.1] (/dev/mmcblk0p3, ext4, booted)
	bootname: system1
	mounted: /
	boot status: bad

o [rootfs.0] (/dev/mmcblk0p2, ext4, inactive)
	bootname: system0
	boot status: bad


/etc/rauc/system.conf:

[system]
compatible=insidem2m-s
bootloader=barebox

[keyring]
path=ca.cert.pem

[slot.rootfs.0]
device=/dev/mmcblk0p2
type=ext4
bootname=system0

[slot.rootfs.1]
device=/dev/mmcblk0p3
type=ext4
bootname=system1


barebox-state:

last_chosen=2
system0.remaining_attempts=0
system0.priority=21
system0.ok=0
system1.remaining_attempts=2
system1.priority=20
system1.ok=0


So rauc is not happy, is somethong wrong with the system.conf?


################ PLAN B ##################

I had a previous state device tree setup, which made userspace happy,
but not barebox. I had a parent bootstate section containing system0 and
system1:

/ {
	aliases {
		state = &state_eeprom;
	};

	state_eeprom: state_eeprom {
		#address-cells = <1>;
		#size-cells = <1>;
		compatible = "barebox,state";
		magic = <0xcafebabe>;
		backend-type = "raw";
		backend = <&backend_state_mmc2>;
		backend-storage-type = "direct";
		backend-stridesize = <54>;
		bootstate {
			#address-cells = <1>;
			#size-cells = <1>;
			last_chosen {
				reg = <0x0 0x4>;
				type = "uint32";
			};
			system0 {
				#address-cells = <1>;
				#size-cells = <1>;
				remaining_attempts {
					reg = <0x4 0x4>;
					type = "uint32";
					default = <3>;
				};
				priority {
					reg = <0x8 0x4>;
					type = "uint32";
					default = <21>;
				};
				ok {
					reg = <0xc 0x4>;
					type = "uint32";
					default = <0>;
				};
			};
			system1 {
				#address-cells = <1>;
				#size-cells = <1>;
				remaining_attempts {
					reg = <0x10 0x4>;
					type = "uint32";
					default = <3>;
				};
				priority {
					reg = <0x14 0x4>;
					type = "uint32";
					default = <20>;
				};
				ok {
					reg = <0x18 0x4>;
					type = "uint32";
					default = <0>;
				};
			};
		};
	};
};

&mmc2 {
	backend_state_mmc2: part@1000 {
		label = "state";
		reg = <0x1000 0x1000>;
	};
};

With this device tree barebox bootschooser is unhappy:

barebox@TI AM335x BeagleBone black:/ devinfo state
Parameters:
  bootstate.last_chosen: 2 (type: uint32)
  bootstate.system0.ok: 0 (type: uint32)
  bootstate.system0.priority: 21 (type: uint32)
  bootstate.system0.remaining_attempts: 0 (type: uint32)
  bootstate.system1.ok: 0 (type: uint32)
  bootstate.system1.priority: 20 (type: uint32)
  bootstate.system1.remaining_attempts: 2 (type: uint32)
  dirty: 0 (type: bool)
  init_from_defaults: 0 (type: bool)
  save_on_shutdown: 1 (type: bool)
barebox@TI AM335x BeagleBone black:/ boot
WARNING: bootchooser: Cannot read priority for target system0, using default 1
WARNING: bootchooser: Cannot read remaining attempts for target system0, using default 3
WARNING: bootchooser: Cannot read priority for target system1, using default 1
WARNING: bootchooser: Cannot read remaining attempts for target system1, using default 3
Cannot set parameter state.system0.remaining_attempts: No such device
ERROR: bootchooser: Failed to save bootchooser state: No such device
Booting entry 'bootchooser'
WARNING: bootchooser: Cannot read priority for target system0, using default 1
WARNING: bootchooser: Cannot read remaining attempts for target system0, using default 3
WARNING: bootchooser: Cannot read priority for target system1, using default 1
WARNING: bootchooser: Cannot read remaining attempts for target system1, using default 3
Cannot set parameter state.last_chosen: No such device
Cannot set parameter state.system0.remaining_attempts: No such device
Booting entry 'system0'
ext4 ext40: EXT2 rev 1, inode_size 256, descriptor size 64
mounted /dev/mmc1.1 on /mnt/mmc1.1
[...]

But userspace is fine:

rauc-Message: 18:58:50.111: rauc status: marked slot rootfs.0 as good

rauc status:

=== System Info ===
Compatible:  insidem2m
Variant:
Booted from: rootfs.0 (system0)

=== Bootloader ===
Activated: rootfs.0 (system0)

=== Slot States ===
  [bootloader.0] (/dev/mmcblk0p1, vfat, inactive)

o [rootfs.1] (/dev/mmcblk0p3, ext4, inactive)
	bootname: system1
	boot status: good

x [rootfs.0] (/dev/mmcblk0p2, ext4, booted)
	bootname: system0
	mounted: /
	boot status: good


barebox-state -d:

bootstate.last_chosen=2
bootstate.system0.remaining_attempts=3
bootstate.system0.priority=21
bootstate.system0.ok=0
bootstate.system1.remaining_attempts=2
bootstate.system1.priority=20
bootstate.system1.ok=0


I assume this has to do with bootchooser.state_prefix. If I change from
state to bootstate (yes, brute force) I get:

global excerpt:

* bootchooser.state_prefix: bootstate

devinfo state looks the same as previous.

boot:

barebox@TI AM335x BeagleBone black:/ boot
ERROR: bootchooser: Cannot get state 'bootstate'
Nothing bootable found on 'bootchooser'
Booting entry 'insidem2m_1'
ext4 ext40: EXT2 rev 1, inode_size 256, descriptor size 64
mounted /dev/mmc1.1 on /mnt/mmc1.1
[...]



When I set:

* bootchooser.state_prefix: state.bootstate

I get best of both worlds!

"devinfo state" still the same as previous two cases (logical, since DT
setup is the same, only bootchooser.state_prefix changed), "bootchooser
-i" looks sane, booting happens w/o any error, and userspace
(barebox-state -d, rauc status, barebox-state -g bootstate.system0.ok)
too!

Wall of text, two questions:

Is this resulting setup (DT with bootstate parent, state_prefix:
state.bootstate) sane?

Can the variant without the boostate variant work too? If it was the
other way around, userspace working w/o the bootstate variant but bnot
_with_ I would say additional configuration required or something, but
this way... I would like to understand this fully.


Kind Regards
Konstantin


-- 
INSIDE M2M GmbH
Konstantin Kletschke
Berenbosteler Straße 76 B
30823 Garbsen

Telefon: +49 (0) 5137 90950136
Mobil: +49 (0) 151 15256238
Fax: +49 (0) 5137 9095010

konstantin.kletschke@inside-m2m.de
http://www.inside-m2m.de 

Geschäftsführung: Michael Emmert, Ingo Haase, Dr. Fred Könemann, Derek Uhlig
HRB: 111204, AG Hannover


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2021-12-22 14:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-03 12:40 Konstantin Kletschke
2021-12-03 17:52 ` Trent Piepho
2021-12-05 22:55   ` Roland Hieber
2021-12-06  8:52     ` Konstantin Kletschke
2021-12-14 21:40     ` Konstantin Kletschke
2021-12-15 10:56       ` Ahmad Fatoum
2021-12-16 19:35         ` Konstantin Kletschke
2021-12-17 10:00           ` Ahmad Fatoum
2021-12-17 12:50             ` Konstantin Kletschke
2022-01-03 15:24         ` Roland Hieber
2021-12-06  8:30   ` Konstantin Kletschke
2021-12-14 21:28   ` Konstantin Kletschke
2021-12-15 10:50     ` Ahmad Fatoum
     [not found]       ` <297b3425baa118783dccb6446900fbfa@inside-m2m.de>
2021-12-16 19:42         ` Fwd: " Konstantin Kletschke
2021-12-17  9:46           ` Ahmad Fatoum
2021-12-17 12:43             ` Konstantin Kletschke
2021-12-17 13:08               ` Ahmad Fatoum
2021-12-17 14:21                 ` Konstantin Kletschke
2021-12-22 14:05                   ` Konstantin Kletschke [this message]
2022-01-05 17:50                     ` Ahmad Fatoum
2022-01-06  9:59                       ` Konstantin Kletschke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YcMwk6mncQ8fSwTJ@Hephaistos \
    --to=konstantin.kletschke@inside-m2m.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox