/*
* Copyright 2018 NXP
*/
-
#include <common.h>
#include <spl.h>
#include <errno.h>
#define MMC_DEV 0
#define QSPI_DEV 1
+#define RAM_DEV 3
#define SEC_SECURE_RAM_BASE (0x31800000UL)
#define SEC_SECURE_RAM_END_BASE (SEC_SECURE_RAM_BASE + 0xFFFFUL)
static int start_offset;
static void *device;
-static int read(int start, int len, void *load_addr)
+static int read(u32 start, u32 len, void *load_addr)
{
int ret = -ENODEV;
- if (!device) {
+ if (!device && current_dev_type != RAM_DEV) {
debug("No device selected\n");
return ret;
}
}
#endif
+ if (current_dev_type == RAM_DEV) {
+ memcpy(load_addr, (const void *)(ulong)start, len);
+ ret = 0;
+ }
+
return ret;
}
if (!image) {
ret = -EINVAL;
+ if (sc_seco_authenticate(-1, SC_MISC_REL_CONTAINER, 0) != SC_ERR_NONE)
+ printf("Error: release container failed!\n");
goto out;
}
return ret;
}
+
+int sdp_load_image_parse_container(struct spl_image_info *spl_image,
+ unsigned long offset)
+{
+ int ret = 0;
+
+ current_dev_type = RAM_DEV;
+ device = NULL;
+
+ start_offset = offset;
+
+ ret = read_auth_container(spl_image);
+
+ return ret;
+}
NULL,
};
+#ifdef CONFIG_PARSE_CONTAINER
+int __weak sdp_load_image_parse_container(struct spl_image_info *spl_image,
+ unsigned long offset)
+{
+ return -EINVAL;
+}
+#endif
+
void __weak board_sdp_cleanup(void)
{
}
return count;
}
+#ifdef CONFIG_SPL_BUILD
+#ifdef CONFIG_PARSE_CONTAINER
+static ulong search_container_header(ulong p, int size)
+{
+ int i = 0;
+ uint8_t *hdr;
+ for (i = 0; i < size; i += 4) {
+ hdr = (uint8_t *)(p +i);
+ if (*(hdr + 3) == 0x87 && *hdr == 0 &&
+ (*(hdr + 1) != 0 || *(hdr + 2) != 0))
+ return p +i;
+ }
+ return 0;
+}
+#else
+static ulong search_fit_header(ulong p, int size)
+{
+ int i = 0;
+ for (i = 0; i < size; i += 4) {
+ if (genimg_get_format((const void *)(p+i)) == IMAGE_FORMAT_FIT)
+ return p + i;
+ }
+
+ return 0;
+}
+#endif
+#endif
+
static void sdp_handle_in_ep(void)
{
u8 *data = sdp_func->in_req->buf;
struct image_header *header;
struct spl_image_info spl_image = {};
+#ifdef CONFIG_PARSE_CONTAINER
+ sdp_func->jmp_address = (u32)search_container_header((ulong)sdp_func->jmp_address,
+ sdp_func->dnl_bytes);
+#else
+ if (IS_ENABLED(CONFIG_SPL_LOAD_FIT))
+ sdp_func->jmp_address = (u32)search_fit_header((ulong)sdp_func->jmp_address,
+ sdp_func->dnl_bytes);
+#endif
+ if (sdp_func->jmp_address == 0) {
+ panic("Error in search header, failed to jump\n");
+ }
+
+ printf("Found header at 0x%08x\n", sdp_func->jmp_address);
+
header = (struct image_header *)(ulong)(sdp_func->jmp_address);
if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
sdp_func->jmp_address,
(void *)header);
} else {
+#ifdef CONFIG_PARSE_CONTAINER
+ sdp_load_image_parse_container(&spl_image,
+ sdp_func->jmp_address);
+#else
/* In SPL, allow jumps to U-Boot images */
spl_parse_image_header(&spl_image,
(struct image_header *)(ulong)(sdp_func->jmp_address));
+#endif
}
board_sdp_cleanup();