Skip to content

Commit 273eb3c

Browse files
committed
conditional: Document the new expression filter and new Pi5 boot variables
1 parent 5780e46 commit 273eb3c

File tree

2 files changed

+100
-8
lines changed

2 files changed

+100
-8
lines changed

documentation/asciidoc/computers/config_txt/conditional.adoc

+83-6
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Some models of Raspberry Pi, including Zero, Compute Module, and Keyboard models
9797
The `[none]` filter prevents any settings that follow from being applied to any hardware. Although there is nothing that you can't do without `[none]`, it can be a useful way to keep groups of unused settings in config.txt without having to comment out every line.
9898

9999
=== The `[partition=N]` filter
100-
This `partition` filter can be be used to select alternate boot flows according to the requested partition number (`sudo reboot N`) or via direct usage of the `PM_RSTS` watchdog register.
100+
This `partition` filter can be used to select alternate boot flows according to the requested partition number (`sudo reboot N`) or via direct usage of the `PM_RSTS` watchdog register.
101101

102102
[source,ini]
103103
----
@@ -123,19 +123,96 @@ cmdline=cmdline-recovery.txt
123123

124124
The raw value of the `PM_RSTS` register at bootup is available via `/proc/device-tree/chosen/bootloader/rsts` and the final partition number used for booting is available via `/proc/device-tree/chosen/bootloader/partition`. These are big-endian binary values.
125125

126-
=== The `[boot_partition=N]` filter
127-
The `boot_partition` filter can be used to select alternate OS files (e.g. `cmdline.txt`) to be loaded, depending on which partition `config.txt` was loaded from after processing `autoboot.txt`. This is intended for use with an `A/B` boot-system with `autoboot.txt` where it is desirable to be able to have identical files installed to the boot partition for both the `A` and `B` images.
126+
=== The expression filter
128127

129-
Example `config.txt` - select the matching root filesystem for the `A/B` boot file-system.
128+
The expression filter provides support for comparing unsigned integer `boot variables` with constants using a simple set of expressions. It is intended to support OTA update mechanisms, debug and test.
129+
130+
* The `boot variables` are `boot_count`, `boot_arg1`, `boot_partition` and `partition`.
131+
* Boot variables in the expressions case must always be lower case.
132+
* Constants may be written as decimal or as hex.
133+
* Expression conditional filters have no side-effects e.g. no assignment operators.
134+
* As with other filter types the expression filter cannot be nested.
135+
* Use the `[all]` filter to reset expressions and all other conditional filter types.
136+
137+
Syntax:
138+
[source,ini]
139+
----
140+
# ARG is a boot-variable
141+
# VALUE is an integer constant
142+
[ARG=VALUE] # selected if (ARG == VALUE)
143+
[ARG&MASK] # selected if ((ARG & VALUE) != 0)
144+
[ARG&MASK=VALUE] # selected if ((ARG & MASK) == VALUE)
145+
[ARG<VALUE] # selected if (ARG < VALUE)
146+
[ARG>VALUE] # selected if (ARG > VALUE)
147+
148+
----
149+
150+
=== `boot_arg1`
151+
Raspberry Pi 5 and newer flagship devices only.
152+
153+
`boot_arg1` is a 32-bit user defined value which stored in a reset-safe register allowing parameters can be passed accross a reboot.
154+
155+
Setting `boot_arg1` to 42 via `config.txt`:
130156
[source,ini]
131157
----
158+
set_reboot_arg1=42
159+
----
160+
161+
Setting `boot_arg1` to 42 via vcmailbox:
162+
[source,console]
163+
----
164+
sudo vcmailbox 0x0003808c 8 8 1 42
165+
----
166+
167+
Reading `boot_arg1` via vcmailbox:
168+
[source,console]
169+
----
170+
sudo vcmailbox 0x0003008c 8 8 1 0
171+
# Example output - boot_arg1 is 42
172+
# 0x00000020 0x80000000 0x0003008c 0x00000008 0x80000008 0x00000001 0x0000002a 0x0000000
173+
174+
The value of the `boot_arg1` variable when the OS was started can be read via xref:configuration.adoc#part4[device-tree] at `/proc/device-tree/chosen/bootloader/arg1`
175+
----
176+
177+
=== `boot_count`
178+
Raspberry Pi 5 and newer flagship devices only.
179+
180+
`boot_count` variable is an 8-bit value that is incremented (wrapping back to zero at 256) at boot and is reset to zero by a power on reset.
181+
182+
To read `boot_count` via vcmailbox:
183+
[source,console]
184+
----
185+
sudo vcmailbox 0x0003008d 4 4 0
186+
# Example - boot count is 3
187+
# 0x0000001c 0x80000000 0x0003008d 0x00000004 0x80000004 0x00000003 0x00000000
188+
----
189+
190+
Setting/clearing `boot_count` via vcmailbox:
191+
[source,console]
192+
----
193+
# Clear boot_count by setting it to zero.
194+
sudo vcmailbox 0x0003808d 4 4 0
195+
----
196+
The value of `boot_count` at when the OS was started can be read via xref:configuration.adoc#part4[device-tree] at `/proc/device-tree/chosen/bootloader/count`
197+
198+
==== `boot_partition`
199+
The `boot_partition` variable can be used to select alternate OS files (e.g. `cmdline.txt`) to be loaded, depending on which partition `config.txt` was loaded from after processing `autoboot.txt`. This is intended for use with an `A/B` boot-system with `autoboot.txt` where it is desirable to be able to have identical files installed to the boot partition for both the `A` and `B` images.
200+
201+
The value of the `boot_partition` can be different to the `partition` variable because the required `partition` can be overriden by `autoboot.txt`.
202+
203+
Example `config.txt` - select the matching root filesystem for the `A/B` boot file-system:
204+
[source,ini]
205+
----
206+
# Use different cmdline files to point to different root filesystems based on which partition the system booted from.
132207
[boot_partition=1]
133-
cmdline=cmdline_rootfs_a.txt
208+
cmdline=cmdline_rootfs_a.txt # Points to root filesystem A
134209
135210
[boot_partition=2]
136-
cmdline=cmdline_rootfs_b.txt
211+
cmdline=cmdline_rootfs_b.txt # Points to root filesystem B
137212
----
138213

