Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sbabic/libubootenv
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.3.4
Choose a base ref
...
head repository: sbabic/libubootenv
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Jun 15, 2023

  1. Revert "fw_setenv: fix bug when SPI flash write size != sector size"

    This reverts commit 44ecc1c.
    
    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>
    sbabic committed Jun 15, 2023
    Copy the full SHA
    9f17a00 View commit details

Commits on Aug 14, 2023

  1. validate_flags: Bugfix for TYPE_ATTR_HEX

    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>
    philip-ro authored and sbabic committed Aug 14, 2023
    Copy the full SHA
    3e450ba View commit details
  2. validate_flags: Use isdigit() instead of strtoull()

    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>
    philip-ro authored and sbabic committed Aug 14, 2023
    Copy the full SHA
    1105150 View commit details

Commits on Sep 2, 2023

  1. Try to autoselect namespace based on DT property

    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>
    fschrempf authored and sbabic committed Sep 2, 2023
    Copy the full SHA
    3210931 View commit details
  2. docs: fw_env_config.md: Limit line length

    Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
    fschrempf authored and sbabic committed Sep 2, 2023
    Copy the full SHA
    13db287 View commit details
  3. docs: fw_env_config.md: Add info about namespace selection in YAML co…

    …nfig
    
    Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
    fschrempf authored and sbabic committed Sep 2, 2023
    Copy the full SHA
    eac01b4 View commit details
  4. README: fix Build dtatus link

    Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
    sbabic committed Sep 2, 2023
    Copy the full SHA
    3a9e42f View commit details

Commits on Sep 20, 2023

  1. Add libuboot_namespace_from_dt

    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>
    sbabic committed Sep 20, 2023
    Copy the full SHA
    beb2dc8 View commit details

Commits on Oct 6, 2023

  1. Allow specifying UBI Volumes by MTD path

    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>
    jameshilliard authored and sbabic committed Oct 6, 2023
    Copy the full SHA
    fc9a399 View commit details

Commits on Oct 8, 2023

  1. Prepare 0.3.5

    Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
    sbabic committed Oct 8, 2023
    Copy the full SHA
    3f4d15e View commit details

Commits on Nov 28, 2023

  1. Move MTD related function to separate file

    This is to support other OS that do not have MTD support like Linux.
    
    Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
    sbabic committed Nov 28, 2023
    Copy the full SHA
    86421eb View commit details

Commits on Dec 6, 2023

  1. uboot_env: Make consume_event static

    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>
    stormc authored and sbabic committed Dec 6, 2023
    Copy the full SHA
    9c8fb7f View commit details
  2. uboot_env: Emulate %ms in sscanf()

    Signed-off-by: Christian Storm <christian.storm@siemens.com>
    stormc authored and sbabic committed Dec 6, 2023
    Copy the full SHA
    c478e8d View commit details

Commits on Jan 22, 2024

  1. Use stdint.h integer types on FreeBSD

    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>
    stormc authored and sbabic committed Jan 22, 2024
    Copy the full SHA
    0efb622 View commit details

Commits on Apr 21, 2024

  1. Handle race conditions in UBI_IOCATT

    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>
    jameshilliard authored and sbabic committed Apr 21, 2024
    Copy the full SHA
    5a6f16a View commit details

Commits on May 10, 2024

  1. Update README.md

    Removed unused entry for code.
    sbabic authored May 10, 2024
    Copy the full SHA
    248ae58 View commit details

Commits on May 29, 2024

  1. Factorize function to set variables's flags

    Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
    sbabic committed May 29, 2024
    Copy the full SHA
    07ea1db View commit details
  2. Remove warnings

    Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
    sbabic committed May 29, 2024
    Copy the full SHA
    e4d6ae5 View commit details
  3. Let set a list of writable variables

    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>
    sbabic committed May 29, 2024
    Copy the full SHA
    6b1c689 View commit details

Commits on Jul 6, 2024

  1. src/uboot_env.c: Increase line length

    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>
    leon-anavi authored and sbabic committed Jul 6, 2024
    Copy the full SHA
    123383e View commit details

Commits on Oct 17, 2024

  1. Update mail address in sources

    Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
    sbabic committed Oct 17, 2024
    Copy the full SHA
    676208e View commit details

