Skip to contentSkip to conversation

U-Boot environment data as a filesystem

PATCH Applied Andrey Smirnov 2 participants 9 messages Jun 4, 2019 – Jun 7, 2019

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

v2 cover U-Boot environment data as a filesystem

Everyone:

This series adds code needed to expose U-Boot environemnt variable data partition as a regular filesystem in Barebox. It currently only supports the use-case where environment is stored on SD/MMC device, since that is the only use-case I have access to for testing, however adding support for other cases should be relatively straightforward.

Feedback is welcome!

Changes since [v1]:

- ubootvar changed to not rely on struct resource */mem_write/mem_read etc. and use a private pointer instead

- ubootvar changed to handle the case of no valid environment data by allocation parition 0 as empty/new

- Added documentation for ubootvarfs as well as ubootvar DT bindings

Thanks,
Andrey Smirnov

[v1] http://lists.infradead.org/pipermail/barebox/2019-May/038223.html

Andrey Smirnov (6):
filetype: Add "U-Boot environmemnt variable data" filetype
filetype: Allow specifying cdev's filetype explicitly
drivers: Introduce late_platform_driver()
misc: Add a driver to expose U-Boot environment variable data
fs: Add a driver to access U-Boot environment variables
ARM: rdu2: Add U-Boot environment partitions

Cory Tusar (1):
ARM: rdu1: Add U-Boot environment partition

 .../barebox/barebox,uboot-environment.rst     |  43 ++
 Documentation/filesystems/ubootvarfs.rst      |  28 +
 arch/arm/dts/imx51-zii-rdu1.dts               |  21 +
 arch/arm/dts/imx6qdl-zii-rdu2.dtsi            |  27 +
 common/filetype.c                             |   8 +
 drivers/misc/Kconfig                          |  12 +
 drivers/misc/Makefile                         |   1 +
 drivers/misc/ubootvar.c                       | 360 +++++++++++++
 fs/Kconfig                                    |   8 +
 fs/Makefile                                   |   1 +
 fs/ubootvarfs.c                               | 499 ++++++++++++++++++
 include/driver.h                              |   4 +
 include/filetype.h                            |   1 +
 13 files changed, 1013 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/barebox/barebox,uboot-environment.rst
 create mode 100644 Documentation/filesystems/ubootvarfs.rst
 create mode 100644 drivers/misc/ubootvar.c
 create mode 100644 fs/ubootvarfs.c
Signature · 7 lines
2.21.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH v2 1/7 filetype: Add "U-Boot environmemnt variable data" filetype

---
 common/filetype.c  | 2 ++
 include/filetype.h | 1 +
 2 files changed, 3 insertions(+)
common/filetype.c +2 -0
index e2d707b15..429911533 100644
@@ -77,6 +77,8 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_imx_image_v2] = { "i.MX image (v2)", "imx-image-v2" },
 	[filetype_layerscape_image] = { "Layerscape image", "layerscape-PBL" },
 	[filetype_layerscape_qspi_image] = { "Layerscape QSPI image", "layerscape-qspi-PBL" },
+	[filetype_ubootvar] = { "U-Boot environmemnt variable data",
+				"ubootvar" },
 };
 
 const char *file_type_to_string(enum filetype f)
include/filetype.h +1 -0
index dcb331a6c..f1be04e81 100644
@@ -47,6 +47,7 @@ enum filetype {
 	filetype_imx_image_v2,
 	filetype_layerscape_image,
 	filetype_layerscape_qspi_image,
+	filetype_ubootvar,
 	filetype_max,
 };
 
Signature · 7 lines
2.21.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH v2 2/7 filetype: Allow specifying cdev's filetype explicitly

In reply to Andrey Smirnov

Allow specifying cdev's filetype explicitly to support the cases where the type of a cdev is known apriori, yet cannot be determined by reading the cdev's content.

---
 common/filetype.c | 6 ++++++
 include/driver.h  | 2 ++
 2 files changed, 8 insertions(+)
common/filetype.c +6 -0
index 429911533..e4c8005b5 100644
@@ -425,6 +425,11 @@ enum filetype cdev_detect_type(const char *name)
 	if (!cdev)
 		return type;
 
+	if (cdev->filetype != filetype_unknown) {
+		type = cdev->filetype;
+		goto cdev_close;
+	}
+
 	buf = xzalloc(FILE_TYPE_SAFE_BUFSIZE);
 	ret = cdev_read(cdev, buf, FILE_TYPE_SAFE_BUFSIZE, 0, 0);
 	if (ret < 0)
@@ -434,6 +439,7 @@ enum filetype cdev_detect_type(const char *name)
 
 err_out:
 	free(buf);
+cdev_close:
 	cdev_close(cdev);
 	return type;
 }
include/driver.h +2 -0
index 26ec413bd..fe2d30ab5 100644
@@ -22,6 +22,7 @@
 #include <linux/list.h>
 #include <linux/ioport.h>
 #include <of.h>
+#include <filetype.h>
 
 #define FORMAT_DRIVER_NAME_ID	"%s%d"
 
