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 797C1C433EF for ; Fri, 25 Feb 2022 14:58:35 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C4D2283B6D; Fri, 25 Feb 2022 15:58:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=softathome.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=softathome1.onmicrosoft.com header.i=@softathome1.onmicrosoft.com header.b="lm25tJ+1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8319B837F6; Fri, 25 Feb 2022 15:58:08 +0100 (CET) Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-pr2fra01on062b.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e18::62b]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5BA29837F6 for ; Fri, 25 Feb 2022 15:58:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=softathome.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=philippe.reynes@softathome.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mFXK5JkSsyFhwD2a68Zpi7jQ2Gc+hp5V+qgsu7OEgq+NLU1kB5K9sfpsqv7FVUZgfVRJ/tZRHPLswWSoUNMrj81qxwtSmrA6yiznZ858ms3rRnSPg1PRF1lbk7V40Lw1y0efGZHbPwNAAIvOHh+xvt2G2wbhZP666z7KzCipWE1/kuqbieEyy9b7/T+/r8ayHbguSLDJeU2o/a4p/BzoU4VypqLAp7S/OzP1/Saj7XtT8DHyOCLHQnJzXF+WCDQE5RspBmFi+S4w8Wz59Q4ac6bl/azYAFjOOnIyxDHCV8hneSPmoZJzhUDd08DEkk3LBvMmjxEXo2rGbdoYYlPbtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ju+dTXHCzQooHwcbiAdS2U9QZQ8pwu8wOZw1KOIa7qs=; b=oa+OOmlf1h4gA1iiKxf5CA0dy0JVLgxywhokmn4ZaK9yyM+04/kFLinfLabgugt5TdmgPYJ2IvNuHvllAy2//kq3N0eejPl/y44ZnBpTM6hagI+O4FuakzltnxHTfV6aOKi5tWucVzIp/xnlXTyNFOtS3+tFS4lSfJX+MdMipxmwg1mvIfR/ovEoqX541J7jkOjesH1t8AcbML7t/1cCZRCSSz7vD2kekOeqEtyqQ0dJlv6HUNUszV6dLkA8cSVasJEIeF+QlCyy6Uclok73AfRhXtS5gNuSbFXC1rPLWpN0s1kBSC5EFid1QI+Fj1D4qCY7T2ctIzogIwdAo1rbLg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.6.166.170) smtp.rcpttodomain=chromium.org smtp.mailfrom=softathome.com; dmarc=bestguesspass action=none header.from=softathome.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=softathome1.onmicrosoft.com; s=selector1-softathome1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ju+dTXHCzQooHwcbiAdS2U9QZQ8pwu8wOZw1KOIa7qs=; b=lm25tJ+1gxfNevi9+B+F+mlvUKxwLLqJopUTeDqAyzI+UmKXj7wARu5EOhZ35uP7o/fHbYoYqRK6gNkAnXy9KiLr9ig35friRjVPG4i6qwQfW75XRwXrHOs54cBd6M4tmt4SWPslqVlymyNwh2j/iMe/1EGorRTYmja7nCWkCjjzlf99NWP50JdgvUBdFZ4RpyPTABRhCwDsnLuSFVa+LXWcyxZ6CuBvf64WFe4YcIuG/0529Usy6W7mHpn81qq4ndBBXH+STRjfPRVCYF1z89fpuqWXh7crVGSk3cIytr8l3pH8LEJnjShk+HoLt7wnXRtcko6sTghsYJ30bshW2w== Received: from PR0P264CA0212.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1f::32) by PAZP264MB2589.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1e4::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Fri, 25 Feb 2022 14:57:59 +0000 Received: from PR2FRA01FT001.eop-fra01.prod.protection.outlook.com (2603:10a6:100:1f:cafe::40) by PR0P264CA0212.outlook.office365.com (2603:10a6:100:1f::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21 via Frontend Transport; Fri, 25 Feb 2022 14:57:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.6.166.170) smtp.mailfrom=softathome.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=softathome.com; Received-SPF: Pass (protection.outlook.com: domain of softathome.com designates 149.6.166.170 as permitted sender) receiver=protection.outlook.com; client-ip=149.6.166.170; helo=proxy.softathome.com; Received: from proxy.softathome.com (149.6.166.170) by PR2FRA01FT001.mail.protection.outlook.com (10.152.48.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22 via Frontend Transport; Fri, 25 Feb 2022 14:57:58 +0000 Received: from localhost.localdomain (unknown [192.168.72.32]) by proxy.softathome.com (Postfix) with ESMTPSA id B9A3C20032; Fri, 25 Feb 2022 15:57:58 +0100 (CET) From: Philippe Reynes To: sjg@chromium.org, rasmus.villemoes@prevas.dk Cc: u-boot@lists.denx.de, Philippe Reynes Subject: [PATCH v6 08/16] cmd: bootm: add a stage pre-load Date: Fri, 25 Feb 2022 15:57:46 +0100 Message-Id: <20220225145754.30217-9-philippe.reynes@softathome.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220225145754.30217-1-philippe.reynes@softathome.com> References: <20220225145754.30217-1-philippe.reynes@softathome.com> X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 6fea1aeb-9c8e-419a-53bb-08d9f86f368f X-MS-TrafficTypeDiagnostic: PAZP264MB2589:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5dYIdR2n6iFYi1E3gbDKEGIorzFoDtCEsT743gx+1FQddkfW4xWmFH8ZH82YtvpOqlTqJ14bSKFon88nGJuRKGZpoGrMPeIfnlZCi+cUsA9hgeGU9bmRQuQopiX088kJxFWCr3B5S+yE3CKFiNTQ9qqUshRyNsTInexPLzYrWiIz15jCDRubOmtWM5EWXEzEbCsQsH3Ce466Rke58/NeH6mZ+lcdtmT1QEZpscKuGR0wbj13n2dEMIE+apJZkm8tLmRR5fgBAZTfNi6sCWBzEq9sEIbrqMDfLo+OkK+alcOdB/yQQ4JivQPPgU8qUvW2iEFPxPOmVGj4hQLz3KfeOuyX0+sqKWqDJna9pQzXnpVyQF9CucE4RM5EBnNxC+QZyrzAykzT5Vi0peR/xHNMA41wLcy2PHS85BkUxEXnOgFIS/zaB14SIcHleq6M39BKWbSpJt1L1HS2W7encxX3NPhQ873HdmXe9FOIWg4UeD5HJLRocqkkX0jXBwz3lS6dpfIeoC8EhH12wizVQPk0Zw9Kl5QqgvErMmXvRwpWTkphhY6hAPQA7Ao39b/2Kf30SySll0DFfwJm3YkJyO8ktMpFsbJvz+hO889ewX/xM2LpbLd3PsLUrj/D+2exY4yA1w6zNGv21w5eIMo+t+1smnVlJdoIuEQZX8l1vV58mrjdTRCuTgMOhNBNnuD2PfHwhGiQEx1GS6F9Qxg8a2cvuw== X-Forefront-Antispam-Report: CIP:149.6.166.170; CTRY:FR; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:proxy.softathome.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(8936002)(70206006)(1076003)(8676002)(70586007)(107886003)(4326008)(47076005)(316002)(6966003)(86362001)(36756003)(2616005)(36860700001)(82310400004)(2906002)(44832011)(6266002)(26005)(186003)(356005)(6666004)(81166007)(336012)(426003)(508600001)(82960400001)(40460700003)(5660300002)(83380400001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: softathome.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2022 14:57:58.9744 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6fea1aeb-9c8e-419a-53bb-08d9f86f368f X-MS-Exchange-CrossTenant-Id: aa10e044-e405-4c10-8353-36b4d0cce511 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=aa10e044-e405-4c10-8353-36b4d0cce511; Ip=[149.6.166.170]; Helo=[proxy.softathome.com] X-MS-Exchange-CrossTenant-AuthSource: PR2FRA01FT001.eop-fra01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAZP264MB2589 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.5 at phobos.denx.de X-Virus-Status: Clean Add a stage pre-load to the command bootm. Right now, this stage may be used to read a header and check the signature of the full image. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- boot/bootm.c | 33 +++++++++++++++++++++++++++++++++ cmd/Kconfig | 10 ++++++++++ cmd/bootm.c | 2 +- include/image.h | 1 + 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/boot/bootm.c b/boot/bootm.c index 00c00aef84..714406ab66 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -87,6 +87,33 @@ static int bootm_start(struct cmd_tbl *cmdtp, int flag, int argc, return 0; } +static ulong bootm_data_addr(int argc, char *const argv[]) +{ + ulong addr; + + if (argc > 0) + addr = simple_strtoul(argv[0], NULL, 16); + else + addr = image_load_addr; + + return addr; +} + +static int bootm_pre_load(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + ulong data_addr = bootm_data_addr(argc, argv); + int ret = 0; + + if (CONFIG_IS_ENABLED(CMD_BOOTM_PRE_LOAD)) + ret = image_pre_load(data_addr); + + if (ret) + ret = CMD_RET_FAILURE; + + return ret; +} + static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -677,6 +704,9 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, if (states & BOOTM_STATE_START) ret = bootm_start(cmdtp, flag, argc, argv); + if (!ret && (states & BOOTM_STATE_PRE_LOAD)) + ret = bootm_pre_load(cmdtp, flag, argc, argv); + if (!ret && (states & BOOTM_STATE_FINDOS)) ret = bootm_find_os(cmdtp, flag, argc, argv); @@ -866,6 +896,9 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc, &fit_uname_config, &fit_uname_kernel); + if (CONFIG_IS_ENABLED(CMD_BOOTM_PRE_LOAD)) + img_addr += image_load_offset; + bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC); /* check image type, for FIT images get FIT kernel node */ diff --git a/cmd/Kconfig b/cmd/Kconfig index 5e25e45fd2..87aa3fb11a 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -194,6 +194,16 @@ config CMD_BOOTM help Boot an application image from the memory. +config CMD_BOOTM_PRE_LOAD + bool "enable pre-load on bootm" + depends on CMD_BOOTM + depends on IMAGE_PRE_LOAD + default n + help + Enable support of stage pre-load for the bootm command. + This stage allow to check or modify the image provided + to the bootm command. + config BOOTM_EFI bool "Support booting UEFI FIT images" depends on CMD_BOOTEFI && CMD_BOOTM && FIT diff --git a/cmd/bootm.c b/cmd/bootm.c index e8b7066888..c5de339fba 100644 --- a/cmd/bootm.c +++ b/cmd/bootm.c @@ -126,7 +126,7 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START | - BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER | + BOOTM_STATE_FINDOS | BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOTHER | BOOTM_STATE_LOADOS | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH BOOTM_STATE_RAMDISK | diff --git a/include/image.h b/include/image.h index fbcf70f5e4..496b7af3f3 100644 --- a/include/image.h +++ b/include/image.h @@ -351,6 +351,7 @@ typedef struct bootm_headers { #define BOOTM_STATE_OS_PREP (0x00000100) #define BOOTM_STATE_OS_FAKE_GO (0x00000200) /* 'Almost' run the OS */ #define BOOTM_STATE_OS_GO (0x00000400) +#define BOOTM_STATE_PRE_LOAD 0x00000800 int state; #if defined(CONFIG_LMB) && !defined(USE_HOSTCC) -- 2.17.1