summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRouven Czerwinski <r.czerwinski@pengutronix.de>2019-08-06 07:10:56 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-08-07 09:42:09 +0200
commitf5fb1262857619dd3c15dfa4266a4534dd85f736 (patch)
tree4c9e342b1a7c80ab9987ed801b3027e1adf7d987
parent390ee3ebcd25570ac44d4e4fcfc00e120422f057 (diff)
downloadbarebox-f5fb1262857619dd3c15dfa4266a4534dd85f736.tar.gz
barebox-f5fb1262857619dd3c15dfa4266a4534dd85f736.tar.xz
esdhc-pbl: add piggy load function
Add a function to load and copy the piggy data to the correct offset expected by barebox in the RAM. This way the PBL can later verify the piggydata before uncompressing and loading the main barebox. Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--arch/arm/mach-imx/include/mach/xload.h5
-rw-r--r--arch/arm/mach-imx/xload-common.c6
-rw-r--r--drivers/mci/imx-esdhc-pbl.c46
3 files changed, 57 insertions, 0 deletions
diff --git a/arch/arm/mach-imx/include/mach/xload.h b/arch/arm/mach-imx/include/mach/xload.h
index 8f141bc37e..a605e76339 100644
--- a/arch/arm/mach-imx/include/mach/xload.h
+++ b/arch/arm/mach-imx/include/mach/xload.h
@@ -6,7 +6,12 @@ int imx6_spi_load_image(int instance, unsigned int flash_offset, void *buf, int
int imx6_spi_start_image(int instance);
int imx6_esdhc_start_image(int instance);
int imx8_esdhc_start_image(int instance);
+int imx8_esdhc_load_piggy(int instance);
int imx_image_size(void);
+int piggydata_size(void);
+
+extern unsigned char input_data[];
+extern unsigned char input_data_end[];
#endif /* __MACH_XLOAD_H */
diff --git a/arch/arm/mach-imx/xload-common.c b/arch/arm/mach-imx/xload-common.c
index c5727eba38..bd6405258e 100644
--- a/arch/arm/mach-imx/xload-common.c
+++ b/arch/arm/mach-imx/xload-common.c
@@ -8,3 +8,9 @@ int imx_image_size(void)
/* i.MX header is 4k */
return barebox_image_size + SZ_4K;
}
+
+int piggydata_size(void)
+{
+ return input_data_end - input_data;
+}
+
diff --git a/drivers/mci/imx-esdhc-pbl.c b/drivers/mci/imx-esdhc-pbl.c
index 49514fc538..fb27c84163 100644
--- a/drivers/mci/imx-esdhc-pbl.c
+++ b/drivers/mci/imx-esdhc-pbl.c
@@ -425,6 +425,52 @@ int imx8_esdhc_start_image(int instance)
return esdhc_start_image(&esdhc, MX8MQ_DDR_CSD1_BASE_ADDR,
MX8MQ_ATF_BL33_BASE_ADDR, SZ_32K);
}
+
+int imx8_esdhc_load_piggy(int instance)
+{
+ void *buf = (void *)MX8MQ_ATF_BL33_BASE_ADDR;
+ struct imx_flash_header_v2 *hdr = NULL;
+ void *bb = 0;
+ struct esdhc esdhc;
+ int ret, len;
+ int offset = SZ_32K;
+
+
+ switch (instance) {
+ case 0:
+ esdhc.regs = IOMEM(MX8MQ_USDHC1_BASE_ADDR);
+ break;
+ case 1:
+ esdhc.regs = IOMEM(MX8MQ_USDHC2_BASE_ADDR);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ esdhc.is_be = 0;
+ esdhc.is_mx6 = 1;
+
+ ret = esdhc_search_header(&esdhc, &hdr, buf, &offset);
+ if (ret)
+ return ret;
+
+ len = offset + hdr->boot_data.size + piggydata_size();
+ len = ALIGN(len, SECTOR_SIZE);
+
+ ret = esdhc_read_blocks(&esdhc, buf, len);
+
+ /*
+ * Calculate location of the piggydata at the offset loaded into RAM
+ */
+ buf = buf + offset + hdr->boot_data.size;
+ /*
+ * Barebox expects the piggydata right behind the PBL in the beginning
+ * of RAM.
+ */
+ bb = (void *) MX8MQ_DDR_CSD1_BASE_ADDR + barebox_pbl_size;
+ memcpy(bb, buf, piggydata_size());
+ return ret;
+}
#endif
#ifdef CONFIG_ARCH_LS1046