From patchwork Tue Jun 4 19:56:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sjoerd Simons X-Patchwork-Id: 1110113 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=collabora.co.uk Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45JN594Zqgz9sNC for ; Wed, 5 Jun 2019 05:58:05 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5B934C21E57; Tue, 4 Jun 2019 19:57:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 9D936C21E26; Tue, 4 Jun 2019 19:56:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B6202C21C50; Tue, 4 Jun 2019 19:56:32 +0000 (UTC) Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lists.denx.de (Postfix) with ESMTPS id 4CEB1C21DA1 for ; Tue, 4 Jun 2019 19:56:32 +0000 (UTC) Received: from beast.luon.net (unknown [IPv6:2001:470:78b1:0:40e2:7ff:fef4:3122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: sjoerd) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id DE0DC2842B4; Tue, 4 Jun 2019 20:56:31 +0100 (BST) Received: by beast.luon.net (Postfix, from userid 1000) id B080B3E1F26; Tue, 4 Jun 2019 21:56:29 +0200 (CEST) From: Sjoerd Simons To: u-boot@lists.denx.de Date: Tue, 4 Jun 2019 21:56:29 +0200 Message-Id: <20190604195629.27049-4-sjoerd.simons@collabora.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190604195629.27049-1-sjoerd.simons@collabora.co.uk> References: <20190604195629.27049-1-sjoerd.simons@collabora.co.uk> MIME-Version: 1.0 Cc: Marek Vasut Subject: [U-Boot] [PATCH v2 3/3] usb: gadget: f_sdp: Allow SPL to load and boot FIT via SDP X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Frieder Schrempf Add support for loading u-boot FIT images over the USB SDP protocol in the SPL Signed-off-by: Frieder Schrempf [Various build fixes] Signed-off-by: Sjoerd Simons Tested-by: Fabio Estevam Tested-by: Lukasz Majewski --- Changes in v2: - Fix build with CMD_USB_SDP - Add SoB from Frieder Schrempf common/spl/spl_sdp.c | 12 ++++++--- drivers/usb/gadget/f_sdp.c | 53 +++++++++++++++++++++++++++++++++----- include/sdp.h | 9 ++++++- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/common/spl/spl_sdp.c b/common/spl/spl_sdp.c index 807256e908..51b245b886 100644 --- a/common/spl/spl_sdp.c +++ b/common/spl/spl_sdp.c @@ -25,10 +25,14 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image, return -ENODEV; } - /* This command typically does not return but jumps to an image */ - sdp_handle(controller_index); - pr_err("SDP ended\n"); + /* + * This command either loads a legacy image, jumps and never returns, + * or it loads a FIT image and returns it to be handled by the SPL + * code. + */ + ret = spl_sdp_handle(controller_index, spl_image); + debug("SDP ended\n"); - return -EINVAL; + return ret; } SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image); 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 } } diff --git a/include/sdp.h b/include/sdp.h index f6252d027f..6ac64fb1f3 100644 --- a/include/sdp.h +++ b/include/sdp.h @@ -10,6 +10,13 @@ #define __SDP_H_ int sdp_init(int controller_index); -void sdp_handle(int controller_index); + +#ifdef CONFIG_SPL_BUILD +#include + +int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image); +#else +int sdp_handle(int controller_index); +#endif #endif /* __SDP_H_ */