From patchwork Fri Jul 7 04:00:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 700015 Delivered-To: patch@linaro.org Received: by 2002:ab3:710f:0:b0:238:a68b:2c7d with SMTP id n15csp1717771lte; Thu, 6 Jul 2023 21:02:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlEo2O/Y5DWfnZAVLY/P3PnDWN7ELgjfIW1WcXw2khE7R4ux1RcY2ltuOHSYYhIYpJblhPv9 X-Received: by 2002:a6b:dc16:0:b0:783:74a5:b73f with SMTP id s22-20020a6bdc16000000b0078374a5b73fmr4009509ioc.13.1688702531249; Thu, 06 Jul 2023 21:02:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688702531; cv=none; d=google.com; s=arc-20160816; b=IOqd1bsIGmNr/hQjQ9J1YQR6G1E0M2t0PHVBFJv5K0srklrHwQBMUyKt1p2pxTETK3 Q4Mu1nRnK4xLrE8bgnttQjUhD1MpJc401AtoQGdiKlJSGpgnqEVq0liXNLpBhy1rpxLo PzmEGz2zBbpLrOBTwernkSjp7Sl/vRiMTKsmq9oxpdAIWHR8GxDO5jYKbJ3nZ9no3/EV OqZ+t6jbBpbqG41LAd22BiUUWK8HUE7UwlZIX1dZvBYYj7K1ozQPbldbagpq/QwFw8tP CjH+mywCoPkB71BiO6tTZkd1WYjBvrpJuGDKEZywyER/yEHNXFJhGO/2+SVYu9nE06Ka FSzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EY1QPDVQku2nwBLXHfn67UCpf37ADO4x0TeMnlmebXY=; fh=UqK/4Wc1IgH8GVyLylIZPdO/qWI3a/IzA+fwLs4tfXk=; b=ne9mtSdQQhYMbme5Tnlah/rimhKDPZ/4W5MVtP9BWOkVPvmQ6fegsj5NCRTWHQ9ZbF +XQsboUwXG3OrB02RqKVHc/G2W0Ttr47ZJvpAzpjVX4QflyYmwDdTPLAITgFCLHUpI3F 5FhTguYXb0r1SFzeIFrf2i330RlksbpYNvy3SGxpUNExnnNwg76qrhifZLInGzV8m96X lXPnMueASBP+8Co3SXPt8FBbS311buUfjWSlNtoN7aXRaBTrs5yyKHoS2y5pZkylLb16 L7ju6HmdEXlH5bq8LSAkm/NaT+6gy8ohs48AGOwbZgyj/kg7plDODCqKOnBf0fxRBI2S sfpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VzqPdg6G; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id i11-20020a6b7e0b000000b00786ea00bf58si62899iom.102.2023.07.06.21.02.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 21:02:11 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VzqPdg6G; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 52069863E6; Fri, 7 Jul 2023 06:01:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="VzqPdg6G"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4D63E863B2; Fri, 7 Jul 2023 06:01:44 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) (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 349D7863D5 for ; Fri, 7 Jul 2023 06:01:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-262ef07be72so819225a91.1 for ; Thu, 06 Jul 2023 21:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688702499; x=1691294499; 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=EY1QPDVQku2nwBLXHfn67UCpf37ADO4x0TeMnlmebXY=; b=VzqPdg6GAhIdh/I0BrhsSHbn8ozgU4J/B/JYsz7AwqwSMmKqMBggIsryFn8ikpVTOy xJBvUMpxBp9zXu1hcS64EPZfqWTJwB5xbrd/p4x6qBe27/apJ+CuCbZ8wY+/pUfN+h5d pKVzBUvqljWQojixU9zKrFLVHCWcMx1owsHLhO04Gef0irH7mm4thWeh3T7Ml3FuoSR/ 0U6uuvR3Lud3EHB+E4hnW75QCmS0qY+Epg0shqbT+mTm6n41QD4A2OIs7gMzg33HCcBb uijnp3/tiU++whMntPMNK/UIa2k2ggnFPZrxhaOnl4S/s5cgFWX35vbBNmNAHCT+m9dH mBmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688702499; x=1691294499; 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=EY1QPDVQku2nwBLXHfn67UCpf37ADO4x0TeMnlmebXY=; b=gLenCGfbutazWx4CngL7pcR/8U9HkQvlw4ody745EWYC2mLvK3UuNmGtMlrgftdJZw C0bpPCkzcYGxrZRCNEDnBloF/oQjLVfJwfCzpekGsSWAblpRcPM4L1VDXL+A/pPn4cA/ e36cn0NBfQAV+1cVD3rLcQp+BwHM++1MG7Rmyd7wtHqTvPaob6W7LdV1Cnivs5fsjWch N+qEx9eGFnHyxjNzEP2RpLJcNvh7GjW7skUjQ6LnbHKQql43n2467J20flPogaVTx2hG XPYjiTiCbys9Hy2V0D18BnvngqAYXJEejlYQIXEIqp+h0aihbbQbYnK3zZbeOrRjOmYF f37g== X-Gm-Message-State: ABy/qLbyS1sscbw1pXMinSFnX2AnbPCrAKM16n6F83fhRp7Amc7pT4/d nKuItYZhssTzJjUx4eKyMOadIDIggOxZYuIO6a4= X-Received: by 2002:a17:90b:1d10:b0:263:8c2:6290 with SMTP id on16-20020a17090b1d1000b0026308c26290mr3018208pjb.43.1688702499252; Thu, 06 Jul 2023 21:01:39 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id h13-20020a17090a3d0d00b00262eb0d141esm576430pjc.28.2023.07.06.21.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 21:01:38 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , AKASHI Takahiro , Masahisa Kojima Subject: [PATCH 3/4] cmd: efidebug: add RAM disk mount command Date: Fri, 7 Jul 2023 13:00:43 +0900 Message-Id: <20230707040045.485790-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230707040045.485790-1-masahisa.kojima@linaro.org> References: <20230707040045.485790-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean This commit implements the test commands for EFI_RAM_DISK_PROTOCOL. With the disk load/unload commands, user can mount the ISO image in the volatile memory through EFI_RAM_DISK_PROTOCOL. Currently the load command can load only one image at a time even if UEFI specification does not limit the number of images. Anyway one image is enough for testing. Signed-off-by: Masahisa Kojima --- cmd/efidebug.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 9622430c47..3466ae7e32 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -1421,6 +1421,113 @@ static int do_efi_query_info(struct cmd_tbl *cmdtp, int flag, return CMD_RET_SUCCESS; } +#ifdef CONFIG_EFI_RAM_DISK_PROTOCOL +static struct efi_device_path *ram_disk_dp; +static efi_guid_t virtual_cd_guid = EFI_VIRTUAL_CD_GUID; + +static int do_efi_disk_load(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + u64 addr, size; + efi_status_t ret; + struct efi_ram_disk_protocol *ram_disk = NULL; + + if (ram_disk_dp) { + printf("Only one image can be loaded\n"); + return CMD_RET_FAILURE; + } + + argc--; + argv++; + + if (argc != 2) + return CMD_RET_USAGE; + + addr = hextoul(argv[0], NULL); + size = hextoul(argv[1], NULL); + + ret = EFI_CALL(BS->locate_protocol(&efi_guid_ram_disk_protocol, NULL, + (void **)&ram_disk)); + if (ret != EFI_SUCCESS || !ram_disk) { + printf("No EFI_RAM_DISK_PROTOCOL found(ret = %lu)\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = EFI_CALL(ram_disk->disk_register(addr, size, &virtual_cd_guid, NULL, + &ram_disk_dp)); + if (ret != EFI_SUCCESS || !ram_disk_dp) { + printf("RAM DISK register failed(ret = %lu)\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +} + +static int do_efi_disk_unload(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + efi_status_t ret; + struct efi_ram_disk_protocol *ram_disk = NULL; + + ret = EFI_CALL(BS->locate_protocol(&efi_guid_ram_disk_protocol, NULL, + (void **)&ram_disk)); + if (ret != EFI_SUCCESS || !ram_disk) { + printf("No EFI_RAM_DISK_PROTOCOL found(ret = %lu)\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = EFI_CALL(ram_disk->unregister(ram_disk_dp)); + if (ret != EFI_SUCCESS) { + printf("RAM DISK unregister failed(ret = %lu)\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ram_disk_dp = NULL; + + return CMD_RET_SUCCESS; +} + +static struct cmd_tbl cmd_efidebug_disk_sub[] = { + U_BOOT_CMD_MKENT(load, CONFIG_SYS_MAXARGS, 1, do_efi_disk_load, "", ""), + U_BOOT_CMD_MKENT(unload, CONFIG_SYS_MAXARGS, 1, do_efi_disk_unload, "", ""), +}; + +/** + * do_efi_disk() - manage UEFI ram disk device + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * Return: CMD_RET_SUCCESS on success, + * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure + * + * Implement efidebug "disk" sub-command. + */ +static int do_efi_disk(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct cmd_tbl *cp; + + if (argc < 2) + return CMD_RET_USAGE; + + argc--; + argv++; + + cp = find_cmd_tbl(argv[0], cmd_efidebug_disk_sub, + ARRAY_SIZE(cmd_efidebug_disk_sub)); + if (!cp) + return CMD_RET_USAGE; + + return cp->cmd(cmdtp, flag, argc, argv); +} +#endif + static struct cmd_tbl cmd_efidebug_sub[] = { U_BOOT_CMD_MKENT(boot, CONFIG_SYS_MAXARGS, 1, do_efi_boot_opt, "", ""), #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT @@ -1441,6 +1548,10 @@ static struct cmd_tbl cmd_efidebug_sub[] = { "", ""), U_BOOT_CMD_MKENT(query, CONFIG_SYS_MAXARGS, 1, do_efi_query_info, "", ""), +#ifdef CONFIG_EFI_RAM_DISK_PROTOCOL + U_BOOT_CMD_MKENT(disk, CONFIG_SYS_MAXARGS, 1, do_efi_disk, + "", ""), +#endif }; /** @@ -1526,6 +1637,12 @@ static char efidebug_help_text[] = " - show UEFI memory map\n" "efidebug tables\n" " - show UEFI configuration tables\n" +#ifdef CONFIG_EFI_RAM_DISK_PROTOCOL + "efidebug disk load
\n" + " - load ISO image\n" + "efidebug disk unload\n" + " - unload ISO image\n" +#endif #ifdef CONFIG_CMD_BOOTEFI_BOOTMGR "efidebug test bootmgr\n" " - run simple bootmgr for test\n"