diff options
Diffstat (limited to 'common/boards/qemu-virt')
-rw-r--r-- | common/boards/qemu-virt/Makefile | 13 | ||||
-rw-r--r-- | common/boards/qemu-virt/board.c | 90 | ||||
-rw-r--r-- | common/boards/qemu-virt/fitimage-pubkey.dts | 7 | ||||
-rw-r--r-- | common/boards/qemu-virt/qemu-virt-flash.dtso | 99 | ||||
-rw-r--r-- | common/boards/qemu-virt/qemu-virt-flash.h | 22 |
5 files changed, 231 insertions, 0 deletions
diff --git a/common/boards/qemu-virt/Makefile b/common/boards/qemu-virt/Makefile new file mode 100644 index 0000000000..30bf4f1955 --- /dev/null +++ b/common/boards/qemu-virt/Makefile @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-y += board.o +obj-y += qemu-virt-flash.dtbo.o fitimage-pubkey.dtb.o +ifeq ($(CONFIG_RISCV),y) +DTC_CPP_FLAGS_qemu-virt-flash.dtbo := -DCONFIG_RISCV +endif +ifeq ($(CONFIG_ARM),y) +DTC_CPP_FLAGS_qemu-virt-flash.dtbo := -DCONFIG_ARM +endif + +clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.z +clean-files += *.dtbo *.dtbo.S .*.dtso diff --git a/common/boards/qemu-virt/board.c b/common/boards/qemu-virt/board.c new file mode 100644 index 0000000000..4f2f7374c5 --- /dev/null +++ b/common/boards/qemu-virt/board.c @@ -0,0 +1,90 @@ +// 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> +#include "qemu-virt-flash.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 __dtbo_qemu_virt_flash_start[]; +extern char __dtb_fitimage_pubkey_start[]; + +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); + +/* + * We don't have a dedicated qemu-virt device tree and instead rely + * on what Qemu passes us. To be able to get fundamental changes + * in very early, we forego having a board driver here and do this + * directly in the initcall. + */ +static int virt_board_driver_init(void) +{ + struct device_node *root = of_get_root_node(); + struct device_node *flash, *overlay, *pubkey; + const struct of_device_id *id; + void (*init)(void); + + id = of_match_node(virt_of_match, root); + if (!id) + return 0; + + if (id->data) { + init = id->data; + init(); + } + + /* + * Catch both old Qemu versions that place /flash in /soc and + * configurations, where the first flash bank is secure-world only + */ + flash = of_find_node_by_path(PARTS_TARGET_PATH_STR); + if (flash && of_device_is_available(flash)) { + overlay = of_unflatten_dtb(__dtbo_qemu_virt_flash_start, INT_MAX); + of_overlay_apply_tree(root, overlay); + } + + pubkey = of_unflatten_dtb(__dtb_fitimage_pubkey_start, INT_MAX); + of_merge_nodes(root, pubkey); + + /* fragment may have added aliases to the DT */ + of_alias_scan(); + + /* of_probe() will happen later at of_populate_initcall */ + + return 0; +} +postcore_initcall(virt_board_driver_init); diff --git a/common/boards/qemu-virt/fitimage-pubkey.dts b/common/boards/qemu-virt/fitimage-pubkey.dts new file mode 100644 index 0000000000..497799fa4b --- /dev/null +++ b/common/boards/qemu-virt/fitimage-pubkey.dts @@ -0,0 +1,7 @@ +/dts-v1/; + +#ifdef CONFIG_BOOTM_FITIMAGE_PUBKEY +#include CONFIG_BOOTM_FITIMAGE_PUBKEY +#endif + +/{ }; diff --git a/common/boards/qemu-virt/qemu-virt-flash.dtso b/common/boards/qemu-virt/qemu-virt-flash.dtso new file mode 100644 index 0000000000..087568a26d --- /dev/null +++ b/common/boards/qemu-virt/qemu-virt-flash.dtso @@ -0,0 +1,99 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +/dts-v1/; +/plugin/; + +#include "qemu-virt-flash.h" + +&{PARTS_TARGET_PATH} { +#ifdef CONFIG_ARM + virtual-reg = <0x1000>; +#endif + 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>; + }; + }; +}; + +&{/chosen} { + environment { + compatible = "barebox,environment"; + device-path = ENV_DEVICE_PATH_STR; + }; +}; + +&{/} { + 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/boards/qemu-virt/qemu-virt-flash.h b/common/boards/qemu-virt/qemu-virt-flash.h new file mode 100644 index 0000000000..85f67ff030 --- /dev/null +++ b/common/boards/qemu-virt/qemu-virt-flash.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __QEMU_VIRT_FLASH_H__ +#define __QEMU_VIRT_FLASH_H__ + +#include <linux/stringify.h> + +#ifdef CONFIG_RISCV +#define PARTS_TARGET_PATH /flash@20000000 +#define ENV_DEVICE_PATH /flash@20000000/partitions/partition@3c00000 +#elif defined CONFIG_ARM +#define PARTS_TARGET_PATH /flash@0 +#define ENV_DEVICE_PATH /flash@0/partitions/partition@3c00000 +#else +#define PARTS_TARGET_PATH +#define ENV_DEVICE_PATH +#endif + +#define PARTS_TARGET_PATH_STR __stringify(PARTS_TARGET_PATH) +#define ENV_DEVICE_PATH_STR __stringify(ENV_DEVICE_PATH) + +#endif |