summaryrefslogtreecommitdiff
path: root/drivers/usb
diff options
context:
space:
mode:
authorFrieder Schrempf <frieder.schrempf@kontron.de>2019-06-04 21:56:29 +0200
committerStefano Babic <sbabic@denx.de>2019-06-27 13:50:28 +0200
commit2c72ead7387404eba16c556d2f204c52c36c27f9 (patch)
treeefc335707cfcf133857db93717f6ed03fef594fe /drivers/usb
parent77f6e2dd0551d8a825bab391a1bd6b838874bcd4 (diff)
usb: gadget: f_sdp: Allow SPL to load and boot FIT via SDP
Add support for loading u-boot FIT images over the USB SDP protocol in the SPL Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de> [Various build fixes] Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk> Tested-by: Fabio Estevam <festevam@gmail.com> Tested-by: Lukasz Majewski <lukma@denx.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/gadget/f_sdp.c53
1 files changed, 47 insertions, 6 deletions
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index ae97ab2b49..fab7ce6f97 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -638,7 +638,20 @@ static u32 sdp_jump_imxheader(void *address)
return 0;
}
-static void sdp_handle_in_ep(void)
+#ifdef CONFIG_SPL_BUILD
+#ifdef CONFIG_SPL_LOAD_FIT
+static ulong sdp_fit_read(struct spl_load_info *load, ulong sector,
+ ulong count, void *buf)
+{
+ debug("%s: sector %lx, count %lx, buf %lx\n",
+ __func__, sector, count, (ulong)buf);
+ memcpy(buf, (void *)(load->dev + sector), count);
+ return count;
+}
+#endif
+#endif
+
+static void sdp_handle_in_ep(struct spl_image_info *spl_image)
{
u8 *data = sdp_func->in_req->buf;
u32 status;
@@ -690,10 +703,25 @@ static void sdp_handle_in_ep(void)
/* If imx header fails, try some U-Boot specific headers */
if (status) {
#ifdef CONFIG_SPL_BUILD
+ image_header_t *header =
+ sdp_ptr(sdp_func->jmp_address);
+#ifdef CONFIG_SPL_LOAD_FIT
+ if (image_get_magic(header) == FDT_MAGIC) {
+ struct spl_load_info load;
+
+ debug("Found FIT\n");
+ load.dev = header;
+ load.bl_len = 1;
+ load.read = sdp_fit_read;
+ spl_load_simple_fit(spl_image, &load, 0,
+ header);
+
+ return;
+ }
+#endif
/* In SPL, allow jumps to U-Boot images */
struct spl_image_info spl_image = {};
- spl_parse_image_header(&spl_image,
- (struct image_header *)sdp_func->jmp_address);
+ spl_parse_image_header(&spl_image, header);
jump_to_image_no_args(&spl_image);
#else
/* In U-Boot, allow jumps to scripts */
@@ -715,19 +743,32 @@ static void sdp_handle_in_ep(void)
};
}
-void sdp_handle(int controller_index)
+#ifndef CONFIG_SPL_BUILD
+int sdp_handle(int controller_index)
+#else
+int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image)
+#endif
{
printf("SDP: handle requests...\n");
while (1) {
if (ctrlc()) {
puts("\rCTRL+C - Operation aborted.\n");
- return;
+ return -EINVAL;
}
+#ifdef CONFIG_SPL_BUILD
+ if (spl_image->flags & SPL_FIT_FOUND)
+ return 0;
+#endif
+
WATCHDOG_RESET();
usb_gadget_handle_interrupts(controller_index);
- sdp_handle_in_ep();
+#ifdef CONFIG_SPL_BUILD
+ sdp_handle_in_ep(spl_image);
+#else
+ sdp_handle_in_ep(NULL);
+#endif
}
}