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 45D71C433EF for ; Mon, 28 Mar 2022 20:58:42 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9B5A283FB5; Mon, 28 Mar 2022 22:57:55 +0200 (CEST) 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="iLKRm5Kr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C07C983C7B; Mon, 28 Mar 2022 22:57:25 +0200 (CEST) Received: from FRA01-MR2-obe.outbound.protection.outlook.com (mail-mr2fra01on0625.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e19::625]) (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 041BB83F87 for ; Mon, 28 Mar 2022 22:57:16 +0200 (CEST) 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=lxNivQrsdBpzCitXUGW7SfYqmdZF1/RrU4V/Mb0Fc1klB7ohauOSHkiff+WRSPxjaNGS6bVkMn5ZybdU0Nx8iaYRpeFBqHSlA8z1Zd8YhGBcRQRvXrXHtjunqXj9uNjwB0NLdDwlHcTnr0Bk6aO25O4FD5eRuivFhb32HSztE2R23enrT8ike0adMkrvqgoq/etXCjrChpOp905+q++RcY6Alyi04OwYNz2EE5GLtSkLNp+QFEfab5n3od3ht2bnDb0V+EAFOP5mrWD/IDrme7ShctMWZ1vcHNfNIxgawxe2WTfoD+BmWBINrbwMJIrxYJ0+txWRYQqrUYbCQPaKpg== 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=QI0MJ946vywOgAPHuanolK/6i8O7pJseNkRlSeM14sw=; b=COU3GazYbBrADyrXR/QNgkvlRlFVqjxeIv0SRPRfhqSUf0aPhY5OggQtsYjfIwLFCEiTGBXMgWClBS61Bs+DaV9WXoPtaPP7H5HQxYfVcwXXx/3Z47n1Audemugjqz1L3lB7ohw1qZySI0dCh0hVh1gV2JMqZvtt158xR7hqbxFczc264aZMitj2C3sZy+YdoQOfYSfoHfKESPoz7xbUXupLyfkLFwm5gq8P3HFBQcu0/g4PHTzipdI6jVJBwRSErYsGD5hy0mjXjHapUbG00Ab9VHG9tc1wMlYRNPsN+rl2xyDdtIbBr9URmNvr8D0zqK7tBOA5S3kPF5r3dh0DfA== 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=QI0MJ946vywOgAPHuanolK/6i8O7pJseNkRlSeM14sw=; b=iLKRm5KrOiMEAMSevU6IwkhIsoOo/AULYvrcxAxfqCQxS0VGdUZjXKqJGcuaiUtw/dmRXFYuQ+VXxkGAS0XE53iKbrxiBszX0m0Gv4/pmPYaZYp1Jv4JXMkY89PzS00HCzPEjLr7fPZPIr6FqdS/kAwc/9lplrZl/1tYapomKDOxOV848j/wa9NUtK2ztp6jBH/JcymbpkuTfRp8uxWiCJrgTCdjDASRpT8uewioeh6Md5cNasE9GXOlgnvgc+rp5nbloxI4mw4eMQhc1LcL9UOB9MmTLTF73II9RAaSMni/FoWCxPXkQscJyxvqbPc9lj9Sx3AF9H2uRBBWtWwS3A== Received: from AM5PR0601CA0048.eurprd06.prod.outlook.com (2603:10a6:203:68::34) by MRZP264MB3161.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:1a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Mon, 28 Mar 2022 20:57:14 +0000 Received: from PR2FRA01FT003.eop-fra01.prod.protection.outlook.com (2603:10a6:203:68:cafe::31) by AM5PR0601CA0048.outlook.office365.com (2603:10a6:203:68::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18 via Frontend Transport; Mon, 28 Mar 2022 20:57:13 +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 PR2FRA01FT003.mail.protection.outlook.com (10.152.48.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.17 via Frontend Transport; Mon, 28 Mar 2022 20:57:13 +0000 Received: from localhost.localdomain (unknown [192.168.72.32]) by proxy.softathome.com (Postfix) with ESMTPSA id 6DD1220150; Mon, 28 Mar 2022 22:57:12 +0200 (CEST) From: Philippe Reynes To: sjg@chromium.org, rasmus.villemoes@prevas.dk Cc: u-boot@lists.denx.de, Philippe Reynes Subject: [PATCH v8 08/15] cmd: bootm: add a stage pre-load Date: Mon, 28 Mar 2022 22:57:00 +0200 Message-Id: <20220328205707.348270-9-philippe.reynes@softathome.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220328205707.348270-1-philippe.reynes@softathome.com> References: <20220328205707.348270-1-philippe.reynes@softathome.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 2ff273f1-9af2-4bfc-d82b-08da10fd88dc X-MS-TrafficTypeDiagnostic: MRZP264MB3161: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: wNYupVCmEl3RikIIByMIqs5kuM/kFLvGxldeTmPq/4/gjcysV88uBPJjxKHEA9JyvJ4+AoX0gEGLHeSuc2X+sCMVmDqqXQQlTAYxT+84SXWsbOI2p7RjzrVCqSZYa7XviFVwou9/j0ejxTna1ZghvW5oMLOW2QYNCt1XdK611fkI1ikyelPGfwDiUvraiPaN6xKPeV7dKSz7BrBXHikEC4czirCPAxqFGq9bw+xN6yEwJDqK5Bhed6WxD15gxSAhtDQQruSUc/bc5d5s8Tdv0y+u3iRFX2uHlwx9vn+Je+n90Jomk2MYk5Th8qNWm/qz9mXJmKHIPoAuD2Vpk6yMl0GUJexiFcPdUs3mnCzVqFXS7V76bQLUK8H58d+KertvIJDYGUSE/Ir+8hHKQr8te7D571NsQqjMaLosoe8YuAarDpUgexvE16RK33IaP75Stogcr5VOZ8dQf0+VXdwCu95Kpy3JoH4V6L4ZnIawgecHDf8iUAeZ25f+KJodJYnytpHHAp6C8NXsrn+Lrvgbp2SOAbNsp5rPJxjFfEb1jO5hIPWxsMbSnpY2Cqpmftnx7ShGim1ErRSTKPtVoBfBgEOVJ1GwSd2MKyE5EArehdjAu/DAOKP0Sja8DYLS+CJPit7KPJMiUoeTUMGz7BU5Sx3XqaDuJlNFg2JfIeoh5Xzed/1tgWADNW7KOvuvx9m1o0jd68Ze+CV4WfKgNBzxRw== 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)(40470700004)(36840700001)(46966006)(6266002)(36756003)(36860700001)(83380400001)(2906002)(508600001)(8936002)(47076005)(336012)(40460700003)(426003)(6966003)(6666004)(107886003)(81166007)(5660300002)(186003)(1076003)(356005)(82960400001)(2616005)(26005)(316002)(86362001)(82310400004)(8676002)(4326008)(70586007)(70206006)(44832011)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: softathome.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2022 20:57:13.5134 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ff273f1-9af2-4bfc-d82b-08da10fd88dc 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: PR2FRA01FT003.eop-fra01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MRZP264MB3161 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 | 5 +++-- include/image.h | 1 + 4 files changed, 47 insertions(+), 2 deletions(-) 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..87d40d494c 100644 --- a/cmd/bootm.c +++ b/cmd/bootm.c @@ -70,7 +70,8 @@ static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc, if (c) { state = (long)c->cmd; if (state == BOOTM_STATE_START) - state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER; + state |= BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOS | + BOOTM_STATE_FINDOTHER; } else { /* Unrecognized command */ return CMD_RET_USAGE; @@ -126,7 +127,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.25.1