Commits on Oct 18, 2024

  1. Prepare 0.3.6

    Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
    sbabic committed Oct 18, 2024
    Copy the full SHA
    5507339 View commit details

Commits on Oct 29, 2024

  1. Make libyaml optional

    NewYAML format is required for extended features because the format
    foreseen by U-Boot is very limited. However, some systems due to
    low resources don't want to link to libyaml. Add the option
    NO_YML_SUPPORT to disable YAML configuration file and just use
    fw_env.config in the U-Boot format.
    
    There are no functional changes in this patch - function depending on
    YML are moved in a separate file, and some functions are factorized.
    
    Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
    sbabic committed Oct 29, 2024
    Copy the full SHA
    0052cdc View commit details
Showing with 1,528 additions and 1,011 deletions.
  1. +8 −2 CMakeLists.txt
  2. +2 −4 README.md
  3. +30 −5 docs/fw_env_config.md
  4. +10 −2 src/CMakeLists.txt
  5. +248 −0 src/common.c
  6. +15 −0 src/common.h
  7. +452 −0 src/extended_config.c
  8. +7 −2 src/fw_printenv.c
  9. +9 −2 src/libuboot.h
  10. +1 −1 src/libubootenv.pc.in
  11. +176 −991 src/uboot_env.c
  12. +499 −0 src/uboot_mtd.c
  13. +71 −2 src/uboot_private.h
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2019-2021 Stefano Babic <sbabic@denx.de>
# SPDX-FileCopyrightText: 2019-2021 Stefano Babic stefano.babic@swupdate.org.
#
# SPDX-License-Identifier: LGPL-2.1-or-later

@@ -8,10 +8,12 @@ project (libubootenv C)
# The version number.
# set (libubootenv_VERSION_MAJOR 1)
# set (libubootenv_VERSION_MAJOR_VERSION_MINOR 0)
set(VERSION "0.3.4")
set(VERSION "0.3.6")
SET(SOVERSION "0")
add_definitions(-DVERSION="${VERSION}")

option(NO_YML_SUPPORT "YML Support")

if(DEFAULT_CFG_FILE)
add_definitions(-DDEFAULT_CFG_FILE="${DEFAULT_CFG_FILE}")
endif(DEFAULT_CFG_FILE)
@@ -20,6 +22,10 @@ if(DEFAULT_ENV_FILE)
add_definitions(-DDEFAULT_ENV_FILE="${DEFAULT_ENV_FILE}")
endif(DEFAULT_ENV_FILE)

if(NO_YML_SUPPORT)
add_definitions(-DNO_YAML_SUPPORT)
endif(NO_YML_SUPPORT)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")

#set(CMAKE_C_FLAGS_DEBUG "-g")
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!--
SPDX-FileCopyrightText: 2019-2021 Stefano Babic <sbabic@denx.de>
SPDX-FileCopyrightText: 2019-2024 Stefano Babic <stefano.babic@swupdate.org>
SPDX-License-Identifier: LGPL-2.1-or-later
-->
libubootenv - Library to access U-Boot environment
==================================================

