Commit 2c72ead7387404eba16c556d2f204c52c36c27f9
Committed by
Stefano Babic
1 parent
77f6e2dd05
Exists in
smarc_8mq_lf_v2020.04
and in
11 other branches
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>
Showing 3 changed files with 63 additions and 11 deletions Side-by-side Diff
common/spl/spl_sdp.c
... | ... | @@ -25,11 +25,15 @@ |
25 | 25 | return -ENODEV; |
26 | 26 | } |
27 | 27 | |
28 | - /* This command typically does not return but jumps to an image */ | |
29 | - sdp_handle(controller_index); | |
30 | - pr_err("SDP ended\n"); | |
28 | + /* | |
29 | + * This command either loads a legacy image, jumps and never returns, | |
30 | + * or it loads a FIT image and returns it to be handled by the SPL | |
31 | + * code. | |
32 | + */ | |
33 | + ret = spl_sdp_handle(controller_index, spl_image); | |
34 | + debug("SDP ended\n"); | |
31 | 35 | |
32 | - return -EINVAL; | |
36 | + return ret; | |
33 | 37 | } |
34 | 38 | SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image); |
drivers/usb/gadget/f_sdp.c
... | ... | @@ -638,8 +638,21 @@ |
638 | 638 | return 0; |
639 | 639 | } |
640 | 640 | |
641 | -static void sdp_handle_in_ep(void) | |
641 | +#ifdef CONFIG_SPL_BUILD | |
642 | +#ifdef CONFIG_SPL_LOAD_FIT | |
643 | +static ulong sdp_fit_read(struct spl_load_info *load, ulong sector, | |
644 | + ulong count, void *buf) | |
642 | 645 | { |
646 | + debug("%s: sector %lx, count %lx, buf %lx\n", | |
647 | + __func__, sector, count, (ulong)buf); | |
648 | + memcpy(buf, (void *)(load->dev + sector), count); | |
649 | + return count; | |
650 | +} | |
651 | +#endif | |
652 | +#endif | |
653 | + | |
654 | +static void sdp_handle_in_ep(struct spl_image_info *spl_image) | |
655 | +{ | |
643 | 656 | u8 *data = sdp_func->in_req->buf; |
644 | 657 | u32 status; |
645 | 658 | int datalen; |
646 | 659 | |
... | ... | @@ -690,10 +703,25 @@ |
690 | 703 | /* If imx header fails, try some U-Boot specific headers */ |
691 | 704 | if (status) { |
692 | 705 | #ifdef CONFIG_SPL_BUILD |
706 | + image_header_t *header = | |
707 | + sdp_ptr(sdp_func->jmp_address); | |
708 | +#ifdef CONFIG_SPL_LOAD_FIT | |
709 | + if (image_get_magic(header) == FDT_MAGIC) { | |
710 | + struct spl_load_info load; | |
711 | + | |
712 | + debug("Found FIT\n"); | |
713 | + load.dev = header; | |
714 | + load.bl_len = 1; | |
715 | + load.read = sdp_fit_read; | |
716 | + spl_load_simple_fit(spl_image, &load, 0, | |
717 | + header); | |
718 | + | |
719 | + return; | |
720 | + } | |
721 | +#endif | |
693 | 722 | /* In SPL, allow jumps to U-Boot images */ |
694 | 723 | struct spl_image_info spl_image = {}; |
695 | - spl_parse_image_header(&spl_image, | |
696 | - (struct image_header *)sdp_func->jmp_address); | |
724 | + spl_parse_image_header(&spl_image, header); | |
697 | 725 | jump_to_image_no_args(&spl_image); |
698 | 726 | #else |
699 | 727 | /* In U-Boot, allow jumps to scripts */ |
700 | 728 | |
701 | 729 | |
702 | 730 | |
... | ... | @@ -715,19 +743,32 @@ |
715 | 743 | }; |
716 | 744 | } |
717 | 745 | |
718 | -void sdp_handle(int controller_index) | |
746 | +#ifndef CONFIG_SPL_BUILD | |
747 | +int sdp_handle(int controller_index) | |
748 | +#else | |
749 | +int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image) | |
750 | +#endif | |
719 | 751 | { |
720 | 752 | printf("SDP: handle requests...\n"); |
721 | 753 | while (1) { |
722 | 754 | if (ctrlc()) { |
723 | 755 | puts("\rCTRL+C - Operation aborted.\n"); |
724 | - return; | |
756 | + return -EINVAL; | |
725 | 757 | } |
726 | 758 | |
759 | +#ifdef CONFIG_SPL_BUILD | |
760 | + if (spl_image->flags & SPL_FIT_FOUND) | |
761 | + return 0; | |
762 | +#endif | |
763 | + | |
727 | 764 | WATCHDOG_RESET(); |
728 | 765 | usb_gadget_handle_interrupts(controller_index); |
729 | 766 | |
730 | - sdp_handle_in_ep(); | |
767 | +#ifdef CONFIG_SPL_BUILD | |
768 | + sdp_handle_in_ep(spl_image); | |
769 | +#else | |
770 | + sdp_handle_in_ep(NULL); | |
771 | +#endif | |
731 | 772 | } |
732 | 773 | } |
733 | 774 |
include/sdp.h
... | ... | @@ -10,7 +10,14 @@ |
10 | 10 | #define __SDP_H_ |
11 | 11 | |
12 | 12 | int sdp_init(int controller_index); |
13 | -void sdp_handle(int controller_index); | |
13 | + | |
14 | +#ifdef CONFIG_SPL_BUILD | |
15 | +#include <spl.h> | |
16 | + | |
17 | +int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image); | |
18 | +#else | |
19 | +int sdp_handle(int controller_index); | |
20 | +#endif | |
14 | 21 | |
15 | 22 | #endif /* __SDP_H_ */ |