diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2022-06-29 09:00:56 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-06-29 09:00:56 +0200 |
commit | bd0e1e5dde37cb927ad9e5d225d55d0cb636a53d (patch) | |
tree | 52390373b797d525e283ada7609b22bdc4fe25d2 /common | |
parent | 8828e1226981b6a31b12a643768cac63fae3576e (diff) | |
parent | 370f346bca176a93d034af2c0021b5da9a6101ad (diff) | |
download | barebox-bd0e1e5dde37cb927ad9e5d225d55d0cb636a53d.tar.gz barebox-bd0e1e5dde37cb927ad9e5d225d55d0cb636a53d.tar.xz |
Merge branch 'for-next/misc'
Diffstat (limited to 'common')
-rw-r--r-- | common/Kconfig | 5 | ||||
-rw-r--r-- | common/block.c | 8 | ||||
-rw-r--r-- | common/bootchooser.c | 12 | ||||
-rw-r--r-- | common/bootsource.c | 8 | ||||
-rw-r--r-- | common/efi/payload/init.c | 3 | ||||
-rw-r--r-- | common/env.c | 32 | ||||
-rw-r--r-- | common/fastboot.c | 3 | ||||
-rw-r--r-- | common/hush.c | 1 | ||||
-rw-r--r-- | common/memory.c | 21 | ||||
-rw-r--r-- | common/menutree.c | 12 | ||||
-rw-r--r-- | common/reset_source.c | 20 | ||||
-rw-r--r-- | common/state/backend_format_raw.c | 2 |
12 files changed, 77 insertions, 50 deletions
diff --git a/common/Kconfig b/common/Kconfig index f7a6a96e87..3ff45d6c9d 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -1004,6 +1004,11 @@ config STATE select ENVIRONMENT_VARIABLES select OFTREE select PARAMETER + help + barebox state is a generic framework for atomic power fail-safe + variable storage and retrieval. It can be used to safely maintain + data over reboots and to exchange information with Linux, e.g. + for redundant boot with bootchooser. config STATE_CRYPTO bool "HMAC based authentication support" diff --git a/common/block.c b/common/block.c index 1d386edcfd..19bb81df2c 100644 --- a/common/block.c +++ b/common/block.c @@ -361,6 +361,14 @@ static struct cdev_operations block_ops = { .discard_range = block_op_discard_range, }; +struct block_device *cdev_get_block_device(struct cdev *cdev) +{ + if (!cdev || cdev->ops != &block_ops) + return NULL; + + return container_of(cdev, struct block_device, cdev); +} + int blockdevice_register(struct block_device *blk) { loff_t size = (loff_t)blk->num_blocks * BLOCKSIZE(blk); diff --git a/common/bootchooser.c b/common/bootchooser.c index 75dfbc6166..eb3dda52ab 100644 --- a/common/bootchooser.c +++ b/common/bootchooser.c @@ -128,7 +128,7 @@ static void pr_target(struct bootchooser_target *target) printf(" disabled due to %s\n", reason); } -static int pr_setenv(struct bootchooser *bc, const char *fmt, ...) +static int bc_setenv(struct bootchooser *bc, const char *fmt, ...) { va_list ap; int ret = 0; @@ -162,7 +162,7 @@ err: return ret; } -static const char *pr_getenv(const char *fmt, ...) +static const char *bc_getenv(const char *fmt, ...) { va_list ap; char *str; @@ -258,7 +258,7 @@ static struct bootchooser_target *bootchooser_target_new(struct bootchooser *bc, target->remaining_attempts = 0; } - val = pr_getenv("%s.boot", target->prefix); + val = bc_getenv("%s.boot", target->prefix); if (!val) val = target->name; target->boot = xstrdup(val); @@ -497,17 +497,17 @@ int bootchooser_save(struct bootchooser *bc) int ret; if (bc->last_chosen) - pr_setenv(bc, "%s.last_chosen=%d", bc->state_prefix, + bc_setenv(bc, "%s.last_chosen=%d", bc->state_prefix, bc->last_chosen->id); list_for_each_entry(target, &bc->targets, list) { - ret = pr_setenv(bc, "%s.remaining_attempts=%d", + ret = bc_setenv(bc, "%s.remaining_attempts=%d", target->state_prefix, target->remaining_attempts); if (ret) return ret; - ret = pr_setenv(bc, "%s.priority=%d", + ret = bc_setenv(bc, "%s.priority=%d", target->state_prefix, target->priority); if (ret) return ret; diff --git a/common/bootsource.c b/common/bootsource.c index 1f8d053a81..79dacfd1d0 100644 --- a/common/bootsource.c +++ b/common/bootsource.c @@ -113,16 +113,12 @@ void bootsource_set(enum bootsource src) void bootsource_set_instance(int instance) { - char buf[32]; - bootsource_instance = instance; if (instance < 0) - sprintf(buf, "unknown"); + setenv("bootsource_instance","unknown"); else - snprintf(buf, sizeof(buf), "%d", instance); - - setenv("bootsource_instance", buf); + pr_setenv("bootsource_instance", "%d", instance); } enum bootsource bootsource_get(void) diff --git a/common/efi/payload/init.c b/common/efi/payload/init.c index 1541683186..6976285fb3 100644 --- a/common/efi/payload/init.c +++ b/common/efi/payload/init.c @@ -31,7 +31,6 @@ #include <binfmt.h> #include <wchar.h> #include <envfs.h> -#include <efi.h> #include <efi/efi-payload.h> #include <efi/efi-device.h> #include <libfile.h> @@ -360,7 +359,7 @@ static int efi_late_init(void) return PTR_ERR(state); ret = state_load(state); - if (ret) + if (ret != -ENOMEDIUM) pr_warn("Failed to load persistent state, continuing with defaults, %d\n", ret); diff --git a/common/env.c b/common/env.c index 05add63f62..5ac1e62b8c 100644 --- a/common/env.c +++ b/common/env.c @@ -244,13 +244,12 @@ static int dev_setenv(const char *name, const char *val) /** * setenv - set environment variables - * @_name - Variable name + * @name - Variable name * @value - the value to set, empty string not handled specially * * Returns 0 for success and a negative error code otherwise * Use unsetenv() to unset. */ - int setenv(const char *_name, const char *value) { char *name = strdup(_name); @@ -277,6 +276,35 @@ out: } EXPORT_SYMBOL(setenv); +/** + * pr_setenv - set environment variables + * @name - Variable name + * @fmt - the format string to use + * + * Returns 0 for success and a negative error code otherwise + * Use unsetenv() to unset. + */ +int pr_setenv(const char *name, const char *fmt, ...) +{ + va_list ap; + int ret = 0; + char *value; + int len; + + va_start(ap, fmt); + len = vasprintf(&value, fmt, ap); + va_end(ap); + + if (len < 0) + return -ENOMEM; + + ret = setenv(name, value); + free(value); + + return ret; +} +EXPORT_SYMBOL(pr_setenv); + int export(const char *varname) { const char *val = getenv_raw(&context->local, varname); diff --git a/common/fastboot.c b/common/fastboot.c index f8ed40c86e..330a06f5a3 100644 --- a/common/fastboot.c +++ b/common/fastboot.c @@ -673,7 +673,8 @@ static void cb_flash(struct fastboot *fb, const char *cmd) goto out; } - if (IS_ENABLED(CONFIG_BAREBOX_UPDATE) && filetype_is_barebox_image(filetype)) { + if (IS_ENABLED(CONFIG_BAREBOX_UPDATE) && + (filetype_is_barebox_image(filetype) || strstarts(fentry->name, "bbu-"))) { void *buf; struct bbu_handler *handler; struct bbu_data data = { diff --git a/common/hush.c b/common/hush.c index d80df7a181..6a089fabf1 100644 --- a/common/hush.c +++ b/common/hush.c @@ -112,7 +112,6 @@ #include <slice.h> #include <getopt.h> #include <libfile.h> -#include <libbb.h> #include <magicvar.h> #include <linux/list.h> #include <binfmt.h> diff --git a/common/memory.c b/common/memory.c index 95995bb6e3..fd782c7f24 100644 --- a/common/memory.c +++ b/common/memory.c @@ -3,6 +3,8 @@ * Copyright (c) 2011 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix */ +#define pr_fmt(fmt) "memory: " fmt + #include <common.h> #include <memory.h> #include <of.h> @@ -12,6 +14,7 @@ #include <asm-generic/memory_layout.h> #include <asm/sections.h> #include <malloc.h> +#include <of.h> /* * Begin and End of memory area for malloc(), and current "brk" @@ -53,9 +56,20 @@ void mem_malloc_init(void *start, void *end) mem_malloc_initialized = 1; } -#if !defined __SANDBOX__ +static int request_reservation(const struct resource *res) +{ + if (!(res->flags & IORESOURCE_EXCLUSIVE)) + return 0; + + pr_debug("region %s %pa-%pa\n", res->name, &res->start, &res->end); + + request_sdram_region(res->name, res->start, resource_size(res)); + return 0; +} + static int mem_malloc_resource(void) { +#if !defined __SANDBOX__ /* * Normally it's a bug when one of these fails, * but we have some setups where some of these @@ -77,13 +91,14 @@ static int mem_malloc_resource(void) (unsigned long)&__bss_start, (unsigned long)&__bss_stop - (unsigned long)&__bss_start); +#endif #ifdef STACK_BASE request_sdram_region("stack", STACK_BASE, STACK_SIZE); #endif - return 0; + + return of_reserved_mem_walk(request_reservation); } coredevice_initcall(mem_malloc_resource); -#endif static void *sbrk_no_zero(ptrdiff_t increment) { diff --git a/common/menutree.c b/common/menutree.c index 9a14005ea2..751350d754 100644 --- a/common/menutree.c +++ b/common/menutree.c @@ -34,14 +34,7 @@ static void menutree_action(struct menu *m, struct menu_entry *me) static void setenv_bool(const char *var, bool val) { - const char *str; - - if (val) - str = "1"; - else - str = "0"; - - setenv(var, str); + pr_setenv(var, "%d", val); } static void menutree_box(struct menu *m, struct menu_entry *me) @@ -87,7 +80,6 @@ int menutree(const char *path, int toplevel) glob_t g = {}; int i; char *globpath, *display; - size_t size; menu = menu_alloc(); @@ -100,7 +92,7 @@ int menutree(const char *path, int toplevel) } globpath = basprintf("%s/title", path); - display = read_file(globpath, &size); + display = read_file(globpath, NULL); free(globpath); if (!display) { eprintf("no title found in %s/title\n", path); diff --git a/common/reset_source.c b/common/reset_source.c index 3554cbd0fb..774ea5fc8c 100644 --- a/common/reset_source.c +++ b/common/reset_source.c @@ -76,7 +76,9 @@ EXPORT_SYMBOL(reset_source_set_prinst); void reset_source_set_device(struct device_d *dev, enum reset_src_type st) { - int priority = of_get_reset_source_priority(dev->device_node); + unsigned int priority = RESET_SOURCE_DEFAULT_PRIORITY; + + of_property_read_u32(dev->device_node, "reset-source-priority", &priority); __reset_source_set(dev, st, priority, -1); } @@ -92,19 +94,3 @@ static int reset_source_init(void) return 0; } coredevice_initcall(reset_source_init); - -/** - * of_get_reset_source_priority() - get the desired reset source priority from - * device tree - * @node: The device_node to read the property from - * - * return: The priority - */ -unsigned int of_get_reset_source_priority(struct device_node *node) -{ - unsigned int priority = RESET_SOURCE_DEFAULT_PRIORITY; - - of_property_read_u32(node, "reset-source-priority", &priority); - - return priority; -} diff --git a/common/state/backend_format_raw.c b/common/state/backend_format_raw.c index 1fecdeb9cf..7835f977c9 100644 --- a/common/state/backend_format_raw.c +++ b/common/state/backend_format_raw.c @@ -16,14 +16,12 @@ */ #include <common.h> -#include <common.h> #include <crypto/keystore.h> #include <digest.h> #include <linux/kernel.h> #include <malloc.h> #include <crc.h> #include <of.h> -#include <crc.h> #include "state.h" |