Skip to contentSkip to conversation

Expose RPi4's bootloader configuration

PATCH Applied Nicolas Saenz Julienne 3 participants 9 messages Jan 12, 2021 – Jan 25, 2021

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v3 cover Expose RPi4's bootloader configuration

Soon to be released versions of RPi4's firmware will take of care passing their bootloader's configuration[1] to the OS by copying it into memory and creating a reserved memory node in the board's DT. By modeling this reserved memory node as an nvmem device using 'nvmem-rmem', which this series introduces, user-space applications will be able to query this information through nvmem's sysfs interface.

An alternative approach, less nice IMO, would be to create a platform-specific 'soc' driver.

Regards,
Nicolas

[1] https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711_bootloader_config.md

---

Changes since v2:
- Fix DT bingins

Changes since v1:
- Avoid the reserved-memory indirection by integrating the nvmem driver into the reserved memory node.

Nicolas Saenz Julienne (5):
dt-bindings: nvmem: Add bindings for rmem driver
nvmem: Add driver to expose reserved memory as nvmem
ARM: dts: bcm2711: Add reserved memory template to hold firmware
configuration
arm64: defconfig: Enable nvmem's rmem driver
ARM: multi_v7_defconfig: Enable nvmem's rmem driver

 .../devicetree/bindings/nvmem/rmem.yaml       | 49 ++++++++++
 arch/arm/boot/dts/bcm2711-rpi-4-b.dts         | 17 ++++
 arch/arm/configs/multi_v7_defconfig           |  1 +
 arch/arm64/configs/defconfig                  |  1 +
 drivers/nvmem/Kconfig                         |  8 ++
 drivers/nvmem/Makefile                        |  2 +
 drivers/nvmem/rmem.c                          | 97 +++++++++++++++++++
 drivers/of/platform.c                         |  1 +
 8 files changed, 176 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/rmem.yaml
 create mode 100644 drivers/nvmem/rmem.c
Signature · 1 line
2.29.2
#1 lore raw

PATCH v3 1/5 dt-bindings: nvmem: Add bindings for rmem driver

Firmware/co-processors might use reserved memory areas in order to pass data stemming from an nvmem device otherwise non accessible to Linux. For example an EEPROM memory only physically accessible to firmware, or data only accessible early at boot time.

Introduce the dt-bindings to nvmem's rmem.

---

Changes since v2:
- Run yamllint and fix indentation issues

Changes since v1:
- Update schema to new driver design

 .../devicetree/bindings/nvmem/rmem.yaml       | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/rmem.yaml
Documentation/devicetree/bindings/nvmem/rmem.yaml new file +49 -0
new file mode 100644
index 000000000000..1d85a0a30846
@@ -0,0 +1,49 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/rmem.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Reserved Memory Based nvmem Device
+
+maintainers:
+  - Nicolas Saenz Julienne <[email protected]>
+
+allOf:
+  - $ref: "nvmem.yaml#"
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - raspberrypi,bootloader-config
+      - const: nvmem-rmem
+
+  no-map:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description:
+      Avoid creating a virtual mapping of the region as part of the OS'
+      standard mapping of system memory.
+
+required:
+  - compatible
+  - no-map
+
+unevaluatedProperties: false
+
+examples:
+  - |
+        reserved-memory {
+                #address-cells = <1>;
+                #size-cells = <1>;
+
+                blconfig: nvram@10000000 {
+                        compatible = "raspberrypi,bootloader-config", "nvmem-rmem";
+                        #address-cells = <1>;
+                        #size-cells = <1>;
+                        reg = <0x10000000 0x1000>;
+                        no-map;
+                };
+        };
+
+...
Signature · 1 line
2.29.2
maintainer Reviewed-by on v3 1/5
#2 lore raw

Re: [PATCH v3 1/5] dt-bindings: nvmem: Add bindings for rmem driver

Quoted 14 lines · Nicolas Saenz Julienne

Firmware/co-processors might use reserved memory areas in order to pass data stemming from an nvmem device otherwise non accessible to Linux. For example an EEPROM memory only physically accessible to firmware, or data only accessible early at boot time.

Introduce the dt-bindings to nvmem's rmem.

---

Changes since v2:
- Run yamllint and fix indentation issues

Quoted 7 lines

Changes since v1:
- Update schema to new driver design

 .../devicetree/bindings/nvmem/rmem.yaml       | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/rmem.yaml
#3 lore raw

