Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40435C433FE for ; Thu, 13 Oct 2022 12:36:14 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A214384F9B; Thu, 13 Oct 2022 14:32:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="UH9w29zv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6FFB684F6E; Thu, 13 Oct 2022 14:31:14 +0200 (CEST) Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B7BB384F63 for ; Thu, 13 Oct 2022 14:30:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2d.google.com with SMTP id 187so1160361iov.10 for ; Thu, 13 Oct 2022 05:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/wQsNeQVndBhwkH+AIVgPH/1GnZC49AQct6Ru5tNRFE=; b=UH9w29zvbsunmz/WJl2B8lUOlfEOB2W21ydXLNh3swgfAgwQKnt1Ft/p0yn+cw7wOJ 2QaWsX2He0GGF3B/18iWUJbamuMspc77nemhPgvm4JmS0QVdNhyTW4XxcPju6XRCMed/ pp2X1ZhgNA1tbz7EXQ8AYxilnt4iqCN9Aw1Ec= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/wQsNeQVndBhwkH+AIVgPH/1GnZC49AQct6Ru5tNRFE=; b=lVS4W3xbOcAXD1FZTo5DebiO17jz69drAjgeXwSxuJbcProNeOukROHw9iIy5lhplL KiB5+NBendeCdSGGjMQaw4yeiwy8WkAYuJkuxiO5EmR3pDRobHyNQyMj6lswRLZzMI9F aZfMH4cn1HzMlrlsdz9lo+4wmP1VpwC5kjDjCtcqvUau07N+cZqeyeVcHNNBT5JXcIpe qGcDabRcPoFLviPwrS/FaW6gkrxDHKBXO8IPXRN6x10u5LY7EBugJhnGn9zqEOnL0XJG wP+mcdWgnMxhtIq23iT4N6eIoOwECi012XpNLshvxqlcawz3zrdCyspkbCeOK8J58jfN CvQQ== X-Gm-Message-State: ACrzQf2NjBKHduu8dPubvZB1ZpIzLdZJYmrk82BW6ywxKj+RzcqFTuHg 6VgKKOKZHxdOW6IEhxnQQDlW7p5nX2+gCA== X-Google-Smtp-Source: AMsMyM7/YwoaNHHEPItNGIAcecCe/8jz8qaEf/L5dxpY+38gzbo5nWLi7SbvqKMxHri/kMpvSJcgbg== X-Received: by 2002:a05:6602:125d:b0:6bc:61ec:29c0 with SMTP id o29-20020a056602125d00b006bc61ec29c0mr7578254iou.81.1665664242938; Thu, 13 Oct 2022 05:30:42 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id a9-20020a027a09000000b003635ab4a7b7sm7321626jac.3.2022.10.13.05.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 05:30:42 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Alper Nebi Yasak , Heiko Thiery , Heinrich Schuchardt , =?UTF-8?q?Marek=20Beh=C3=BAn?= , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Ricardo Salveti , Stefan Roese , Vaishnav Achath Subject: [PATCH v2 33/45] sandbox: Support obtaining the next phase from an image Date: Thu, 13 Oct 2022 06:29:15 -0600 Message-Id: <20221013122927.636867-34-sjg@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221013122927.636867-1-sjg@chromium.org> References: <20221013122927.636867-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean At present sandbox runs the next phase from discrete executables, so for example u-boot-tpl runs u-boot-vpl to get to the next phase. In some cases the phases are all built into a single firmware image, as is done for real boards. Add support for this to sandbox. Make it higher priority so that it takes precedence over the existing method. Signed-off-by: Simon Glass --- (no changes since v1) arch/sandbox/cpu/spl.c | 52 +++++++++++++++++++++++++++++++++++++++++- include/spl.h | 3 +++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c index 2678370481a..75f4601fdfb 100644 --- a/arch/sandbox/cpu/spl.c +++ b/arch/sandbox/cpu/spl.c @@ -78,7 +78,48 @@ static int spl_board_load_file(struct spl_image_info *spl_image, return 0; } -SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_file); +SPL_LOAD_IMAGE_METHOD("sandbox_file", 9, BOOT_DEVICE_BOARD, + spl_board_load_file); + +static int load_from_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) +{ + struct sandbox_state *state = state_get_current(); + enum u_boot_phase next_phase; + const char *fname; + ulong pos, size; + int full_size; + void *buf; + int ret; + + if (!IS_ENABLED(CONFIG_SANDBOX_VPL)) + return -ENOENT; + + next_phase = spl_next_phase(); + pos = spl_get_image_pos(); + size = spl_get_image_size(); + if (pos == BINMAN_SYM_MISSING || size == BINMAN_SYM_MISSING) { + log_debug("No image found\n"); + return -ENOENT; + } + log_info("Reading from pos %lx size %lx\n", pos, size); + + /* + * Set up spl_image to boot from jump_to_image_no_args(). Allocate this + * outside the RAM buffer (i.e. don't use strdup()). + */ + fname = state->prog_fname ? state->prog_fname : state->argv[0]; + ret = os_read_file(fname, &buf, &full_size); + if (ret) + return log_msg_ret("rd", -ENOMEM); + spl_image->flags = SPL_SANDBOXF_ARG_IS_BUF; + spl_image->arg = buf; + spl_image->offset = pos; + spl_image->size = size; + + return 0; +} +SPL_LOAD_IMAGE_METHOD("sandbox_image", 7, BOOT_DEVICE_BOARD, load_from_image); void spl_board_init(void) { @@ -109,6 +150,15 @@ void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) } break; } + case SPL_SANDBOXF_ARG_IS_BUF: { + int ret; + + ret = os_jump_to_image(spl_image->arg + spl_image->offset, + spl_image->size); + if (ret) + log_err("Failed to load image\n"); + break; + } default: log_err("Invalid flags\n"); break; diff --git a/include/spl.h b/include/spl.h index e711fb13654..e407c7fe55b 100644 --- a/include/spl.h +++ b/include/spl.h @@ -232,9 +232,12 @@ static inline const char *spl_phase_prefix(enum u_boot_phase phase) * enum spl_sandbox_flags - flags for sandbox's use of spl_image_info->flags * * @SPL_SANDBOXF_ARG_IS_FNAME: arg is the filename to jump to (default) + * @SPL_SANDBOXF_ARG_IS_BUF: arg is the containing image to jump to, @offset is + * the start offset within the image, @size is the size of the image */ enum spl_sandbox_flags { SPL_SANDBOXF_ARG_IS_FNAME = 0, + SPL_SANDBOXF_ARG_IS_BUF, }; struct spl_image_info { -- 2.38.0.rc1.362.ged0d419d3c-goog