From patchwork Fri Jul 14 05:44:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 702719 Delivered-To: patch@linaro.org Received: by 2002:adf:db4e:0:b0:314:25da:8dc4 with SMTP id f14csp906701wrj; Thu, 13 Jul 2023 22:48:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlGMUy/WYAQJ1h12dQtwBmQiC/j3ZrkzsVZQXN+l6nYfBYBvYk6gydmCLgV4N0sUDuAcgn4z X-Received: by 2002:a2e:3c0c:0:b0:2b4:7f2e:a42d with SMTP id j12-20020a2e3c0c000000b002b47f2ea42dmr3157334lja.41.1689313685752; Thu, 13 Jul 2023 22:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689313685; cv=none; d=google.com; s=arc-20160816; b=agkld/m/MoxFQ9YM6Qd7uURxiRLQrwb033MpiLRiPOb7E5cMVKZFB+7QdCqcbfv2GT B6iESpmD7WiM9vsjI+34QOmvMEHgUscvBi+1Z3vizUTdWvlx1FGLfWgMKq8ULDsi8Jdi Brz6kVxdllkxO+gwc1x6rZGkBdnEVY19cbbRWiaX3eTuUHN/dbR8SoTXkxypntw69yKn WRsmgrblEaFcbMNfxit1MhvoXKq1D8ekjTmh4RoUOs5nylX6htiLNQvVPDeFGLXkQ6Td Zm2Q9SsyS9bD1syDgChyjFrZ/NULFFjQlrckavbEidu9zYkqer+CdwdOwSO384xf6sI3 ryCA== 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=utZVaj/9AyfylhDu3zdsKb32s2Pn8M6nBwqueVmPOKo=; fh=xTN8zo5rzpABERcWHVpYCdCrcH4F7J76p6VSzZMpffc=; b=wSd6Y9kXbmMdrjWQ13Q3uy3c/kOEj776mY2XKtYXTbr3unj4UO/14SHRkwOkMrhRrp ECIn3cBqe4PKKMen+toywBETmfVub/oVZDz9EV++8KSdfeQfnU5ec4vgNrmY5F1oV1ah HqjeLuBaore0zZJbtxBkTha2tARbSxBe3dVbS1+SfAyNMeEFq1ywr3MJS+X8qDAkKryH Vo/ixe/ksPF6ItpXiXTT2p+rKTt3bRCHgTZ3msa5mKvejvASwzrzi1ffMCzVPd9O6up0 8W0DOA13vTQU755jvd2c+Bps6NmHFSH8OrISDs/A7tGljlf4ZilzySProB0YcQTsdMtF L8zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=shX22ee3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id z18-20020a170906075200b00988fc062668si7779241ejb.446.2023.07.13.22.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:48:05 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=shX22ee3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 BA26786D2F; Fri, 14 Jul 2023 07:47:37 +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="shX22ee3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7929386D32; Fri, 14 Jul 2023 07:47:36 +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-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) (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 BF91C86D31 for ; Fri, 14 Jul 2023 07:47:33 +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-pf1-x432.google.com with SMTP id d2e1a72fcca58-668704a5b5bso1518445b3a.0 for ; Thu, 13 Jul 2023 22:47:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689313652; x=1691905652; 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=utZVaj/9AyfylhDu3zdsKb32s2Pn8M6nBwqueVmPOKo=; b=shX22ee3wD1mmV1iMZJj190gFqEsL6JUuWDKJfMd8pYZj0c+1OH6J06/D0zgq2G1lu xD6jn+8nk1a0IucvRTFqFotpPRmJAYeEM0/qDNPUNqzhseko8HoRa8ir0huM2AVHkXpr i5FPSZMT+QWdCb7XQkZyyf4+qffo/Y/BQ8wHjJzkfU/K6FL+G8WHCBnU6cWB4DSF/nkB KFack8I1hLfa0nAJccVluegEDAO4doVUASr1cXoj37nHoHsvibZGYxLBiTzZkXdI9kby HlJe1PkBlxhgPNnSjZa88+4o8DGw7GBc6bhghc9PiBF2946AVxJExXo5WFJa7z6OMpog o65g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689313652; x=1691905652; 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=utZVaj/9AyfylhDu3zdsKb32s2Pn8M6nBwqueVmPOKo=; b=IUOpW2l9LU7cvsMn48/AiD2+59uS2+7om3Ch8uufqE+4u4lTMmufQG74t9MFm+2jsj 3gwKSdSmDRokj1gZJ/Fqnm/A3jnaCBzgsbWy58F88zRDVbLtoVe4htHlrgFsp51mxM/u H49yQCFCZnPRQzkuz86B5p4FSOZqf2gR3+B3SrLZVb4kDBMNjOnbfaPnnuIquPbXeUFR 8a8zmq7tuBVF5sElo5QmZZHEcfc0gS1DSFivpvR6Z9faV1BZPB0dir7xPxnqoCamsAuw 4PpiMPZxZD5qKlhh2QbUrqurhns6HIT3uKg6CiJkHkcd4y/n4zGhgbE3+Ft7rHLKL9Yo cdnA== X-Gm-Message-State: ABy/qLaR5+IBmBji/6uAo1Pz4nIImNmhn+o1p3o0UHwViYmlQ64DI/RV ld+nssVD/bxOFY860zcBawxVyOJ4cZlHB0Ak0Eo= X-Received: by 2002:a05:6a20:12c9:b0:126:df8b:e812 with SMTP id v9-20020a056a2012c900b00126df8be812mr4486567pzg.25.1689313651976; Thu, 13 Jul 2023 22:47:31 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id fe23-20020a056a002f1700b0066ebaeb149dsm6320251pfb.88.2023.07.13.22.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:31 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v2 5/6] cmd: efidebug: add RAM disk mount command Date: Fri, 14 Jul 2023 14:44:05 +0900 Message-Id: <20230714054406.761508-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230714054406.761508-1-masahisa.kojima@linaro.org> References: <20230714054406.761508-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 --- Changes in v2: - renamed command load/unload -> mount/umount cmd/efidebug.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 9622430c47..2f8e6b6234 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -1421,6 +1421,114 @@ 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_mount(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_umount(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; + } + + efi_free_pool(ram_disk_dp); + ram_disk_dp = NULL; + + return CMD_RET_SUCCESS; +} + +static struct cmd_tbl cmd_efidebug_disk_sub[] = { + U_BOOT_CMD_MKENT(mount, CONFIG_SYS_MAXARGS, 1, do_efi_disk_mount, "", ""), + U_BOOT_CMD_MKENT(umount, CONFIG_SYS_MAXARGS, 1, do_efi_disk_umount, "", ""), +}; + +/** + * 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 +1549,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 +1638,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 mount
\n" + " - load ISO image\n" + "efidebug disk umount\n" + " - unload ISO image\n" +#endif #ifdef CONFIG_CMD_BOOTEFI_BOOTMGR "efidebug test bootmgr\n" " - run simple bootmgr for test\n"