[![Build Status](https://travis-ci.org/sbabic/libubootenv.svg?branch=master)](https://travis-ci.org/sbabic/libubootenv)
[![pipeline status](https://source.denx.de/swupdate/libubootenv/badges/master/pipeline.svg?ignore_skipped=true)](https://source.denx.de/swupdate/libubootenv/-/commits/master)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/21387/badge.svg)](https://scan.coverity.com/projects/21387)
[![REUSE status](https://api.reuse.software/badge/github.com/sbabic/libubootenv)](https://api.reuse.software/info/github.com/sbabic/libubootenv)

@@ -26,8 +26,6 @@ can be used with any board - they accept as parameter a file as initial environm
on the persistent storage. The syntax for the data configuration file is the same as the one
described in the U-Boot project whilst the syntax of the script file is a subset of the original one.

::

Usage fw_printenv [OPTION]
-h, : print this help
-c, --config <filename> : configuration file (by default: /etc/fw_env.config)
35 changes: 30 additions & 5 deletions docs/fw_env_config.md
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ SPDX-License-Identifier: LGPL-2.1-or-later
fw_env.config Configuration File- Legacy format
================================================

This is the configuration file for fw_{printenv,setenv} utility. It was defined in U-Boot project
and it is defined here as legacy format.
This is the configuration file for fw_{printenv,setenv} utility. It was defined
in U-Boot project and it is defined here as legacy format.

Up to two entries are valid, in this case the redundant
environment sector is assumed present.
@@ -30,7 +30,8 @@ Entries must be separated by spaces or tabs.
- Device Offset: offset from start of file or device (mandatory)
- Environment Size: size of environment (in bytes)
- Flash Sector Size: (optional) if not set, it is read from kernel
- Number of Sectors: (optional) number of sectors for environment (mainly used with raw NAND)
- Number of Sectors: (optional) number of sectors for environment (mainly used
with raw NAND)
- Disable Lock Mechanism : (optional), 0|1, default=0 (LOCK enabled)


@@ -97,16 +98,39 @@ UBI Volume by Name Example
| /dev/ubi0:env | 0x0 | 0x1f000 | 0x1f000 | | |
| /dev/ubi0:redund | 0x0 | 0x1f000 | 0x1f000 | | |

UBI Volume by Name from MTD Path Example
--------------------------

| Device Name | Device Offset | Environment Size | Flash Sector Size | Number of Sectors | Disable Lock Mechanism |
|------------------|---------------|------------------|-------------------|-------------------|------------------------|
| /dev/mtd0:env | 0x0 | 0x1f000 | 0x1f000 | | |
| /dev/mtd0:redund | 0x0 | 0x1f000 | 0x1f000 | | |

Configuration File in YAML
==========================

A YAML format is defined to allow multiple sets of variable. This lets have same features (redundancy, power-cut safe) for
environment that are not bound to the U-Boot bootloader.
A YAML format is defined to allow multiple sets of variable. This lets have same
features (redundancy, power-cut safe) for environment that are not bound to the
U-Boot bootloader.

A set is selected by using the `-m/--namespace` argument. In case the bootloader
tells us where the environment is located by setting the
`/chosen/u-boot,env-config` property in the devicetree, `fw_printenv/fw_setenv`
automatically uses the string from this property as a selector for the namespace
in the YAML config file.

The sequence `writelist` implements the CONFIG_ENV_WRITEABLE_LIST in U-Boot. The list
is in the same format used in the bootloader: <name>:<flags>. See in bootloader documentation
for the list of supported flags.

```yaml
uboot:
size : 0x4000
lockfile : /var/lock/fw_printenv.lock
writelist:
- var1:sw
- var2:sw
- var3:dw
devices:
- path : /dev/mtd0
offset : 0xA0000
@@ -120,6 +144,7 @@ uboot:
appvar:
size : 0x4000
lockfile : /var/lock/appvar.lock

devices:
- path : /dev/mtd1
offset : 0
12 changes: 10 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# SPDX-FileCopyrightText: 2019-2021 Stefano Babic <sbabic@denx.de>
# SPDX-FileCopyrightText: 2019-2021 Stefano Babic <stefano.babic@swupdate.org>
#
# SPDX-License-Identifier: LGPL-2.1-or-later
cmake_minimum_required (VERSION 2.6)
# Sources and private headers
SET(libubootenv_SOURCES
uboot_env.c
uboot_mtd.c
extended_config.c
common.c
common.h
uboot_private.h
)

@@ -21,7 +25,11 @@ SET_TARGET_PROPERTIES(ubootenv PROPERTIES VERSION ${VERSION} SOVERSION ${SOVERSI
ADD_LIBRARY(ubootenv_static STATIC ${libubootenv_SOURCES} ${include_HEADERS})
SET_TARGET_PROPERTIES(ubootenv_static PROPERTIES OUTPUT_NAME ubootenv)
add_executable(fw_printenv fw_printenv.c)
target_link_libraries(ubootenv z yaml)
target_link_libraries(ubootenv z)
if (NOT NO_YML_SUPPORT)
target_link_libraries(ubootenv yaml)
endif(NOT NO_YML_SUPPORT)

target_link_libraries(fw_printenv ubootenv)
add_custom_target(fw_setenv ALL ${CMAKE_COMMAND} -E create_symlink fw_printenv fw_setenv)

Loading