214+
The value of `boot_partition` i.e. the partition used to boot the OS can be read from device-tree at `/proc/device-tree/chosen/bootloader/partition`
215+
139216
=== The `[tryboot]` filter
140217

141218
This filter succeeds if the `tryboot` reboot flag was set.

documentation/asciidoc/computers/configuration/device-tree.adoc

+17-2
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,14 @@ For a list of supported overlays and parameters, see the https://github.com/rasp
833833
[[part4]]
834834
=== Firmware parameters
835835

836-
The firmware uses the special https://www.kernel.org/doc/html/latest/devicetree/usage-model.html#runtime-configuration[/chosen] node to pass parameters between the bootloader and/or firmware and the operating system. Each property is stored as a 32-bit integer unless indicated otherwise.
836+
The firmware uses the special https://www.kernel.org/doc/html/latest/devicetree/usage-model.html#runtime-configuration[/chosen] node to pass parameters between the bootloader and/or firmware and the operating system. Each property is stored as a 32-bit unsigned integer unless indicated otherwise.
837+
838+
Numbers in device-tree are stored in binary and are big-endian.
839+
[source,console]
840+
----
841+
# Example shell script for reading a 32-bit unsigned number from device-tree
842+
printf "%d" "0x$(od "/proc/device-tree/chosen/bootloader/partition" -v -An -t x1 | tr -d ' ' )"
843+
----
837844

838845
`overlay_prefix`:: _(string)_ The xref:config_txt.adoc#overlay_prefix[overlay_prefix] string selected by `config.txt`.
839846

@@ -859,9 +866,17 @@ Each property is stored as a 32-bit integer unless indicated otherwise.
859866

860867
`tryboot`:: Set to `1` if the `tryboot` flag was set at boot.
861868

869+
==== Boot variables `/chosen/bootloader`
870+
871+
Raspberry Pi 5 only. Each property is stored as a 32-bit unsigned integer unless indicated otherwise.
872+
873+
`arg1`:: The value of the user defined reboot argument from the previous boot. See xref:config_txt.adoc#boot_arg1[boot_arg1]
874+
875+
`count`:: The value of the 8-bit `boot_count` variable when the OS was started. See xref:config_txt.adoc#boot_count[boot_count]
876+
862877
==== Power supply properties `/chosen/power`
863878

864-
Raspberry Pi 5 only. Each property is stored as a 32-bit integer unless indicated otherwise.
879+
Raspberry Pi 5 only. Each property is stored as a 32-bit unsigned integer unless indicated otherwise.
865880

866881
`max_current`:: The maximum current in mA that the power supply can supply. The firmware reports the value indicated by the USB-C, USB-PD or PoE interfaces. For bench power supplies (e.g. connected to the GPIO header) define `PSU_MAX_CURRENT` in the bootloader configuration to indicate the power supply current capability.
867882

0 commit comments

Comments
 (0)