From patchwork Fri Jul 14 05:44:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 702715 Delivered-To: patch@linaro.org Received: by 2002:adf:db4e:0:b0:314:25da:8dc4 with SMTP id f14csp906512wrj; Thu, 13 Jul 2023 22:47:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlGYgmfVUWEzv4MHD/8IFSLDcDnHIoTQm9ShRg/G3+uFcIGJIHz+W+05cCY0OK8UBT+ROD/m X-Received: by 2002:a17:906:7681:b0:98e:2334:af12 with SMTP id o1-20020a170906768100b0098e2334af12mr3054454ejm.45.1689313646375; Thu, 13 Jul 2023 22:47:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689313646; cv=none; d=google.com; s=arc-20160816; b=c4B7+MW7IT5xxgJ83ImVJzKzoUeD2BBt7UHlTeNs4pDvend6qO4Hb7WJMpz+9monXt AJb2D3ios5XCcR6iC1P7fszhWn7SBnIQ2d4Efd5t8J0jW37/5/SWDr3KcAg/tMZxT1mx n54AcLjfk2cGeXhTwo94d8Hy8TyWVvG7Q2Sbp7Aebs6tm2egcCYRWDYaJ7jl0moMCngB 47NDEeLwD6jnDUMt4CHql2PYlXg9pRHFTwwsjEX2l94AiS+PTNqFmIA+BxBtpoLOUcsZ 6KHOqx5VEhZEybvwNO06Smr0aYs2yR3KzDIWZPZrAlUadk4gvDyKSIIAt8n8qkHiavqV N7Aw== 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=fJTbWm4mf+sRF2LwUIwwgOkSYQIrEIiiGr4ORL1uNA0=; fh=xTN8zo5rzpABERcWHVpYCdCrcH4F7J76p6VSzZMpffc=; b=E7kF/eCVdjDg04zwvRiA1uSv0pkKVwtfbFjXQTGqgBBJW2OzR8U5Nav1MzVrJs5EHu 8aGatOGMr8DxNn2dZzgGCv5ldo2+aCXkdbWGp/P2WxDktVyLjll02AoEc7CVV0p8m0Bu zNav/PMN3zETxshafSEn2fiQCj3XIoCoGmo+ZoxZpyOmf9f0BEF84JvIriA0ZppLd9Np eGl6J0PpA2tjyd3e8YsXCNWn+Lt+5hHuK/71QVLi4RRRDk5nkpU0lCF6USrtckQ2kiyl zpiKH3W9IA+S0GHlT75AW4WEoyaR/RkAZ4uXtkYr0ABdjxABHFtl/+TtzojBD5eafqWL AWvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UubrC6Cu; 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 j8-20020a170906254800b00991cb7517bbsi8094543ejb.947.2023.07.13.22.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:26 -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=UubrC6Cu; 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 137C286D1E; Fri, 14 Jul 2023 07:47:18 +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="UubrC6Cu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 21CDA86D22; Fri, 14 Jul 2023 07:47:17 +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-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) (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 987B486D13 for ; Fri, 14 Jul 2023 07:47:14 +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-oi1-x236.google.com with SMTP id 5614622812f47-3a43cbb432aso432105b6e.3 for ; Thu, 13 Jul 2023 22:47:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689313633; x=1691905633; 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=fJTbWm4mf+sRF2LwUIwwgOkSYQIrEIiiGr4ORL1uNA0=; b=UubrC6Cu6ZXUeIDD0M0MeB9eHPI4/lxcpeN3sAjsJOt8pyqiP2QG5X2Gb6LITWJhbE 7TcKvxk3jZPnwY97bUeZ3XXQ6CQkyfHHnJw0wd+pfxcXZyCLkZIUdkNML/HNtKzqOKXz Ed6h3Hzm1TrUv213PRUuEy6YVLmNIDOERRYbXMDxycy4zhyDzVopRXqFPsj1enM7Fg1R WItexOL8ngghjciNt+MTzUjVOt3VMelvEFPZsAH4XnYmir+XXnufFWvclg2/SX8ZKgz+ /10ZP5ztad2btjS31SVyra+YNY3FpZKmRf3TTy4Dijyor9hQzI/NvtumhHgNPQaabclt j7dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689313633; x=1691905633; 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=fJTbWm4mf+sRF2LwUIwwgOkSYQIrEIiiGr4ORL1uNA0=; b=KY87YVnM0bZ5qQpGP/+G0zKouG6AeCW6H6bP/Eab+BY/G1bFr8TLPB2fvOgpXHRAdk Ca0rLtqr9rT+QluD1PWhBxse8OQEf9FVYBsfOW+J6ltQMBt3Sls16ZEXQfFH++yHY6nu 3hSIsa4A+tI+uYH003ws072jEPHdrLHvD9yaigOhLRgy33K+S5XbMpfAW2KCU13B0FFS xxWgf9eertTB9FFH7Xra6rtDaePclcklPg6DgGfsDNPFn9ZoahXPbsTimr93+pnvHp1B Cju65H9gXFdqubi1mbPFlmEf3bzHNtCiQnOwhYbajjqXPzCt1T4ydidm1s7yA7be1eOI z7kQ== X-Gm-Message-State: ABy/qLa51UbbP178LHSMApzeLrOeKm0F7gP8Ib3c9Zr30gaaDuM9MWtM azEZpy+I3lI82bb3itx+QNl3+ZzR9ETzq8xfF6k= X-Received: by 2002:a05:6808:11cf:b0:3a3:fa64:b543 with SMTP id p15-20020a05680811cf00b003a3fa64b543mr4065265oiv.12.1689313633074; Thu, 13 Jul 2023 22:47:13 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id g12-20020a63ad0c000000b00553d42a7cb5sm6473061pgf.68.2023.07.13.22.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:12 -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 1/6] efi_loader: add RAM disk device path Date: Fri, 14 Jul 2023 14:44:01 +0900 Message-Id: <20230714054406.761508-2-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 is a preparation to add the EFI_RAM_DISK_PROTOCOL. This commit adds the RAM disk device path structure and text conversion to Device Path to Text Protocol. Signed-off-by: Masahisa Kojima --- No update since v1 include/efi_api.h | 19 +++++++++++++++++++ lib/efi_loader/efi_device_path_to_text.c | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/efi_api.h b/include/efi_api.h index 55a4c989fc..4ee4a1b5e9 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -682,6 +682,7 @@ struct efi_device_path_uri { # define DEVICE_PATH_SUB_TYPE_CDROM_PATH 0x02 # define DEVICE_PATH_SUB_TYPE_VENDOR_PATH 0x03 # define DEVICE_PATH_SUB_TYPE_FILE_PATH 0x04 +# define DEVICE_PATH_SUB_TYPE_RAM_DISK_PATH 0x09 struct efi_device_path_hard_drive_path { struct efi_device_path dp; @@ -705,6 +706,24 @@ struct efi_device_path_file_path { u16 str[]; } __packed; +/* This GUID defines a RAM Disk supporting a raw disk format in volatile memory */ +#define EFI_VIRTUAL_DISK_GUID \ + EFI_GUID(0x77ab535a, 0x45fc, 0x624b, \ + 0x55, 0x60, 0xf7, 0xb2, 0x81, 0xd1, 0xf9, 0x6e) + +/* This GUID defines a RAM Disk supporting an ISO image in volatile memory */ +#define EFI_VIRTUAL_CD_GUID \ + EFI_GUID(0x3d5abd30, 0x4175, 0x87ce, \ + 0x6d, 0x64, 0xd2, 0xad, 0xe5, 0x23, 0xc4, 0xbb) + +struct efi_device_path_ram_disk_path { + struct efi_device_path dp; + u64 starting_address; + u64 ending_address; + efi_guid_t disk_type_guid; + u16 disk_instance; +} __packed; + #define EFI_BLOCK_IO_PROTOCOL_GUID \ EFI_GUID(0x964e5b21, 0x6459, 0x11d2, \ 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) diff --git a/lib/efi_loader/efi_device_path_to_text.c b/lib/efi_loader/efi_device_path_to_text.c index 8c76d8be60..4395e79f33 100644 --- a/lib/efi_loader/efi_device_path_to_text.c +++ b/lib/efi_loader/efi_device_path_to_text.c @@ -324,6 +324,20 @@ static char *dp_media(char *s, struct efi_device_path *dp) free(buffer); break; } + case DEVICE_PATH_SUB_TYPE_RAM_DISK_PATH: { + struct efi_device_path_ram_disk_path *rddp = + (struct efi_device_path_ram_disk_path *)dp; + u64 start; + u64 end; + + /* Copy from packed structure to aligned memory */ + memcpy(&start, &rddp->starting_address, sizeof(start)); + memcpy(&end, &rddp->ending_address, sizeof(end)); + + s += sprintf(s, "RamDisk(0x%llx,%llx,%pUl,0x%x)", start, end, + &rddp->disk_type_guid, rddp->disk_instance); + break; + } default: s = dp_unknown(s, dp); break; From patchwork Fri Jul 14 05:44:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 702716 Delivered-To: patch@linaro.org Received: by 2002:adf:db4e:0:b0:314:25da:8dc4 with SMTP id f14csp906548wrj; Thu, 13 Jul 2023 22:47:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlGiQ1/N3Z2EDC8xcPHVwUgeofbSfLKfOHa5k9BvDeLmPIr8oDaEPqV70a/NCKITSK5T3DQL X-Received: by 2002:a05:6402:74a:b0:51e:2525:68a3 with SMTP id p10-20020a056402074a00b0051e252568a3mr3189454edy.25.1689313655318; Thu, 13 Jul 2023 22:47:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689313655; cv=none; d=google.com; s=arc-20160816; b=vHj1X9kXHivhlhLVJmIlAj6UEjisyZLZUR40LfAc6xrcSP5mZz6Bm3YjX6jZ1DvLm2 2YO69nGhVnmg6jwv46qRUEdCkdTdPwPdcZYIGmD/hTk5WTrRqLIzxf3B/gol0UolxWs3 3/59rrYgXTznt9elRTi7x7QOoMk6pdWZ+9Vv/iT+ynN4VaZ1IfRBoGX6IfSGbam1fosE lRMn4KgF66Fndcx/EjD2VuyncyZHgnBpmubKQnMs99l85n4r2QA5d4tECqPtJNi4elgt jsif0SMSvHLo5eam9jgL0IgTjy39E9Le4k8RrSCuLRwx5UIl6u6DOwa7f7c4SEiwHPrs 0N3Q== 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=hmx1rMHVzdbCstJRGar5e3Y8ZRpsgZDh/0wT1sTHdOM=; fh=k9uRNNo8VKxGprAjZaZf0XqLyq3c3E+oTj31oN2BOMo=; b=sLwRu6kVwPQzyk1Vqj9uR6GMm7vWhGn3MYBWxoGTqk0moMoO1qL11ivluTtWflHiJe xzu6463EfqLEvkTxIrhTvb4x0WIjriodS8ZV/67mVR6vECqkFahHIHWQaIYoIhQXpqLH dhvHIZWAydMW5kcG7TctTetKoaC7FhVNvMdVchA9CRneXb5rvLANE/Pupbbu8C1mM17O CDUkFnBkjQ1fQBIn3BHNz2K6yPXEhdm5cwA3/nmYSLnVCFRzmZw06w/eLjHe3U805Awp zhROC/gw1dwzrhQNqVo0RJPJLFxVu4CFhJU9964aa54VhHQgC7KQwj7RlC/vyNMuQKSO 2pcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VkDxpccj; 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 u18-20020aa7d892000000b0051e2cab35b7si8316135edq.369.2023.07.13.22.47.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:35 -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=VkDxpccj; 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 50B6986D24; Fri, 14 Jul 2023 07:47:25 +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="VkDxpccj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1F91E86D24; Fri, 14 Jul 2023 07:47:24 +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-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) (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 B67F086D2C for ; Fri, 14 Jul 2023 07:47:20 +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-oi1-x230.google.com with SMTP id 5614622812f47-3a38953c928so1238753b6e.1 for ; Thu, 13 Jul 2023 22:47:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689313639; x=1691905639; 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=hmx1rMHVzdbCstJRGar5e3Y8ZRpsgZDh/0wT1sTHdOM=; b=VkDxpccjSesmX1bkfldUPofHEDChxkOFLke/sbYO0GHnK6F3zr/Mj/f7W6Ydp2ZoNA 9U1l9xn9OweasjxthB3wrRX2/bmip2a1A8/METVJDEk3Gm8TyPVrNslUURAzgcMkx423 E/Ejmk4aCsSR49BL/zvpxnnXEs64dbB1o1ncUSontDLOPHv8RieADvh8b6WZQ9r5hXww HcqjDuCBwtQWJpclipIqYvB7FRWtXVkLc4Rt+cXTO+GBKQ01Av69AXYVkR5mV7iZkrD6 rOP6fZBOR6A4hNJaNAs1oZ2zQVd6Xiswn0iTVt3/zcYUbHS4hFHf82QpfUfb+IooHGws IFAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689313639; x=1691905639; 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=hmx1rMHVzdbCstJRGar5e3Y8ZRpsgZDh/0wT1sTHdOM=; b=UKKCAoHRo1oSjwM02h1UgxUAWSmH+BrhBjgeEuye8JUgNgw6UN7+g+7K7BXWHZEd0U v7dr+AnRqQJZ2ALhEkjaRBjz5nx5cphbZbWmt0Ocn9vUPk8l56Omp4rsPMNL5gdxN/qU BcbHmLBj8iJYd5RKFs2wo+POv9RbjZno0eznMqp8vKi9X2nOhYnUy7n5Us0L1RZrLeKB o8K9mdoYalZ+Or4PhI75xWoXuIS7/sMiqqZni7ZGNYARLc0oroZwRvHHWq7BQ4tjoH0R djbCPKkG5Ar+OHmiJgWyR2JVDDOot87qnWqhacqLT1+9uNnYnbejcNJsY2NoN5SeG/OQ M9Gg== X-Gm-Message-State: ABy/qLac0mSpTz5FaRIz1pZYJUJqcgGL4LI5ZEMVcjkTPoc/4ZIGxhIi 6QXDU99U7m/4flCF20uUJFhlCRSvnzthOGlxEDo= X-Received: by 2002:aca:b9c6:0:b0:3a3:dda9:b90d with SMTP id j189-20020acab9c6000000b003a3dda9b90dmr3875458oif.45.1689313639031; Thu, 13 Jul 2023 22:47:19 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id f13-20020a63380d000000b0052858b41008sm6530003pga.87.2023.07.13.22.47.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:18 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Tobias Waldekranz , Heiko Schocher , Stefan Herbrechtsmeier , Jaehoon Chung , Michal Suchanek , Abdellatif El Khlifi Subject: [PATCH v2 2/6] ramdisk: add ramdisk uclass and driver Date: Fri, 14 Jul 2023 14:44:02 +0900 Message-Id: <20230714054406.761508-3-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 introcudes the ramdisk uclass and driver. Signed-off-by: Masahisa Kojima --- Newly introcuded in v2 disk/part.c | 3 + drivers/block/Kconfig | 7 +- drivers/block/Makefile | 2 + drivers/block/blk-uclass.c | 1 + drivers/block/blk_ramdisk.c | 187 +++++++++++++++++++++++++++++++ drivers/block/ramdisk-uclass.c | 14 +++ include/dm/uclass-id.h | 1 + include/ramdisk.h | 32 ++++++ lib/efi_loader/efi_device_path.c | 25 +++++ 9 files changed, 271 insertions(+), 1 deletion(-) create mode 100644 drivers/block/blk_ramdisk.c create mode 100644 drivers/block/ramdisk-uclass.c create mode 100644 include/ramdisk.h diff --git a/disk/part.c b/disk/part.c index 35300df590..d0cee3cc03 100644 --- a/disk/part.c +++ b/disk/part.c @@ -152,6 +152,9 @@ void dev_print(struct blk_desc *dev_desc) case UCLASS_EFI_MEDIA: printf("EFI media Block Device %d\n", dev_desc->devnum); break; + case UCLASS_RAM_DISK: + printf("RAM Disk Block Device %d\n", dev_desc->devnum); + break; case UCLASS_INVALID: puts("device type unknown\n"); return; diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig index 5a1aeb3d2b..ab56ef3406 100644 --- a/drivers/block/Kconfig +++ b/drivers/block/Kconfig @@ -2,7 +2,7 @@ config BLK bool # "Support block devices" depends on DM default y if MMC || USB || SCSI || NVME || IDE || AHCI || SATA - default y if EFI_MEDIA || VIRTIO_BLK || PVBLOCK + default y if EFI_MEDIA || VIRTIO_BLK || PVBLOCK || RAM_DISK help Enable support for block devices, such as SCSI, MMC and USB flash sticks. These provide a block-level interface which permits @@ -255,3 +255,8 @@ config SYS_64BIT_LBA help Make the block subsystem use 64bit sector addresses, rather than the default of 32bit. + +config RAM_DISK + bool "Enable RAM disk" + help + This option enables to mount the RAM disk. diff --git a/drivers/block/Makefile b/drivers/block/Makefile index a161d145fd..e867c7a126 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -19,3 +19,5 @@ obj-$(CONFIG_BLKMAP) += blkmap.o obj-$(CONFIG_EFI_MEDIA) += efi-media-uclass.o obj-$(CONFIG_EFI_MEDIA_SANDBOX) += sb_efi_media.o obj-$(CONFIG_EFI_MEDIA_BLK) += efi_blk.o +obj-$(CONFIG_RAM_DISK) += blk_ramdisk.o +obj-$(CONFIG_RAM_DISK) += ramdisk-uclass.o diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index 614b975e25..ea411fe674 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -34,6 +34,7 @@ static struct { { UCLASS_VIRTIO, "virtio" }, { UCLASS_PVBLOCK, "pvblock" }, { UCLASS_BLKMAP, "blkmap" }, + { UCLASS_RAM_DISK, "ramdisk" }, }; static enum uclass_id uclass_name_to_iftype(const char *uclass_idname) diff --git a/drivers/block/blk_ramdisk.c b/drivers/block/blk_ramdisk.c new file mode 100644 index 0000000000..8016837a80 --- /dev/null +++ b/drivers/block/blk_ramdisk.c @@ -0,0 +1,187 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * RAM Disk block device driver + * + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#if (IS_ENABLED(CONFIG_EFI_LOADER)) +#include +#endif + +#define MEM_BLOCK_SIZE_SHIFT 9 /* 512 bytes */ + +/** + * ramdisk_read() - read from block device + * + * @dev: device + * @blknr: first block to be read + * @blkcnt: number of blocks to read + * @buffer: output buffer + * Return: number of blocks transferred + */ +static ulong ramdisk_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, + void *buffer) +{ + u8 *start; + struct ramdisk_blk_plat *plat = dev_get_plat(dev); + + log_debug("read buf=%p, block=%lx, count=%lx: ", buffer, (ulong)blknr, + (ulong)blkcnt); + + if (!buffer) + return 0; + + if (blknr + blkcnt > (plat->size >> MEM_BLOCK_SIZE_SHIFT)) + return 0; + + start = plat->start + (blknr << MEM_BLOCK_SIZE_SHIFT); + memmove(buffer, start, blkcnt << MEM_BLOCK_SIZE_SHIFT); + + return blkcnt; +} + +/** + * ramdisk_write() - write to block device + * + * @dev: device + * @blknr: first block to be write + * @blkcnt: number of blocks to write + * @buffer: input buffer + * Return: number of blocks transferred + */ +static ulong ramdisk_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, + const void *buffer) +{ + u8 *start; + struct ramdisk_blk_plat *plat = dev_get_plat(dev); + + log_debug("write buf=%p, block=%lx, count=%lx: ", buffer, (ulong)blknr, + (ulong)blkcnt); + + if (!buffer) + return 0; + + if (blknr + blkcnt > (plat->size >> MEM_BLOCK_SIZE_SHIFT)) + return 0; + + start = plat->start + (blknr << MEM_BLOCK_SIZE_SHIFT); + memmove(start, buffer, blkcnt << MEM_BLOCK_SIZE_SHIFT); + + return blkcnt; +} + +static const struct blk_ops ramdisk_blk_ops = { + .read = ramdisk_read, + .write = ramdisk_write, +}; + +U_BOOT_DRIVER(ramdisk_blk) = { + .name = "ramdisk_blk", + .id = UCLASS_BLK, + .ops = &ramdisk_blk_ops, + .plat_auto = sizeof(struct ramdisk_blk_plat), +}; + +/* + * ramdisk_mount - mount ramdisk + * + * @start_address: The base address of registered RAM disk + * @size: The size of registered RAM disk + * @guid: The type of registered RAM disk + * Return: Pointer to the udevice strucure, return NULL if failed + */ +struct udevice *ramdisk_mount(u64 start_address, u64 size, void *guid) +{ + int ret; + char name[20]; + struct udevice *parent, *bdev; + static struct ramdisk_blk_plat *plat; + + if (!start_address || !size) + return NULL; + + ret = device_bind(dm_root(), DM_DRIVER_GET(ramdisk), "ramdisk", NULL, + ofnode_null(), &parent); + if (ret) { + log_err("bind ramdisk error\n"); + return NULL; + } + snprintf(name, sizeof(name), "ramdisk%d", dev_seq(parent)); + device_set_name(parent, name); + + ret = blk_create_device(parent, "ramdisk_blk", "ramdisk_blk", + UCLASS_RAM_DISK, dev_seq(parent), + 1 << MEM_BLOCK_SIZE_SHIFT, + (size >> MEM_BLOCK_SIZE_SHIFT) - 1, &bdev); + if (ret) { + log_err("ramdisk create block device failed\n"); + goto err; + } + snprintf(name, sizeof(name), "ramdisk_blk#%d", dev_seq(parent)); + device_set_name(bdev, name); + + plat = dev_get_plat(bdev); + plat->start = (u8 *)start_address; + plat->size = size; +#if (IS_ENABLED(CONFIG_EFI_LOADER)) + if (guid) + guidcpy(&plat->disk_type_guid, guid); +#endif + ret = blk_probe_or_unbind(bdev); + if (ret) { + log_err("ramdisk probe error\n"); + goto err; + } + + return bdev; + +err: + if (parent) { + ret = device_remove(parent, DM_REMOVE_NORMAL); + if (ret) + return NULL; + + ret = device_unbind(parent); + } + + return NULL; +} + +/* + * ramdisk_unmount - unmount ramdisk + * + * @dev: The device to be unmounted + * Return: 0 if success, negative value if error + */ +int ramdisk_unmount(struct udevice *dev) +{ + int ret; + struct udevice *parent; + + if (!dev) + return -EINVAL; + + parent = dev->parent; + ret = device_remove(parent, DM_REMOVE_NORMAL); + if (ret) + return ret; + + ret = device_unbind(parent); + + return ret; +} + +U_BOOT_DRIVER(ramdisk) = { + .name = "ramdisk", + .id = UCLASS_RAM_DISK, +}; diff --git a/drivers/block/ramdisk-uclass.c b/drivers/block/ramdisk-uclass.c new file mode 100644 index 0000000000..f1bf68f635 --- /dev/null +++ b/drivers/block/ramdisk-uclass.c @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * RAM Disk block device driver + * + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include + +UCLASS_DRIVER(ramdisk) = { + .name = "ramdisk", + .id = UCLASS_RAM_DISK, +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 307ad6931c..42b4907b1f 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -109,6 +109,7 @@ enum uclass_id { UCLASS_PWRSEQ, /* Power sequence device */ UCLASS_QFW, /* QEMU firmware config device */ UCLASS_RAM, /* RAM controller */ + UCLASS_RAM_DISK, /* RAM disk device */ UCLASS_REBOOT_MODE, /* Reboot mode */ UCLASS_REGULATOR, /* Regulator device */ UCLASS_REMOTEPROC, /* Remote Processor device */ diff --git a/include/ramdisk.h b/include/ramdisk.h new file mode 100644 index 0000000000..71383be5b8 --- /dev/null +++ b/include/ramdisk.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * ramdisk support + * + * Copyright (c) 2023, Linaro Limited + */ + +#ifndef _RAMDISK_H +#define _RAMDISK_H + +#ifdef CONFIG_EFI_LOADER +#include +#endif + +/** + * struct ramdisk_blk_plat - attributes of a block device + * + * @handle: handle of the controller on which this driver is installed + * @io: block io protocol proxied by this driver + */ +struct ramdisk_blk_plat { + u8 *start; + u64 size; +#if (IS_ENABLED(CONFIG_EFI_LOADER)) + efi_guid_t disk_type_guid; +#endif +}; + +struct udevice *ramdisk_mount(u64 start_address, u64 size, void *guid); +int ramdisk_unmount(struct udevice *dev); + +#endif diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 04ebb449ca..1f16bda6ac 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include /* U16_MAX */ @@ -568,6 +569,11 @@ __maybe_unused static unsigned int dp_size(struct udevice *dev) */ return dp_size(dev->parent) + sizeof(struct efi_device_path_vendor) + 1; +#endif +#ifdef CONFIG_RAM_DISK + case UCLASS_RAM_DISK: + return dp_size(dev->parent) + + sizeof(struct efi_device_path_ram_disk_path) + 1; #endif default: return dp_size(dev->parent); @@ -766,6 +772,25 @@ __maybe_unused static void *dp_fill(void *buf, struct udevice *dev) dp->controller_number = desc->lun; return &dp[1]; } +#endif +#if defined(CONFIG_RAM_DISK) + case UCLASS_RAM_DISK: { + struct ramdisk_blk_plat *plat = dev_get_plat(dev); + struct efi_device_path_ram_disk_path *dp = + dp_fill(buf, dev->parent); + + dp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE; + dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_RAM_DISK_PATH; + dp->dp.length = + sizeof(struct efi_device_path_ram_disk_path); + put_unaligned_le64((u64)plat->start, + &dp->starting_address); + put_unaligned_le64((u64)(plat->start + plat->size - 1), + &dp->ending_address); + guidcpy(&dp->disk_type_guid, &plat->disk_type_guid); + dp->disk_instance = 0; + return &dp[1]; + } #endif default: debug("%s(%u) %s: unhandled parent class: %s (%u)\n", From patchwork Fri Jul 14 05:44:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 702717 Delivered-To: patch@linaro.org Received: by 2002:adf:db4e:0:b0:314:25da:8dc4 with SMTP id f14csp906594wrj; Thu, 13 Jul 2023 22:47:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlEdehH8qpxgfCZtwQyHsAJw9eI+Fekk0XGQwOUFDwQZ+yTVQvrWZG0LrSVyM1jxOJzwb7xG X-Received: by 2002:a17:907:8f17:b0:98d:d26c:e142 with SMTP id wg23-20020a1709078f1700b0098dd26ce142mr3103808ejc.46.1689313665313; Thu, 13 Jul 2023 22:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689313665; cv=none; d=google.com; s=arc-20160816; b=c/QBLnDEO9VP3YTLTUw2hADPFERjJLB+Ex+77c1OvKzhqqRaN4ukUTMtHRkYmTJkZD m8fbD4P64bw1rFrq+jute3L8fD3y7hba+2Lfbv2mibqDHvxPFN+7sRiwn4DLSPl1hZIq h52A+mFIq+zxLhKrAC1PMNiWCoOfpzuoLEkPyU28VJ9WirGcQz4OyPtBLc4bwhSvPVlb 9Ns7Y+O7f8z6UI7vEU5R6AMWQWTVTQM9GxVjvfrC1fz86xP58QuGZ43QRr3xyjQx+4/G yQHjS/0zx+ccXtiEd4Em4PByriMEoVOtVwpvlcjY+Wt0hm70P7dAhJ+TH3o/sVXleTrL zY/Q== 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=aLYToA/kZ0sQwIIJzTmfa8ikJi13yU4NIih1cYHz/go=; fh=jRN2B8z80fClEYkayl7MjwCY1OA6DAaCfFIm+/EH5dc=; b=ABWDPhbreioWiSJkMIuqJi1TTsIHtIblGvLwI7XS93+Nac/EhGh6CZAiAlIgQxUjJB Mw9t0YvqkHf+Y2/5HKZNYR65mH2bvIM/01P0pbOxZhUDEWigpPHvwqq/VI99bKCJZOAo HLhkZo3PhhpdPE6p82k7ngGKcww+4ZZHbJ4u4odVMZ0KHzUYUfl2Nc75hUPkrk18S7Be hikqsJieS2C0UAaZcVSOnd+5gu5+JPtpHm0lZfz8cTfLW7axkVJEGdZg2YsF6jhTwdsx OLg5NQpoWy9IRCZiAly796v5tRb7MjLm1/T7e1U5Zlx0qu5NuC5qZFgn6rtUBye16e1B aCAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zb4WUsMR; 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 pv7-20020a170907208700b00992bf74c314si8125500ejb.983.2023.07.13.22.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:45 -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=zb4WUsMR; 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 6680186D25; Fri, 14 Jul 2023 07:47:29 +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="zb4WUsMR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1AE1486D13; Fri, 14 Jul 2023 07:47:28 +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=unavailable autolearn_force=no version=3.4.2 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) (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 C0C1F86D2A for ; Fri, 14 Jul 2023 07:47:25 +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-oo1-xc35.google.com with SMTP id 006d021491bc7-565a8d9d832so1058270eaf.1 for ; Thu, 13 Jul 2023 22:47:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689313644; x=1691905644; 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=aLYToA/kZ0sQwIIJzTmfa8ikJi13yU4NIih1cYHz/go=; b=zb4WUsMR12ongGK03jLSu7y0msjblUItT2p2DCM1u8YN/PfmnLzIKpeD5fduDVQdFD w3B5FVmu6NtS0ZLhlaZ7cAId8787zifxyPBBJdn27lra6l2cqkvMklwquaCk2jA2lB8C JICk946CZRakiDPLmKNWEAVPy2yNmBCDno80dYta47ndLz29YhMWBDKAceaLEsOmcRN5 f5cKPUrYVYa6q4csyMHn6GccGmQplkwGar+SLgf09DyVEDuZJ0pwoTx5h2Q0vj/om7TJ SkQlgZIaDfZeRxOsjA5quKfVJMlwDHmtW0Pl0ruR0JpoD4CC/EiGp15/Mps3Pl4gggzE GRvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689313644; x=1691905644; 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=aLYToA/kZ0sQwIIJzTmfa8ikJi13yU4NIih1cYHz/go=; b=MVqEw+JHHSMLA+TVjSBAyb29HJ/5dXCwFDifVordLsnGRBYcZE7Ey0yoSI+jsW1foo VifEQlfXv2DVT9vOs+LAa3+lqIWH0RLNfcYH+Mz7nN6aRf6WX2QS8xu1i3X4rIqP5Wvs BdTGafDnFNvfhar6A2DuxJOKipCzyDWH0fS6sNPllu/kfxntFpsUlsr88A5Fr8D/Oo5M x8/ridQPQ6Z772N/K/T6KAQMjlB1oSg9OZEiE8S7MJhJ62HR9KCI2P3m/vGkvB+ANuTD /6VT6DUX6MXRb9VoTHwMwFYvRd52LhgXHRY6H1zho4AL/dnyxE+rc6H7kv/Y8Ng6CSjn Fb9Q== X-Gm-Message-State: ABy/qLZewZCsGfE+rXBTS1sM687TY4H1wYmDtNGmexzEaxR612T0LWiL RFQ9Neeb8GKeAo55tBlrgr2STSIccYOrUwI+SSw= X-Received: by 2002:a05:6358:9188:b0:134:5667:a16c with SMTP id j8-20020a056358918800b001345667a16cmr4049380rwa.32.1689313644160; Thu, 13 Jul 2023 22:47:24 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id c19-20020aa78e13000000b00682b2fbd20fsm6370579pfr.31.2023.07.13.22.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:23 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Ramon Fried , Sean Edmond , Tobias Waldekranz , Stefan Roese , John Keeping , Neil Armstrong , Roger Knecht , Alexey Romanov , Dzmitry Sankouski Subject: [PATCH v2 3/6] cmd: ramdisk: add ramdisk control command Date: Fri, 14 Jul 2023 14:44:03 +0900 Message-Id: <20230714054406.761508-4-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 introcudes the ramdisk command, to control the ramdisk devices. Signed-off-by: Masahisa Kojima --- Newly introcuded in v2 cmd/Kconfig | 7 ++++ cmd/Makefile | 1 + cmd/ramdisk.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 cmd/ramdisk.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 365371fb51..5f3022b0c9 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1592,6 +1592,13 @@ config CMD_AXI Interface) busses, a on-chip interconnect specification for managing functional blocks in SoC designs, which is also often used in designs involving FPGAs (e.g. communication with IP cores in Xilinx FPGAs). + +config CMD_RAM_DISK + bool "ramdisk" + depends on RAM_DISK + help + This provides commands to control the ramdisk devices. + endmenu diff --git a/cmd/Makefile b/cmd/Makefile index 6c37521b4e..eb7d86a3c6 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -142,6 +142,7 @@ obj-$(CONFIG_CMD_PWM) += pwm.o obj-$(CONFIG_CMD_PXE) += pxe.o obj-$(CONFIG_CMD_WOL) += wol.o obj-$(CONFIG_CMD_QFW) += qfw.o +obj-$(CONFIG_CMD_RAM_DISK) += ramdisk.o obj-$(CONFIG_CMD_READ) += read.o obj-$(CONFIG_CMD_WRITE) += read.o obj-$(CONFIG_CMD_REGINFO) += reginfo.o diff --git a/cmd/ramdisk.c b/cmd/ramdisk.c new file mode 100644 index 0000000000..8df29729aa --- /dev/null +++ b/cmd/ramdisk.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * ramdisk command + * + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include +#include + +static int ramdisk_curr_dev; /* current device */ + +static int get_desc(enum uclass_id uclass_id, int devnum, struct blk_desc **descp) +{ + struct udevice *dev; + struct uclass *uc; + int ret; + + *descp = NULL; + ret = uclass_get(UCLASS_BLK, &uc); + if (ret) + return ret; + + uclass_foreach_dev(dev, uc) { + struct blk_desc *desc = dev_get_uclass_plat(dev); + + if (desc->uclass_id == uclass_id) { + if (desc->devnum == devnum) { + *descp = desc; + return 0; + } + } + } + + return -1; +} + +static int do_ramdisk(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + int ret; + u64 addr, size; + struct udevice *dev; + + if (strncmp(argv[1], "mount", 5) == 0) { + if (argc != 4) + return CMD_RET_USAGE; + + addr = hextoul(argv[2], NULL); + size = hextoul(argv[3], NULL); + dev = ramdisk_mount(addr, size, NULL); + if (!dev) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; + } + + if (strncmp(argv[1], "umount", 6) == 0) { + struct blk_desc *desc; + + ret = get_desc(UCLASS_RAM_DISK, ramdisk_curr_dev, &desc); + if (ret) { + printf("ramdisk device not found(dev %d)\n", ramdisk_curr_dev); + return CMD_RET_FAILURE; + } + + ret = ramdisk_unmount(desc->bdev); + if (ret) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; + } + + return blk_common_cmd(argc, argv, UCLASS_RAM_DISK, &ramdisk_curr_dev); +} + +U_BOOT_CMD( + ramdisk, 5, 1, do_ramdisk, + "ramdisk sub-system", + "ramdisk info - show available ramdisk devices\n" + "ramdisk mount
- mount ramdisk\n" + "ramdisk umount - unmount ramdisk\n" + "ramdisk device [dev] - show or set current device\n" + "ramdisk part [dev] - print partition table of one or all ramdisk devices\n" + "ramdisk read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n" + " to memory address `addr'\n" + "ramdisk write addr blk# cnt - write `cnt' blocks starting at block\n" + " `blk#' from memory address `addr'" +); From patchwork Fri Jul 14 05:44:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 702718 Delivered-To: patch@linaro.org Received: by 2002:adf:db4e:0:b0:314:25da:8dc4 with SMTP id f14csp906649wrj; Thu, 13 Jul 2023 22:47:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlGfFm0wsh7U6F6hij1CXK6xc0QnZ61XcqTo3FPtMcLjqIVGZ1OuPtzja9iPE71BuNKZRI8y X-Received: by 2002:aa7:cd52:0:b0:51e:1927:6ade with SMTP id v18-20020aa7cd52000000b0051e19276ademr3502241edw.11.1689313675106; Thu, 13 Jul 2023 22:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689313675; cv=none; d=google.com; s=arc-20160816; b=njnfLPGYOXSNQp8ZzZV+KaLJihtSh07NZbkqcMhNpUn1XjvhRS1rN4F2oVn/Kl2X77 k6GZwAROvcCdc1ViY5uV5R+7QUPvT5RXhCMe7NLeBlZDPD4JTGeAeWAxl/XYgQIbqydO 9vQ5flOOqLYIBh2xYrife3g5ytEFIPdIeX65LOZWP2X091haKiO5MbRWPD9lpmXvp6mf 1ix/bm2Y1zTiN177d2CScZSSevbPTSzqpKDQk48ukFAfkOF6KrSdYL2fRf6JYbYkiwme UNAagsNG5T/nAKEY9j4Z3ImbJwHhDTPghJdp4Fm3Ca9qETAny1/67fe2BeRqA8hmWl4i YijQ== 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=fuBtsKKs6Xscb6hShrpv0FUiQQVc8uUxScLU2PrgXlc=; fh=2Cgl+3Z0VvBZsINoafPcrCuvHpnrKYJDE1GTVTHRCXA=; b=N4qtoielqUZawegW37vWKcKUxAQA9WBqeOEa53sh5JCA8GcvcEzFsc77qBMvEU75tN LX5DwfKfpRAusYb+CXlzie8q3WxhEbRKMSopdK4IfoVZJSm4xQwq+n+MpqXj5VAYtQ8p qtv8EmZr5lUrfDfk4t5jHF+UHGSrkvUm4hX5KJeTTsPzxr/ZRy0T7CZA3FosMMl4abHA gBjTStw7sekNXMn9Xx0Gsf+1vjGqCx3pVJMQdFMj/mVn4qHUtBCEcCAOQKuvTB4SHlvk 01SsNb0Qcfq9AQRZFJlGM4mzkXUYdzGyY1swpP5BZmT0BuzlxdpGbAsjLx0QmAAqAk72 I6aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KxF+Lzz2; 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 p4-20020aa7d304000000b0051e0e38a950si9425796edq.637.2023.07.13.22.47.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:55 -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=KxF+Lzz2; 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 B218186D2A; Fri, 14 Jul 2023 07:47:35 +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="KxF+Lzz2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8FE0A86D2C; Fri, 14 Jul 2023 07:47:34 +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-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) (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 200AA86D34 for ; Fri, 14 Jul 2023 07:47:30 +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-x431.google.com with SMTP id d2e1a72fcca58-668711086f4so951564b3a.1 for ; Thu, 13 Jul 2023 22:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689313648; x=1691905648; 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=fuBtsKKs6Xscb6hShrpv0FUiQQVc8uUxScLU2PrgXlc=; b=KxF+Lzz2So5mYDruYwUAQqWYf1DEBgjQfW026mYyfSxwG3JfFI9SlFTEqVZKurxBYH 0Qx3CIP0lOiJJYCmhgrJFUPiwuXnSBsqx7eqZdL1QjmIj17DIIEzvEAodG9dV7dOMAa3 vH++OTFGJFk+8MT+4kMvjIhZuL+yNTWPiJhfB9tJWL1psuzqZZex2YhOubSN8bS4xSok wdlUCbdGrJxYqMiXC4spqa5GgIU48DLTNRVdUWYeyxaNdpqY4HgmSPzk/W4lhoCxhpxd 7E2ENK6d/kJgfLLL3dQqwQdJsvRFEN9RuUc6QBTFbun6ql6VM7cLdrQtQRmRsOaQJpbE HZuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689313648; x=1691905648; 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=fuBtsKKs6Xscb6hShrpv0FUiQQVc8uUxScLU2PrgXlc=; b=D18Iad8CdR33akhW0YC1LhFcTcHkaeOi9Yp/qObf96Id+nNkxN/LL1w/oii7NZAmGF 914I7WlQ9A1s8vasmhuU5zVhfnGyfQ7D6yH0bPt0LnGiDbQgTSO3AsJE8hN/JzL4SnXz LdKmYdhg1utKzRbAb1ljpdK2kYrVR5ZNDKeL0//MGy90gA2oR27nUzPUKcViss0fiDuO qNkBj5zRw+Ar8imL6+60JTwO8lA6U/VO/UbDtyF3tXczWV8McOSh5IOKK++PWPrpi0ss Xa4rIXOGjmbN3y0Eaw8ZaeCJJo2hCb1eec4mH51Q65yKWn3V36BTVlkxAo42dM+6TTy1 MaXw== X-Gm-Message-State: ABy/qLYtON4dpZItZoM9PWBoyz9M/r4Nxh2UcpanAJHTXFo6lvk2QZXS PYJrxWq4+SH6oGraNd+u1DeluKdDxODWehjgHSc= X-Received: by 2002:a05:6a00:392a:b0:67a:52a7:b278 with SMTP id fh42-20020a056a00392a00b0067a52a7b278mr2483666pfb.9.1689313648217; Thu, 13 Jul 2023 22:47:28 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id q7-20020a63ae07000000b004fab4455748sm6625263pgf.75.2023.07.13.22.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:27 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Jose Marinho Subject: [PATCH v2 4/6] efi_loader: add EFI_RAM_DISK_PROTOCOL implementation Date: Fri, 14 Jul 2023 14:44:04 +0900 Message-Id: <20230714054406.761508-5-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 adds the EFI_RAM_DISK_PROTOCOL implementation. User can mount the distro installer by registering the memory mapped ISO image through EFI_RAM_DISK_PROTOCOL. Note that the installation process may not proceed after the distro installer calls ExitBootServices() since there is no hand-off process for the block device of memory mapped ISO image. Signed-off-by: Masahisa Kojima --- Changes in v2: - implement EFI_RAM_DISK_PROTOCOL based on the ramdisk uclass include/efi_api.h | 13 ++++ include/efi_loader.h | 4 + lib/efi_loader/Kconfig | 7 ++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_ram_disk.c | 142 ++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 6 ++ lib/uuid.c | 4 + 7 files changed, 177 insertions(+) create mode 100644 lib/efi_loader/efi_ram_disk.c diff --git a/include/efi_api.h b/include/efi_api.h index 4ee4a1b5e9..3982ab89bc 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -764,6 +764,19 @@ struct efi_block_io { efi_status_t (EFIAPI *flush_blocks)(struct efi_block_io *this); }; +#define EFI_RAM_DISK_PROTOCOL_GUID \ + EFI_GUID(0xab38a0df, 0x6873, 0x44a9, \ + 0x87, 0xe6, 0xd4, 0xeb, 0x56, 0x14, 0x84, 0x49) + +struct efi_ram_disk_protocol { + /* "register" is a reserved keyword in C, use "disk_register" instead */ + efi_status_t(EFIAPI *disk_register)( + u64 ram_disk_base, u64 ram_disk_size, efi_guid_t *ram_disk_type, + struct efi_device_path *parent_device_path, + struct efi_device_path **device_path); + efi_status_t (EFIAPI *unregister)(struct efi_device_path *device_path); +}; + struct simple_text_output_mode { s32 max_mode; s32 mode; diff --git a/include/efi_loader.h b/include/efi_loader.h index 604fd765f7..70c8c83099 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -333,6 +333,8 @@ extern const efi_guid_t smbios_guid; /*GUID of console */ extern const efi_guid_t efi_guid_text_input_protocol; extern const efi_guid_t efi_guid_text_output_protocol; +/* GUID of Ram Disk protocol */ +extern const efi_guid_t efi_guid_ram_disk_protocol; extern char __efi_runtime_start[], __efi_runtime_stop[]; extern char __efi_runtime_rel_start[], __efi_runtime_rel_stop[]; @@ -1159,4 +1161,6 @@ efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int */ void efi_add_known_memory(void); +efi_status_t efi_ram_disk_register(void); + #endif /* _EFI_LOADER_H */ diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index c5835e6ef6..ff0559e8c4 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -433,4 +433,11 @@ config EFI_RISCV_BOOT_PROTOCOL replace the transfer via the device-tree. The latter is not possible on systems using ACPI. +config EFI_RAM_DISK_PROTOCOL + bool "EFI_RAM_DISK_PROTOCOL support" + depends on PARTITIONS + depends on RAM_DISK + help + Provide a EFI_RAM_DISK_PROTOCOL implementation to register the + RAM disk and create the block device. endif diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 1a8c8d7cab..4197f594a2 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -86,6 +86,7 @@ obj-$(CONFIG_EFI_RISCV_BOOT_PROTOCOL) += efi_riscv.o obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_load_initrd.o obj-$(CONFIG_EFI_SIGNATURE_SUPPORT) += efi_signature.o obj-$(CONFIG_EFI_ECPT) += efi_conformance.o +obj-$(CONFIG_EFI_RAM_DISK_PROTOCOL) += efi_ram_disk.o EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE)) $(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE) diff --git a/lib/efi_loader/efi_ram_disk.c b/lib/efi_loader/efi_ram_disk.c new file mode 100644 index 0000000000..a261d93963 --- /dev/null +++ b/lib/efi_loader/efi_ram_disk.c @@ -0,0 +1,142 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * RAM Disk Protocol + * + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include + +const efi_guid_t efi_guid_ram_disk_protocol = EFI_RAM_DISK_PROTOCOL_GUID; + +/* + * ram_disk_register - Register service of the RAM disk protocol + * + * @ram_disk_base: The base address of registered RAM disk + * @ram_disk_size: The size of registered RAM disk + * @ram_disk_type: The type of registered RAM disk + * @parent_device_path: Pointer to the parent device path + * @device_path: Pointer to the device path + * Return: status code + */ +static efi_status_t EFIAPI +ram_disk_register(u64 ram_disk_base, u64 ram_disk_size, + efi_guid_t *ram_disk_type, + struct efi_device_path *parent_device_path, + struct efi_device_path **device_path) +{ + efi_status_t ret; + struct udevice *bdev; + efi_handle_t disk_handle; + struct efi_handler *handler; + struct efi_device_path *dp; + + EFI_ENTRY("%llu %llu %pUs %p, %p", ram_disk_base, ram_disk_size, + ram_disk_type, parent_device_path, device_path); + + if (!ram_disk_size || !ram_disk_type || !device_path) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + + *device_path = NULL; + + /* TODO: Add parent_device_path */ + bdev = ramdisk_mount(ram_disk_base, ram_disk_size, ram_disk_type); + if (!bdev) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + + if (dev_tag_get_ptr(bdev, DM_TAG_EFI, (void **)&disk_handle)) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + + ret = efi_search_protocol(disk_handle, &efi_guid_device_path, &handler); + if (ret != EFI_SUCCESS) + goto out; + + ret = efi_protocol_open(handler, (void **)&dp, NULL, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) + goto out; + + log_debug("EFI_RAM_DISK_PROTOCOL register %pD\n", dp); + + *device_path = efi_dp_dup(dp); + if (!(*device_path)) + ret = EFI_OUT_OF_RESOURCES; + +out: + return EFI_EXIT(ret); +} + +/* + * ram_disk_unregister - Unregister service of the RAM disk protocol + * + * @device_path: Pointer to the device path + * Return: status code + */ +static efi_status_t EFIAPI +ram_disk_unregister(struct efi_device_path *device_path) +{ + int ret; + efi_status_t status = EFI_SUCCESS; + enum uclass_id id; + efi_handle_t disk_handle; + + EFI_ENTRY("%pD", device_path); + + if (!device_path) { + status = EFI_INVALID_PARAMETER; + goto out; + } + + disk_handle = efi_dp_find_obj(device_path, &efi_block_io_guid, NULL); + if (!disk_handle) { + status = EFI_NOT_FOUND; + goto out; + } + + id = device_get_uclass_id(disk_handle->dev); + if (id != UCLASS_BLK) { + status = EFI_INVALID_PARAMETER; + goto out; + } + + ret = ramdisk_unmount(disk_handle->dev); + if (ret) { + log_err("EFI_RAM_DISK_PROTOCOL unregister failed(%d)\n", ret); + status = EFI_INVALID_PARAMETER; + goto out; + } + +out: + return EFI_EXIT(status); +} + +static const struct efi_ram_disk_protocol efi_ram_disk_protocol = { + .disk_register = ram_disk_register, + .unregister = ram_disk_unregister, +}; + +/** + * efi_ram_disk_register() - register EFI_RAM_DISK_PROTOCOL + * + * Return: status code + */ +efi_status_t efi_ram_disk_register(void) +{ + efi_status_t ret; + + ret = efi_add_protocol(efi_root, &efi_guid_ram_disk_protocol, + (void *)&efi_ram_disk_protocol); + if (ret != EFI_SUCCESS) + log_err("Cannot install EFI_RAM_DISK_PROTOCOL\n"); + + return ret; +} diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 877f3878d6..8c430d4a9c 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -344,6 +344,12 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + if (IS_ENABLED(CONFIG_EFI_RAM_DISK_PROTOCOL)) { + ret = efi_ram_disk_register(); + if (ret != EFI_SUCCESS) + goto out; + } + /* Initialize EFI runtime services */ ret = efi_reset_system_init(); if (ret != EFI_SUCCESS) diff --git a/lib/uuid.c b/lib/uuid.c index 96e1af3c8b..9827588186 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -195,6 +195,10 @@ static const struct { "Firmware Management", EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID }, + { + "Ram Disk", + EFI_RAM_DISK_PROTOCOL_GUID + }, /* Configuration table GUIDs */ { "ACPI table", 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" From patchwork Fri Jul 14 05:44:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 702720 Delivered-To: patch@linaro.org Received: by 2002:adf:db4e:0:b0:314:25da:8dc4 with SMTP id f14csp906753wrj; Thu, 13 Jul 2023 22:48:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlFE5Taupp5IxACbrLJjSoEDteCt2JS4jun4oLnbxhoSnWJMx0JJUNFO6yFPEMLheqXnSx0U X-Received: by 2002:a17:906:7a05:b0:993:dcca:9607 with SMTP id d5-20020a1709067a0500b00993dcca9607mr3397490ejo.2.1689313695490; Thu, 13 Jul 2023 22:48:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689313695; cv=none; d=google.com; s=arc-20160816; b=ZEUISl2VPZsgg8FpooJaYN9b7dAJbnTc06flnl//16VnDer5N5curL1y40fozV+Sd7 R3hb/a2/mA5a2A6to00oQz85rsd6UB6zgAdfCSgubhyblN2fncGFJO0v8OGBO+z1LY5L VTEZp2R56uwGVYa+N854qpM2hxVdrV6ztGR8de4cqb54Tk9uDbEyIQT+edttQUk71Eq4 7az+CJk6TM0RIsnBJvvETv5E0ED50vOUMzFTobhfC4JTBJk0Q0kc3ggbgBvYnk+YD5so BEqt0/FzdEA/rxJZmBTPJ3AcGF53MzSxmedAmDzVXN4qXHQi2ZysMhcjaQ6tiX2rjHc0 82yQ== 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=nJfYSV3KtEu6wwaZAgeBAdh2YqYk06dljWME3Xxy/kk=; fh=xTN8zo5rzpABERcWHVpYCdCrcH4F7J76p6VSzZMpffc=; b=ENnts3Hr1eeoi9DSP+KXDnkw/LJMORFPWk+bsXTgTg5bHzbUVZw/ZjOEooBOOFdXWN m4d05Urn2eHaUv0EL1hdzrY4VJdvPDZoCK4a2YT+pB5Ci5WYf/1WL2sF4T86H53xPP1Z 5fdJr7fB7Sdst75neBkqtLffca6Kiwr++xFDWYWVU61f+3luzHVpkfxAzTATjFixKWqq Q7hITxGG+dKXUGCo5/rcgUN4EKRWhiQ/DECOQb4414ZcXk3dYYyqV0LzV91b7yQ2YtT7 Qb4SVyeQK7oVVxJGPldSJikstEKHt52HowRZiGPdMi8uyC5c08YhuwpuEYG8LfLA/0T7 XvzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dm+ASQKe; 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 l20-20020a1709066b9400b00992e0e54464si8737089ejr.254.2023.07.13.22.48.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:48:15 -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=dm+ASQKe; 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 D290A86D3D; Fri, 14 Jul 2023 07:47:42 +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="dm+ASQKe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A9D9F86D26; Fri, 14 Jul 2023 07:47:41 +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-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) (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 1DB9086D13 for ; Fri, 14 Jul 2023 07:47:38 +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-x435.google.com with SMTP id d2e1a72fcca58-666ed230c81so1510267b3a.0 for ; Thu, 13 Jul 2023 22:47:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689313656; x=1691905656; 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=nJfYSV3KtEu6wwaZAgeBAdh2YqYk06dljWME3Xxy/kk=; b=dm+ASQKeif0RwjyIyycvuMk1JjMiB8+3QZw6lH/ryW1g2gD8ihTvSybqvfqOY3Agz0 /BWZlV6BCCJes+fO3Rq3jYG9XCHWmdz+x8ubvXnfKM0GE4nUxPRM+2ooIgMLka1PzJdh QlQNEFA22yP1E+hsFvL67Tc8shcJe7jcBacAElclXJZuRlAYDED0qNgien7cLKV2Xe0P QYb/sNegg2Moah3XKW3VhpNT0fIzSWVBvzEadUn4oOywn9tlnJTkUJd6IA2hbgtdAH1P 61Mv+EIinTvdV3OdlgOEFT+j4+39NJC1uGKiXv+w2e1t05lKnyovVDW4Huq1ZUMraCVY oP4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689313656; x=1691905656; 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=nJfYSV3KtEu6wwaZAgeBAdh2YqYk06dljWME3Xxy/kk=; b=KzAdcbJfUqKkXHtXEXZsU2ZWkhjmbL7J8AX0lsK7/gU6L4+K7AY0xOrgdw42XX9wx/ OecF93QFzSSSbMx/27v1Rr+j4JtD/pn4QPZfdG73EyOYmhV7bn2H2ZgqQUIIePDA5xPx J9MONVZrHB2CA0qvjHtPCa4UHKEYCbiAs0bBg1xWqEa671hI4vMg/W6hMeLRVgeN6gJs Pxwd2G/zM5UYdLL370o3obqykW9gMF3Cfp3wztJoUbD571PPJz+LikZrPmgH2r50Rxgz BGAHfbc6UGbGgLFuuIpT72ayo9aiLEwcJmm7w6CNcq9CPP2mXcWkNYelWN7tYAmggDx/ fMVQ== X-Gm-Message-State: ABy/qLYorLxDFsTp2JR84x1PtYe+7sUWx869zS3Jn8ESf3S5D+g/+fxH v147CJFqwLdgH+7mdc0L/1AEXKdAeZvSLm13lF0= X-Received: by 2002:a05:6a00:2d19:b0:676:76ea:e992 with SMTP id fa25-20020a056a002d1900b0067676eae992mr4738879pfb.5.1689313656169; Thu, 13 Jul 2023 22:47:36 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id u22-20020aa78396000000b0068285a7f107sm6502320pfm.177.2023.07.13.22.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:35 -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 6/6] efi_selftest: add EFI_RAM_DISK_PROTOCOL selftest Date: Fri, 14 Jul 2023 14:44:06 +0900 Message-Id: <20230714054406.761508-7-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 adds the selftest for the EFI_RAM_DISK_PROTOCOL. Signed-off-by: Masahisa Kojima --- No update since v1 lib/efi_selftest/Makefile | 1 + lib/efi_selftest/efi_selftest_ram_disk.c | 511 +++++++++++++++++++++++ 2 files changed, 512 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_ram_disk.c diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index e4d75420bf..899f2278d5 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -70,6 +70,7 @@ endif ifeq ($(CONFIG_BLK)$(CONFIG_DOS_PARTITION),yy) obj-y += efi_selftest_block_device.o +obj-$(CONFIG_EFI_RAM_DISK_PROTOCOL) += efi_selftest_ram_disk.o endif obj-$(CONFIG_EFI_ESRT) += efi_selftest_esrt.o diff --git a/lib/efi_selftest/efi_selftest_ram_disk.c b/lib/efi_selftest/efi_selftest_ram_disk.c new file mode 100644 index 0000000000..5d6ae1f44f --- /dev/null +++ b/lib/efi_selftest/efi_selftest_ram_disk.c @@ -0,0 +1,511 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * efi_selftest_ram_disk + * The disk image defined in efi_selftest_disk_image.h is + * used in this test. + * Most source code originates from efi_selftest_block_device.c. + * + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include "efi_selftest_disk_image.h" +#include + +/* Block size of compressed disk image */ +#define COMPRESSED_DISK_IMAGE_BLOCK_SIZE 8 + +/* Binary logarithm of the block size */ +#define LB_BLOCK_SIZE 9 + +static struct efi_boot_services *boottime; + +static const efi_guid_t block_io_protocol_guid = EFI_BLOCK_IO_PROTOCOL_GUID; +static const efi_guid_t guid_device_path = EFI_DEVICE_PATH_PROTOCOL_GUID; +static const efi_guid_t guid_simple_file_system_protocol = + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID; +static const efi_guid_t guid_file_system_info = EFI_FILE_SYSTEM_INFO_GUID; +static const efi_guid_t guid_ram_disk_protocol = EFI_RAM_DISK_PROTOCOL_GUID; +static efi_guid_t guid_virtual_disk = EFI_VIRTUAL_DISK_GUID; + +/* One 8 byte block of the compressed disk image */ +struct line { + size_t addr; + char *line; +}; + +/* Compressed disk image */ +struct compressed_disk_image { + size_t length; + struct line lines[]; +}; + +static const struct compressed_disk_image img = EFI_ST_DISK_IMG; + +/* Decompressed disk image */ +static u8 *image; +static u8 *image2; + +/* + * Decompress the disk image. + * + * @image decompressed disk image + * Return: status code + */ +static efi_status_t decompress(u8 **image) +{ + u8 *buf; + size_t i; + size_t addr; + size_t len; + efi_status_t ret; + + ret = boottime->allocate_pool(EFI_LOADER_DATA, img.length, + (void **)&buf); + if (ret != EFI_SUCCESS) { + efi_st_error("Out of memory\n"); + return ret; + } + boottime->set_mem(buf, img.length, 0); + + for (i = 0; ; ++i) { + if (!img.lines[i].line) + break; + addr = img.lines[i].addr; + len = COMPRESSED_DISK_IMAGE_BLOCK_SIZE; + if (addr + len > img.length) + len = img.length - addr; + boottime->copy_mem(buf + addr, img.lines[i].line, len); + } + *image = buf; + return ret; +} + +/* + * Setup unit test. + * + * @handle: handle of the loaded image + * @systable: system table + * Return: EFI_ST_SUCCESS for success + */ +static int setup(const efi_handle_t handle, + const struct efi_system_table *systable) +{ + boottime = systable->boottime; + + decompress(&image); + decompress(&image2); + + return EFI_ST_SUCCESS; +} + +/* + * Tear down unit test. + * + * Return: EFI_ST_SUCCESS for success + */ +static int teardown(void) +{ + efi_status_t r; + + if (image) { + r = boottime->free_pool(image); + if (r != EFI_SUCCESS) { + efi_st_error("Failed to free image\n"); + return EFI_ST_FAILURE; + } + } + if (image2) { + r = boottime->free_pool(image2); + if (r != EFI_SUCCESS) { + efi_st_error("Failed to free image\n"); + return EFI_ST_FAILURE; + } + } + return EFI_ST_SUCCESS; +} + +/* + * Get length of device path without end tag. + * + * @dp device path + * Return: length of device path in bytes + */ +static efi_uintn_t dp_size(struct efi_device_path *dp) +{ + struct efi_device_path *pos = dp; + + while (pos->type != DEVICE_PATH_TYPE_END) + pos = (struct efi_device_path *)((char *)pos + pos->length); + return (char *)pos - (char *)dp; +} + +/* + * Execute unit test. + * + * Return: EFI_ST_SUCCESS for success + */ +static int execute(void) +{ + efi_status_t ret; + struct efi_device_path *ram_disk_dp, *ram_disk_dp2; + struct efi_ram_disk_protocol *ram_disk = NULL; + efi_uintn_t no_handles, i, len; + efi_handle_t *handles; + efi_handle_t handle_partition = NULL; + struct efi_device_path *dp_partition; + struct efi_block_io *block_io_protocol; + struct efi_simple_file_system_protocol *file_system; + struct efi_file_handle *root, *file; + struct { + struct efi_file_system_info info; + u16 label[12]; + } system_info; + efi_uintn_t buf_size; + char buf[16] __aligned(ARCH_DMA_MINALIGN); + u32 part1_size; + u64 pos; + char block_io_aligned[1 << LB_BLOCK_SIZE] __aligned(1 << LB_BLOCK_SIZE); + + /* load first disk image */ + ret = boottime->locate_protocol(&guid_ram_disk_protocol, NULL, (void **)&ram_disk); + if (ret != EFI_SUCCESS || !ram_disk) { + efi_st_error("Failed to locate ram disk protocol\n"); + return EFI_ST_FAILURE; + } + ret = ram_disk->disk_register((u64)image, img.length, &guid_virtual_disk, + NULL, &ram_disk_dp); + if (ret != EFI_SUCCESS || !ram_disk_dp) { + efi_st_error("Failed to register ram disk image\n"); + return EFI_ST_FAILURE; + } + + /* Get the handle for the partition */ + ret = boottime->locate_handle_buffer( + BY_PROTOCOL, &guid_device_path, NULL, + &no_handles, &handles); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to locate handles\n"); + return EFI_ST_FAILURE; + } + len = dp_size(ram_disk_dp); + for (i = 0; i < no_handles; ++i) { + ret = boottime->open_protocol(handles[i], &guid_device_path, + (void **)&dp_partition, + NULL, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open device path protocol\n"); + return EFI_ST_FAILURE; + } + if (len >= dp_size(dp_partition)) + continue; + if (memcmp(ram_disk_dp, dp_partition, len)) + continue; + handle_partition = handles[i]; + break; + } + ret = boottime->free_pool(handles); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to free pool memory\n"); + return EFI_ST_FAILURE; + } + if (!handle_partition) { + efi_st_error("Partition handle not found\n"); + return EFI_ST_FAILURE; + } + + /* Open the block_io_protocol */ + ret = boottime->open_protocol(handle_partition, + &block_io_protocol_guid, + (void **)&block_io_protocol, NULL, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open block IO protocol\n"); + return EFI_ST_FAILURE; + } + /* Get size of first MBR partition */ + memcpy(&part1_size, image + 0x1ca, sizeof(u32)); + if (block_io_protocol->media->last_block != part1_size - 1) { + efi_st_error("Last LBA of partition %x, expected %x\n", + (unsigned int)block_io_protocol->media->last_block, + part1_size - 1); + return EFI_ST_FAILURE; + } + /* Open the simple file system protocol */ + ret = boottime->open_protocol(handle_partition, + &guid_simple_file_system_protocol, + (void **)&file_system, NULL, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open simple file system protocol\n"); + return EFI_ST_FAILURE; + } + + /* Open volume */ + ret = file_system->open_volume(file_system, &root); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open volume\n"); + return EFI_ST_FAILURE; + } + buf_size = sizeof(system_info); + ret = root->getinfo(root, &guid_file_system_info, &buf_size, + &system_info); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to get file system info\n"); + return EFI_ST_FAILURE; + } + if (system_info.info.block_size != 512) { + efi_st_error("Wrong block size %u, expected 512\n", + system_info.info.block_size); + return EFI_ST_FAILURE; + } + if (efi_st_strcmp_16_8(system_info.info.volume_label, "U-BOOT TEST")) { + efi_st_todo( + "Wrong volume label '%ps', expected 'U-BOOT TEST'\n", + system_info.info.volume_label); + } + + /* Read file */ + ret = root->open(root, &file, u"hello.txt", EFI_FILE_MODE_READ, + 0); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open file\n"); + return EFI_ST_FAILURE; + } + ret = file->setpos(file, 1); + if (ret != EFI_SUCCESS) { + efi_st_error("SetPosition failed\n"); + return EFI_ST_FAILURE; + } + buf_size = sizeof(buf) - 1; + ret = file->read(file, &buf_size, buf); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to read file\n"); + return EFI_ST_FAILURE; + } + if (buf_size != 12) { + efi_st_error("Wrong number of bytes read: %u\n", + (unsigned int)buf_size); + return EFI_ST_FAILURE; + } + if (memcmp(buf, "ello world!", 11)) { + efi_st_error("Unexpected file content\n"); + return EFI_ST_FAILURE; + } + ret = file->getpos(file, &pos); + if (ret != EFI_SUCCESS) { + efi_st_error("GetPosition failed\n"); + return EFI_ST_FAILURE; + } + if (pos != 13) { + efi_st_error("GetPosition returned %u, expected 13\n", + (unsigned int)pos); + return EFI_ST_FAILURE; + } + ret = file->close(file); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to close file\n"); + return EFI_ST_FAILURE; + } + + /* + * Test that read_blocks() can read same file data. + * + * In the test data, the partition starts at block 1 and the file + * hello.txt with the content 'Hello world!' is located at 0x5000 + * of the disk. Here we read block 0x27 (offset 0x4e00 of the + * partition) and expect the string 'Hello world!' to be at the + * start of block. + */ + ret = block_io_protocol->read_blocks(block_io_protocol, + block_io_protocol->media->media_id, + (0x5000 >> LB_BLOCK_SIZE) - 1, + block_io_protocol->media->block_size, + block_io_aligned); + if (ret != EFI_SUCCESS) { + efi_st_error("ReadBlocks failed\n"); + return EFI_ST_FAILURE; + } + + if (memcmp(block_io_aligned + 1, buf, 11)) { + efi_st_error("Unexpected block content\n"); + return EFI_ST_FAILURE; + } + +#ifdef CONFIG_FAT_WRITE + /* Write file */ + ret = root->open(root, &file, u"u-boot.txt", EFI_FILE_MODE_READ | + EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open file\n"); + return EFI_ST_FAILURE; + } + buf_size = 7; + boottime->set_mem(buf, sizeof(buf), 0); + boottime->copy_mem(buf, "U-Boot", buf_size); + ret = file->write(file, &buf_size, buf); + if (ret != EFI_SUCCESS || buf_size != 7) { + efi_st_error("Failed to write file\n"); + return EFI_ST_FAILURE; + } + ret = file->getpos(file, &pos); + if (ret != EFI_SUCCESS) { + efi_st_error("GetPosition failed\n"); + return EFI_ST_FAILURE; + } + if (pos != 7) { + efi_st_error("GetPosition returned %u, expected 7\n", + (unsigned int)pos); + return EFI_ST_FAILURE; + } + ret = file->close(file); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to close file\n"); + return EFI_ST_FAILURE; + } + + /* Verify file */ + boottime->set_mem(buf, sizeof(buf), 0); + ret = root->open(root, &file, u"u-boot.txt", EFI_FILE_MODE_READ, + 0); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open file\n"); + return EFI_ST_FAILURE; + } + buf_size = sizeof(buf) - 1; + ret = file->read(file, &buf_size, buf); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to read file\n"); + return EFI_ST_FAILURE; + } + if (buf_size != 7) { + efi_st_error("Wrong number of bytes read: %u\n", + (unsigned int)buf_size); + return EFI_ST_FAILURE; + } + if (memcmp(buf, "U-Boot", 7)) { + efi_st_error("Unexpected file content %s\n", buf); + return EFI_ST_FAILURE; + } + ret = file->close(file); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to close file\n"); + return EFI_ST_FAILURE; + } +#else + efi_st_todo("CONFIG_FAT_WRITE is not set\n"); +#endif /* CONFIG_FAT_WRITE */ + + /* Close volume */ + ret = root->close(root); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to close volume\n"); + return EFI_ST_FAILURE; + } + +#ifdef CONFIG_FAT_WRITE + /* load second disk image, then check the disk image is same as original */ + ret = ram_disk->disk_register((u64)image2, img.length, + &guid_virtual_disk, NULL, &ram_disk_dp2); + if (ret != EFI_SUCCESS || !ram_disk_dp2) { + efi_st_error("Failed to register ram disk image\n"); + return EFI_ST_FAILURE; + } + + /* Get the handle for the partition */ + ret = boottime->locate_handle_buffer(BY_PROTOCOL, &guid_device_path, + NULL, &no_handles, &handles); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to locate handles\n"); + return EFI_ST_FAILURE; + } + len = dp_size(ram_disk_dp2); + for (i = 0; i < no_handles; ++i) { + ret = boottime->open_protocol(handles[i], &guid_device_path, + (void **)&dp_partition, NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open device path protocol\n"); + return EFI_ST_FAILURE; + } + if (len >= dp_size(dp_partition)) + continue; + if (memcmp(ram_disk_dp2, dp_partition, len)) + continue; + handle_partition = handles[i]; + break; + } + ret = boottime->free_pool(handles); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to free pool memory\n"); + return EFI_ST_FAILURE; + } + if (!handle_partition) { + efi_st_error("Partition handle not found\n"); + return EFI_ST_FAILURE; + } + + /* Open the block_io_protocol */ + ret = boottime->open_protocol(handle_partition, &block_io_protocol_guid, + (void **)&block_io_protocol, NULL, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open block IO protocol\n"); + return EFI_ST_FAILURE; + } + + /* Open the simple file system protocol */ + ret = boottime->open_protocol(handle_partition, + &guid_simple_file_system_protocol, + (void **)&file_system, NULL, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open simple file system protocol\n"); + return EFI_ST_FAILURE; + } + + /* Open volume */ + ret = file_system->open_volume(file_system, &root); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open volume\n"); + return EFI_ST_FAILURE; + } + + boottime->set_mem(buf, sizeof(buf), 0); + ret = root->open(root, &file, u"u-boot.txt", EFI_FILE_MODE_READ, 0); + if (ret == EFI_SUCCESS) { + efi_st_error("wrong image loaded\n"); + return EFI_ST_FAILURE; + } + + /* Close volume */ + ret = root->close(root); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to close volume\n"); + return EFI_ST_FAILURE; + } + + /* unload disk images */ + ret = ram_disk->unregister(ram_disk_dp); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to unregister ramdisk\n"); + return EFI_ST_FAILURE; + } + ret = ram_disk->unregister(ram_disk_dp2); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to unregister ramdisk2\n"); + return EFI_ST_FAILURE; + } +#endif + return EFI_ST_SUCCESS; +} + +EFI_UNIT_TEST(ramdisk) = { + .name = "ramdisk", + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, + .setup = setup, + .execute = execute, + .teardown = teardown, +};