From patchwork Mon Apr 10 09:07:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 672029 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp151434wrx; Mon, 10 Apr 2023 02:07:09 -0700 (PDT) X-Google-Smtp-Source: AKy350YPpgH5vbyLZd86imG2rKyOo28TRPVTgcGHVOriEGL8d0A7UUGiIwutIwOFlq8Vhi8Jl2pM X-Received: by 2002:a05:622a:547:b0:3e6:332a:70df with SMTP id m7-20020a05622a054700b003e6332a70dfmr14629075qtx.44.1681117629124; Mon, 10 Apr 2023 02:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681117629; cv=none; d=google.com; s=arc-20160816; b=uIB9uq8k98a5bmYQQm+8gKc19NPu+fPy7KyIFuJa/jVEoArLMkjVzkyhRZTkRatEdo 5QH1/VY8TzrIg+n0HFbHVf+M6jeVALKV/cmvEe5vveEV92U8pMUFGMjvY1m+7uvrEMAk MmCz1SSqz0buwd4HEVEjyOrYYDJ0MK+IOg3evtUwtEgbal100o07OAs9cCbMZHnnzz3m SsRWOmmnSseRT1Lt27IFRynLoYvOVAntk5Fg5d8L/km4iGTQ9SblkhbuBCMPSHRTF+Yt z6NQwPlYTEfTtZwVerEHbi5OdhoNLo9yOWBnGz5hPBNDbkv90Gm2ZxSyWryhLUICwaKZ AUag== 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:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=OQiWnUThY2ZRwn3oVvt9AoGOhbrdwXS/0URdWJqiJys=; b=WM3HEX9+yd0lGJHfkaJW7/hw9smeLRqnnjk9u5j3Y8bSmlkH6pja8L3oyJpofgPCpl bCxjA43X1OAze1N4lAzWextTwuR0NaPwyu0PZbfd1FmhVEMz450ZUXbHuA9RQawy0XFO ILHhy40vNplNJC38cLtmTw8K1pTa44jb+jCouWXoYEBb1/S6zO3j1iAz3U6thqSQLNWo 4wLhxRXGahfcd0LAGV8At97LiZ4CQgFIpylU3ISEjgNF/3FJQoilzGWJmimYtOeC+TeR IrzGx3WOehRP7A1qjc+rvgignvkBfGc57D4l+uYldS71kfQJsK/QHL7R3XUVSWsh0kRf C61Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CKnU+yCZ; 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 a6-20020ae9e806000000b0074a4dbc4cc9si6855671qkg.667.2023.04.10.02.07.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 02:07:09 -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=CKnU+yCZ; 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 7A249856B2; Mon, 10 Apr 2023 11:06:52 +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="CKnU+yCZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DAA3680B9E; Mon, 10 Apr 2023 11:06:35 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (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 0905683981 for ; Mon, 10 Apr 2023 11:06:31 +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-pl1-x629.google.com with SMTP id y6so3081127plp.2 for ; Mon, 10 Apr 2023 02:06:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681117589; x=1683709589; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=OQiWnUThY2ZRwn3oVvt9AoGOhbrdwXS/0URdWJqiJys=; b=CKnU+yCZklzHu7qSkSdIsZEdvRjp8AdOVUzqXwosNEuxZfWvrOb7kUePJcooLBVZ6h cre9etlGD5EkDOAdWOL8wDYETfUsgNyDxWeBlACWJsmvgOPxEfR4l0+XRqcuGxOaAsgn a2mwakljc1WsHacRy9yuUTv1oaSnLjybNJd0G2NiuNNjHSsx38MV5QSWduZJB4eOS41d TGBasST8Y3hPEW0c6B0YX6csTtLqquJN/rlvDwWkA+X3acQ+J06C2zZ756dFdzIA0a1w NCg/MfT74cD9Kkdnm2MqpCLPL4CChkEaSmLWtMAgIH0NJua2OMj1zrOYMNPNy8pb/YKB yTuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681117589; x=1683709589; h=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=OQiWnUThY2ZRwn3oVvt9AoGOhbrdwXS/0URdWJqiJys=; b=HGnsCvwpWNLrg4bUKKIwsMZdWIafdi9yfNp4vp2hknZoxOJalYVgzOZArQjZlvnVwb m3RC/hPQ+7FmQuArYkm5JLAT6zr3yr2mExyZ7UcfL4ViLXmH3L/aoWI9VWBzh6lv+6G9 MzLCaGxyyp7WGtnS3+ayW3VuLP9b+6Q3Ogfpvqzhg2Dt034vaqftzeVyxc0m5hqsDmRf 4S5lPght/ZwG5nTd7JhtXDPgSGyAI/IB3AD50omCV8K2bpFbhxbflgHivneBK0PFNvbw idWgMj82TfWgYNDR73rMEpm3kTZQMMsKCJLQgraK8ZPvgSTZyXm6DCOCQ3dKN7LKsqmF 89EQ== X-Gm-Message-State: AAQBX9dsOjoP4Gc7mqiduY+ByxgoUbbHI6s3OdMwb+DxAoQMqmkD4H4Q ZG7kTM1+7pkJveE98FuQsH34vTrU8St0Q5BOrrw= X-Received: by 2002:a17:90a:f197:b0:246:594d:3b05 with SMTP id bv23-20020a17090af19700b00246594d3b05mr11746937pjb.17.1681117589022; Mon, 10 Apr 2023 02:06:29 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id s15-20020a17090a5d0f00b0023f8bdc4a7fsm7189279pji.14.2023.04.10.02.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 02:06:28 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v5 1/4] efi_loader: get version information from device tree Date: Mon, 10 Apr 2023 18:07:29 +0900 Message-Id: <20230410090732.1676-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230410090732.1676-1-masahisa.kojima@linaro.org> References: <20230410090732.1676-1-masahisa.kojima@linaro.org> 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 Current FMP->GetImageInfo() always return 0 for the firmware version, user can not identify which firmware version is currently running through the EFI interface. This commit gets the version information from device tree, then fills the firmware version, lowest supported version in FMP->GetImageInfo(). Now FMP->GetImageInfo() and ESRT have the meaningful version number. Signed-off-by: Masahisa Kojima --- Changes in v5: - newly implement a device tree based versioning .../firmware/firmware-version.txt | 25 ++++++++ lib/efi_loader/efi_firmware.c | 63 +++++++++++++++++-- 2 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 doc/device-tree-bindings/firmware/firmware-version.txt diff --git a/doc/device-tree-bindings/firmware/firmware-version.txt b/doc/device-tree-bindings/firmware/firmware-version.txt new file mode 100644 index 0000000000..6112de4a1d --- /dev/null +++ b/doc/device-tree-bindings/firmware/firmware-version.txt @@ -0,0 +1,25 @@ +firmware-version bindings +------------------------------- + +Required properties: +- image-type-id : guid for image blob type +- image-index : image index +- fw-version : firmware version +- lowest-supported-version : lowest supported version + +Example: + + firmware-version { + image1 { + image-type-id = "09D7CF52-0720-4710-91D1-08469B7FE9C8"; + image-index = <1>; + fw-version = <5>; + lowest-supported-version = <3>; + }; + image2 { + image-type-id = "5A7021F5-FEF2-48B4-AABA-832E777418C0"; + image-index = <2>; + fw-version = <10>; + lowest-supported-version = <7>; + }; + }; diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 93e2b01c07..1c6ef468bf 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -102,6 +102,56 @@ efi_status_t EFIAPI efi_firmware_set_package_info_unsupported( return EFI_EXIT(EFI_UNSUPPORTED); } +/** + * efi_firmware_get_firmware_version - get firmware version from dtb + * @image_index: Image index + * @image_type_id: Image type id + * @fw_version: Pointer to store the version number + * @lsv: Pointer to store the lowest supported version + * + * Authenticate the capsule if authentication is enabled. + * The image pointer and the image size are updated in case of success. + */ +void efi_firmware_get_firmware_version(u8 image_index, + efi_guid_t *image_type_id, + u32 *fw_version, u32 *lsv) +{ + const void *fdt = gd->fdt_blob; + const fdt32_t *val; + const char *guid_str; + int len, offset, index; + int parent; + + parent = fdt_subnode_offset(fdt, 0, "firmware-version"); + if (parent < 0) + return; + + fdt_for_each_subnode(offset, fdt, parent) { + efi_guid_t guid; + + guid_str = fdt_getprop(fdt, offset, "image-type-id", &len); + if (!guid_str) + continue; + uuid_str_to_bin(guid_str, guid.b, UUID_STR_FORMAT_GUID); + + val = fdt_getprop(fdt, offset, "image-index", &len); + if (!val) + continue; + index = fdt32_to_cpu(*val); + + if (!guidcmp(&guid, image_type_id) && index == image_index) { + val = fdt_getprop(fdt, offset, "fw-version", &len); + if (val) + *fw_version = fdt32_to_cpu(*val); + + val = fdt_getprop(fdt, offset, + "lowest-supported-version", &len); + if (val) + *lsv = fdt32_to_cpu(*val); + } + } +} + /** * efi_fill_image_desc_array - populate image descriptor array * @image_info_size: Size of @image_info @@ -148,13 +198,19 @@ static efi_status_t efi_fill_image_desc_array( *package_version_name = NULL; /* not supported */ for (i = 0; i < num_image_type_guids; i++) { + u32 fw_version = 0; + u32 lowest_supported_version = 0; + image_info[i].image_index = fw_array[i].image_index; image_info[i].image_type_id = fw_array[i].image_type_id; image_info[i].image_id = fw_array[i].image_index; image_info[i].image_id_name = fw_array[i].fw_name; - - image_info[i].version = 0; /* not supported */ + efi_firmware_get_firmware_version(fw_array[i].image_index, + &fw_array[i].image_type_id, + &fw_version, + &lowest_supported_version); + image_info[i].version = fw_version; image_info[i].version_name = NULL; /* not supported */ image_info[i].size = 0; image_info[i].attributes_supported = @@ -168,7 +224,7 @@ static efi_status_t efi_fill_image_desc_array( image_info[0].attributes_setting |= IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED; - image_info[i].lowest_supported_image_version = 0; + image_info[i].lowest_supported_image_version = lowest_supported_version; image_info[i].last_attempt_version = 0; image_info[i].last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS; image_info[i].hardware_instance = 1; @@ -290,7 +346,6 @@ efi_status_t EFIAPI efi_firmware_get_image_info( descriptor_version, descriptor_count, descriptor_size, package_version, package_version_name); - return EFI_EXIT(ret); }