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>
First reason is because index/rindex aren't present in Bionic C library.
Also, per the man page [1]:
"marked as LEGACY in POSIX.1-2001. POSIX.1-2008 removes the
specifications of index() and rindex(), recommending strchr(3) and
strrchr(3) instead."
[1] https://man7.org/linux/man-pages/man3/index.3.html
Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com>
Add description of the fw_setenv script syntax
v2:
* mention that lines without '=' are ignored
* remove the incompatibily note
* aligned README.md with the usage help of fw_setenv
* mention that part of the original U-Boot syntax is not supporte
* add --help and --version in the usage help messages
Signed-off-by: Domenico Andreoli <domenico.andreoli@linux.com>
The attribute of the a hex flag is 'x' iso 'h'.
The type attributes are:
s - String (default)
d - Decimal
x - Hexadecimal
b - Boolean ([1yYtT|0nNfF])
i - IP address
m - MAC address
It's correct though throughout the rest of the code.
Signed-off-by: Bartel Eerdekens <bartel.eerdekens@constell8.be>
strlen(flagsvar) is re-evaluated on each while-loop iteration.
As \0 string terminators are added, the loop ends prematurely,
stopping after the first introduced \0 string terminator.
Signed-off-by: Bartel Eerdekens <bartel.eerdekens@constell8.be>
Signed-off-by: Stefano Babic <sbabic@denx.de>
Some flashes have issue by locking/unlocking. The additional flag in
configuration file allows to disable the LOCK/UNLOCK mechanism in MTD.
Signed-off-by: Stefano Babic <sbabic@denx.de>
libuboot_set_env() already tests if '=' is in variable name and returns -EINVAL
in this case.
Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com>
Acked-by: Stefano Babic <sbabic@denx.de>
Before this patch, it was possible to do the following:
fw_setenv '' foo
Which leads to having this in the environment:
=foo
Which in turns causes U-Boot to throw error when parsing environment.
Now, if the above command is given, an error code is returned and environment is
not modified.
Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com>
Acked-by: Stefano Babic <sbabic@denx.de>
Library is using crc32(), therefore needs to link against zlib.
Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
Reviewed-by: Stefano Babic <sbabic@denx.de>
Currently fsync() only gets called at the end of fileprotect(), which
only occurs on mmcblk devices. I am storing a U-Boot environment inside
a fat32 filesystem, so the fsync() call does not get hit, and so the new
environment may be lost if power is lost.
Instead always fsync after the write has completed, regardless of the
device type.
Signed-off-by: Brandon Maier <brandon.maier@rockwellcollins.com>
Acked-by: Stefano Babic <sbabic@denx.de>
U-Boot's setenv command has treated '=' as an illegal character since
2006[1]. Per the original commit there is some form of backdoor when
doing commands like 'setenv ethaddr=', which it seems reasonable for us
to avoid.
For me, I have problems with users accidentally running `fw_setenv
var=value` (as it's a common idiom in shell scripting) and fw_setenv
prints no error as it thinks user wanted to delete a variable named
'var=value'.
Detect and return an error in libuboot_set_env(). Also detect in
fw_setenv() so we can print a user-friendly error message.
[1] 471a7be7a0
Signed-off-by: Brandon Maier <brandon.maier@rockwellcollins.com>
Acked-by: Stefano Babic <sbabic@denx.de>
* Adjust calculated usable envsize in case redundand environment is used.
Signed-off-by: Sava Jakovljev <sava.jakovljev@teufel.de>
Acked-by: Stefano Babic <sbabic@denx.de>
libuboot_configure() fails to initialise dev->offset from the envdevs
structure and also doesn't setup ctx->size as happens in
libuboot_read_config(); use the same logic as exists there.
Signed-off-by: Alex Kiernan <alexk@zuma.ai>
Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Before commit ed1a53ec "Dont store to device if no value changes" it was
possible to fill an uninitialized or broken environment using the
command "fw_setenv -f <default-environment-file>". This was considered
to be a feature.
The problem occurs because fw_setenv will now skip writing the
environment in case no environment variables to be changed are passed to
fw_setenv.
This commit will fix this problem by always storing the environment if
loading the environment failed and a default environment was given.
Signed-off-by: Wang Xin <xin.wang7@cn.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
Acked-by: Stefano Babic <sbabic@denx.de>
ctx->size would be correct from start of struct / environment,
however usable environment payload starts from data header (offsetdata)
Signed-off-by: Manuel Dipolt <manuel.dipolt@robart.cc>
Acked-by: Stefano Babic <sbabic@denx.de>
Environment lines are terminated with a single null byte, followed
by another null byte to terminate the env itself. Fix termination
in case where flags need saving.
Signed-off-by: Sami Hartikainen <sami.hartikainen@teleste.com>
If the U-Boot environment configuration file fw_env.config happens
to have specified a length larger than the actual file's size, the
result is an infinite loop. Hence, check read()'s return value for
being 0, meaning EOF, and return an error.
Signed-off-by: Christian Storm <christian.storm@siemens.com>
Acked-by: Stefano Babic <sbabic@denx.de>
Trying to use fw_printenv/fw_setenv with
/sys/bus/i2c/devices/0-0050/eeprom always fails for me:
$ fw_printenv
Cannot read environment, using default
Cannot read default environment from file
$
The problem is that fileread() and filewrite() in src/uboot_env.c
read/write once, and callers treat it as error if they did read/write
fewer bytes than requested.
In C it is not an error if fewer bytes get read/written than requested,
the caller is supposed to retry with the remaining bytes until everything
is done or an error occurs.
Signed-off-by: Adrian Bunk <bunk@stusta.de>