Increase LINE_LENGTH from 1024 to 2048 because nowadays for some
boards U-Boot CONFIG_SYS_CBSIZE (and CONFIG_SYS_PBSIZE respectively)
is greater than 1024. This leads to truncating longer lines which
can be fatal in specific cases, for example with a long bootcmd.
Signed-off-by: Leon Anavi <leon.anavi@konsulko.com>
Acked-by: Stefano Babic <stefano.babic@swupdate.org>
In U-Boot, it is possible to list which variables could be changed via
CONFIG_ENV_WRITEABLE_LIST. This was not supported by this library, but
it does not raise a security leak. In fact, U-Boot will simply discard
if a variable is not in the list. However, in user space any variable
can be set, and the output of fw_printenv is not what the bootloader
really accepts. This patch fills the gap and let add (just for YML
configuration) a list of variables that can be set and their flags. The
default policy is that all variables are accepted, exactly as it is done
in U-Boot, and check is done only if the list is found in the
configuration file.
Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
If UBI_IOCATT was called while the attachment was already in progress
we may get an EEXIST error.
If this happens get the ubi_num with ubi_get_dev_id_from_mtd instead.
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Acked-by: Stefano Babic <stefano.babic@swupdate.org>
FreeBSD and other BSDs have not defined u{8,32,64}, so use their
stdint.h pendants.
This is in the BSD #ifdef path providing a shim for MTD which
is not available on BSDs anyway.
Signed-off-by: Christian Storm <christian.storm@siemens.com>
Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
consume_event() is only used locally in the same compilation
unit and needn't be exported.
Signed-off-by: Christian Storm <christian.storm@siemens.com>
In cases where the env is in an unattached UBI volume we may need
to specify the volume name via the MTD path to attach.
For this to work correctly we should first scan for any already
attached UBI devices to see if they correspond to the mtd partition
number in our configuration, if no corresponding attached mtd devices
are found we should attempt to ubiattach to the configured MTD path.
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Move code from fw_printenv to library. libuboot_namespace_from_dt looks
into DT and reads the namespace for the bootloader, if any.
Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
Suggested-by: Frieder Schrempf <frieder.schrempf@kontron.de>
Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>
The bootloader might be able to tell us where the currently used
environment is located. Use the string from the
"/chosen/u-boot,env-config" devicetree property as namespace
selector if available.
Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
Reviewed-by: Stefano Babic <stefano.babic@swupdate.org>
Using strtoull() is unreliable for testing if the input is a number. It
is implementation-defined, whether or not errno is set.
Furthermore, the decimal type has to be handled separately from the hex
type. U-Boot will reject an "0x10" entry as decimal, "16" is expected
instead.
Reviewed-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Philip Oberfichtner <pro@denx.de>
value should start with the '0' character, corresponding to 0x30. Before
this patch we checked for 0x00 instead.
Reviewed-by: Stefano Babic <sbabic@denx.de>
Signed-off-by: Philip Oberfichtner <pro@denx.de>
This reverts commit 44ecc1c216.
mtd writesize was errouneously interpreted as maximum allowed size, but
it is the minimum size. The patch raises performance issues because on
NOR flashes single bytes are written.
Signed-off-by: Stefano Babic <sbabic@denx.de>
This helps the caller to identify the version of the running version of
libubootenv. It returns a pointer to a static structure. Applications
should use this information to judge if things are possible to do or not,
instead of using compile-time checks, as libraries loaded via dlopen()
can be changed independent from the application.
Signed-off-by: Stefano Babic <sbabic@denx.de>
Make transition to new API simpler. Older application can still call
libuboot_read_config() as in the past. This function requires to have a
valid context as input.
Newer applications just call libuboot_read_config_ext(struct uboot_env
**ctx). It gets the pointer to an array of ctx. Allocation is done by
the libuboot_read_config_ext(9 function.
Old API:
// Allocate ctx
struct uboot_env *ctx;
libuboot_initialize(&ctx);
libuboot_read_config(ctx, configfile);
New API:
struct uboot_env *ctx;
libuboot_read_config_ext(&ctx, configfile);
Signed-off-by: Stefano Babic <sbabic@denx.de>
Tested-by: Joris Offouga <offougajoris@gmail.com>
CI with focal reports:
/builds/swupdate/swupdate/libubootenv/src/uboot_env.c:1247:4: error:
a label can only be part of a statement and a declaration is not a statement
1247 | struct uboot_ctx *newctx;
Just move the declaration at the beginning of the function.
Signed-off-by: Stefano Babic <sbabic@denx.de>
Now that we might have set name and lockfile of the
structure, we need to free these fields, too.
It should also not be assumed that the list start is passed
as pointer.
Signed-off-by: Michael Heimpold <mhei@heimpold.de>
Acked-by: Stefano Babic <sbabic@denx.de>
According to the documentation, the function returns zero on success,
else a negative value.
However, at the moment the return value of parse_yaml_config might
also be passed through which can be FAILURE (define as 1).
So map this one to a generic -1 and pass all other as-is
to match the documented API.
Signed-off-by: Michael Heimpold <mhei@heimpold.de>
Acked-by: Stefano Babic <sbabic@denx.de>
Now that it is possible to define a custom lockfile via YAML configuration
let's use it when it is appropriate.
Signed-off-by: Michael Heimpold <mhei@heimpold.de>
Acked-by: Stefano Babic <sbabic@denx.de>
Legacy configuration file was taken by U-Boot project. Its format is
very simple, but unflexible and it cannot be extended. Changes in the
format could lead to uncompatibility with U-Boot tools, that are still
part of U-Boot.
This introduces a new format, letting the old format as fallback if YAML
cannot be parsed. It uses the libyaml library.
Multiple sets can be configured - an environment is not bound with the
bootloader, and can be used for other purposes, but still having the
features provided by the handling for the bootloader (redundancy,
power-cut safe).
See documentation for the format of the yaml file. Each not recognized
keyword generates an error.
Signed-off-by: Stefano Babic <sbabic@denx.de>
Instead of compiling the same source file twice, just
add a symlink at install time. This is how the "original"
tools also worked.
It also reduces the storage footprint.
Signed-off-by: Michael Heimpold <mhei@heimpold.de>
While at, remove .gitignore self from the list since it does not
make sense to ignore these files when it is recommended a few lines
above to add subdirectory files where appropriate.
Signed-off-by: Michael Heimpold <mhei@heimpold.de>
For headings, apply Title Case.
For the tables remove abbreviations and apply consistent spacing around.
Also use Title Case for the heading line.
Signed-off-by: Michael Heimpold <mhei@heimpold.de>
While reading over the doxygen generated output I stumpled
over a few minor things, eg. typos, HTML-like tags which
do not make it into the final HTML output and other minor
stuff.
Signed-off-by: Michael Heimpold <mhei@heimpold.de>
Avoid to hard-code configuration and environment files, allow them to
be configurable during build. This is usefull when some end users want
to distinguish these files at build time rather than run time with
command parameters.
Signed-off-by: Ming Liu <liu.ming50@gmail.com>
Reviewed-by: Stefano Babic <sbabic@denx.de>
Some SPI flash have a write size that is different (smaller) than the
sector size. For example, the sst25vf016b has an erase size of 4096,
but a write size of 1 byte. For this flash device, the write()
function will be called with a size equal to the sector size of 4096,
and the return value will incorrectly be set to 4096, indicating that
4096 bytes have been written to the device. However, after inspecting
the flash content, only the first byte is written to the device, and
the remaining 4095 bytes are all 0xFF.
Fix this incorrect behavior by adapting mtdwrite() to use the write
size obtained from the MEMGETINFO ioctl when writing data.
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Reviewed-by: Stefano Babic <sbabic@denx.de>
- adding libubootenv as vendor dynamic library
- adding fw_printenv and fw_setenv as vendor binaries
- as Android uses clang, a few warning flags are needed:
- Wno-pointer-arith for all the buffer address assignments
- Wno-switch for the flagstype missing default/NONE case
- Wno-date-time to allow __DATE__ usage
- using same license as CMake files (LGPLv2.1+)
Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com>