PATCH v3 2/5 nvmem: Add driver to expose reserved memory as nvmem

In reply to Nicolas Saenz Julienne

Firmware/co-processors might use reserved memory areas in order to pass data stemming from an nvmem device otherwise non accessible to Linux. For example an EEPROM memory only physically accessible to firmware, or data only accessible early at boot time.

In order to expose this data to other drivers and user-space, the driver models the reserved memory area as an nvmem device.

---

Changes since v1:
- Remove reserved memory phandle indirection by directly creating a platform device from the reserved memory DT node
- Only map memory upon reading it to avoid corruption
- Small cosmetic cleanups

 drivers/nvmem/Kconfig  |  8 ++++
 drivers/nvmem/Makefile |  2 +
 drivers/nvmem/rmem.c   | 97 ++++++++++++++++++++++++++++++++++++++++++
 drivers/of/platform.c  |  1 +
 4 files changed, 108 insertions(+)
 create mode 100644 drivers/nvmem/rmem.c
drivers/nvmem/Kconfig +8 -0
index 954d3b4a52ab..fecc19b884bf 100644
@@ -270,4 +270,12 @@ config SPRD_EFUSE
 	  This driver can also be built as a module. If so, the module
 	  will be called nvmem-sprd-efuse.
 
+config NVMEM_RMEM
+	tristate "Reserved Memory Based Driver Support"
+	help
+	  This drivers maps reserved memory into an nvmem device. It might be
+	  useful to expose information left by firmware in memory.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem-rmem.
 endif
drivers/nvmem/Makefile +2 -0
index a7c377218341..5376b8e0dae5 100644
@@ -55,3 +55,5 @@ obj-$(CONFIG_NVMEM_ZYNQMP)	+= nvmem_zynqmp_nvmem.o
 nvmem_zynqmp_nvmem-y		:= zynqmp_nvmem.o
 obj-$(CONFIG_SPRD_EFUSE)	+= nvmem_sprd_efuse.o
 nvmem_sprd_efuse-y		:= sprd-efuse.o
+obj-$(CONFIG_NVMEM_RMEM) 	+= nvmem-rmem.o
+nvmem-rmem-y			:= rmem.o
drivers/nvmem/rmem.c new file +97 -0

97 lines not on this page · raw message

drivers/of/platform.c +1 -0
index 79bd5f5a1bf1..6699cdbe58b6 100644
@@ -511,6 +511,7 @@ static const struct of_device_id reserved_mem_matches[] = {
 	{ .compatible = "qcom,rmtfs-mem" },
 	{ .compatible = "qcom,cmd-db" },
 	{ .compatible = "ramoops" },
+	{ .compatible = "nvmem-rmem" },
 	{}
 };
 
Signature · 1 line
2.29.2
#4 lore raw

PATCH v3 3/5 ARM: dts: bcm2711: Add reserved memory template to hold firmware configuration

In reply to Nicolas Saenz Julienne

RPi4's co-processor will copy the board's bootloader[1] configuration into memory for the OS to consume. Specifically, for the bootloader configuration and upgrade user-space routines to query it through nvmem's sysfs interface.

Introduce a reserved-memory area template for the co-processor to edit before booting the system so as for Linux not to overwrite that memory and to expose it as an nvmem device.

[1] https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711_bootloader_config.md
---

Changes since v1:
- Introduce compatible string
- Change alias name to something more explicit

 arch/arm/boot/dts/bcm2711-rpi-4-b.dts | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
