Switching to realpath to detect where the environment is stored
generates much longer filenames. Increase the maximum size to 256.
Signed-off-by: Stefano Babic <sbabic@denx.de>
Some platform uses softlinks to the devices that hold environment
data. The mechanism used to read device type from config is not robust
in this case. Calculating the canonicalized absolute pathname of the
device could fix the problem.
Signed-off-by: Mathias Thore <mathias.thore@atlascopco.com>
Signed-off-by: Ming Liu <liu.ming50@gmail.com>
The return value from lseek is not checked correctly, causing that the
environment is not read or written if an offset is set.
Signed-off-by: Stefano Babic <sbabic@denx.de>
When fw_setenv is called, it could happen that the new value is same
with the old one, in which case, we should avoid storing data to
device.
Signed-off-by: Ming Liu <liu.ming50@gmail.com>
Double close: caller of mtdread() is responsible to close the file
descriptor, remove close() calls from mtdread.
Signed-off-by: Stefano Babic <sbabic@denx.de>
This used to work in the fw-utils based on U-Boot itself.
Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>
Reviewed-by: Stefano Babic <sbabic@denx.de>
The UBI_IOCVOLUP ioctl expects a __s64*, however the struct
uboot_flash_env.envsize is of type size_t, which depending on the
architecture may be only 4 bytes long and cause the ioctl to read a
bogus size value. This fixes this by converting the size_t envsize to
a int64_t and passing a ptr to that to the ioctl.
Signed-off-by: Markus Klotzbuecher <mk@mkio.de>
Acked-by: Stefano Babic <sbabic@denx.de>
Port of U-Boot commit f4742ca0fb94 ("allow negative offsets"):
==========
A negative value for the offset is treated as a backwards offset for
from the end of the device/partition for block devices. This aligns
the behavior of the config file with the syntax of CONFIG_ENV_OFFSET
where the functionality has been introduced with
commit 5c088ee841f9 ("env_mmc: allow negative CONFIG_ENV_OFFSET").
Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
==========
Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
Acked-by: Stefano Babic <sbabic@denx.de>
Sector size is in fw_env.config, but it could be redundant because the
value can be detected at runtime via ioctl().
Signed-off-by: Stefano Babic <sbabic@denx.de>
The list is not released in the close and this cause a segfault if the
same context is reused (as it is supposed to be). Segfault does not
happen if the context is released and a new one is created.
Signed-off-by: Stefano Babic <sbabic@denx.de>
Environment size must be set (it was optional for old tools). Skip all
configuration line without a correct value for the environment size.
Signed-off-by: Stefano Babic <sbabic@denx.de>
Use GNUInstallDirs to get the path where to install artifacts. This
solves the issue with OE if multilib is set.
Signed-off-by: Stefano Babic <sbabic@denx.de>
Create a libubootenv.pc file for pkg-config. Allows to use
PKG_CHECK_MODULE in autoconf-based projects or :
ubootenv_dep = dependency('libubootenv', version : '>= 0.2')
for meson build system.
Fixes:
$: meson build
The Meson build system
Cross C compiler: arm-poky-linux-gnueabi-gcc ...
[...]
Cross dependency libubootenv found: NO (tried pkgconfig)
With this commit:
$: meson builld
The Meson build system
Cross C compiler: arm-poky-linux-gnueabi-gcc ...
[...]
Cross dependency libubootenv found: YES 0.2
Build targets in project: 1
Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
This allows linking from C++ applications without the need of using
extern "C" when including libuboot header file.
This follows the guide line of many other libraries.
Fixes:
foo.cpp:(.text+0x19) : undefined reference to « libuboot_initialize(uboot_ctx**, uboot_env_device*) »
...
Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
libubootenv/src/uboot_env.c: In function ‘fileprotect’:
libubootenv/src/uboot_env.c:557:3: warning: ignoring return value of ‘write’,
declared with attribute warn_unused_result [-Wunused-result]
write(fd_force_ro, &c_unprot_char, 1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libubootenv/src/uboot_env.c:560:3: warning: ignoring return value of ‘write’,
declared with attribute warn_unused_result [-Wunused-result]
write(fd_force_ro, &c_prot_char, 1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libubootenv/src/uboot_env.c: In function ‘check_env_device.isra.4’:
libubootenv/src/uboot_env.c:44:30: warning: ‘__builtin___sprintf_chk’ may write
a terminating nul past the end of the destination [-Wformat-overflow=]
#define SYS_UBI_VOLUME_NAME "/sys/class/ubi/ubi%d/ubi%d_%d/name"
^
libubootenv/src/uboot_env.c:44:30: note: in definition of macro ‘SYS_UBI_VOLUME_NAME’
#define SYS_UBI_VOLUME_NAME "/sys/class/ubi/ubi%d/ubi%d_%d/name"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/stdio.h:862:0,
from libubootenv/src/uboot_env.c:17:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:33:10:
note: ‘__builtin___sprintf_chk’ output between 32 and 61 bytes into a destination of size 40
return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Stefano Babic <sbabic@denx.de>
In the function ubi_get_vol_id, when we search the volume id
with the volume name, we try all id from 0 to num_volume. But
the volume id may be greater than the actual number of volume.
To avoid this issue, we try all the id from 0 to 128 (max ubi
volume id).
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Some block devices support physical write protection. The kernel
provides a standard interface to enable or disable protection in
/sys/class/block/*/force_ro.
This patch adds functionality to automatically detect these memory
types. If read-only mode is enabled on the partition on which the
uboot environment must be written, libubootenv temporarily switches
to read/write mode.ease enter the commit message for your changes.
Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
The libubootenv code uses some C99 constructs, but old compilers such
as gcc 4.7 don't default to -std=c99. This commit makes sure libubootenv
is built with -std=gnu99.
Fixes:
src/uboot_env.c:897:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
for (int i = 0; i < strlen(pval); i++) {
^
Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Whilst working on the Reproducible Builds effort [0] we noticed
that libubootenv could not be built reproducibly.
This is due to the docs using absolute build paths. This was
originally filed in Debian as #939547 [1].
[0] https://reproducible-builds.org/
[1] https://bugs.debian.org/939547
Signed-off-by: Chris Lamb <lamby@debian.org>
The environement may be read and write from
a file or a mtd (raw nor or raw nand). This
commit add the support of ubi volume.
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
This commit add a flag device_type in
struct uboot_flash_env, then we could
manage the read and write according to
the device type.
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
The flash type MTD_DATAFLASH and MTD_UBI_VOLUME aren't
supported by function devread and devwrite. So it's not
usefull to accept them when checking the device type.
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Acked-by: Stefano Babic <sbabic@denx.de>
When the function devwrite write the environement
to a nand, the value returned is always 0. But,
the check on the value returned is done on the
environment size, so we return the size of data
written.
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Acked-by: Stefano Babic <sbabic@denx.de>
When the function devread read the environement
from a nand, the value returned is always 0. But,
the check on the value returned is done on the
environment size, so we return the size of data
read.
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Acked-by: Stefano Babic <sbabic@denx.de>