summaryrefslogtreecommitdiffstats
path: root/common/boards/qemu-virt
diff options
context:
space:
mode:
Diffstat (limited to 'common/boards/qemu-virt')
-rw-r--r--common/boards/qemu-virt/Makefile10
-rw-r--r--common/boards/qemu-virt/board.c66
-rw-r--r--common/boards/qemu-virt/fitimage-pubkey.dts7
-rw-r--r--common/boards/qemu-virt/overlay-of-flash.dts113
-rw-r--r--common/boards/qemu-virt/qemu-virt-flash.dtso99
-rw-r--r--common/boards/qemu-virt/qemu-virt-flash.h22
6 files changed, 180 insertions, 137 deletions
diff --git a/common/boards/qemu-virt/Makefile b/common/boards/qemu-virt/Makefile
index 88184e9a79..30bf4f1955 100644
--- a/common/boards/qemu-virt/Makefile
+++ b/common/boards/qemu-virt/Makefile
@@ -1,7 +1,13 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-y += board.o
-obj-y += overlay-of-flash.dtb.o
+obj-y += qemu-virt-flash.dtbo.o fitimage-pubkey.dtb.o
ifeq ($(CONFIG_RISCV),y)
-DTC_CPP_FLAGS_overlay-of-flash.dtb := -DRISCV_VIRT=1
+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
index 4064409c80..4f2f7374c5 100644
--- a/common/boards/qemu-virt/board.c
+++ b/common/boards/qemu-virt/board.c
@@ -7,6 +7,7 @@
#include <init.h>
#include <of.h>
#include <deep-probe.h>
+#include "qemu-virt-flash.h"
#ifdef CONFIG_64BIT
#define MACHINE "virt64"
@@ -34,35 +35,56 @@ static inline void arm_virt_init(void)
static inline void arm_virt_init(void) {}
#endif
-extern char __dtb_overlay_of_flash_start[];
+extern char __dtbo_qemu_virt_flash_start[];
+extern char __dtb_fitimage_pubkey_start[];
-static int virt_probe(struct device_d *dev)
+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 *overlay;
+ struct device_node *root = of_get_root_node();
+ struct device_node *flash, *overlay, *pubkey;
+ const struct of_device_id *id;
void (*init)(void);
- init = device_get_match_data(dev);
- if (init)
+ id = of_match_node(virt_of_match, root);
+ if (!id)
+ return 0;
+
+ if (id->data) {
+ init = id->data;
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 */
+ /*
+ * 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);
+ }
- return 0;
-}
+ pubkey = of_unflatten_dtb(__dtb_fitimage_pubkey_start, INT_MAX);
+ of_merge_nodes(root, pubkey);
-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);
+ /* fragment may have added aliases to the DT */
+ of_alias_scan();
-static struct driver_d virt_board_driver = {
- .name = "board-qemu-virt",
- .probe = virt_probe,
- .of_compatible = virt_of_match,
-};
+ /* of_probe() will happen later at of_populate_initcall */
-postcore_platform_driver(virt_board_driver);
+ 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/overlay-of-flash.dts b/common/boards/qemu-virt/overlay-of-flash.dts
deleted file mode 100644
index ace2c7026b..0000000000
--- a/common/boards/qemu-virt/overlay-of-flash.dts
+++ /dev/null
@@ -1,113 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-/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 = "/chosen";
- __overlay__ {
- environment {
- compatible = "barebox,environment";
- device-path = ENV_DEVICE_PATH;
- };
- };
- };
-
- fragment@2 {
- target-path = "/";
- __overlay__ {
- 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.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