* [PATCH 01/10] block: have cdev_get_block_device accept const cdev
2022-10-10 6:11 [PATCH 00/10] treewide: misc cleanup for efiloader prep Ahmad Fatoum
@ 2022-10-10 6:11 ` Ahmad Fatoum
2022-10-10 6:11 ` [PATCH 02/10] treewide: replace errno_str() with %m printf format specifier Ahmad Fatoum
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Having a non-const cdev parameter for cdev_get_block_device() limits its
use as a user may want to just read struct block_device members without
change. Allow this by changing parameter to be pointer to const instead.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/block.c | 2 +-
include/block.h | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/common/block.c b/common/block.c
index 19bb81df2c3d..6290a45b7c46 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/include/block.h b/include/block.h
index 1fb40e942f9f..8740a03d36bc 100644
--- a/include/block.h
+++ b/include/block.h
@@ -50,9 +50,9 @@ static inline int block_flush(struct block_device *blk)
}
#ifdef CONFIG_BLOCK
-struct block_device *cdev_get_block_device(struct cdev *cdev);
+struct block_device *cdev_get_block_device(const struct cdev *cdev);
#else
-static inline struct block_device *cdev_get_block_device(struct cdev *cdev)
+static inline struct block_device *cdev_get_block_device(const struct cdev *cdev)
{
return NULL;
}
--
2.30.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 02/10] treewide: replace errno_str() with %m printf format specifier
2022-10-10 6:11 [PATCH 00/10] treewide: misc cleanup for efiloader prep Ahmad Fatoum
2022-10-10 6:11 ` [PATCH 01/10] block: have cdev_get_block_device accept const cdev Ahmad Fatoum
@ 2022-10-10 6:11 ` Ahmad Fatoum
2022-10-10 6:11 ` [PATCH 03/10] common: misc: remove now unused errno_str Ahmad Fatoum
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Both errno_str() and printf("%m" end up calling strerror(). %m is
more convenient to use, so switch over all instances to it.
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/mach-at91/boot_test_cmd.c | 2 +-
arch/arm/mach-omap/am33xx_bbu_emmc.c | 15 +++++++--------
arch/arm/mach-omap/am33xx_bbu_spi_mlo.c | 6 +++---
commands/cat.c | 2 +-
commands/edit.c | 4 ++--
commands/flash.c | 8 ++++----
commands/ls.c | 3 +--
commands/mkdir.c | 2 +-
commands/rm.c | 2 +-
commands/rmdir.c | 2 +-
common/elf.c | 13 ++++++-------
common/envfs-core.c | 3 +--
common/environment.c | 11 +++++------
common/firmware.c | 5 ++---
common/misc.c | 2 +-
common/uimage.c | 4 ++--
fs/bpkfs.c | 6 +++---
fs/uimagefs.c | 4 ++--
lib/libfile.c | 6 +++---
19 files changed, 47 insertions(+), 53 deletions(-)
diff --git a/arch/arm/mach-at91/boot_test_cmd.c b/arch/arm/mach-at91/boot_test_cmd.c
index 7bb40f2e4026..9a5c0e3e4e06 100644
--- a/arch/arm/mach-at91/boot_test_cmd.c
+++ b/arch/arm/mach-at91/boot_test_cmd.c
@@ -57,7 +57,7 @@ static int do_at91_boot_test(int argc, char *argv[])
fd = open(sram, O_WRONLY);
if (fd < 0) {
- printf("could not open %s: %s\n", sram, errno_str());
+ printf("could not open %s: %m\n", sram);
ret = fd;
goto err;
}
diff --git a/arch/arm/mach-omap/am33xx_bbu_emmc.c b/arch/arm/mach-omap/am33xx_bbu_emmc.c
index 29e13de778aa..c3d4f9c42236 100644
--- a/arch/arm/mach-omap/am33xx_bbu_emmc.c
+++ b/arch/arm/mach-omap/am33xx_bbu_emmc.c
@@ -42,16 +42,15 @@ static int emmc_mlo_handler(struct bbu_handler *handler, struct bbu_data *data)
fd = open(handler->devicefile, O_RDWR);
if (fd < 0) {
- pr_err("could not open %s: %s\n", handler->devicefile,
- errno_str());
+ pr_err("could not open %s: %m\n", handler->devicefile);
return fd;
}
/* save the partition table */
ret = pread(fd, part_table, PART_TABLE_SIZE, PART_TABLE_OFFSET);
if (ret < 0) {
- pr_err("could not read partition table from fd %s: %s\n",
- handler->devicefile, errno_str());
+ pr_err("could not read partition table from fd %s: %m\n",
+ handler->devicefile);
goto error;
}
@@ -59,8 +58,8 @@ static int emmc_mlo_handler(struct bbu_handler *handler, struct bbu_data *data)
for (i = 0; i < 4; i++) {
ret = pwrite(fd, image, size, i * 0x20000);
if (ret < 0) {
- pr_err("could not write MLO %i/4 to fd %s: %s\n",
- i + 1, handler->devicefile, errno_str());
+ pr_err("could not write MLO %i/4 to fd %s: %m\n",
+ i + 1, handler->devicefile);
goto error_save_part_table;
}
}
@@ -69,8 +68,8 @@ error_save_part_table:
/* write the partition table back */
ret = pwrite(fd, part_table, PART_TABLE_SIZE, PART_TABLE_OFFSET);
if (ret < 0)
- pr_err("could not write partition table to fd %s: %s\n",
- handler->devicefile, errno_str());
+ pr_err("could not write partition table to fd %s: %m\n",
+ handler->devicefile);
error:
close(fd);
diff --git a/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c b/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
index 7d2ef1f0f225..f36c2c3bf02b 100644
--- a/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
+++ b/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
@@ -51,7 +51,7 @@ static int spi_nor_mlo_handler(struct bbu_handler *handler,
ret = stat(data->devicefile, &s);
if (ret) {
- printf("could not open %s: %s", data->devicefile, errno_str());
+ printf("could not open %s: %m", data->devicefile);
return ret;
}
@@ -66,14 +66,14 @@ static int spi_nor_mlo_handler(struct bbu_handler *handler,
dstfd = open(data->devicefile, O_WRONLY);
if (dstfd < 0) {
- printf("could not open %s: %s", data->devicefile, errno_str());
+ printf("could not open %s: %m", data->devicefile);
ret = dstfd;
goto out;
}
ret = erase(dstfd, ERASE_SIZE_ALL, 0);
if (ret < 0) {
- printf("could not erase %s: %s", data->devicefile, errno_str());
+ printf("could not erase %s: %m", data->devicefile);
goto out1;
}
diff --git a/commands/cat.c b/commands/cat.c
index 17c31ed08368..503520dc64a5 100644
--- a/commands/cat.c
+++ b/commands/cat.c
@@ -40,7 +40,7 @@ static int do_cat(int argc, char *argv[])
fd = open(argv[args], O_RDONLY);
if (fd < 0) {
err = 1;
- printf("could not open %s: %s\n", argv[args], errno_str());
+ printf("could not open %s: %m\n", argv[args]);
goto out;
}
diff --git a/commands/edit.c b/commands/edit.c
index 12695d39e4fd..dea383aae7a6 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -185,7 +185,7 @@ static int edit_read_file(const char *path)
if (!stat(path, &s)) {
filebuffer = read_file(path, NULL);
if (!filebuffer) {
- printf("could not read %s: %s\n", path, errno_str());
+ printf("could not read %s: %m\n", path);
return -1;
}
@@ -249,7 +249,7 @@ static int save_file(const char *path)
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT);
if (fd < 0) {
- printf("could not open file for writing: %s\n", errno_str());
+ printf("could not open file for writing: %m\n");
return fd;
}
diff --git a/commands/flash.c b/commands/flash.c
index 3d7c8fd5773d..5b7060aeadfb 100644
--- a/commands/flash.c
+++ b/commands/flash.c
@@ -25,7 +25,7 @@ static int do_flerase(int argc, char *argv[])
filename = argv[1];
if (stat(filename, &s)) {
- printf("stat %s: %s\n", filename, errno_str());
+ printf("stat %s: %m\n", filename);
return 1;
}
@@ -33,7 +33,7 @@ static int do_flerase(int argc, char *argv[])
fd = open(filename, O_WRONLY);
if (fd < 0) {
- printf("open %s: %s\n", filename, errno_str());
+ printf("open %s: %m\n", filename);
return 1;
}
@@ -89,7 +89,7 @@ static int do_protect(int argc, char *argv[])
prot = 0;
if (stat(filename, &s)) {
- printf("stat %s: %s\n", filename, errno_str());
+ printf("stat %s: %m\n", filename);
return 1;
}
@@ -97,7 +97,7 @@ static int do_protect(int argc, char *argv[])
fd = open(filename, O_WRONLY);
if (fd < 0) {
- printf("open %s: %s\n", filename, errno_str());
+ printf("open %s: %m\n", filename);
return 1;
}
diff --git a/commands/ls.c b/commands/ls.c
index 1192aed971cf..09a20e0a2342 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -164,8 +164,7 @@ static int do_ls(int argc, char *argv[])
while (o < argc) {
ret = stat(argv[o], &s);
if (ret) {
- printf("%s: %s: %s\n", argv[0],
- argv[o], errno_str());
+ printf("%s: %s: %m\n", argv[0], argv[o]);
o++;
exitcode = COMMAND_ERROR;
continue;
diff --git a/commands/mkdir.c b/commands/mkdir.c
index e7153b8732c5..01fc0b083b1a 100644
--- a/commands/mkdir.c
+++ b/commands/mkdir.c
@@ -37,7 +37,7 @@ static int do_mkdir(int argc, char *argv[])
ret = mkdir(argv[optind], 0);
}
if (ret) {
- printf("could not create %s: %s\n", argv[optind], errno_str());
+ printf("could not create %s: %m\n", argv[optind]);
return 1;
}
optind++;
diff --git a/commands/rm.c b/commands/rm.c
index ba52b185cb34..be5c19222141 100644
--- a/commands/rm.c
+++ b/commands/rm.c
@@ -37,7 +37,7 @@ static int do_rm(int argc, char *argv[])
else
ret = unlink(argv[i]);
if (ret) {
- printf("could not remove %s: %s\n", argv[i], errno_str());
+ printf("could not remove %s: %m\n", argv[i]);
return 1;
}
i++;
diff --git a/commands/rmdir.c b/commands/rmdir.c
index 9b2938a5563c..44793ca56e7f 100644
--- a/commands/rmdir.c
+++ b/commands/rmdir.c
@@ -14,7 +14,7 @@ static int do_rmdir(int argc, char *argv[])
while (i < argc) {
if (rmdir(argv[i])) {
- printf("could not remove %s: %s\n", argv[i], errno_str());
+ printf("could not remove %s: %m\n", argv[i]);
return 1;
}
i++;
diff --git a/common/elf.c b/common/elf.c
index f10fb7795325..eec62cad6141 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 0984d538734f..20b3e647d3c3 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 0d31f5b4f786..e8c487c1a2e2 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/firmware.c b/common/firmware.c
index b87d7da38fa7..e4ad6ac867b0 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 e0e32f47c59d..0c4bbe361db6 100644
--- a/common/misc.c
+++ b/common/misc.c
@@ -114,7 +114,7 @@ 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/uimage.c b/common/uimage.c
index 42e9d9023f3f..72c37b7d15dd 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;
}
diff --git a/fs/bpkfs.c b/fs/bpkfs.c
index 8fc4df65de09..147f4735d9ea 100644
--- a/fs/bpkfs.c
+++ b/fs/bpkfs.c
@@ -381,7 +381,7 @@ static int bpkfs_probe(struct device_d *dev)
ret = read(fd, header, sizeof(*header));
if (ret < 0) {
- dev_err(dev, "could not read: %s (ret = %d)\n", errno_str(), ret);
+ dev_err(dev, "could not read: %m\n");
goto err;
}
@@ -407,7 +407,7 @@ static int bpkfs_probe(struct device_d *dev)
ret = read(fd, &data_header, sizeof(data_header));
if (ret < 0) {
- dev_err(dev, "could not read: %s\n", errno_str());
+ dev_err(dev, "could not read: %m\n");
goto err;
} else if (ret == 0) {
dev_err(dev, "EOF: to_read %llu\n", size);
@@ -456,7 +456,7 @@ static int bpkfs_probe(struct device_d *dev)
priv->nb_data_entries++;
if (lseek(fd, d->size, SEEK_CUR) != d->size) {
- dev_err(dev, "could not seek: %s\n", errno_str());
+ dev_err(dev, "could not seek: %m\n");
ret = -errno;
goto err;
}
diff --git a/fs/uimagefs.c b/fs/uimagefs.c
index daaa3ad24bae..8de2b8881f8e 100644
--- a/fs/uimagefs.c
+++ b/fs/uimagefs.c
@@ -373,7 +373,7 @@ static int __uimage_open(struct uimagefs_handle *priv)
fd = open(filename, O_RDONLY);
if (fd < 0) {
- printf("could not open: %s\n", errno_str());
+ printf("could not open: %m\n");
return fd;
}
@@ -381,7 +381,7 @@ static int __uimage_open(struct uimagefs_handle *priv)
ret = read(fd, header, sizeof(*header));
if (ret < 0) {
- printf("could not read: %s\n", errno_str());
+ printf("could not read: %m\n");
goto err_out;
}
offset += sizeof(*header);
diff --git a/lib/libfile.c b/lib/libfile.c
index 3b7985fbcabb..b967232d198e 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -387,7 +387,7 @@ int copy_file(const char *src, const char *dst, int verbose)
srcfd = open(src, O_RDONLY);
if (srcfd < 0) {
- printf("could not open %s: %s\n", src, errno_str());
+ printf("could not open %s: %m\n", src);
ret = srcfd;
goto out;
}
@@ -396,7 +396,7 @@ int copy_file(const char *src, const char *dst, int verbose)
s = stat(dst, &dststat);
if (s && s != -ENOENT) {
- printf("could not stat %s: %s\n", dst, errno_str());
+ printf("could not stat %s: %m\n", dst);
ret = s;
goto out;
}
@@ -407,7 +407,7 @@ int copy_file(const char *src, const char *dst, int verbose)
dstfd = open(dst, mode);
if (dstfd < 0) {
- printf("could not open %s: %s\n", dst, errno_str());
+ printf("could not open %s: %m\n", dst);
ret = dstfd;
goto out;
}
--
2.30.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 03/10] common: misc: remove now unused errno_str
2022-10-10 6:11 [PATCH 00/10] treewide: misc cleanup for efiloader prep Ahmad Fatoum
2022-10-10 6:11 ` [PATCH 01/10] block: have cdev_get_block_device accept const cdev Ahmad Fatoum
2022-10-10 6:11 ` [PATCH 02/10] treewide: replace errno_str() with %m printf format specifier Ahmad Fatoum
@ 2022-10-10 6:11 ` Ahmad Fatoum
2022-10-10 6:11 ` [PATCH 04/10] driver: don't crash when dev_name/dev_id is called with NULL dev Ahmad Fatoum
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
With all errno_str() instanced removed in a previous commit, we can drop
the now unused definition. New code should use
printf("message: %m\n");
instead of
printf("message: %s\n", errno_str());
or just use strerror(...) directly.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/misc.c | 6 ------
include/errno.h | 1 -
2 files changed, 7 deletions(-)
diff --git a/common/misc.c b/common/misc.c
index 0c4bbe361db6..400c1fb48f9f 100644
--- a/common/misc.c
+++ b/common/misc.c
@@ -105,12 +105,6 @@ 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
diff --git a/include/errno.h b/include/errno.h
index 262c9fc3eb1c..164426596604 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -8,7 +8,6 @@
extern int errno;
void perror(const char *s);
-const char *errno_str(void);
const char *strerror(int errnum);
#endif /* __ERRNO_H */
--
2.30.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 04/10] driver: don't crash when dev_name/dev_id is called with NULL dev
2022-10-10 6:11 [PATCH 00/10] treewide: misc cleanup for efiloader prep Ahmad Fatoum
` (2 preceding siblings ...)
2022-10-10 6:11 ` [PATCH 03/10] common: misc: remove now unused errno_str Ahmad Fatoum
@ 2022-10-10 6:11 ` Ahmad Fatoum
2022-10-10 6:11 ` [PATCH 05/10] lds: introduce <asm/barebox.lds.h> Ahmad Fatoum
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
cdev->dev being NULL is normal for virtual device files like /dev/null,
but can trip developers over. Ensure dev_name(cdev->dev) returns NULL
instead of crashing for more robustness.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/driver.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/driver.h b/include/driver.h
index 543287a27638..c81aa8587c13 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -184,6 +184,8 @@ char *deviceid_from_spec_str(const char *str, char **endp);
static inline const char *dev_id(const struct device_d *dev)
{
+ if (!dev)
+ return NULL;
return (dev->id != DEVICE_ID_SINGLE) ? dev->unique_name : dev->name;
}
--
2.30.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 05/10] lds: introduce <asm/barebox.lds.h>
2022-10-10 6:11 [PATCH 00/10] treewide: misc cleanup for efiloader prep Ahmad Fatoum
` (3 preceding siblings ...)
2022-10-10 6:11 ` [PATCH 04/10] driver: don't crash when dev_name/dev_id is called with NULL dev Ahmad Fatoum
@ 2022-10-10 6:11 ` Ahmad Fatoum
2022-10-10 6:11 ` [PATCH 06/10] lds: move OUTPUT_FORMAT/ARCH definition into header Ahmad Fatoum
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We have a separate linker script for each architecture and one more for
PBL if supported. All linker scripts include <asm-generic/barebox.lds.h>.
In future, we may want to use a linker script common to more than one
architecture. Prepare for this by having each architecture define a
<asm/barebox.lds.h>. Currently, these files contain little more than
1-2 #include directives, but this will change in later commits.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/include/asm/barebox.lds.h | 7 +++++++
arch/arm/lib/pbl.lds.S | 2 +-
arch/arm/lib32/barebox.lds.S | 2 +-
arch/arm/lib64/barebox.lds.S | 2 +-
arch/kvx/cpu/barebox.lds.S | 2 +-
arch/kvx/include/asm/barebox.lds.h | 3 +++
arch/mips/include/asm/barebox.lds.h | 3 +++
arch/mips/lib/barebox.lds.S | 2 +-
arch/mips/lib/pbl.lds.S | 2 +-
arch/mips/pbl/zbarebox.lds.S | 2 +-
arch/openrisc/cpu/barebox.lds.S | 2 +-
arch/openrisc/include/asm/barebox.lds.h | 3 +++
arch/powerpc/boards/pcm030/barebox.lds.S | 2 +-
arch/powerpc/include/asm/barebox.lds.h | 3 +++
arch/powerpc/mach-mpc85xx/barebox.lds.S | 2 +-
arch/riscv/include/asm/barebox.lds.h | 3 +++
arch/riscv/lib/barebox.lds.S | 2 +-
arch/riscv/lib/pbl.lds.S | 2 +-
arch/sandbox/board/barebox.lds.S | 2 +-
arch/sandbox/include/asm/barebox.lds.h | 3 +++
arch/x86/include/asm/barebox.lds.h | 3 +++
arch/x86/mach-efi/elf_ia32_efi.lds.S | 2 +-
arch/x86/mach-efi/elf_x86_64_efi.lds.S | 2 +-
common/module.lds.S | 2 +-
include/asm-generic/barebox.lds.h | 4 ----
lib/logo/Makefile | 2 +-
scripts/Makefile.lib | 4 ++--
scripts/gen-dtb-s | 2 +-
28 files changed, 48 insertions(+), 24 deletions(-)
create mode 100644 arch/arm/include/asm/barebox.lds.h
create mode 100644 arch/kvx/include/asm/barebox.lds.h
create mode 100644 arch/mips/include/asm/barebox.lds.h
create mode 100644 arch/openrisc/include/asm/barebox.lds.h
create mode 100644 arch/powerpc/include/asm/barebox.lds.h
create mode 100644 arch/riscv/include/asm/barebox.lds.h
create mode 100644 arch/sandbox/include/asm/barebox.lds.h
create mode 100644 arch/x86/include/asm/barebox.lds.h
diff --git a/arch/arm/include/asm/barebox.lds.h b/arch/arm/include/asm/barebox.lds.h
new file mode 100644
index 000000000000..327beaf4bfb8
--- /dev/null
+++ b/arch/arm/include/asm/barebox.lds.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#if defined CONFIG_ARCH_EP93XX
+#include <mach/barebox.lds.h>
+#endif
+
+#include <asm-generic/barebox.lds.h>
diff --git a/arch/arm/lib/pbl.lds.S b/arch/arm/lib/pbl.lds.S
index d48f27bc43b5..cc4b12f44893 100644
--- a/arch/arm/lib/pbl.lds.S
+++ b/arch/arm/lib/pbl.lds.S
@@ -2,7 +2,7 @@
/* SPDX-FileCopyrightText: 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix */
#include <linux/sizes.h>
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
#include <asm-generic/memory_layout.h>
#ifdef CONFIG_PBL_RELOCATABLE
diff --git a/arch/arm/lib32/barebox.lds.S b/arch/arm/lib32/barebox.lds.S
index 77a5c525c5ae..2bf66657a367 100644
--- a/arch/arm/lib32/barebox.lds.S
+++ b/arch/arm/lib32/barebox.lds.S
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/* SPDX-FileCopyrightText: 2000-2004 Wolfgang Denk <wd@denx.de>, DENX Software Engineering */
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
#include <asm/secure.h>
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
diff --git a/arch/arm/lib64/barebox.lds.S b/arch/arm/lib64/barebox.lds.S
index 2ebaabef0f1d..c1069c896f27 100644
--- a/arch/arm/lib64/barebox.lds.S
+++ b/arch/arm/lib64/barebox.lds.S
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/* SPDX-FileCopyrightText: 2000-2004 Wolfgang Denk <wd@denx.de>, DENX Software Engineering */
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64")
OUTPUT_ARCH(aarch64)
diff --git a/arch/kvx/cpu/barebox.lds.S b/arch/kvx/cpu/barebox.lds.S
index 77ebaf0aeac0..a22998190f78 100644
--- a/arch/kvx/cpu/barebox.lds.S
+++ b/arch/kvx/cpu/barebox.lds.S
@@ -5,7 +5,7 @@
#include <asm/common.h>
#include <asm/sys_arch.h>
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
OUTPUT_FORMAT("elf64-kvx")
OUTPUT_ARCH("kvx:kv3-1:64")
diff --git a/arch/kvx/include/asm/barebox.lds.h b/arch/kvx/include/asm/barebox.lds.h
new file mode 100644
index 000000000000..540d740959ff
--- /dev/null
+++ b/arch/kvx/include/asm/barebox.lds.h
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <asm-generic/barebox.lds.h>
diff --git a/arch/mips/include/asm/barebox.lds.h b/arch/mips/include/asm/barebox.lds.h
new file mode 100644
index 000000000000..540d740959ff
--- /dev/null
+++ b/arch/mips/include/asm/barebox.lds.h
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <asm-generic/barebox.lds.h>
diff --git a/arch/mips/lib/barebox.lds.S b/arch/mips/lib/barebox.lds.S
index c954df41f3cc..87668c7a7320 100644
--- a/arch/mips/lib/barebox.lds.S
+++ b/arch/mips/lib/barebox.lds.S
@@ -4,7 +4,7 @@
*/
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
OUTPUT_ARCH(mips)
ENTRY(_start)
diff --git a/arch/mips/lib/pbl.lds.S b/arch/mips/lib/pbl.lds.S
index 413f24b9ab05..521333df0be0 100644
--- a/arch/mips/lib/pbl.lds.S
+++ b/arch/mips/lib/pbl.lds.S
@@ -4,7 +4,7 @@
* (C) Copyright 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
*/
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
#include <asm-generic/memory_layout.h>
#include <linux/sizes.h>
diff --git a/arch/mips/pbl/zbarebox.lds.S b/arch/mips/pbl/zbarebox.lds.S
index 04b5b8680f27..2d82065bce08 100644
--- a/arch/mips/pbl/zbarebox.lds.S
+++ b/arch/mips/pbl/zbarebox.lds.S
@@ -3,7 +3,7 @@
* (C) Copyright 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
*/
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
#include <asm-generic/memory_layout.h>
OUTPUT_ARCH("mips")
diff --git a/arch/openrisc/cpu/barebox.lds.S b/arch/openrisc/cpu/barebox.lds.S
index 45c5f2553951..f6999a113438 100644
--- a/arch/openrisc/cpu/barebox.lds.S
+++ b/arch/openrisc/cpu/barebox.lds.S
@@ -14,7 +14,7 @@
*/
#include <config.h>
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
OUTPUT_FORMAT("elf32-or1k", "elf32-or1k", "elf32-or1k")
ENTRY(__reset)
diff --git a/arch/openrisc/include/asm/barebox.lds.h b/arch/openrisc/include/asm/barebox.lds.h
new file mode 100644
index 000000000000..540d740959ff
--- /dev/null
+++ b/arch/openrisc/include/asm/barebox.lds.h
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <asm-generic/barebox.lds.h>
diff --git a/arch/powerpc/boards/pcm030/barebox.lds.S b/arch/powerpc/boards/pcm030/barebox.lds.S
index 2536db745cf8..b90e88058113 100644
--- a/arch/powerpc/boards/pcm030/barebox.lds.S
+++ b/arch/powerpc/boards/pcm030/barebox.lds.S
@@ -14,7 +14,7 @@
*
*/
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
OUTPUT_ARCH("powerpc")
ENTRY(_start)
diff --git a/arch/powerpc/include/asm/barebox.lds.h b/arch/powerpc/include/asm/barebox.lds.h
new file mode 100644
index 000000000000..540d740959ff
--- /dev/null
+++ b/arch/powerpc/include/asm/barebox.lds.h
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <asm-generic/barebox.lds.h>
diff --git a/arch/powerpc/mach-mpc85xx/barebox.lds.S b/arch/powerpc/mach-mpc85xx/barebox.lds.S
index 2b73fda4e6b8..253fd3735e48 100644
--- a/arch/powerpc/mach-mpc85xx/barebox.lds.S
+++ b/arch/powerpc/mach-mpc85xx/barebox.lds.S
@@ -13,7 +13,7 @@
* GNU General Public License for more details.
*/
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
#ifdef CONFIG_RESET_VECTOR_ADDRESS
#define RESET_VECTOR_ADDRESS CONFIG_RESET_VECTOR_ADDRESS
diff --git a/arch/riscv/include/asm/barebox.lds.h b/arch/riscv/include/asm/barebox.lds.h
new file mode 100644
index 000000000000..540d740959ff
--- /dev/null
+++ b/arch/riscv/include/asm/barebox.lds.h
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <asm-generic/barebox.lds.h>
diff --git a/arch/riscv/lib/barebox.lds.S b/arch/riscv/lib/barebox.lds.S
index 7856b57a5220..5de32a47e7c0 100644
--- a/arch/riscv/lib/barebox.lds.S
+++ b/arch/riscv/lib/barebox.lds.S
@@ -11,7 +11,7 @@
*
*/
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
OUTPUT_ARCH(riscv)
ENTRY(start)
diff --git a/arch/riscv/lib/pbl.lds.S b/arch/riscv/lib/pbl.lds.S
index ccf64fc6d3aa..ba59024ae037 100644
--- a/arch/riscv/lib/pbl.lds.S
+++ b/arch/riscv/lib/pbl.lds.S
@@ -2,7 +2,7 @@
/* SPDX-FileCopyrightText: 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix */
#include <linux/sizes.h>
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
#include <asm-generic/memory_layout.h>
OUTPUT_ARCH(riscv)
diff --git a/arch/sandbox/board/barebox.lds.S b/arch/sandbox/board/barebox.lds.S
index 84d085a25911..ab2801f3d207 100644
--- a/arch/sandbox/board/barebox.lds.S
+++ b/arch/sandbox/board/barebox.lds.S
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
SECTIONS
{
diff --git a/arch/sandbox/include/asm/barebox.lds.h b/arch/sandbox/include/asm/barebox.lds.h
new file mode 100644
index 000000000000..540d740959ff
--- /dev/null
+++ b/arch/sandbox/include/asm/barebox.lds.h
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <asm-generic/barebox.lds.h>
diff --git a/arch/x86/include/asm/barebox.lds.h b/arch/x86/include/asm/barebox.lds.h
new file mode 100644
index 000000000000..540d740959ff
--- /dev/null
+++ b/arch/x86/include/asm/barebox.lds.h
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <asm-generic/barebox.lds.h>
diff --git a/arch/x86/mach-efi/elf_ia32_efi.lds.S b/arch/x86/mach-efi/elf_ia32_efi.lds.S
index ac89fd89a4d3..14ae702e5049 100644
--- a/arch/x86/mach-efi/elf_ia32_efi.lds.S
+++ b/arch/x86/mach-efi/elf_ia32_efi.lds.S
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
diff --git a/arch/x86/mach-efi/elf_x86_64_efi.lds.S b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
index b620ba5b3797..8c666235ce1a 100644
--- a/arch/x86/mach-efi/elf_x86_64_efi.lds.S
+++ b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
-#include <asm-generic/barebox.lds.h>
+#include <asm/barebox.lds.h>
/* Same as elf_x86_64_fbsd_efi.lds, except for OUTPUT_FORMAT below - KEEP IN SYNC */
diff --git a/common/module.lds.S b/common/module.lds.S
index 76f3b6d1bba1..b2d685670bb0 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/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index 48c10b173852..d3736ebaed59 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -8,10 +8,6 @@
#define STRUCT_ALIGNMENT 32
#define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
-#if defined CONFIG_ARCH_EP93XX
-#include <mach/barebox.lds.h>
-#endif
-
#ifndef PRE_IMAGE
#define PRE_IMAGE
#endif
diff --git a/lib/logo/Makefile b/lib/logo/Makefile
index d076a19a7657..382701fb365c 100644
--- a/lib/logo/Makefile
+++ b/lib/logo/Makefile
@@ -25,7 +25,7 @@ obj-$(CONFIG_BAREBOX_LOGO) += logo.o
quiet_cmd_logo_S = LOGO.S $@
cmd_logo_S = \
( \
- echo '\#include <asm-generic/barebox.lds.h>'; \
+ echo '\#include <asm/barebox.lds.h>'; \
echo '.section .bblogo.rodata.$(subst -,_,$(*F)),"a"'; \
echo '.balign STRUCT_ALIGNMENT'; \
echo '.global __bblogo_$(subst -,_,$(*F))_start'; \
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 16308497b845..85d18f07a2b6 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -379,7 +379,7 @@ dtc-tmp = $(subst $(comma),_,$(dot-target).dts)
quiet_cmd_env_S = ENV.S $@
cmd_env_S = \
( \
- echo '\#include <asm-generic/barebox.lds.h>'; \
+ echo '\#include <asm/barebox.lds.h>'; \
echo '.section .bbenv.rodata.$(subst -,_,$(*F)),"a"'; \
echo '.balign STRUCT_ALIGNMENT'; \
echo '.global __bbenv_$(subst -,_,$(*F))_start'; \
@@ -528,7 +528,7 @@ quiet_cmd_check_file_size = CHKFILESIZE $2
quiet_cmd_imximage__S_dcd= DCD_S $@
cmd_imximage_S_dcd= \
( \
- echo '\#include <asm-generic/barebox.lds.h>'; \
+ echo '\#include <asm/barebox.lds.h>'; \
echo '.balign STRUCT_ALIGNMENT'; \
echo '.global $(subst -,_,$(*F))_start'; \
echo '$(subst -,_,$(*F))_start:'; \
diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
index eadf4d76f313..c5c46a4d8675 100755
--- a/scripts/gen-dtb-s
+++ b/scripts/gen-dtb-s
@@ -4,7 +4,7 @@ name=$1
dtb=$2
imd=$3
-echo "#include <asm-generic/barebox.lds.h>"
+echo "#include <asm/barebox.lds.h>"
le32() {
printf ".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" \
--
2.30.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 06/10] lds: move OUTPUT_FORMAT/ARCH definition into header
2022-10-10 6:11 [PATCH 00/10] treewide: misc cleanup for efiloader prep Ahmad Fatoum
` (4 preceding siblings ...)
2022-10-10 6:11 ` [PATCH 05/10] lds: introduce <asm/barebox.lds.h> Ahmad Fatoum
@ 2022-10-10 6:11 ` Ahmad Fatoum
2022-10-10 6:11 ` [PATCH 07/10] ARM: lds: define and use BAREBOX_RELOCATION_TABLE Ahmad Fatoum
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
In order to allow us having architecture-indepenent linker scripts, move
the definition for the format and the architecture into the new
<asm/barebox.lds.h> header file.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/include/asm/barebox.lds.h | 8 ++++++++
arch/arm/lib/pbl.lds.S | 10 +++-------
arch/arm/lib32/barebox.lds.S | 4 ++--
arch/arm/lib64/barebox.lds.S | 4 ++--
arch/kvx/include/asm/barebox.lds.h | 3 +++
arch/mips/include/asm/barebox.lds.h | 2 ++
arch/mips/lib/barebox.lds.S | 2 +-
arch/mips/lib/pbl.lds.S | 2 +-
arch/mips/pbl/zbarebox.lds.S | 2 +-
arch/openrisc/cpu/barebox.lds.S | 2 +-
arch/openrisc/include/asm/barebox.lds.h | 2 ++
arch/powerpc/boards/pcm030/barebox.lds.S | 2 +-
arch/powerpc/include/asm/barebox.lds.h | 2 ++
arch/powerpc/mach-mpc85xx/barebox.lds.S | 2 +-
arch/riscv/include/asm/barebox.lds.h | 7 +++++++
arch/riscv/lib/barebox.lds.S | 8 ++------
arch/riscv/lib/pbl.lds.S | 8 ++------
arch/x86/include/asm/barebox.lds.h | 8 ++++++++
arch/x86/mach-efi/elf_ia32_efi.lds.S | 4 ++--
arch/x86/mach-efi/elf_x86_64_efi.lds.S | 4 ++--
20 files changed, 53 insertions(+), 33 deletions(-)
diff --git a/arch/arm/include/asm/barebox.lds.h b/arch/arm/include/asm/barebox.lds.h
index 327beaf4bfb8..e358064ec6f8 100644
--- a/arch/arm/include/asm/barebox.lds.h
+++ b/arch/arm/include/asm/barebox.lds.h
@@ -4,4 +4,12 @@
#include <mach/barebox.lds.h>
#endif
+#ifdef CONFIG_CPU_32
+#define BAREBOX_OUTPUT_FORMAT "elf32-littlearm", "elf32-littlearm", "elf32-littlearm"
+#define BAREBOX_OUTPUT_ARCH "arm"
+#else
+#define BAREBOX_OUTPUT_FORMAT "elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64"
+#define BAREBOX_OUTPUT_ARCH "aarch64"
+#endif
+
#include <asm-generic/barebox.lds.h>
diff --git a/arch/arm/lib/pbl.lds.S b/arch/arm/lib/pbl.lds.S
index cc4b12f44893..42c7a4f91fb4 100644
--- a/arch/arm/lib/pbl.lds.S
+++ b/arch/arm/lib/pbl.lds.S
@@ -11,13 +11,9 @@
#define BASE (TEXT_BASE - SZ_2M)
#endif
-#ifdef CONFIG_CPU_32
-OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
-OUTPUT_ARCH(arm)
-#else
-OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64")
-OUTPUT_ARCH(aarch64)
-#endif
+OUTPUT_FORMAT(BAREBOX_OUTPUT_FORMAT)
+OUTPUT_ARCH(BAREBOX_OUTPUT_ARCH)
+
SECTIONS
{
. = BASE;
diff --git a/arch/arm/lib32/barebox.lds.S b/arch/arm/lib32/barebox.lds.S
index 2bf66657a367..ea66b3c3feaf 100644
--- a/arch/arm/lib32/barebox.lds.S
+++ b/arch/arm/lib32/barebox.lds.S
@@ -4,8 +4,8 @@
#include <asm/barebox.lds.h>
#include <asm/secure.h>
-OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
-OUTPUT_ARCH(arm)
+OUTPUT_FORMAT(BAREBOX_OUTPUT_FORMAT)
+OUTPUT_ARCH(BAREBOX_OUTPUT_ARCH)
ENTRY(start)
SECTIONS
{
diff --git a/arch/arm/lib64/barebox.lds.S b/arch/arm/lib64/barebox.lds.S
index c1069c896f27..e2049753fdd5 100644
--- a/arch/arm/lib64/barebox.lds.S
+++ b/arch/arm/lib64/barebox.lds.S
@@ -3,8 +3,8 @@
#include <asm/barebox.lds.h>
-OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64")
-OUTPUT_ARCH(aarch64)
+OUTPUT_FORMAT(BAREBOX_OUTPUT_FORMAT)
+OUTPUT_ARCH(BAREBOX_OUTPUT_ARCH)
ENTRY(start)
SECTIONS
{
diff --git a/arch/kvx/include/asm/barebox.lds.h b/arch/kvx/include/asm/barebox.lds.h
index 540d740959ff..4b0581c81aeb 100644
--- a/arch/kvx/include/asm/barebox.lds.h
+++ b/arch/kvx/include/asm/barebox.lds.h
@@ -1,3 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
+#define LDS_OUTPUT_FORMAT "elf64-kvx"
+#define LDS_OUTPUT_ARCH "kvx:kv3-1:64"
+
#include <asm-generic/barebox.lds.h>
diff --git a/arch/mips/include/asm/barebox.lds.h b/arch/mips/include/asm/barebox.lds.h
index 540d740959ff..124f3d5d6667 100644
--- a/arch/mips/include/asm/barebox.lds.h
+++ b/arch/mips/include/asm/barebox.lds.h
@@ -1,3 +1,5 @@
/* SPDX-License-Identifier: GPL-2.0-only */
+#define BAREBOX_OUTPUT_ARCH "mips"
+
#include <asm-generic/barebox.lds.h>
diff --git a/arch/mips/lib/barebox.lds.S b/arch/mips/lib/barebox.lds.S
index 87668c7a7320..1259a4e94fc5 100644
--- a/arch/mips/lib/barebox.lds.S
+++ b/arch/mips/lib/barebox.lds.S
@@ -6,7 +6,7 @@
#include <asm/barebox.lds.h>
-OUTPUT_ARCH(mips)
+OUTPUT_ARCH(BAREBOX_OUTPUT_ARCH)
ENTRY(_start)
SECTIONS
{
diff --git a/arch/mips/lib/pbl.lds.S b/arch/mips/lib/pbl.lds.S
index 521333df0be0..4cf0398f33d1 100644
--- a/arch/mips/lib/pbl.lds.S
+++ b/arch/mips/lib/pbl.lds.S
@@ -10,7 +10,7 @@
#define BASE (TEXT_BASE - SZ_2M)
-OUTPUT_ARCH("mips")
+OUTPUT_ARCH(BAREBOX_OUTPUT_ARCH)
SECTIONS
{
. = BASE;
diff --git a/arch/mips/pbl/zbarebox.lds.S b/arch/mips/pbl/zbarebox.lds.S
index 2d82065bce08..e3114dfe2230 100644
--- a/arch/mips/pbl/zbarebox.lds.S
+++ b/arch/mips/pbl/zbarebox.lds.S
@@ -6,7 +6,7 @@
#include <asm/barebox.lds.h>
#include <asm-generic/memory_layout.h>
-OUTPUT_ARCH("mips")
+OUTPUT_ARCH(BAREBOX_OUTPUT_ARCH)
ENTRY(pbl_start)
SECTIONS
{
diff --git a/arch/openrisc/cpu/barebox.lds.S b/arch/openrisc/cpu/barebox.lds.S
index f6999a113438..3fae1af37594 100644
--- a/arch/openrisc/cpu/barebox.lds.S
+++ b/arch/openrisc/cpu/barebox.lds.S
@@ -16,7 +16,7 @@
#include <config.h>
#include <asm/barebox.lds.h>
-OUTPUT_FORMAT("elf32-or1k", "elf32-or1k", "elf32-or1k")
+OUTPUT_FORMAT(BAREBOX_OUTPUT_FORMAT)
ENTRY(__reset)
__DYNAMIC = 0;
diff --git a/arch/openrisc/include/asm/barebox.lds.h b/arch/openrisc/include/asm/barebox.lds.h
index 540d740959ff..87d868e1ad21 100644
--- a/arch/openrisc/include/asm/barebox.lds.h
+++ b/arch/openrisc/include/asm/barebox.lds.h
@@ -1,3 +1,5 @@
/* SPDX-License-Identifier: GPL-2.0-only */
+#define BAREBOX_OUTPUT_FORMAT "elf32-or1k", "elf32-or1k", "elf32-or1k"
+
#include <asm-generic/barebox.lds.h>
diff --git a/arch/powerpc/boards/pcm030/barebox.lds.S b/arch/powerpc/boards/pcm030/barebox.lds.S
index b90e88058113..146b63fe8889 100644
--- a/arch/powerpc/boards/pcm030/barebox.lds.S
+++ b/arch/powerpc/boards/pcm030/barebox.lds.S
@@ -16,7 +16,7 @@
#include <asm/barebox.lds.h>
-OUTPUT_ARCH("powerpc")
+OUTPUT_ARCH(BAREBOX_OUTPUT_ARCH)
ENTRY(_start)
/* Do we need any of these for elf?
__DYNAMIC = 0; */
diff --git a/arch/powerpc/include/asm/barebox.lds.h b/arch/powerpc/include/asm/barebox.lds.h
index 540d740959ff..14477bd44a37 100644
--- a/arch/powerpc/include/asm/barebox.lds.h
+++ b/arch/powerpc/include/asm/barebox.lds.h
@@ -1,3 +1,5 @@
/* SPDX-License-Identifier: GPL-2.0-only */
+#define BAREBOX_OUTPUT_ARCH "powerpc"
+
#include <asm-generic/barebox.lds.h>
diff --git a/arch/powerpc/mach-mpc85xx/barebox.lds.S b/arch/powerpc/mach-mpc85xx/barebox.lds.S
index 253fd3735e48..764854a860e7 100644
--- a/arch/powerpc/mach-mpc85xx/barebox.lds.S
+++ b/arch/powerpc/mach-mpc85xx/barebox.lds.S
@@ -21,7 +21,7 @@
#define RESET_VECTOR_ADDRESS 0xfffffffc
#endif
-OUTPUT_ARCH("powerpc")
+OUTPUT_ARCH(BAREBOX_OUTPUT_ARCH)
ENTRY(_start_e500)
PHDRS
diff --git a/arch/riscv/include/asm/barebox.lds.h b/arch/riscv/include/asm/barebox.lds.h
index 540d740959ff..0fa05df6ff2e 100644
--- a/arch/riscv/include/asm/barebox.lds.h
+++ b/arch/riscv/include/asm/barebox.lds.h
@@ -1,3 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0-only */
+#define BAREBOX_OUTPUT_ARCH "riscv"
+#ifdef CONFIG_64BIT
+#define BAREBOX_OUTPUT_FORMAT "elf64-littleriscv"
+#else
+#define BAREBOX_OUTPUT_FORMAT "elf32-littleriscv"
+#endif
+
#include <asm-generic/barebox.lds.h>
diff --git a/arch/riscv/lib/barebox.lds.S b/arch/riscv/lib/barebox.lds.S
index 5de32a47e7c0..101615ab052a 100644
--- a/arch/riscv/lib/barebox.lds.S
+++ b/arch/riscv/lib/barebox.lds.S
@@ -13,13 +13,9 @@
#include <asm/barebox.lds.h>
-OUTPUT_ARCH(riscv)
+OUTPUT_ARCH(BAREBOX_OUTPUT_ARCH)
ENTRY(start)
-#ifdef CONFIG_64BIT
-OUTPUT_FORMAT("elf64-littleriscv")
-#else
-OUTPUT_FORMAT("elf32-littleriscv")
-#endif
+OUTPUT_FORMAT(BAREBOX_OUTPUT_FORMAT)
SECTIONS
{
. = 0x0;
diff --git a/arch/riscv/lib/pbl.lds.S b/arch/riscv/lib/pbl.lds.S
index ba59024ae037..0fe7dfda8eb4 100644
--- a/arch/riscv/lib/pbl.lds.S
+++ b/arch/riscv/lib/pbl.lds.S
@@ -5,12 +5,8 @@
#include <asm/barebox.lds.h>
#include <asm-generic/memory_layout.h>
-OUTPUT_ARCH(riscv)
-#ifdef CONFIG_64BIT
-OUTPUT_FORMAT("elf64-littleriscv")
-#else
-OUTPUT_FORMAT("elf32-littleriscv")
-#endif
+OUTPUT_ARCH(BAREBOX_OUTPUT_ARCH)
+OUTPUT_FORMAT(BAREBOX_OUTPUT_FORMAT)
SECTIONS
{
. = 0x0;
diff --git a/arch/x86/include/asm/barebox.lds.h b/arch/x86/include/asm/barebox.lds.h
index 540d740959ff..f00d36c4e747 100644
--- a/arch/x86/include/asm/barebox.lds.h
+++ b/arch/x86/include/asm/barebox.lds.h
@@ -1,3 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0-only */
+#ifdef CONFIG_X86_32
+#define BAREBOX_OUTPUT_FORMAT "elf32-i386", "elf32-i386", "elf32-i386"
+#define BAREBOX_OUTPUT_ARCH "i386"
+#else
+#define BAREBOX_OUTPUT_FORMAT "elf64-x86-64", "elf64-x86-64", "elf64-x86-64"
+#define BAREBOX_OUTPUT_ARCH "i386:x86-64"
+#endif
+
#include <asm-generic/barebox.lds.h>
diff --git a/arch/x86/mach-efi/elf_ia32_efi.lds.S b/arch/x86/mach-efi/elf_ia32_efi.lds.S
index 14ae702e5049..4b1300724300 100644
--- a/arch/x86/mach-efi/elf_ia32_efi.lds.S
+++ b/arch/x86/mach-efi/elf_ia32_efi.lds.S
@@ -2,8 +2,8 @@
#include <asm/barebox.lds.h>
-OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
-OUTPUT_ARCH(i386)
+OUTPUT_FORMAT(BAREBOX_OUTPUT_FORMAT)
+OUTPUT_ARCH(BAREBOX_OUTPUT_ARCH)
ENTRY(_start)
SECTIONS
{
diff --git a/arch/x86/mach-efi/elf_x86_64_efi.lds.S b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
index 8c666235ce1a..f63c0c0c939e 100644
--- a/arch/x86/mach-efi/elf_x86_64_efi.lds.S
+++ b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
@@ -4,8 +4,8 @@
/* Same as elf_x86_64_fbsd_efi.lds, except for OUTPUT_FORMAT below - KEEP IN SYNC */
-OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
-OUTPUT_ARCH(i386:x86-64)
+OUTPUT_FORMAT(BAREBOX_OUTPUT_FORMAT)
+OUTPUT_ARCH(BAREBOX_OUTPUT_ARCH)
ENTRY(_start)
SECTIONS
{
--
2.30.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 07/10] ARM: lds: define and use BAREBOX_RELOCATION_TABLE
2022-10-10 6:11 [PATCH 00/10] treewide: misc cleanup for efiloader prep Ahmad Fatoum
` (5 preceding siblings ...)
2022-10-10 6:11 ` [PATCH 06/10] lds: move OUTPUT_FORMAT/ARCH definition into header Ahmad Fatoum
@ 2022-10-10 6:11 ` Ahmad Fatoum
2022-10-10 6:11 ` [PATCH 08/10] lib: random: add hwrng_get_crypto_bytes Ahmad Fatoum
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The structure of the relocation table is one of the main differences
between different architectures' linker scripts. Hoist it out for ARM
into <asm/barebox.lds.h>.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/include/asm/barebox.lds.h | 15 +++++++++++++++
arch/arm/lib/pbl.lds.S | 12 +-----------
arch/arm/lib32/barebox.lds.S | 8 +-------
arch/arm/lib64/barebox.lds.S | 8 +-------
4 files changed, 18 insertions(+), 25 deletions(-)
diff --git a/arch/arm/include/asm/barebox.lds.h b/arch/arm/include/asm/barebox.lds.h
index e358064ec6f8..b9c824c4dbf1 100644
--- a/arch/arm/include/asm/barebox.lds.h
+++ b/arch/arm/include/asm/barebox.lds.h
@@ -12,4 +12,19 @@
#define BAREBOX_OUTPUT_ARCH "aarch64"
#endif
+#ifdef CONFIG_CPU_32
+#define BAREBOX_RELOCATION_TYPE rel
+#else
+#define BAREBOX_RELOCATION_TYPE rela
+#endif
+
+#define BAREBOX_RELOCATION_TABLE \
+ .rel_dyn_start : { *(.__rel_dyn_start) } \
+ .BAREBOX_RELOCATION_TYPE.dyn : { *(.BAREBOX_RELOCATION_TYPE*) } \
+ .rel_dyn_end : { *(.__rel_dyn_end) } \
+ .__dynsym_start : { *(.__dynsym_start) } \
+ .dynsym : { *(.dynsym) } \
+ .__dynsym_end : { *(.__dynsym_end) }
+
+
#include <asm-generic/barebox.lds.h>
diff --git a/arch/arm/lib/pbl.lds.S b/arch/arm/lib/pbl.lds.S
index 42c7a4f91fb4..ae1babdcfd27 100644
--- a/arch/arm/lib/pbl.lds.S
+++ b/arch/arm/lib/pbl.lds.S
@@ -58,17 +58,7 @@ SECTIONS
}
__shasum_end = .;
- .rel_dyn_start : { *(.__rel_dyn_start) }
-#ifdef CONFIG_CPU_32
- .rel.dyn : { *(.rel*) }
-#else
- .rela.dyn : { *(.rela*) }
-#endif
- .rel_dyn_end : { *(.__rel_dyn_end) }
-
- .__dynsym_start : { *(.__dynsym_start) }
- .dynsym : { *(.dynsym) }
- .__dynsym_end : { *(.__dynsym_end) }
+ BAREBOX_RELOCATION_TABLE
pbl_code_size = . - BASE;
diff --git a/arch/arm/lib32/barebox.lds.S b/arch/arm/lib32/barebox.lds.S
index ea66b3c3feaf..ec145569bea3 100644
--- a/arch/arm/lib32/barebox.lds.S
+++ b/arch/arm/lib32/barebox.lds.S
@@ -71,13 +71,7 @@ SECTIONS
. = .;
- .rel_dyn_start : { *(.__rel_dyn_start) }
- .rel.dyn : { *(.rel*) }
- .rel_dyn_end : { *(.__rel_dyn_end) }
-
- .__dynsym_start : { *(.__dynsym_start) }
- .dynsym : { *(.dynsym) }
- .__dynsym_end : { *(.__dynsym_end) }
+ BAREBOX_RELOCATION_TABLE
_edata = .;
.image_end : { *(.__image_end) }
diff --git a/arch/arm/lib64/barebox.lds.S b/arch/arm/lib64/barebox.lds.S
index e2049753fdd5..de777ddb542b 100644
--- a/arch/arm/lib64/barebox.lds.S
+++ b/arch/arm/lib64/barebox.lds.S
@@ -49,13 +49,7 @@ SECTIONS
.barebox_imd : { BAREBOX_IMD }
- .rel_dyn_start : { *(.__rel_dyn_start) }
- .rela.dyn : { *(.rela*) }
- .rel_dyn_end : { *(.__rel_dyn_end) }
-
- .__dynsym_start : { *(.__dynsym_start) }
- .dynsym : { *(.dynsym) }
- .__dynsym_end : { *(.__dynsym_end) }
+ BAREBOX_RELOCATION_TABLE
_edata = .;
--
2.30.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 08/10] lib: random: add hwrng_get_crypto_bytes
2022-10-10 6:11 [PATCH 00/10] treewide: misc cleanup for efiloader prep Ahmad Fatoum
` (6 preceding siblings ...)
2022-10-10 6:11 ` [PATCH 07/10] ARM: lds: define and use BAREBOX_RELOCATION_TABLE Ahmad Fatoum
@ 2022-10-10 6:11 ` Ahmad Fatoum
2022-10-10 6:11 ` [PATCH 09/10] common: bootm: factor out FIT parsing code into bootm_open_bit Ahmad Fatoum
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We already have get_crypto_bytes to get access to hardware generated
randomness. barebox as EFI loader would provide a handle for each HWRNG,
so add a hwrng_get_crypto_bytes function that can be used to implement
the load-side protocol.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/linux/hw_random.h | 6 +++++-
include/stdlib.h | 2 ++
lib/random.c | 25 ++++++++++++-------------
3 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h
index 116afd9721e5..e541abfa176e 100644
--- a/include/linux/hw_random.h
+++ b/include/linux/hw_random.h
@@ -36,12 +36,16 @@ struct hwrng {
/* Register a new Hardware Random Number Generator driver. */
int hwrng_register(struct device_d *dev, struct hwrng *rng);
-int hwrng_get_data(struct hwrng *rng, void *buffer, size_t size, int wait);
#ifdef CONFIG_HWRNG
struct hwrng *hwrng_get_first(void);
+int hwrng_get_data(struct hwrng *rng, void *buffer, size_t size, int wait);
#else
static inline struct hwrng *hwrng_get_first(void) { return ERR_PTR(-ENODEV); };
+static inline int hwrng_get_data(struct hwrng *rng, void *buffer, size_t size, int wait)
+{
+ return -ENODEV;
+}
#endif
void hwrng_unregister(struct hwrng *rng);
diff --git a/include/stdlib.h b/include/stdlib.h
index 8eb419e111f0..0305970557df 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -15,6 +15,8 @@ void srand(unsigned int seed);
/* fill a buffer with pseudo-random data */
void get_random_bytes(void *buf, int len);
int get_crypto_bytes(void *buf, int len);
+struct hwrng;
+int hwrng_get_crypto_bytes(struct hwrng *rng, void *buf, int len);
static inline u32 random32(void)
{
diff --git a/lib/random.c b/lib/random.c
index fb3580f9c086..c6532df55249 100644
--- a/lib/random.c
+++ b/lib/random.c
@@ -34,17 +34,8 @@ void get_random_bytes(void *_buf, int len)
*buf++ = rand() % 256;
}
-/**
- * get_crypto_bytes - get random numbers suitable for cryptographic needs.
- */
-static int _get_crypto_bytes(void *buf, int len)
+int hwrng_get_crypto_bytes(struct hwrng *rng, void *buf, int len)
{
- struct hwrng *rng;
-
- rng = hwrng_get_first();
- if (IS_ERR(rng))
- return PTR_ERR(rng);
-
while (len) {
int bytes = hwrng_get_data(rng, buf, len, true);
if (!bytes)
@@ -60,13 +51,21 @@ static int _get_crypto_bytes(void *buf, int len)
return 0;
}
+/**
+ * get_crypto_bytes - get random numbers suitable for cryptographic needs.
+ */
int get_crypto_bytes(void *buf, int len)
{
+ struct hwrng *rng;
int err;
- err = _get_crypto_bytes(buf, len);
- if (!err)
- return 0;
+ rng = hwrng_get_first();
+ err = PTR_ERR_OR_ZERO(rng);
+ if (!err) {
+ err = hwrng_get_crypto_bytes(rng, buf, len);
+ if (!err)
+ return 0;
+ }
if (!IS_ENABLED(CONFIG_ALLOW_PRNG_FALLBACK)) {
pr_err("error: no HWRNG available!\n");
--
2.30.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 09/10] common: bootm: factor out FIT parsing code into bootm_open_bit
2022-10-10 6:11 [PATCH 00/10] treewide: misc cleanup for efiloader prep Ahmad Fatoum
` (7 preceding siblings ...)
2022-10-10 6:11 ` [PATCH 08/10] lib: random: add hwrng_get_crypto_bytes Ahmad Fatoum
@ 2022-10-10 6:11 ` Ahmad Fatoum
2022-10-10 6:11 ` [PATCH 10/10] common: bootm: use switch-case Ahmad Fatoum
2022-10-11 14:46 ` [PATCH 00/10] treewide: misc cleanup for efiloader prep Sascha Hauer
10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We already have counterpart functions for ELF and uimage. Add one for
FIT as well in preparation for moving to a more readable switch statement.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/bootm.c | 107 +++++++++++++++++++++++++++----------------------
1 file changed, 59 insertions(+), 48 deletions(-)
diff --git a/common/bootm.c b/common/bootm.c
index 2f02c156e56f..f507aece8c18 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -519,6 +519,62 @@ 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)
{
if (!IS_ENABLED(CONFIG_ELF))
@@ -633,55 +689,10 @@ 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 (os_type == filetype_oftree) {
+ ret = bootm_open_fit(data);
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. */
- }
+ return ret;
}
if (os_type == filetype_uimage) {
--
2.30.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 10/10] common: bootm: use switch-case
2022-10-10 6:11 [PATCH 00/10] treewide: misc cleanup for efiloader prep Ahmad Fatoum
` (8 preceding siblings ...)
2022-10-10 6:11 ` [PATCH 09/10] common: bootm: factor out FIT parsing code into bootm_open_bit Ahmad Fatoum
@ 2022-10-10 6:11 ` Ahmad Fatoum
2022-10-11 14:46 ` [PATCH 00/10] treewide: misc cleanup for efiloader prep Sascha Hauer
10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:11 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The switch statement is more readable and lends itself to be easily
extended for future file types, e.g. PE/COFF for EFI loading.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/bootm.c | 47 +++++++++++++++++++++++------------------------
1 file changed, 23 insertions(+), 24 deletions(-)
diff --git a/common/bootm.c b/common/bootm.c
index f507aece8c18..fb1ed36a26dc 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -577,16 +577,19 @@ static int bootm_open_fit(struct image_data *data)
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;
}
@@ -689,29 +692,25 @@ int bootm_boot(struct bootm_data *bootm_data)
}
}
- if (os_type == filetype_oftree) {
+ switch (os_type) {
+ case filetype_oftree:
ret = bootm_open_fit(data);
- if (ret)
- return ret;
- }
-
- if (os_type == filetype_uimage) {
+ 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) {
--
2.30.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 00/10] treewide: misc cleanup for efiloader prep
2022-10-10 6:11 [PATCH 00/10] treewide: misc cleanup for efiloader prep Ahmad Fatoum
` (9 preceding siblings ...)
2022-10-10 6:11 ` [PATCH 10/10] common: bootm: use switch-case Ahmad Fatoum
@ 2022-10-11 14:46 ` Sascha Hauer
10 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2022-10-11 14:46 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Oct 10, 2022 at 08:11:12AM +0200, Ahmad Fatoum wrote:
> The patches have in common that no functional change sould be introduced
> and that they resulted during efiloader implementation.
>
> Ahmad Fatoum (10):
> block: have cdev_get_block_device accept const cdev
> treewide: replace errno_str() with %m printf format specifier
> common: misc: remove now unused errno_str
> driver: don't crash when dev_name/dev_id is called with NULL dev
> lds: introduce <asm/barebox.lds.h>
> lds: move OUTPUT_FORMAT/ARCH definition into header
> ARM: lds: define and use BAREBOX_RELOCATION_TABLE
> lib: random: add hwrng_get_crypto_bytes
> common: bootm: factor out FIT parsing code into bootm_open_bit
> common: bootm: use switch-case
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 12+ messages in thread