diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2021-12-15 08:25:16 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-12-15 08:25:16 +0100 |
commit | a2501c9e889abd22b47d42956d27b02607dbb0d8 (patch) | |
tree | f30b5c829fe0adcc784c143aaf436abb6eb9724d /common | |
parent | abad1451586d8e8b36f86ef2772cef81d4ce2651 (diff) | |
parent | 2962e19b55e970c7a2f1b0048abf1ef95463c6f5 (diff) | |
download | barebox-a2501c9e889abd22b47d42956d27b02607dbb0d8.tar.gz barebox-a2501c9e889abd22b47d42956d27b02607dbb0d8.tar.xz |
Merge branch 'for-next/misc'
Diffstat (limited to 'common')
-rw-r--r-- | common/Kconfig | 7 | ||||
-rw-r--r-- | common/Makefile | 1 | ||||
-rw-r--r-- | common/boards/Kconfig | 4 | ||||
-rw-r--r-- | common/boards/Makefile | 3 | ||||
-rw-r--r-- | common/boards/qemu-virt/Makefile | 7 | ||||
-rw-r--r-- | common/boards/qemu-virt/board.c | 68 | ||||
-rw-r--r-- | common/boards/qemu-virt/overlay-of-flash.dts | 106 | ||||
-rw-r--r-- | common/efi/Kconfig | 2 | ||||
-rw-r--r-- | common/envfs-core.c | 14 | ||||
-rw-r--r-- | common/state/backend_format_raw.c | 7 | ||||
-rw-r--r-- | common/state/backend_storage.c | 17 | ||||
-rw-r--r-- | common/state/state.c | 4 | ||||
-rw-r--r-- | common/state/state.h | 14 |
13 files changed, 235 insertions, 19 deletions
diff --git a/common/Kconfig b/common/Kconfig index 7386649a1a..814b820e2a 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -1,3 +1,5 @@ +source "common/boards/Kconfig" + config GREGORIAN_CALENDER bool @@ -1394,6 +1396,11 @@ config DEBUG_STARFIVE depends on SOC_STARFIVE select DEBUG_LL_NS16550 +config DEBUG_RISCV_VIRT + bool "RISC-V Virt ns16550 port" + depends on SOC_VIRT + select DEBUG_LL_NS16550 + config DEBUG_SIFIVE bool "SiFive serial0 port" depends on SOC_SIFIVE diff --git a/common/Makefile b/common/Makefile index 9ed279806a..f4496c4d9b 100644 --- a/common/Makefile +++ b/common/Makefile @@ -1,3 +1,4 @@ +obj-y += boards/ obj-y += memory.o obj-y += memory_display.o pbl-$(CONFIG_PBL_CONSOLE) += memory_display.o diff --git a/common/boards/Kconfig b/common/boards/Kconfig new file mode 100644 index 0000000000..e27273b767 --- /dev/null +++ b/common/boards/Kconfig @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config BOARD_QEMU_VIRT + bool diff --git a/common/boards/Makefile b/common/boards/Makefile new file mode 100644 index 0000000000..5b4e429c13 --- /dev/null +++ b/common/boards/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_BOARD_QEMU_VIRT) += qemu-virt/ diff --git a/common/boards/qemu-virt/Makefile b/common/boards/qemu-virt/Makefile new file mode 100644 index 0000000000..88184e9a79 --- /dev/null +++ b/common/boards/qemu-virt/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-y += board.o +obj-y += overlay-of-flash.dtb.o +ifeq ($(CONFIG_RISCV),y) +DTC_CPP_FLAGS_overlay-of-flash.dtb := -DRISCV_VIRT=1 +endif diff --git a/common/boards/qemu-virt/board.c b/common/boards/qemu-virt/board.c new file mode 100644 index 0000000000..4064409c80 --- /dev/null +++ b/common/boards/qemu-virt/board.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2020 Pengutronix e.K. + * + */ +#include <common.h> +#include <init.h> +#include <of.h> +#include <deep-probe.h> + +#ifdef CONFIG_64BIT +#define MACHINE "virt64" +#else +#define MACHINE "virt" +#endif + +#ifdef CONFIG_ARM +#include <asm/system_info.h> + +static inline void arm_virt_init(void) +{ + const char *hostname = MACHINE; + + if (cpu_is_cortex_a7()) + hostname = "virt-a7"; + else if (cpu_is_cortex_a15()) + hostname = "virt-a15"; + + barebox_set_model("ARM QEMU " MACHINE); + barebox_set_hostname(hostname); +} + +#else +static inline void arm_virt_init(void) {} +#endif + +extern char __dtb_overlay_of_flash_start[]; + +static int virt_probe(struct device_d *dev) +{ + struct device_node *overlay; + void (*init)(void); + + init = device_get_match_data(dev); + if (init) + init(); + + overlay = of_unflatten_dtb(__dtb_overlay_of_flash_start, INT_MAX); + of_overlay_apply_tree(dev->device_node, overlay); + /* of_probe() will happen later at of_populate_initcall */ + + return 0; +} + +static const struct of_device_id virt_of_match[] = { + { .compatible = "linux,dummy-virt", .data = arm_virt_init }, + { .compatible = "riscv-virtio" }, + { /* Sentinel */}, +}; +BAREBOX_DEEP_PROBE_ENABLE(virt_of_match); + +static struct driver_d virt_board_driver = { + .name = "board-qemu-virt", + .probe = virt_probe, + .of_compatible = virt_of_match, +}; + +postcore_platform_driver(virt_board_driver); diff --git a/common/boards/qemu-virt/overlay-of-flash.dts b/common/boards/qemu-virt/overlay-of-flash.dts new file mode 100644 index 0000000000..a271a45510 --- /dev/null +++ b/common/boards/qemu-virt/overlay-of-flash.dts @@ -0,0 +1,106 @@ +/dts-v1/; +/plugin/; + +#ifdef RISCV_VIRT +#define PARTS_TARGET_PATH "/soc/flash@20000000" +#define ENV_DEVICE_PATH "/soc/flash@20000000/partitions/partition@3c00000" +#else +#define PARTS_TARGET_PATH "/flash@0" +#define ENV_DEVICE_PATH "/flash@0/partitions/partition@3c00000" +#endif + +/ { + fragment@0 { + target-path = PARTS_TARGET_PATH; + __overlay__ { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "initramfs"; + reg = <0x0 0x3c00000>; + }; + + environment_flash: partition@3c00000 { + label = "barebox-environment"; + reg = <0x3c00000 0x200000>; + }; + + backend_state_flash: partition@3e00000 { + label = "barebox-state"; + reg = <0x3e00000 0x200000>; + }; + }; + }; + }; + fragment@1 { + target-path="/"; + __overlay__ { + chosen { + environment { + compatible = "barebox,environment"; + device-path = ENV_DEVICE_PATH; + }; + }; + aliases { + state = "/state"; + }; + + state { + #address-cells = <1>; + #size-cells = <1>; + compatible = "barebox,state"; + magic = <0x290cf8c6>; + backend-type = "raw"; + backend = < &backend_state_flash >; + backend-stridesize = <0x200>; + + bootstate { + #address-cells = <1>; + #size-cells = <1>; + + system0 { + #address-cells = <1>; + #size-cells = <1>; + + remaining_attempts@0 { + reg = <0x0 0x4>; + type = "uint32"; + default = <3>; + }; + + priority@4 { + reg = <0x4 0x4>; + type = "uint32"; + default = <20>; + }; + }; + + system1 { + #address-cells = <1>; + #size-cells = <1>; + + remaining_attempts@8 { + reg = <0x8 0x4>; + type = "uint32"; + default = <3>; + }; + + priority@c { + reg = <0xc 0x4>; + type = "uint32"; + default = <21>; + }; + }; + + last_chosen@10 { + reg = <0x10 0x4>; + type = "uint32"; + }; + }; + }; + }; + }; +}; diff --git a/common/efi/Kconfig b/common/efi/Kconfig index b4d94f739c..15246ccbf0 100644 --- a/common/efi/Kconfig +++ b/common/efi/Kconfig @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0-only menu "EFI (Extensible Firmware Interface) Support" diff --git a/common/envfs-core.c b/common/envfs-core.c index 1898c1c8cb..0984d53873 100644 --- a/common/envfs-core.c +++ b/common/envfs-core.c @@ -12,6 +12,8 @@ * the default environment when building the barebox binary. So * do not add any new barebox related functions here! */ +#define pr_fmt(fmt) "envfs: " fmt + #ifdef __BAREBOX__ #include <common.h> #include <fs.h> @@ -23,6 +25,8 @@ #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 static int dir_remove_action(const char *filename, struct stat *statbuf, @@ -39,17 +43,17 @@ static int dir_remove_action(const char *filename, struct stat *statbuf, int envfs_check_super(struct envfs_super *super, size_t *size) { if (ENVFS_32(super->magic) != ENVFS_MAGIC) { - printf("envfs: no envfs (magic mismatch) - envfs never written?\n"); + pr_info("no envfs (magic mismatch) - envfs never written?\n"); return -EIO; } if (crc32(0, super, sizeof(*super) - 4) != ENVFS_32(super->sb_crc)) { - printf("wrong crc on env superblock\n"); + pr_warn("wrong crc on env superblock\n"); return -EIO; } if (super->major < ENVFS_MAJOR) - printf("envfs version %d.%d loaded into %d.%d\n", + pr_info("version %d.%d loaded into %d.%d\n", super->major, super->minor, ENVFS_MAJOR, ENVFS_MINOR); @@ -64,7 +68,7 @@ int envfs_check_data(struct envfs_super *super, const void *buf, size_t size) crc = crc32(0, buf, size); if (crc != ENVFS_32(super->crc)) { - printf("wrong crc on env\n"); + pr_warn("wrong crc on env\n"); return -EIO; } @@ -93,7 +97,7 @@ int envfs_load_data(struct envfs_super *super, void *buf, size_t size, buf += sizeof(struct envfs_inode); if (ENVFS_32(inode->magic) != ENVFS_INODE_MAGIC) { - printf("envfs: wrong magic\n"); + pr_warn("wrong magic\n"); ret = -EIO; goto out; } diff --git a/common/state/backend_format_raw.c b/common/state/backend_format_raw.c index ea962606cc..1fecdeb9cf 100644 --- a/common/state/backend_format_raw.c +++ b/common/state/backend_format_raw.c @@ -115,11 +115,10 @@ static int backend_format_raw_verify(struct state_backend_format *format, header = (struct backend_raw_header *)buf; crc = crc32(0, header, sizeof(*header) - sizeof(uint32_t)); - if (crc != header->header_crc) { - dev_err(backend_raw->dev, "Error, invalid header crc in raw format, calculated 0x%08x, found 0x%08x\n", + if (crc != header->header_crc) + return dev_err_state_init(backend_raw->dev, header->header_crc ? -EINVAL : -ENOMEDIUM, + "header crc in raw format, calculated 0x%08x, found 0x%08x\n", crc, header->header_crc); - return -EINVAL; - } if (magic && magic != header->magic) { dev_err(backend_raw->dev, "Error, invalid magic in raw format 0x%08x, should be 0x%08x\n", diff --git a/common/state/backend_storage.c b/common/state/backend_storage.c index 7fc7acfdcb..72f8bcf521 100644 --- a/common/state/backend_storage.c +++ b/common/state/backend_storage.c @@ -144,6 +144,7 @@ int state_storage_read(struct state_backend_storage *storage, enum state_flags flags) { struct state_backend_storage_bucket *bucket, *bucket_used = NULL; + int zerobuckets = 0, totalbuckets = 0; int ret; dev_dbg(storage->dev, "Checking redundant buckets...\n"); @@ -152,6 +153,8 @@ int state_storage_read(struct state_backend_storage *storage, * one we want to use. */ list_for_each_entry(bucket, &storage->buckets, bucket_list) { + totalbuckets++; + ret = bucket->read(bucket, &bucket->buf, &bucket->len); if (ret == -EUCLEAN) bucket->needs_refresh = 1; @@ -163,19 +166,19 @@ int state_storage_read(struct state_backend_storage *storage, * .verify overwrites it with the length actually used. */ ret = format->verify(format, magic, bucket->buf, &bucket->len, flags); - if (!ret && !bucket_used) + if (ret == -ENOMEDIUM) + zerobuckets++; + else if (!ret && !bucket_used) bucket_used = bucket; - if (ret) + else if (ret) dev_info(storage->dev, "Ignoring broken bucket %d@0x%08llx...\n", bucket->num, (long long) bucket->offset); } dev_dbg(storage->dev, "Checking redundant buckets finished.\n"); - if (!bucket_used) { - dev_err(storage->dev, "Failed to find any valid state copy in any bucket\n"); - - return -ENOENT; - } + if (!bucket_used) + return dev_err_state_init(storage->dev, zerobuckets == totalbuckets ? -ENOMEDIUM : -ENOENT, + "no valid state copy in any bucket\n"); dev_info(storage->dev, "Using bucket %d@0x%08llx\n", bucket_used->num, (long long) bucket_used->offset); diff --git a/common/state/state.c b/common/state/state.c index 469ee62d40..8c34ae83e5 100644 --- a/common/state/state.c +++ b/common/state/state.c @@ -101,8 +101,8 @@ static int state_do_load(struct state *state, enum state_flags flags) ret = state_storage_read(&state->storage, state->format, state->magic, &buf, &len, flags); if (ret) { - dev_err(&state->dev, "Failed to read state with format %s, %d\n", - state->format->name, ret); + dev_err_state_init(&state->dev, ret, "format %s read failed\n", + state->format->name); goto out; } diff --git a/common/state/state.h b/common/state/state.h index 1881d92ea7..48572c5d41 100644 --- a/common/state/state.h +++ b/common/state/state.h @@ -1,5 +1,6 @@ #include <linux/types.h> #include <linux/list.h> +#include <linux/err.h> #include <driver.h> struct state; @@ -266,3 +267,16 @@ static inline int state_string_copy_to_raw(struct state_string *string, return 0; } + +#ifdef DEBUG +#define MSG_STATE_ZERO_INIT MSG_INFO +#else +#define MSG_STATE_ZERO_INIT MSG_DEBUG +#endif + +#define dev_err_state_init(dev, ret, fmt, ...) ({ \ + int __ret = (ret); \ + __dev_printf(__ret == -ENOMEDIUM ? MSG_STATE_ZERO_INIT : MSG_ERR, \ + (dev), "init error: %pe: " fmt, ERR_PTR(__ret), ##__VA_ARGS__); \ + __ret; \ +}) |