arch/arm/boot/dts/bcm2711-rpi-4-b.dts +17 -0
index 403bacf986eb..3b4ab947492a 100644
@@ -25,6 +25,7 @@ aliases {
 		emmc2bus = &emmc2bus;
 		ethernet0 = &genet;
 		pcie0 = &pcie0;
+		blconfig = &blconfig;
 	};
 
 	leds {
@@ -218,6 +219,22 @@ &pwm1 {
 	status = "okay";
 };
 
+&rmem {
+	/*
+	 * RPi4's co-processor will copy the board's bootloader configuration
+	 * into memory for the OS to consume. It'll also update this node with
+	 * its placement information.
+	 */
+	blconfig: nvram@0 {
+		compatible = "raspberrypi,bootloader-config", "nvmem-rmem";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		reg = <0x0 0x0 0x0>;
+		no-map;
+		status = "disabled";
+	};
+};
+
 /* SDHCI is used to control the SDIO for wireless */
 &sdhci {
 	#address-cells = <1>;
Signature · 1 line
2.29.2
#5 lore raw

PATCH v3 4/5 arm64: defconfig: Enable nvmem's rmem driver

In reply to Nicolas Saenz Julienne

It'll be used by the RPi4 family of boards to access its bootloader configuration.

---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index 9957b6669eb1..81b2418f7f72 100644
@@ -1077,6 +1077,7 @@ CONFIG_ROCKCHIP_EFUSE=y
 CONFIG_NVMEM_SUNXI_SID=y
 CONFIG_UNIPHIER_EFUSE=y
 CONFIG_MESON_EFUSE=m
+CONFIG_NVMEM_RMEM=m
 CONFIG_FPGA=y
 CONFIG_FPGA_MGR_STRATIX10_SOC=m
 CONFIG_FPGA_BRIDGE=m
Signature · 1 line
2.29.2
#6 lore raw

PATCH v3 5/5 ARM: multi_v7_defconfig: Enable nvmem's rmem driver

In reply to Nicolas Saenz Julienne

It'll be used by the RPi4 family of boards to access its bootloader configuration.

---
 arch/arm/configs/multi_v7_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/multi_v7_defconfig +1 -0
index 6492a3601e7c..0914fa09af0c 100644
@@ -1106,6 +1106,7 @@ CONFIG_ROCKCHIP_EFUSE=m
 CONFIG_NVMEM_SUNXI_SID=y
 CONFIG_NVMEM_VF610_OCOTP=y
 CONFIG_MESON_MX_EFUSE=m
+CONFIG_NVMEM_RMEM=m
 CONFIG_FSI=m
 CONFIG_FSI_MASTER_GPIO=m
 CONFIG_FSI_MASTER_HUB=m
Signature · 1 line
2.29.2
#7 lore raw
In reply to Nicolas Saenz Julienne
Quoted 24 lines · Nicolas Saenz Julienne

Soon to be released versions of RPi4's firmware will take of care passing their bootloader's configuration[1] to the OS by copying it into memory and creating a reserved memory node in the board's DT. By modeling this reserved memory node as an nvmem device using 'nvmem-rmem', which this series introduces, user-space applications will be able to query this information through nvmem's sysfs interface.

An alternative approach, less nice IMO, would be to create a platform-specific 'soc' driver.

Regards,
Nicolas

[1] https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711_bootloader_config.md

---

Changes since v2:
- Fix DT bingins

Changes since v1:
- Avoid the reserved-memory indirection by integrating the nvmem driver into the reserved memory node.

Quoted 8 lines

Nicolas Saenz Julienne (5):
dt-bindings: nvmem: Add bindings for rmem driver
nvmem: Add driver to expose reserved memory as nvmem
ARM: dts: bcm2711: Add reserved memory template to hold firmware
configuration
arm64: defconfig: Enable nvmem's rmem driver
ARM: multi_v7_defconfig: Enable nvmem's rmem driver

Thanks Applied (1/5) and (2/5), rest of patches should go via arm-soc tree!

--srini

Quoted 12 lines
  .../devicetree/bindings/nvmem/rmem.yaml       | 49 ++++++++++
  arch/arm/boot/dts/bcm2711-rpi-4-b.dts         | 17 ++++
  arch/arm/configs/multi_v7_defconfig           |  1 +
  arch/arm64/configs/defconfig                  |  1 +
  drivers/nvmem/Kconfig                         |  8 ++
  drivers/nvmem/Makefile                        |  2 +
  drivers/nvmem/rmem.c                          | 97 +++++++++++++++++++
  drivers/of/platform.c                         |  1 +
  8 files changed, 176 insertions(+)

create mode 100644 Documentation/devicetree/bindings/nvmem/rmem.yaml create mode 100644 drivers/nvmem/rmem.c

author Applied
#8 lore raw
In reply to Nicolas Saenz Julienne
Quoted 7 lines · Nicolas Saenz Julienne

Soon to be released versions of RPi4's firmware will take of care passing their bootloader's configuration[1] to the OS by copying it into memory and creating a reserved memory node in the board's DT. By modeling this reserved memory node as an nvmem device using 'nvmem-rmem', which this series introduces, user-space applications will be able to query this information through nvmem's sysfs interface.

Quoted 8 lines

An alternative approach, less nice IMO, would be to create a platform-specific 'soc' driver.

Regards,
Nicolas

[1] https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711_bootloader_config.md

Applied patches #3 to #5 for next.

Regards,
Nicolas

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel