From patchwork Thu Jan 11 05:35:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 761792 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e02:0:b0:337:62d3:c6d5 with SMTP id h2csp2237203wrz; Wed, 10 Jan 2024 21:38:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IG51cTHUDGhM7RS4YGc/xVQmyni+1+PTuBi7f8l/qr4dkEBm5sDyyUN2WCahZp7Ie7cB4ZM X-Received: by 2002:a05:600c:2257:b0:40e:490e:8e7b with SMTP id a23-20020a05600c225700b0040e490e8e7bmr68660wmm.127.1704951482750; Wed, 10 Jan 2024 21:38:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704951482; cv=none; d=google.com; s=arc-20160816; b=SegIy9oMBgTcKNBfUwwB14r7ybzF9K/kmooROF3viAU1y1CTQr/J+x3aGHr5XWutXb D8MGBk9cWhKmwlbOPLhcY7rlxcRmD4q7eUXLzGxNyV5tvQ/mDh9rMvj89/TDJiZl4hg9 74AA+ZnbyX22wcSe1aGIb1IaFace4r5/sSPoUXy64DZ0eRtSk2JS6u3dj+UHTkoa0WBs OifeZ7Cx9lfTatLMdKwnnC8S4jIuVBOdgnOdcgKR7xOjqV2EMhptqLx4emZTrjY3OqSW TcXEJGWyTWrZfgokUNadUkjHhSU9ir7GE0Qg/DOvOEdvQd/eJp3unxkJFtz4dKQK73Qc 7w2Q== 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=Oiu3XdFGrY9VUxnGd/RC4lYGuf7y4wN/HseMcD3PiKg=; fh=vrqNCSWbrItDl40TMygDgSHof0/XikFdntN3a1zOV74=; b=daqu+saTXfdWwT7o+T+Jr6s8fsa1mUWsHQajHCsMWWA8JtxzY+5G5WMSf8oWthkRek n8FH4cEf/Ndr1pyr+lzNKw32OozufhZaPJBLI23QFJ6g1S4CXi8Vdre83wEW+9UjD77H dV5WTiwZgvLimsb/NMXohaDCTALhRlvHLuBvHZti+2a35H2IF7huJsc86iVT4bJ3TA2M 32Eu/PFFbmOk2mVyWXah0ookgjhxDRQgmD6L4AiuRL7ReTiemF+tJ3sQpN16b/Q0wNsB dbJj92Pkv9vUeli6qJGH1GSsHe6cdmoVdpm6FtXevtBHbIJ2JJK9gT/H5ZWaAknLjyBH WDtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WCbU9ER2; 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 v11-20020a05600c12cb00b0040d8cfbb3f4si179273wmd.231.2024.01.10.21.38.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 21:38:02 -0800 (PST) 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=WCbU9ER2; 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 0674187AAB; Thu, 11 Jan 2024 06:37:56 +0100 (CET) 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="WCbU9ER2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 05CE887A88; Thu, 11 Jan 2024 06:37:55 +0100 (CET) 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-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) (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 AFB5587823 for ; Thu, 11 Jan 2024 06:37:52 +0100 (CET) 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-x633.google.com with SMTP id d9443c01a7336-1d4ab4e65aeso38499165ad.0 for ; Wed, 10 Jan 2024 21:37:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704951470; x=1705556270; darn=lists.denx.de; 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=Oiu3XdFGrY9VUxnGd/RC4lYGuf7y4wN/HseMcD3PiKg=; b=WCbU9ER2wvtT6afh0myuF7rTHZl6bxfDIEfhGpasktam1zCs62grWs80/YKG2i4Y0G 0pEkQ+69epWUuirZwytkfPcxl5NpCesnSz25r6shLhALXxQschRkjpONaBm+JRAK+KKT ptfOD9ZVM3eaYeDCH71XKzr+jBFh7Xhqrfh+O/3OeJbIALtFJWXKBPCVOUwtEdOq3Xjb Bj1U8xw2jgK3pdJJAiCp7u6foT+zcP28L6GBKcHcRGw8/k2K7Owk1+nGxRcquh6UMhaq A5vLtjQ2cF3oi6X48376XxxWVCf2Ow8uvAF6v0g8DHZrR9tQJKGrNhRFD6i4DHzAdkCy 8Vkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704951470; x=1705556270; 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=Oiu3XdFGrY9VUxnGd/RC4lYGuf7y4wN/HseMcD3PiKg=; b=OquzWzRE/TBtMEi72K5+/1mArkpko9h0wdaCAQ0CfVUtWMlnaF/9gi7qJkOKxi9k7X 9JBf0bhCKmTmAv/S5+0P13Fz0l3MFCzAbq4gZgtBHg/iamwclEgYMj3taJsEIcr+ibHP WoCMvDDRtDJQDpbVoL0fI8f9MdDgxX3EQKeZDlhVmJ/vzt8qZbLoHhAYMPV7oEe6h89q gyKKpPGzS2fgNeTI7Igr8yO0uMJdzxuhkdj1rvnLjq8tL/wkYozzBjLqOOQndFhmfNPD cQ1E+xmzqN1hf8YI0L5sAPyP+Uc7/YH+6l4WVMNKZCPrB8snORLXSbDS2pc7KP9Ain3V nUtw== X-Gm-Message-State: AOJu0Yz9wTFFJb+PrPd++8oVmQawgYL6Z4ELb8JIpBow+58trqiCVtoU +sH6JTPa1OlT+zpbTvmtqURukOBDjhuPyNWBKI/+2mj4wmg= X-Received: by 2002:a17:902:ee51:b0:1d4:381c:a3e5 with SMTP id 17-20020a170902ee5100b001d4381ca3e5mr301246plo.66.1704951470298; Wed, 10 Jan 2024 21:37:50 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id r19-20020a170902c61300b001d3e9937d92sm273645plr.51.2024.01.10.21.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 21:37:49 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Sughosh Ganu , Masahisa Kojima Subject: [PATCH v3 2/2] efi_loader: support fmp versioning for multi bank update Date: Thu, 11 Jan 2024 14:35:40 +0900 Message-Id: <20240111053540.899997-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240111053540.899997-1-masahisa.kojima@linaro.org> References: <20240111053540.899997-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 stores the firmware version into the array of fmp_state structure to support the fmp versioning for multi bank update. The index of the array is identified by the bank index. This modification keeps the backward compatibility with the existing versioning feature. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_firmware.c | 75 ++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 15 deletions(-) diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index e558336bc1..9fd13297a6 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -206,18 +206,10 @@ void efi_firmware_fill_version_info(struct efi_firmware_image_descriptor *image_ { u16 varname[13]; /* u"FmpStateXXXX" */ efi_status_t ret; - efi_uintn_t size; - struct fmp_state var_state = { 0 }; - - efi_create_indexed_name(varname, sizeof(varname), "FmpState", - fw_array->image_index); - size = sizeof(var_state); - ret = efi_get_variable_int(varname, &fw_array->image_type_id, - NULL, &size, &var_state, NULL); - if (ret == EFI_SUCCESS) - image_info->version = var_state.fw_version; - else - image_info->version = 0; + efi_uintn_t size, expected_size; + uint num_banks = 1; + uint active_index = 0; + struct fmp_state *var_state; efi_firmware_get_lsv_from_dtb(fw_array->image_index, &fw_array->image_type_id, @@ -226,6 +218,31 @@ void efi_firmware_fill_version_info(struct efi_firmware_image_descriptor *image_ image_info->version_name = NULL; /* not supported */ image_info->last_attempt_version = 0; image_info->last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS; + image_info->version = 0; + + /* get the fw_version */ + efi_create_indexed_name(varname, sizeof(varname), "FmpState", + fw_array->image_index); + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { + ret = fwu_get_active_index(&active_index); + if (ret) + return; + + num_banks = CONFIG_FWU_NUM_BANKS; + } + + size = num_banks * sizeof(*var_state); + expected_size = size; + var_state = calloc(1, size); + if (!var_state) + return; + + ret = efi_get_variable_int(varname, &fw_array->image_type_id, + NULL, &size, var_state, NULL); + if (ret == EFI_SUCCESS && expected_size == size) + image_info->version = var_state[active_index].fw_version; + + free(var_state); } /** @@ -361,8 +378,11 @@ efi_status_t efi_firmware_set_fmp_state_var(struct fmp_state *state, u8 image_in { u16 varname[13]; /* u"FmpStateXXXX" */ efi_status_t ret; + uint num_banks = 1; + uint update_bank = 0; + efi_uintn_t size; efi_guid_t *image_type_id; - struct fmp_state var_state = { 0 }; + struct fmp_state *var_state; image_type_id = efi_firmware_get_image_type_id(image_index); if (!image_type_id) @@ -371,19 +391,44 @@ efi_status_t efi_firmware_set_fmp_state_var(struct fmp_state *state, u8 image_in efi_create_indexed_name(varname, sizeof(varname), "FmpState", image_index); + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { + ret = fwu_plat_get_update_index(&update_bank); + if (ret) + return EFI_INVALID_PARAMETER; + + num_banks = CONFIG_FWU_NUM_BANKS; + } + + size = num_banks * sizeof(*var_state); + var_state = calloc(1, size); + if (!var_state) + return EFI_OUT_OF_RESOURCES; + + /* + * GetVariable may fail, EFI_NOT_FOUND is returned if FmpState + * variable has not been set yet. + * Ignore the error here since the correct FmpState variable + * is set later. + */ + efi_get_variable_int(varname, image_type_id, NULL, &size, var_state, + NULL); + /* * Only the fw_version is set here. * lowest_supported_version in FmpState variable is ignored since * it can be tampered if the file based EFI variable storage is used. */ - var_state.fw_version = state->fw_version; + var_state[update_bank].fw_version = state->fw_version; + size = num_banks * sizeof(*var_state); ret = efi_set_variable_int(varname, image_type_id, EFI_VARIABLE_READ_ONLY | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - sizeof(var_state), &var_state, false); + size, var_state, false); + + free(var_state); return ret; }