[PATCH V2] nvmem: add driver handling U-Boot environment variables

Rafał Miłecki zajec5 at gmail.com
Wed May 4 22:46:34 PDT 2022


On 4.05.2022 11:23, Ahmad Fatoum wrote:
> Hello Rafał,
> 
> On 03.05.22 18:56, Rafał Miłecki wrote:
>> From: Rafał Miłecki <rafal at milecki.pl>
>>
>> U-Boot stores its setup as environment variables. It's a list of
>> key-value pairs stored on flash device with a custom header.
>>
>> This commit adds an NVMEM driver that:
>> 1. Provides NVMEM access to environment vars binary data
>> 2. Extracts variables as NVMEM cells
>>
>> It can be used for:
>> 1. Accessing env variables from user-space
> 
> Is this already possible? The only interface I know of is the /nvmem
> file in sysfs, but that one is not per cell, but per device.

Maybe that wasn't precise enough, I should probably write:
1. Parsing binary data from user-space

In future I'd like to extend U-Boot's "printenv" tool to support reading
env variables blob using Linux's sysfs as documented in the
Documentation/ABI/stable/sysfs-bus-nvmem


>> +	label = of_get_property(np->parent, "label", NULL);
>> +	if (!label)
>> +		label = np->parent->name;
>> +
>> +	priv->mtd = get_mtd_device_nm(label);
>> +	if (IS_ERR(priv->mtd)) {
>> +		dev_err(dev, "Failed to find \"%s\" MTD device: %ld\n", label, PTR_ERR(priv->mtd));
>> +		return PTR_ERR(priv->mtd);
>> +	}
> 
> I am trying to make sense of this using the binding, but I can't.
> Do you have an example device tree fragment?

This comes from unreleased yet board I'm working on.

It stores U-Boot env variables in the middle of U-Boot binary.

partitions {
	compatible = "fixed-partitions";
	#address-cells = <1>;
	#size-cells = <1>;

	partition at 0 {
		label = "loader";
		reg = <0x0 0x100000>;

		partition at 40000 {
			compatible = "u-boot,env";
			label = "u-boot-env";
			reg = <0x40000 0x4000>;
		};
	};

	partition at 100000 {
		label = "image";
		reg = <0x100000 0x1fe00000>;
	};
};



More information about the linux-mtd mailing list