From patchwork Thu Jan 20 15:30:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533547 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1676946imu; Thu, 20 Jan 2022 07:30:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMfYlQKqWlBrx6mLw/BsjyOolRoX7mjeDIBz3acywE3Rolv9bX39yGJUz4oMDu8F8n78BK X-Received: by 2002:aa7:cf8c:: with SMTP id z12mr29126512edx.93.1642692658800; Thu, 20 Jan 2022 07:30:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692658; cv=none; d=google.com; s=arc-20160816; b=r4pHF3Bv1r5GFQffseyvkl2oNCl2JKJzBlaVvn+RL3J2nkF5X2ExdyfgAyOzPFuR9i 6sYPRQN8G+gGTMfjlJrELXpSBR1nTzU1KBVAJfXhYwQmlcBnXZcD3G+xiMS0qpbl31xV pzKeV/A47tu2ZNDhgpW3kYH7+foqlHIZcjY95xqniE7Imo4kjgvM365HznYK2NhpwvH7 lkf314dNvONgCnpoFdmKSMidNxVVOwG9gARtg6cRtjxNtNlrkvAY0jTMfBn0n3wZsTZw OTmPBTzwAtJiSzgedLijG68TND6VK+X8nGpXBdixSbWVZN1re3RQw6gxWxS9bphkzP4H QJbA== 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:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=W1C9qj84hBwy+8QqJxCIUXEcLaCgpoKHW2kEN9Ee+TM=; b=GYGsNNXLsaT7ahgc/scIvmdv4PgWd0OrxO1VW84EV48YsF0ivghsJaSaA/5NIP23Qa Tw2FvqtJUwuYfx+3GIwZDLcGtBwr2J042QbTCJMjzTWJx+/sZw3bdNfCx7+pcUQwJ1Za Wklgq1eHcPXnczzMBlGQF+GtTrLptpkTNSTDrjF0KH5hq9dOv9qYaxsxfgHMWgZxJ0AH ORY5K0JsdenutVaFnTayKOOeUoIGB9khjw1ydTNhoDJ2RDVhFsbXUQMp0311yyb8V+vw 9fsmyBC4KY3/qp6BABUObwKxcEdZMmt2cD1yc/EaEofQyKORuycQziUuIJOVmNwlsK8f n8Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=puaiyDG5; 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 dn21si2179132ejc.791.2022.01.20.07.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:58 -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=puaiyDG5; 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 CF3CA838C4; Thu, 20 Jan 2022 16:30:51 +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="puaiyDG5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2A124838D6; Thu, 20 Jan 2022 16:30:50 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) (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 C46C683890 for ; Thu, 20 Jan 2022 16:30:46 +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=masami.hiramatsu@linaro.org Received: by mail-pj1-x1035.google.com with SMTP id s2-20020a17090ad48200b001b501977b23so5451249pju.2 for ; Thu, 20 Jan 2022 07:30:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=W1C9qj84hBwy+8QqJxCIUXEcLaCgpoKHW2kEN9Ee+TM=; b=puaiyDG5rXQtr9ZNodydINeO/oJqgf4kYzBkHJOvFxAXZO8rtgF9wKWAT9yCNjkMJG zOOPhltT8be6gPlkaLYtrN7GBQULZ3hRM5SjYCQ8Zyz6qi7w6Vqbuy21xMfRINfRxbX+ ltDaz7dk2NoSo9HZyAHhEnMCVe18mo7p5MFK8Zok8wAF69Uz45T1sI8W7sSBBYhcA/oA jYOcV+7qqpPlY0fz6LsSFQxm3nWH/3B945WLAeTkWSNfLzkbYgQXis8lo/ABSLcV5n7A 1LGAfIp2EOsxkO3Yx20jOmT8NK+i24UtFydTkpt0/uGoCCwhRfKo84oSAdXXjtuf86me 6c0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=W1C9qj84hBwy+8QqJxCIUXEcLaCgpoKHW2kEN9Ee+TM=; b=McYwUr2U2sSvxRY6Txx3PHxnyU7KAt27u8sR7bb8YdYgIsmnnbEcfJTeZyYG81cbeU awRHvUR1/Ad92qm7SaoQKpyB3C/+vpUm0DY3q6x74jACKk1V0+coQLt7LSe2fSI3RFDw ha0ROss4VWkJtbPM4+pAWmBHKCUDknnwGekoP9pVOJLCizbFWW5qxp2kC7lDYKwo3dGE 0McVReMUh8fjwhS6Q/kW/ToJeqLH6UrWvOVDDlqghh6byyzvUCq/saqun4JgUicU+Nze EIjZhhnCTuwCFclnaktdw4xSDDAbP3TAlkCU0BjLVNcHD8cIdUVdfMn4ducBEKfI9L91 LuiQ== X-Gm-Message-State: AOAM531Hb2ctP7I48IWD9i5sz2j1sEew41Uf+EQ3DbT5V5NXKwc+DwZ/ VNAlSJsT+9uT0iBC0wbhkTTeXsuBm9h2/Q== X-Received: by 2002:a17:90b:1e4c:: with SMTP id pi12mr11372169pjb.224.1642692644976; Thu, 20 Jan 2022 07:30:44 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id l15sm2597365pgh.27.2022.01.20.07.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:44 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 08/14] FWU: Move FWU metadata operation code in fwu_mdata.c Date: Fri, 21 Jan 2022 00:30:40 +0900 Message-Id: <164269264036.39378.11024708444178044567.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.stgit@localhost> User-Agent: StGit/0.19 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.2 at phobos.denx.de X-Virus-Status: Clean Remove some FWU metadata operations which only access or modify the metadata itself from fwu_mdata_ops and move it in fwu_mdata.c. Signed-off-by: Masami Hiramatsu --- include/fwu.h | 9 --- lib/fwu_updates/fwu_mdata.c | 105 ++++++++++++++++++++++++----------- lib/fwu_updates/fwu_mdata_gpt_blk.c | 85 ---------------------------- 3 files changed, 71 insertions(+), 128 deletions(-) diff --git a/include/fwu.h b/include/fwu.h index 6c9b64a9f1..7af94988b7 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -14,26 +14,17 @@ struct fwu_mdata; /** - * @get_active_index: get the current active_index value * @get_image_alt_num: get the alt number to be used for the image * @mdata_check: check the validity of the FWU metadata partitions - * @set_accept_image: set the accepted bit for the image - * @clear_accept_image: clear the accepted bit for the image * @get_mdata() - Get a FWU metadata copy * @update_mdata() - Update the FWU metadata copy */ struct fwu_mdata_ops { - int (*get_active_index)(u32 *active_idx); - int (*get_image_alt_num)(efi_guid_t image_type_id, u32 update_bank, int *alt_num); int (*mdata_check)(void); - int (*set_accept_image)(efi_guid_t *img_type_id, u32 bank); - - int (*clear_accept_image)(efi_guid_t *img_type_id, u32 bank); - int (*get_mdata)(struct fwu_mdata **mdata); int (*update_mdata)(struct fwu_mdata *mdata); diff --git a/lib/fwu_updates/fwu_mdata.c b/lib/fwu_updates/fwu_mdata.c index 1324771a71..505f4f3630 100644 --- a/lib/fwu_updates/fwu_mdata.c +++ b/lib/fwu_updates/fwu_mdata.c @@ -3,6 +3,7 @@ * Copyright (c) 2021, Linaro Limited */ +#include #include #include #include @@ -12,6 +13,9 @@ #include #include +#define IMAGE_ACCEPT_SET BIT(0) +#define IMAGE_ACCEPT_CLEAR BIT(1) + static struct fwu_mdata_ops *get_fwu_mdata_ops(void) { struct fwu_mdata_ops *ops; @@ -66,18 +70,28 @@ int fwu_verify_mdata(struct fwu_mdata *mdata, bool pri_part) */ int fwu_get_active_index(u32 *active_idx) { - struct fwu_mdata_ops *ops; + int ret; + struct fwu_mdata *mdata = NULL; - ops = get_fwu_mdata_ops(); - if (!ops) - return -EPROTONOSUPPORT; + ret = fwu_get_mdata(&mdata); + if (ret < 0) { + log_err("Unable to get valid FWU metadata\n"); + return ret; + } - if (!ops->get_active_index) { - log_err("get_active_index() method not defined for the platform\n"); - return -ENOSYS; + /* + * Found the FWU metadata partition, now read the active_index + * value + */ + *active_idx = mdata->active_index; + if (*active_idx > CONFIG_FWU_NUM_BANKS - 1) { + printf("Active index value read is incorrect\n"); + ret = -EINVAL; } - return ops->get_active_index(active_idx); + free(mdata); + + return ret; } /** @@ -197,12 +211,12 @@ int fwu_revert_boot_index(void) { int ret; u32 cur_active_index; - struct fwu_mdata *mdata = NULL; + struct fwu_mdata *mdata; ret = fwu_get_mdata(&mdata); if (ret < 0) { log_err("Unable to get valid FWU metadata\n"); - goto out; + return ret; } /* @@ -223,6 +237,49 @@ int fwu_revert_boot_index(void) ret = -EIO; } + free(mdata); + + return ret; +} + +static int fwu_set_clear_image_accept(efi_guid_t *img_type_id, + u32 bank, u8 action) +{ + void *buf; + int ret, i; + u32 nimages; + struct fwu_mdata *mdata = NULL; + struct fwu_image_entry *img_entry; + struct fwu_image_bank_info *img_bank_info; + + ret = fwu_get_mdata(&mdata); + if (ret < 0) { + log_err("Unable to get valid FWU metadata\n"); + return ret; + } + + nimages = CONFIG_FWU_NUM_IMAGES_PER_BANK; + img_entry = &mdata->img_entry[0]; + for (i = 0; i < nimages; i++) { + if (!guidcmp(&img_entry[i].image_type_uuid, img_type_id)) { + img_bank_info = &img_entry[i].img_bank_info[bank]; + if (action == IMAGE_ACCEPT_SET) + img_bank_info->accepted |= FWU_IMAGE_ACCEPTED; + else + img_bank_info->accepted = 0; + + buf = &mdata->version; + mdata->crc32 = crc32(0, buf, sizeof(*mdata) - + sizeof(u32)); + + ret = fwu_update_mdata(mdata); + goto out; + } + } + + /* Image not found */ + ret = -EINVAL; + out: free(mdata); @@ -244,18 +301,8 @@ out: */ int fwu_accept_image(efi_guid_t *img_type_id, u32 bank) { - struct fwu_mdata_ops *ops; - - ops = get_fwu_mdata_ops(); - if (!ops) - return -EPROTONOSUPPORT; - - if (!ops->set_accept_image) { - log_err("set_accept_image() method not defined for the platform\n"); - return -ENOSYS; - } - - return ops->set_accept_image(img_type_id, bank); + return fwu_set_clear_image_accept(img_type_id, bank, + IMAGE_ACCEPT_SET); } /** @@ -274,18 +321,8 @@ int fwu_accept_image(efi_guid_t *img_type_id, u32 bank) */ int fwu_clear_accept_image(efi_guid_t *img_type_id, u32 bank) { - struct fwu_mdata_ops *ops; - - ops = get_fwu_mdata_ops(); - if (!ops) - return -EPROTONOSUPPORT; - - if (!ops->clear_accept_image) { - log_err("clear_accept_image() method not defined for the platform\n"); - return -ENOSYS; - } - - return ops->clear_accept_image(img_type_id, bank); + return fwu_set_clear_image_accept(img_type_id, bank, + IMAGE_ACCEPT_CLEAR); } /** diff --git a/lib/fwu_updates/fwu_mdata_gpt_blk.c b/lib/fwu_updates/fwu_mdata_gpt_blk.c index 7f8b8b68fc..af9b1adf94 100644 --- a/lib/fwu_updates/fwu_mdata_gpt_blk.c +++ b/lib/fwu_updates/fwu_mdata_gpt_blk.c @@ -24,9 +24,6 @@ #define MDATA_READ BIT(0) #define MDATA_WRITE BIT(1) -#define IMAGE_ACCEPT_SET BIT(0) -#define IMAGE_ACCEPT_CLEAR BIT(1) - static int gpt_get_mdata_partitions(struct blk_desc *desc, u16 *primary_mpart, u16 *secondary_mpart) @@ -335,34 +332,6 @@ out: return ret; } -int fwu_gpt_get_active_index(u32 *active_idx) -{ - int ret; - struct fwu_mdata *mdata = NULL; - - ret = gpt_get_mdata(&mdata); - if (ret < 0) { - log_err("Unable to get valid FWU metadata\n"); - goto out; - } - - /* - * Found the FWU metadata partition, now read the active_index - * value - */ - *active_idx = mdata->active_index; - if (*active_idx > CONFIG_FWU_NUM_BANKS - 1) { - printf("Active index value read is incorrect\n"); - ret = -EINVAL; - goto out; - } - -out: - free(mdata); - - return ret; -} - static int gpt_get_image_alt_num(struct blk_desc *desc, efi_guid_t image_type_id, u32 update_bank, int *alt_no) @@ -467,63 +436,9 @@ int fwu_gpt_get_mdata(struct fwu_mdata **mdata) return gpt_get_mdata(mdata); } -static int fwu_gpt_set_clear_image_accept(efi_guid_t *img_type_id, - u32 bank, u8 action) -{ - int ret, i; - u32 nimages; - struct fwu_mdata *mdata = NULL; - struct fwu_image_entry *img_entry; - struct fwu_image_bank_info *img_bank_info; - - ret = gpt_get_mdata(&mdata); - if (ret < 0) { - log_err("Unable to get valid FWU metadata\n"); - goto out; - } - - nimages = CONFIG_FWU_NUM_IMAGES_PER_BANK; - img_entry = &mdata->img_entry[0]; - for (i = 0; i < nimages; i++) { - if (!guidcmp(&img_entry[i].image_type_uuid, img_type_id)) { - img_bank_info = &img_entry[i].img_bank_info[bank]; - if (action == IMAGE_ACCEPT_SET) - img_bank_info->accepted |= FWU_IMAGE_ACCEPTED; - else - img_bank_info->accepted = 0; - - ret = fwu_gpt_update_mdata(mdata); - goto out; - } - } - - /* Image not found */ - ret = -EINVAL; - -out: - free(mdata); - - return ret; -} - -static int fwu_gpt_accept_image(efi_guid_t *img_type_id, u32 bank) -{ - return fwu_gpt_set_clear_image_accept(img_type_id, bank, - IMAGE_ACCEPT_SET); -} - -static int fwu_gpt_clear_accept_image(efi_guid_t *img_type_id, u32 bank) -{ - return fwu_gpt_set_clear_image_accept(img_type_id, bank, - IMAGE_ACCEPT_CLEAR); -} - struct fwu_mdata_ops fwu_gpt_blk_ops = { - .get_active_index = fwu_gpt_get_active_index, .get_image_alt_num = fwu_gpt_get_image_alt_num, .mdata_check = fwu_gpt_mdata_check, - .set_accept_image = fwu_gpt_accept_image, - .clear_accept_image = fwu_gpt_clear_accept_image, .get_mdata = fwu_gpt_get_mdata, .update_mdata = fwu_gpt_update_mdata, };