@@ -464,6 +465,7 @@ struct cdev {
 	struct list_head link_entry, links;
 	struct list_head partition_entry, partitions;
 	struct cdev *master;
+	enum filetype filetype;
 };
 
 int devfs_create(struct cdev *);
Signature · 7 lines
2.21.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH v2 3/7 drivers: Introduce late_platform_driver()

In reply to Andrey Smirnov
---
 include/driver.h | 2 ++
 1 file changed, 2 insertions(+)
include/driver.h +2 -0
index fe2d30ab5..300603fa3 100644
@@ -420,6 +420,8 @@ int platform_driver_register(struct driver_d *drv);
 	register_driver_macro(device,platform,drv)
 #define console_platform_driver(drv)	\
 	register_driver_macro(console,platform,drv)
+#define late_platform_driver(drv)	\
+	register_driver_macro(late,platform,drv)
 
 int platform_device_register(struct device_d *new_device);
 
Signature · 7 lines
2.21.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH v2 4/7 misc: Add a driver to expose U-Boot environment variable data

In reply to Andrey Smirnov

Add a driver to expose U-Boot environment variable data as a single mmap-able device, hiding various low-level details such as:

* Preamble format differences
* Read/write logic in presence of redundant partition

Not very useful on its own, it is a crucial low-level plumbing needed by filesystem driver introduced in the following commit.

---
 .../barebox/barebox,uboot-environment.rst     |  43 +++
 drivers/misc/Kconfig                          |  12 +
 drivers/misc/Makefile                         |   1 +
 drivers/misc/ubootvar.c                       | 360 ++++++++++++++++++
 4 files changed, 416 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/barebox/barebox,uboot-environment.rst
 create mode 100644 drivers/misc/ubootvar.c
Documentation/devicetree/bindings/barebox/barebox,uboot-environment.rst new file +43 -0
new file mode 100644
index 000000000..da0ccd2c2
@@ -0,0 +1,43 @@
+U-Boot environment device
+=========================
+
+This driver provides a unified device exposing U-Boot environment
+varaible data, sans the low-level parts. Resulting device is intended
+to be used with corresponding filesystem driver to expose environment
+data as a filesystem.
+
+Required properties:
+
+* ``compatible``: should be ``barebox,uboot-environment``
+* ``device-path``: phandle of the partition the device environment is
+  on (single partiton configuration)
+* ``device-path-0`` and ``device-path-1``: phandle of the partition
+  the environment is on (redundant configuration)
+
+Example:
+
+.. code-block:: none
+
+  environment {
+  	compatible = "barebox,uboot-environment";
+	device-path-0 = &uboot_env_0;
+	device-path-1 = &uboot_env_1;
+  };
+  
+  &usdhc4 {
+	partitions {
+		compatible = "fixed-partitions";
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		uboot_env_0: partition@c0000 {
+			label = "uboot-environment-0";
+			reg = <0xc0000 0x4000>;
+		};
+
+		uboot_env_1: partition@cc800 {
+			label = "uboot-environment-1";
+			reg = <0xcc800 0x4000>;
+		};
+	};
+  };
drivers/misc/Kconfig +12 -0
index 4c8a769c4..0f736f8bd 100644
@@ -23,4 +23,16 @@ config STATE_DRV
 config DEV_MEM
         bool "Generic memory I/O device (/dev/mem)"
 
+config UBOOTVAR
+	bool "U-Boot environment storage"
+	help
+	  This driver exposes U-Boot environment variable storage as a
+	  single mmap-able device, hiding various low-level details
+	  such as:
+	      - Preamble format differences
+	      - Read/write logic in presence of redundant partition
+
+	  While it can be used standalone, it is best when coupled
+	  with corresponding filesystem driver.
+
 endmenu
drivers/misc/Makefile +1 -0
index d4e616d51..bc1c01ea4 100644
@@ -6,3 +6,4 @@ obj-$(CONFIG_JTAG)		+= jtag.o
 obj-$(CONFIG_SRAM)		+= sram.o
 obj-$(CONFIG_STATE_DRV)		+= state.o
 obj-$(CONFIG_DEV_MEM)		+= mem.o
+obj-$(CONFIG_UBOOTVAR)		+= ubootvar.o
drivers/misc/ubootvar.c new file +360 -0

360 lines not on this page · raw message

Signature · 7 lines
2.21.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH v2 5/7 fs: Add a driver to access U-Boot environment variables

In reply to Andrey Smirnov

Add a driver working on top of ubootvar device and exposing U-Boot environment variable data as files.

---
 Documentation/filesystems/ubootvarfs.rst |  28 ++
 fs/Kconfig                               |   8 +
 fs/Makefile                              |   1 +
 fs/ubootvarfs.c                          | 499 +++++++++++++++++++++++
 4 files changed, 536 insertions(+)
 create mode 100644 Documentation/filesystems/ubootvarfs.rst
 create mode 100644 fs/ubootvarfs.c
