diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2022-10-13 13:57:07 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-10-13 13:57:07 +0200 |
commit | 3d46afb56fa3c5e3c41a382dc454b5bcda04d5ac (patch) | |
tree | 957de9cbc6a68e82c84ae26cc4712c3e86dfc964 /common | |
parent | 965a946c49e016bcff5bbfffaa1a468cd74af0db (diff) | |
parent | 8513703c6c46428908264923260504ce81e3e3a7 (diff) | |
download | barebox-3d46afb56fa3c5e3c41a382dc454b5bcda04d5ac.tar.gz barebox-3d46afb56fa3c5e3c41a382dc454b5bcda04d5ac.tar.xz |
Merge branch 'for-next/misc'
Diffstat (limited to 'common')
-rw-r--r-- | common/block.c | 2 | ||||
-rw-r--r-- | common/blspec.c | 4 | ||||
-rw-r--r-- | common/bootm.c | 150 | ||||
-rw-r--r-- | common/console_common.c | 10 | ||||
-rw-r--r-- | common/elf.c | 13 | ||||
-rw-r--r-- | common/envfs-core.c | 3 | ||||
-rw-r--r-- | common/environment.c | 11 | ||||
-rw-r--r-- | common/fastboot.c | 8 | ||||
-rw-r--r-- | common/file-list.c | 7 | ||||
-rw-r--r-- | common/firmware.c | 5 | ||||
-rw-r--r-- | common/misc.c | 8 | ||||
-rw-r--r-- | common/module.lds.S | 2 | ||||
-rw-r--r-- | common/ubiformat.c | 2 | ||||
-rw-r--r-- | common/uimage.c | 4 |
14 files changed, 120 insertions, 109 deletions
diff --git a/common/block.c b/common/block.c index a4cfd6e227..7f28b56419 100644 --- a/common/block.c +++ b/common/block.c @@ -361,7 +361,7 @@ static struct cdev_operations block_ops = { .discard_range = block_op_discard_range, }; -struct block_device *cdev_get_block_device(struct cdev *cdev) +struct block_device *cdev_get_block_device(const struct cdev *cdev) { if (!cdev || cdev->ops != &block_ops) return NULL; diff --git a/common/blspec.c b/common/blspec.c index d391f690ad..9ae7b49a77 100644 --- a/common/blspec.c +++ b/common/blspec.c @@ -677,9 +677,7 @@ static int blspec_scan_cdev(struct bootentries *bootentries, struct cdev *cdev) found += ret; } - rootpath = cdev_get_mount_path(cdev); - if (!rootpath) - rootpath = cdev_mount_default(cdev, NULL); + rootpath = cdev_mount(cdev); if (!IS_ERR(rootpath)) { ret = blspec_scan_directory(bootentries, rootpath); if (ret > 0) diff --git a/common/bootm.c b/common/bootm.c index 2f02c156e5..fb1ed36a26 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -519,18 +519,77 @@ static int bootm_open_os_uimage(struct image_data *data) return 0; } +static int bootm_open_fit(struct image_data *data) +{ + struct fit_handle *fit; + static const char *kernel_img = "kernel"; + int ret; + + if (!IS_ENABLED(CONFIG_FITIMAGE)) + return 0; + + fit = fit_open(data->os_file, data->verbose, data->verify); + if (IS_ERR(fit)) { + pr_err("Loading FIT image %s failed with: %pe\n", data->os_file, fit); + return PTR_ERR(fit); + } + + data->os_fit = fit; + + data->fit_config = fit_open_configuration(data->os_fit, + data->os_part); + if (IS_ERR(data->fit_config)) { + pr_err("Cannot open FIT image configuration '%s'\n", + data->os_part ? data->os_part : "default"); + return PTR_ERR(data->fit_config); + } + + ret = fit_open_image(data->os_fit, data->fit_config, kernel_img, + &data->fit_kernel, &data->fit_kernel_size); + if (ret) + return ret; + if (data->os_address == UIMAGE_SOME_ADDRESS) { + ret = fit_get_image_address(data->os_fit, + data->fit_config, + kernel_img, + "load", &data->os_address); + if (!ret) + pr_info("Load address from FIT '%s': 0x%lx\n", + kernel_img, data->os_address); + /* Note: Error case uses default value. */ + } + if (data->os_entry == UIMAGE_SOME_ADDRESS) { + unsigned long entry; + ret = fit_get_image_address(data->os_fit, + data->fit_config, + kernel_img, + "entry", &entry); + if (!ret) { + data->os_entry = entry - data->os_address; + pr_info("Entry address from FIT '%s': 0x%lx\n", + kernel_img, entry); + } + /* Note: Error case uses default value. */ + } + + return 0; +} + static int bootm_open_elf(struct image_data *data) { + struct elf_image *elf; + if (!IS_ENABLED(CONFIG_ELF)) return -ENOSYS; - data->elf = elf_open(data->os_file); - if (IS_ERR(data->elf)) - return PTR_ERR(data->elf); + elf = elf_open(data->os_file); + if (IS_ERR(elf)) + return PTR_ERR(elf); - pr_info("Entry Point: %08llx\n", data->elf->entry); + pr_info("Entry Point: %08llx\n", elf->entry); - data->os_address = data->elf->entry; + data->os_address = elf->entry; + data->elf = elf; return 0; } @@ -633,74 +692,25 @@ int bootm_boot(struct bootm_data *bootm_data) } } - if (IS_ENABLED(CONFIG_FITIMAGE) && os_type == filetype_oftree) { - struct fit_handle *fit; - static const char *kernel_img = "kernel"; - - fit = fit_open(data->os_file, data->verbose, data->verify); - if (IS_ERR(fit)) { - pr_err("Loading FIT image %s failed with: %pe\n", data->os_file, fit); - ret = PTR_ERR(fit); - goto err_out; - } - - data->os_fit = fit; - - data->fit_config = fit_open_configuration(data->os_fit, - data->os_part); - if (IS_ERR(data->fit_config)) { - pr_err("Cannot open FIT image configuration '%s'\n", - data->os_part ? data->os_part : "default"); - ret = PTR_ERR(data->fit_config); - goto err_out; - } - - ret = fit_open_image(data->os_fit, data->fit_config, kernel_img, - &data->fit_kernel, &data->fit_kernel_size); - if (ret) - goto err_out; - if (data->os_address == UIMAGE_SOME_ADDRESS) { - ret = fit_get_image_address(data->os_fit, - data->fit_config, - kernel_img, - "load", &data->os_address); - if (!ret) - pr_info("Load address from FIT '%s': 0x%lx\n", - kernel_img, data->os_address); - /* Note: Error case uses default value. */ - } - if (data->os_entry == UIMAGE_SOME_ADDRESS) { - unsigned long entry; - ret = fit_get_image_address(data->os_fit, - data->fit_config, - kernel_img, - "entry", &entry); - if (!ret) { - data->os_entry = entry - data->os_address; - pr_info("Entry address from FIT '%s': 0x%lx\n", - kernel_img, entry); - } - /* Note: Error case uses default value. */ - } - } - - if (os_type == filetype_uimage) { + switch (os_type) { + case filetype_oftree: + ret = bootm_open_fit(data); + break; + case filetype_uimage: ret = bootm_open_os_uimage(data); - if (ret) { - pr_err("Loading OS image failed with: %s\n", - strerror(-ret)); - goto err_out; - } + break; + case filetype_elf: + ret = bootm_open_elf(data); + break; + default: + ret = 0; + break; } - if (os_type == filetype_elf) { - ret = bootm_open_elf(data); - if (ret) { - pr_err("Loading ELF image failed with: %s\n", - strerror(-ret)); - data->elf = NULL; - goto err_out; - } + if (ret) { + pr_err("Loading %s image failed with: %pe\n", + file_type_to_short_string(os_type), ERR_PTR(ret)); + goto err_out; } if (bootm_data->appendroot) { diff --git a/common/console_common.c b/common/console_common.c index 7bef74c543..ca1dad0f15 100644 --- a/common/console_common.c +++ b/common/console_common.c @@ -68,7 +68,7 @@ void log_clean(unsigned int limit) } } -static void print_colored_log_level(const int level) +static void print_colored_log_level(unsigned int ch, const int level) { if (!console_allow_color()) return; @@ -77,7 +77,7 @@ static void print_colored_log_level(const int level) if (!colored_log_level[level]) return; - puts(colored_log_level[level]); + console_puts(ch, colored_log_level[level]); } static void pr_puts(int level, const char *str) @@ -112,8 +112,8 @@ nolog: if (level > barebox_loglevel) return; - print_colored_log_level(level); - puts(str); + print_colored_log_level(CONSOLE_STDERR, level); + console_puts(CONSOLE_STDERR, str); } int pr_print(int level, const char *fmt, ...) @@ -217,7 +217,7 @@ void log_print(unsigned flags, unsigned levels) if (!(flags & (BAREBOX_LOG_PRINT_RAW | BAREBOX_LOG_PRINT_TIME | BAREBOX_LOG_DIFF_TIME))) - print_colored_log_level(log->level); + print_colored_log_level(CONSOLE_STDOUT, log->level); if (flags & BAREBOX_LOG_PRINT_RAW) printf("<%i>", log->level); diff --git a/common/elf.c b/common/elf.c index f10fb77953..eec62cad61 100644 --- a/common/elf.c +++ b/common/elf.c @@ -109,7 +109,7 @@ static int load_elf_to_memory(struct elf_image *elf) if (elf->filename) { fd = open(elf->filename, O_RDONLY); if (fd < 0) { - pr_err("could not open: %s\n", errno_str()); + pr_err("could not open: %m\n"); return -errno; } } @@ -133,8 +133,7 @@ static int load_elf_to_memory(struct elf_image *elf) } if (read_full(fd, dst, p_filesz) < 0) { - pr_err("could not read elf segment: %s\n", - errno_str()); + pr_err("could not read elf segment: %m\n"); close(fd); return -errno; } @@ -256,13 +255,13 @@ static struct elf_image *elf_check_init(const char *filename) /* First pass is to read elf header only */ fd = open(filename, O_RDONLY); if (fd < 0) { - pr_err("could not open: %s\n", errno_str()); + pr_err("could not open: %m\n"); ret = -errno; goto err_free_elf; } if (read_full(fd, &hdr, sizeof(hdr)) < 0) { - pr_err("could not read elf header: %s\n", errno_str()); + pr_err("could not read elf header: %m\n"); close(fd); ret = -errno; goto err_free_elf; @@ -290,13 +289,13 @@ static struct elf_image *elf_check_init(const char *filename) */ fd = open(filename, O_RDONLY); if (fd < 0) { - pr_err("could not open: %s\n", errno_str()); + pr_err("could not open: %m\n"); ret = -errno; goto err_free_hdr_buf; } if (read_full(fd, elf->hdr_buf, hdr_size) < 0) { - pr_err("could not read elf program headers: %s\n", errno_str()); + pr_err("could not read elf program headers: %m\n"); ret = -errno; close(fd); goto err_free_hdr_buf; diff --git a/common/envfs-core.c b/common/envfs-core.c index 0984d53873..20b3e647d3 100644 --- a/common/envfs-core.c +++ b/common/envfs-core.c @@ -24,7 +24,6 @@ #include <environment.h> #include <libfile.h> #else -# define errno_str(x) ("void") #define pr_info(fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) #define pr_warn(fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) #endif @@ -151,7 +150,7 @@ int envfs_load_data(struct envfs_super *super, void *buf, size_t size, fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0644); free(str); if (fd < 0) { - printf("Open %s\n", errno_str()); + printf("Open %m\n"); ret = fd; goto out; } diff --git a/common/environment.c b/common/environment.c index 0d31f5b4f7..e8c487c1a2 100644 --- a/common/environment.c +++ b/common/environment.c @@ -27,7 +27,6 @@ #include <globalvar.h> #include <libfile.h> #else -# define errno_str(x) ("void") #define EXPORT_SYMBOL(x) #endif @@ -297,7 +296,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags) envfd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (envfd < 0) { - printf("could not open %s: %s\n", filename, errno_str()); + printf("could not open %s: %m\n", filename); ret = -errno; goto out1; } @@ -306,7 +305,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags) /* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't need it */ if (ret && errno != ENOSYS && errno != EOPNOTSUPP) { - printf("could not unprotect %s: %s\n", filename, errno_str()); + printf("could not unprotect %s: %m\n", filename); goto out; } @@ -314,7 +313,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags) /* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't need it */ if (ret && errno != ENOSYS && errno != EOPNOTSUPP) { - printf("could not erase %s: %s\n", filename, errno_str()); + printf("could not erase %s: %m\n", filename); goto out; } @@ -337,7 +336,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags) /* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't need it */ if (ret && errno != ENOSYS && errno != EOPNOTSUPP) { - printf("could not protect %s: %s\n", filename, errno_str()); + printf("could not protect %s: %m\n", filename); goto out; } @@ -385,7 +384,7 @@ int envfs_load(const char *filename, const char *dir, unsigned flags) envfd = open(filename, O_RDONLY); if (envfd < 0) { - printf("environment load %s: %s\n", filename, errno_str()); + printf("environment load %s: %m\n", filename); if (errno == ENOENT) printf("Maybe you have to create the partition.\n"); return -1; diff --git a/common/fastboot.c b/common/fastboot.c index 72e6ba3c40..ae7f132444 100644 --- a/common/fastboot.c +++ b/common/fastboot.c @@ -95,6 +95,14 @@ static int fastboot_add_partition_variables(struct fastboot *fb, } if (ret) { + if (fentry->flags & FILE_LIST_FLAG_OPTIONAL) { + pr_info("skipping unavailable optional partition %s for fastboot gadget\n", + fentry->filename); + ret = 0; + type = "unavailable"; + goto out; + } + if (fentry->flags & FILE_LIST_FLAG_CREATE) { ret = 0; type = "file"; diff --git a/common/file-list.c b/common/file-list.c index 11db7c6e44..1dc7cd8266 100644 --- a/common/file-list.c +++ b/common/file-list.c @@ -88,6 +88,9 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con case 'u': flags |= FILE_LIST_FLAG_UBI; break; + case 'o': + flags |= FILE_LIST_FLAG_OPTIONAL; + break; default: pr_err("Unknown flag '%c'\n", *partstr); return -EINVAL; @@ -113,7 +116,7 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con static const char *flags_to_str(int flags) { - static char str[sizeof "srcu"]; + static char str[sizeof "srcuo"]; char *s = str;; if (flags & FILE_LIST_FLAG_SAFE) @@ -124,6 +127,8 @@ static const char *flags_to_str(int flags) *s++ = 'c'; if (flags & FILE_LIST_FLAG_UBI) *s++ = 'u'; + if (flags & FILE_LIST_FLAG_OPTIONAL) + *s++ = 'o'; *s = '\0'; diff --git a/common/firmware.c b/common/firmware.c index b87d7da38f..e4ad6ac867 100644 --- a/common/firmware.c +++ b/common/firmware.c @@ -272,8 +272,7 @@ int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *firmware) firmwarefd = open(firmware, O_RDONLY); if (firmwarefd < 0) { - printf("could not open %s: %s\n", firmware, - errno_str()); + printf("could not open %s: %m\n", firmware); ret = firmwarefd; goto out; } @@ -282,7 +281,7 @@ int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *firmware) devicefd = open(dst, O_WRONLY); if (devicefd < 0) { - printf("could not open %s: %s\n", dst, errno_str()); + printf("could not open %s: %m\n", dst); ret = devicefd; goto out; } diff --git a/common/misc.c b/common/misc.c index e0e32f47c5..400c1fb48f 100644 --- a/common/misc.c +++ b/common/misc.c @@ -105,16 +105,10 @@ const char *strerror(int errnum) } EXPORT_SYMBOL(strerror); -const char *errno_str(void) -{ - return strerror(errno); -} -EXPORT_SYMBOL(errno_str); - void perror(const char *s) { #ifdef CONFIG_ERRNO_MESSAGES - printf("%s: %s\n", s, errno_str()); + printf("%s: %m\n", s); #else printf("%s returned with %d\n", s, errno); #endif diff --git a/common/module.lds.S b/common/module.lds.S index 76f3b6d1bb..b2d685670b 100644 --- a/common/module.lds.S +++ b/common/module.lds.S @@ -15,7 +15,7 @@ * */ -#include <asm-generic/barebox.lds.h> +#include <asm/barebox.lds.h> SECTIONS { diff --git a/common/ubiformat.c b/common/ubiformat.c index e10ce31ce6..1edfc5b2a3 100644 --- a/common/ubiformat.c +++ b/common/ubiformat.c @@ -444,7 +444,7 @@ static int format(struct ubiformat_args *args, struct mtd_info *mtd, } if (!args->quiet && !args->verbose) - printf("\n"); + printf("\rubiformat: formatted all eraseblocks -- 100 %% complete\n"); if (!novtbl) { if (eb1 == -1 || eb2 == -1) { diff --git a/common/uimage.c b/common/uimage.c index 42e9d9023f..72c37b7d15 100644 --- a/common/uimage.c +++ b/common/uimage.c @@ -98,7 +98,7 @@ struct uimage_handle *uimage_open(const char *filename) fd = open(filename, O_RDONLY); if (fd < 0) { - printf("could not open: %s\n", errno_str()); + printf("could not open: %m\n"); free(copy); return NULL; } @@ -109,7 +109,7 @@ struct uimage_handle *uimage_open(const char *filename) handle->copy = copy; if (read(fd, header, sizeof(*header)) < 0) { - printf("could not read: %s\n", errno_str()); + printf("could not read: %m\n"); goto err_out; } |