summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/boards/avnet-zedboard/lowlevel.c21
-rw-r--r--arch/arm/mach-zynq/Makefile2
-rw-r--r--arch/arm/mach-zynq/bootm-zynqimg.c49
-rw-r--r--common/filetype.c4
-rw-r--r--drivers/firmware/zynqmp-fpga.c121
-rw-r--r--include/filetype.h1
6 files changed, 135 insertions, 63 deletions
diff --git a/arch/arm/boards/avnet-zedboard/lowlevel.c b/arch/arm/boards/avnet-zedboard/lowlevel.c
index 93e4da9..9b90ef1 100644
--- a/arch/arm/boards/avnet-zedboard/lowlevel.c
+++ b/arch/arm/boards/avnet-zedboard/lowlevel.c
@@ -29,10 +29,17 @@
extern char __dtb_zynq_zed_start[];
-ENTRY_FUNCTION(start_avnet_zedboard, r0, r1, r2)
+static void avnet_zedboard_ps7_init(void)
{
-
- void *fdt = __dtb_zynq_zed_start + get_runtime_offset();
+ /*
+ * Read OCM mapping configuration, if only the upper 64 KByte are
+ * mapped to the high address, it's very likely that we just got control
+ * from the BootROM. If the mapping is changed something other than the
+ * BootROM was running before us. Skip PS7 init to avoid cutting the
+ * branch we are sitting on in that case.
+ */
+ if ((readl(0xf8000910) & 0xf) != 0x8)
+ return;
/* open sesame */
writel(0x0000DF0D, ZYNQ_SLCR_UNLOCK);
@@ -260,8 +267,16 @@ ENTRY_FUNCTION(start_avnet_zedboard, r0, r1, r2)
/* lock up. secure, secure */
writel(0x0000767B, ZYNQ_SLCR_LOCK);
+}
+
+ENTRY_FUNCTION(start_avnet_zedboard, r0, r1, r2)
+{
+
+ void *fdt = __dtb_zynq_zed_start + get_runtime_offset();
arm_cpu_lowlevel_init();
+ avnet_zedboard_ps7_init();
+
barebox_arm_entry(0, SZ_512M, fdt);
}
diff --git a/arch/arm/mach-zynq/Makefile b/arch/arm/mach-zynq/Makefile
index 3252247..c88ab46 100644
--- a/arch/arm/mach-zynq/Makefile
+++ b/arch/arm/mach-zynq/Makefile
@@ -1 +1 @@
-obj-y += zynq.o
+obj-y += zynq.o bootm-zynqimg.o
diff --git a/arch/arm/mach-zynq/bootm-zynqimg.c b/arch/arm/mach-zynq/bootm-zynqimg.c
new file mode 100644
index 0000000..e903ab6
--- /dev/null
+++ b/arch/arm/mach-zynq/bootm-zynqimg.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <bootm.h>
+#include <common.h>
+#include <init.h>
+#include <memory.h>
+
+static int do_bootm_zynqimage(struct image_data *data)
+{
+ resource_size_t start, end;
+ void (*barebox)(void);
+ u32 *header;
+ int ret;
+
+ ret = memory_bank_first_find_space(&start, &end);
+ if (ret)
+ return ret;
+
+ ret = bootm_load_os(data, start);
+ if (ret)
+ return ret;
+
+ header = (u32*)start;
+ barebox = (void*)start + header[12];
+
+ if (data->verbose)
+ printf("Loaded barebox image to 0x%08lx\n",
+ (unsigned long)barebox);
+
+ shutdown_barebox();
+
+ barebox();
+
+ return -EIO;
+}
+
+static struct image_handler zynq_image_handler = {
+ .name = "Zynq image",
+ .bootm = do_bootm_zynqimage,
+ .filetype = filetype_zynq_image,
+};
+
+static int zynq_register_image_handler(void)
+{
+ register_image_handler(&zynq_image_handler);
+
+ return 0;
+}
+late_initcall(zynq_register_image_handler);
diff --git a/common/filetype.c b/common/filetype.c
index 39fea45..fd6e8e3 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -80,6 +80,7 @@ static const struct filetype_str filetype_str[] = {
[filetype_ubootvar] = { "U-Boot environmemnt variable data",
"ubootvar" },
[filetype_stm32_image_v1] = { "STM32 image (v1)", "stm32-image-v1" },
+ [filetype_zynq_image] = { "Zynq image", "zynq-image" },
};
const char *file_type_to_string(enum filetype f)
@@ -392,6 +393,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
if (is_imx_flash_header_v2(_buf))
return filetype_imx_image_v2;
+ if (buf[8] == 0xAA995566 && buf[9] == 0x584C4E58)
+ return filetype_zynq_image;
+
return filetype_unknown;
}
diff --git a/drivers/firmware/zynqmp-fpga.c b/drivers/firmware/zynqmp-fpga.c
index 1728e2a..e026673 100644
--- a/drivers/firmware/zynqmp-fpga.c
+++ b/drivers/firmware/zynqmp-fpga.c
@@ -24,11 +24,32 @@
#define ZYNQMP_PM_VERSION_1_1_FEATURES (ZYNQMP_PM_FEATURE_BYTE_ORDER_IRREL | \
ZYNQMP_PM_FEATURE_SIZE_NOT_NEEDED)
+/*
+ * Xilinx KU040 Bitstream Composition:
+ *
+ * Bitstream can be provided with an optinal header (`struct bs_header`).
+ * The true bitstream starts with the binary-header composed of 21 words:
+ *
+ * 0: 0xFFFFFFFF (Dummy pad word)
+ * ...
+ * 15: 0xFFFFFFFF (Dummy pad word)
+ * 16: 0x000000BB (Bus width auto detect word 1)
+ * 17: 0x11220044 (Bus width auto detect word 2)
+ * 18: 0xFFFFFFFF (Dummy pad word)
+ * 19: 0xFFFFFFFF (Dummy pad word)
+ * 20: 0xAA995566 (Sync word)
+ *
+ * See Xilinx UG570 (v1.11) September 30 2019, Chapter 9 "Configuration
+ * Details - Bitstream Composition" for further details.
+ */
#define DUMMY_WORD 0xFFFFFFFF
-#define BUS_WIDTH_WORD_1 0x000000BB
-#define BUS_WIDTH_WORD_2 0x11220044
+#define BUS_WIDTH_AUTO_DETECT1_OFFSET 16
+#define BUS_WIDTH_AUTO_DETECT1 0x000000BB
+#define BUS_WIDTH_AUTO_DETECT2_OFFSET 17
+#define BUS_WIDTH_AUTO_DETECT2 0x11220044
+#define SYNC_WORD_OFFSET 20
#define SYNC_WORD 0xAA995566
-#define SYNC_WORD_OFFS 20
+#define BIN_HEADER_LENGTH 21
enum xilinx_byte_order {
XILINX_BYTE_ORDER_BIT,
@@ -58,48 +79,6 @@ struct bs_header_entry {
char data[0];
} __attribute__ ((packed));
-/*
- * Xilinx KU040 Bitstream Composition:
- * Bitstream can be provided with an optinal header (`struct bs_header`).
- * The true bitstream starts with the binary-header composed of 21 words:
- *
- * 1: 0xFFFFFFFF (Dummy pad word)
- * ...
- * 16: 0xFFFFFFFF (Dummy pad word)
- * 17: 0x000000BB (Bus width auto detect word 1)
- * 18: 0x11220044 (Bus width auto detect word 2)
- * 19: 0xFFFFFFFF (Dummy pad word)
- * 20: 0xFFFFFFFF (Dummy pad word)
- * 21: 0xAA995566 (Sync word)
- *
- * Please refer to Xilinx UG570 (v1.11) September 30 2019,
- * Chapter 9 Configuration Details - Bitstream Composition
- * for further details!
- */
-static const u32 bin_format[] = {
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- DUMMY_WORD,
- BUS_WIDTH_WORD_1,
- BUS_WIDTH_WORD_2,
- DUMMY_WORD,
- DUMMY_WORD,
- SYNC_WORD,
-};
-
static void copy_words_swapped(u32 *dst, const u32 *src, size_t size)
{
int i;
@@ -111,36 +90,59 @@ static void copy_words_swapped(u32 *dst, const u32 *src, size_t size)
static int get_byte_order(const u32 *bin_header, size_t size,
enum xilinx_byte_order *byte_order)
{
- if (size < sizeof(bin_format))
+ if (size < BIN_HEADER_LENGTH * sizeof(*bin_header))
return -EINVAL;
- if (bin_header[SYNC_WORD_OFFS] == SYNC_WORD) {
+ if (bin_header[SYNC_WORD_OFFSET] == SYNC_WORD) {
*byte_order = XILINX_BYTE_ORDER_BIT;
return 0;
}
- if (bin_header[SYNC_WORD_OFFS] == __swab32(SYNC_WORD)) {
- *byte_order = XILINX_BYTE_ORDER_BIN;
+ if (bin_header[SYNC_WORD_OFFSET] == __swab32(SYNC_WORD)) {
+ *byte_order = XILINX_BYTE_ORDER_BIN;
return 0;
}
return -EINVAL;
}
-static int is_bin_header_valid(const u32 *bin_header, size_t size,
- enum xilinx_byte_order byte_order)
+static bool is_bin_header_valid(const u32 *bin_header, size_t size,
+ enum xilinx_byte_order byte_order)
{
- int i;
+ size_t i;
- if (size < ARRAY_SIZE(bin_format))
- return 0;
+ if (size < BIN_HEADER_LENGTH * sizeof(*bin_header))
+ return false;
+
+ for (i = 0; i < BIN_HEADER_LENGTH; i++, bin_header++) {
+ u32 current;
+ u32 expected;
+
+ if (byte_order == XILINX_BYTE_ORDER_BIT)
+ current = *bin_header;
+ else
+ current = __swab32(*bin_header);
- for (i = 0; i < ARRAY_SIZE(bin_format); i++)
- if (bin_header[i] != (byte_order == XILINX_BYTE_ORDER_BIT) ?
- bin_format[i] : __swab32(bin_format[i]))
- return 0;
+ switch (i) {
+ case BUS_WIDTH_AUTO_DETECT1_OFFSET:
+ expected = BUS_WIDTH_AUTO_DETECT1;
+ break;
+ case BUS_WIDTH_AUTO_DETECT2_OFFSET:
+ expected = BUS_WIDTH_AUTO_DETECT2;
+ break;
+ case SYNC_WORD_OFFSET:
+ expected = SYNC_WORD;
+ break;
+ default:
+ expected = DUMMY_WORD;
+ break;
+ }
+
+ if (current != expected)
+ return false;
+ }
- return 1;
+ return true;
}
static int get_header_length(const char *header, size_t size)
@@ -227,6 +229,7 @@ static int fpgamgr_program_finish(struct firmware_handler *fh)
goto err_free;
if (!is_bin_header_valid(body, body_length, byte_order)) {
+ dev_err(&mgr->dev, "Invalid bitstream header\n");
status = -EINVAL;
goto err_free;
}
diff --git a/include/filetype.h b/include/filetype.h
index 90a03de..db95fda 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -49,6 +49,7 @@ enum filetype {
filetype_layerscape_qspi_image,
filetype_ubootvar,
filetype_stm32_image_v1,
+ filetype_zynq_image,
filetype_max,
};