Documentation/filesystems/ubootvarfs.rst new file +28 -0
new file mode 100644
index 000000000..0433b1294
@@ -0,0 +1,28 @@
+.. index:: ubootvarfs (filesystem)
+
+.. _filesystems_ubootvarfs:
+
+U-Boot environment filesystem
+=============================
+
+barebox supports accessing U-Boot environment contents as a regular
+filesystems in both read and write modes.  U-Boot environment data
+(ubootvar) device supports automount, so no explicit mount command
+should be necessary and accessing the environment should be as easy
+as:
+
+.. code-block:: console
+
+  barebox:/ ls -l /mnt/ubootvar0
+
+However the filesystem can be explicitly mounted with the following
+command:
+
+.. code-block:: console
+
+  barebox:/ mount -t ubootvarfs /dev/device /mnt/path
+
+**NOTE** Current implementation of the filesystem driver uses lazy
+synchronization, any changes made to the environment will not be
+written to the medium until the filesystem is unmounted (will happen
+automatically on Barebox shutdown)
fs/Kconfig +8 -0
index e3a95321c..adf281a5b 100644
@@ -118,4 +118,12 @@ config FS_RATP
 	  This enables support for transferring files over RATP. A host can
 	  export a directory which can then be mounted under barebox.
 
+config FS_UBOOTVARFS
+	bool
+	depends on UBOOTVAR
+	prompt "U-Boot environment variable filesystem support"
+	help
+	  This filesystem driver provides access to U-Boot environment
+	  variables.
+
 endmenu
fs/Makefile +1 -0
index ac3e6a03a..9889a6507 100644
@@ -18,3 +18,4 @@ obj-$(CONFIG_FS_SMHFS) += smhfs.o
 obj-$(CONFIG_FS_PSTORE) += pstore/
 obj-$(CONFIG_FS_SQUASHFS) += squashfs/
 obj-$(CONFIG_FS_RATP)	+= ratpfs.o
+obj-$(CONFIG_FS_UBOOTVARFS) += ubootvarfs.o
fs/ubootvarfs.c new file +499 -0

499 lines not on this page · raw message

Signature · 7 lines
2.21.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH v2 6/7 ARM: rdu2: Add U-Boot environment partitions

In reply to Andrey Smirnov
---
 arch/arm/dts/imx6qdl-zii-rdu2.dtsi | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
arch/arm/dts/imx6qdl-zii-rdu2.dtsi +27 -0
index bfc75ba60..c9a243c22 100644
@@ -47,6 +47,12 @@
 			compatible = "barebox,environment";
 			device-path = &nor_flash, "partname:barebox-environment";
 		};
+
+		ubootenv {
+			compatible = "barebox,uboot-environment";
+			device-path-0 = &uboot_env_0;
+			device-path-1 = &uboot_env_1;
+		};
 	};
 
 	device-info {
@@ -249,6 +255,27 @@
 	dr_mode = "otg";
 };
 
+&usdhc4 {
+	partitions {
+		compatible = "fixed-partitions";
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		/*
+		 * Layout info is taken from /etc/fw_env.config
+		 */
+		uboot_env_0: partition@c0000 {
+			label = "uboot-environment-0";
+			reg = <0xc0000 0x4000>;
+		};
+
+		uboot_env_1: partition@cc800 {
+			label = "uboot-environment-1";
+			reg = <0xcc800 0x4000>;
+		};
+	};
+};
+
 &gpio3 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&pinctrl_gpio3_hog>;
Signature · 7 lines
2.21.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH v2 7/7 ARM: rdu1: Add U-Boot environment partition

In reply to Andrey Smirnov

From: Cory Tusar <[email protected]>

---
 arch/arm/dts/imx51-zii-rdu1.dts | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
arch/arm/dts/imx51-zii-rdu1.dts +21 -0
index 01e46baf2..66d1e0144 100644
@@ -23,6 +23,11 @@
 			compatible = "barebox,environment";
 			device-path = &spinor, "partname:barebox-environment";
 		};
+
+		ubootenv {
+			compatible = "barebox,uboot-environment";
+			device-path = &uboot_env;
+		};
 	};
 
 	aliases {
@@ -61,6 +66,22 @@
 	};
 };
 
+&esdhc1 {
+	partitions {
+		compatible = "fixed-partitions";
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		/*
+		 * Layout info is taken from /etc/fw_env.config
+		 */
+		uboot_env: partition@c0000 {
+			label = "uboot-environment";
+			reg = <0xc0000 0x20000>;
+		};
+	};
+};
+
 &mdio_gpio {
 	switch: switch@0 {};
 };
Signature · 7 lines
2.21.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer Applied
#8 lore raw
In reply to Andrey Smirnov
Quoted 16 lines · Andrey Smirnov

Everyone:

This series adds code needed to expose U-Boot environemnt variable data partition as a regular filesystem in Barebox. It currently only supports the use-case where environment is stored on SD/MMC device, since that is the only use-case I have access to for testing, however adding support for other cases should be relatively straightforward.

Feedback is welcome!

Changes since [v1]:

- ubootvar changed to not rely on struct resource */mem_write/mem_read etc. and use a private pointer instead

Quoted 8 lines

- ubootvar changed to handle the case of no valid environment data by allocation parition 0 as empty/new

- Added documentation for ubootvarfs as well as ubootvar DT bindings

Thanks,
Andrey Smirnov

Applied, thanks

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox