sandbox: Support loading the other FDT
authorSimon Glass <sjg@chromium.org>
Wed, 7 Sep 2022 02:27:09 +0000 (20:27 -0600)
committerTom Rini <trini@konsulko.com>
Thu, 29 Sep 2022 20:09:56 +0000 (16:09 -0400)
We need an 'other' FDT which is different from the control FDT, so we can
check that the ofnode tests correctly handle them both.

Add this to the build along with a way to read it into the sandbox state.

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/sandbox/cpu/state.c
arch/sandbox/dts/Makefile
arch/sandbox/dts/other.dts [new file with mode: 0644]
arch/sandbox/include/asm/state.h

index 787e021..fcc4a33 100644 (file)
@@ -418,6 +418,32 @@ int state_get_rel_filename(const char *rel_path, char *buf, int size)
        return len;
 }
 
+int state_load_other_fdt(const char **bufp, int *sizep)
+{
+       struct sandbox_state *state = state_get_current();
+       char fname[256];
+       int len, ret;
+
+       /* load the file if needed */
+       if (!state->other_fdt_buf) {
+               len = state_get_rel_filename("arch/sandbox/dts/other.dtb",
+                                            fname, sizeof(fname));
+               if (len < 0)
+                       return len;
+
+               ret = os_read_file(fname, &state->other_fdt_buf,
+                                  &state->other_size);
+               if (ret) {
+                       log_err("Cannot read file '%s'\n", fname);
+                       return ret;
+               }
+       }
+       *bufp = state->other_fdt_buf;
+       *sizep = state->other_size;
+
+       return 0;
+}
+
 int state_init(void)
 {
        state = &main_state;
index 6cbc9bb..b6a8847 100644 (file)
@@ -5,7 +5,7 @@ dtb-$(CONFIG_SANDBOX) += sandbox64.dtb
 else
 dtb-$(CONFIG_SANDBOX) += sandbox.dtb
 endif
-dtb-$(CONFIG_UT_DM) += test.dtb
+dtb-$(CONFIG_UT_DM) += test.dtb other.dtb
 dtb-$(CONFIG_CMD_EXTENSION) += overlay0.dtbo overlay1.dtbo
 
 include $(srctree)/scripts/Makefile.dts
diff --git a/arch/sandbox/dts/other.dts b/arch/sandbox/dts/other.dts
new file mode 100644 (file)
index 0000000..395a792
--- /dev/null
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Other devicetree file for running sandbox tests
+ *
+ * This used for tests which want to check they can access multiple device
+ * trees. This one is loaded and checks are made that it is actually visible.
+ */
+
+/dts-v1/;
+
+/ {
+       compatible = "sandbox-other";
+       #address-cells = <1>;
+       #size-cells = <1>;
+
+       node {
+               target = <&target 3 4>;
+
+               subnode {
+                       compatible = "sandbox-other2";
+                       str-prop = "other";
+               };
+
+               subnode2 {
+               };
+       };
+
+       target: target {
+               compatible = "sandbox-other2";
+               #gpio-cells = <2>;
+               str-prop = "other";
+               reg = <0x8000 0x100>;
+               status = "disabled";
+       };
+};
index 12741ee..fd42daa 100644 (file)
@@ -108,6 +108,9 @@ struct sandbox_state {
        bool hwspinlock;                /* Hardware Spinlock status */
        bool allow_memio;               /* Allow readl() etc. to work */
 
+       void *other_fdt_buf;            /* 'other' FDT blob used by tests */
+       int other_size;                 /* size of other FDT blob */
+
        /*
         * This struct is getting large.
         *
@@ -280,6 +283,19 @@ void state_show(struct sandbox_state *state);
 int state_get_rel_filename(const char *rel_path, char *buf, int size);
 
 /**
+ * state_load_other_fdt() - load the 'other' FDT into a buffer
+ *
+ * This loads the other.dtb file into a buffer. This is typically used in tests.
+ *
+ * @bufp: Place to put allocated buffer pointer. The buffer is read using
+ * os_read_file() which calls os_malloc(), so does affect U-Boot's own malloc()
+ * space
+ * @sizep: Returns the size of the buffer
+ * @return 0 if OK, -ve on error
+ */
+int state_load_other_fdt(const char **bufp, int *sizep);
+
+/**
  * Initialize the test system state
  */
 int state_init(void);