uboot_env v0.1.0 UBootEnv

UBootEnv reads a non-replicated U-Boot environment block for storing firmware and provisioning information.

The U-Boot environment format looks like this:

  • CRC32 of bytes 4 through to the end
  • "<key>=<value>" for each key-value pair
  • "" an empty key-value pair to terminate the list. This looks like "" when you're viewing the file in a hex editor.
  • Filler bytes to the end of the environment block. These are usually 0xff.

The U-Boot environment configuration is loaded from /etc/fw_env.config. If you are using OTP >= 21, the contents of the U-Boot environment will be read directly from the device. If not, the code falls back to fw_printenv, but be aware that there's a known issue with values that have embedded newlines.

Link to this section Summary

Functions

Decode a list of fw_env.config key value pairs into a map

Encode a list of key value pairs into the binary form of the U-Boot environment block

Load key-value pairs from U-Boot environment

Read the U-Boot environment into a map or key value pairs

Write a map of key value pairs to the U-Boot environment

Link to this section Functions

Link to this function

decode(env)
decode([String.t()]) :: map()

Decode a list of fw_env.config key value pairs into a map

Link to this function

encode(kv, env_size)
encode(map(), pos_integer()) :: binary()

Encode a list of key value pairs into the binary form of the U-Boot environment block.

Link to this function

load(dev_name, dev_offset, env_size)
load(Path.t(), non_neg_integer(), pos_integer()) ::
  {:ok, map()} | {:error, reason :: binary()}

Load key-value pairs from U-Boot environment

Specify the filename, byte offset and size of the U-Boot environment to load. If you have a fw_env.config file, then consider using read/1 instead.

This function requires OTP 21 or later.

Link to this function

read(config_file \\ nil)
read(Path.t() | nil) :: {:ok, map()} | {:error, reason :: binary()}

Read the U-Boot environment into a map or key value pairs

Optionally specify the path to the fw_env.config file that describes the U-Boot environment block. If unspecified, the default path /etc/fw_env.config will be used.

Link to this function

write(kv, config_file \\ nil)
write(kv :: map(), Path.t() | nil) :: :ok | {:error, reason :: any()}

Write a map of key value pairs to the U-Boot environment

Optionally specify the path to the fw_env.config file that describes the U-Boot environment block.