From patchwork Mon Jan 22 11:54:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 764634 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:10c4:b0:337:62d3:c6d5 with SMTP id b4csp1059587wrx; Mon, 22 Jan 2024 03:57:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHyXiPolrDmyw4Dgr9fWKWfvnmOQjLz3s5Qzv+jCCiTxo2Ss+bk3J6UQDpHuFToHehNd/p3 X-Received: by 2002:a05:600c:5399:b0:40e:7b8c:20d2 with SMTP id hg25-20020a05600c539900b0040e7b8c20d2mr2224283wmb.188.1705924666222; Mon, 22 Jan 2024 03:57:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705924666; cv=none; d=google.com; s=arc-20160816; b=Wruej+/ZREQ4rTUGiAv42XYS6gITonVPRX1c9zUcxAogEU5DxDODK8v/FcdTMRot2l m7F1zPmWkN5CKOpgjjQs9uTEoX1e0z0uPIFndfjLJYfwIbNbTXQpoMsu4/VRGZB+LP7z REbFqQNc+j7GVK0sPg6EG/PZpzDWjkN8Ccz4H73IQJlhmePM6NX0qMnVZkfZyQwte1yk J+7C6kfvNWu2WC/zvph8DljlG21P6t6bWqrCsP45Ee0zZ6fDXCio6NKt6WSLTFiNoo65 1r3aks+SnJcNEU5/mkUKWeYyJ3rMKq6LF2O+RdRFXZ0oogeVEA0QlKsJpioszjYsQ50i 9STw== 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; bh=MyN3uKrqn9ERVau2mhjkItPxse1/o8t9bIwp32i6Y+0=; fh=rhmJ78R78zNUSUA9Nt0a5TbZO4CVsI4vi5GcqSIe+nI=; b=LvmTVMd0c0DO1IRCYlB94ZZz0W/Qf1d1OFY0mnjIAAYhG6rOB4yh5wYpuwuzv+Kslc q7X1LaNJPjkATFmQSxsPHN8gt5CPOno7EAaWr8vBdQdvtRXslEjv1HV8PelO0hyAJMRq F2adf703KyWgSlpvaY7eiNRSoVkq3vBBSVy04KQhvYsbJpCINQsyxOenx/S07NQ6D1Ul BaeuPFY/inA2PN89Ne0jYOoiTOaoMYLUMJGBCs3LxE9gbN+Sk4et436rQ0UkNlFoDDa2 Ab6O81BM6BpxOrjoKgmm6+XPolzOuvIS8DWF9olpz5S3kwaNZfx2P+0o65lwWpEQEnYS MMoQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 k10-20020a7bc40a000000b0040d70cbd60fsi12567261wmi.177.2024.01.22.03.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 03:57:46 -0800 (PST) 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; 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=fail (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 D37E687CA4; Mon, 22 Jan 2024 12:56:06 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 191C887BB3; Mon, 22 Jan 2024 12:56:06 +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=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id F3A1687CAD for ; Mon, 22 Jan 2024 12:56:02 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 788BE1FB; Mon, 22 Jan 2024 03:56:48 -0800 (PST) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C3DA03F73F; Mon, 22 Jan 2024 03:55:59 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima , Patrice Chotard , Patrick Delaunay , Yann Gautier , Etienne Carriere , Sughosh Ganu Subject: [PATCH 16/18] tools: mkfwumdata: Migrate to metadata version 2 Date: Mon, 22 Jan 2024 17:24:37 +0530 Message-Id: <20240122115439.653871-17-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240122115439.653871-1-sughosh.ganu@linaro.org> References: <20240122115439.653871-1-sughosh.ganu@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 Migrate the metadata generation tool to generate the version 2 metadata. Signed-off-by: Sughosh Ganu --- tools/mkfwumdata.c | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/tools/mkfwumdata.c b/tools/mkfwumdata.c index 9732a8ddc5..b43cf38457 100644 --- a/tools/mkfwumdata.c +++ b/tools/mkfwumdata.c @@ -14,12 +14,13 @@ #include #include -/* This will dynamically allocate the fwu_mdata */ -#define CONFIG_FWU_NUM_BANKS 0 -#define CONFIG_FWU_NUM_IMAGES_PER_BANK 0 - /* Since we can not include fwu.h, redefine version here. */ -#define FWU_MDATA_VERSION 1 +#define FWU_MDATA_VERSION 2 + +#define MAX_BANKS 4 + +#define BANK_INVALID 0xFF +#define BANK_ACCEPTED 0xFC typedef uint8_t u8; typedef int16_t s16; @@ -29,8 +30,6 @@ typedef uint64_t u64; #include -/* TODO: Endianness conversion may be required for some arch. */ - static const char *opts_short = "b:i:a:p:gh"; static struct option options[] = { @@ -48,7 +47,7 @@ static void print_usage(void) fprintf(stderr, "Usage: mkfwumdata [options] \n"); fprintf(stderr, "Options:\n" "\t-i, --images Number of images (mandatory)\n" - "\t-b, --banks Number of banks (mandatory)\n" + "\t-b, --banks Number of banks(1-4) (mandatory)\n" "\t-a, --active-bank Active bank (default=0)\n" "\t-p, --previous-bank Previous active bank (default=active_bank - 1)\n" "\t-g, --guid Use GUID instead of UUID\n" @@ -85,6 +84,7 @@ static struct fwu_mdata_object *fwu_alloc_mdata(size_t images, size_t banks) return NULL; mobj->size = sizeof(struct fwu_mdata) + + sizeof(struct fwu_fw_store_desc) + (sizeof(struct fwu_image_entry) + sizeof(struct fwu_image_bank_info) * banks) * images; mobj->images = images; @@ -105,6 +105,7 @@ fwu_get_image(struct fwu_mdata_object *mobj, size_t idx) size_t offset; offset = sizeof(struct fwu_mdata) + + sizeof(struct fwu_fw_store_desc) + (sizeof(struct fwu_image_entry) + sizeof(struct fwu_image_bank_info) * mobj->banks) * idx; @@ -117,6 +118,7 @@ fwu_get_bank(struct fwu_mdata_object *mobj, size_t img_idx, size_t bnk_idx) size_t offset; offset = sizeof(struct fwu_mdata) + + sizeof(struct fwu_fw_store_desc) + (sizeof(struct fwu_image_entry) + sizeof(struct fwu_image_bank_info) * mobj->banks) * img_idx + sizeof(struct fwu_image_entry) + @@ -188,7 +190,7 @@ fwu_parse_fill_image_uuid(struct fwu_mdata_object *mobj, return -EINVAL; if (strcmp(uuid, "0") && - uuid_guid_parse(uuid, (unsigned char *)&image->location_uuid) < 0) + uuid_guid_parse(uuid, (unsigned char *)&image->location_guid) < 0) return -EINVAL; /* Image type UUID */ @@ -196,7 +198,7 @@ fwu_parse_fill_image_uuid(struct fwu_mdata_object *mobj, if (!uuid) return -EINVAL; - if (uuid_guid_parse(uuid, (unsigned char *)&image->image_type_uuid) < 0) + if (uuid_guid_parse(uuid, (unsigned char *)&image->image_type_guid) < 0) return -EINVAL; /* Fill bank image-UUID */ @@ -210,7 +212,7 @@ fwu_parse_fill_image_uuid(struct fwu_mdata_object *mobj, return -EINVAL; if (strcmp(uuid, "0") && - uuid_guid_parse(uuid, (unsigned char *)&bank->image_uuid) < 0) + uuid_guid_parse(uuid, (unsigned char *)&bank->image_guid) < 0) return -EINVAL; } return 0; @@ -225,6 +227,19 @@ static int fwu_parse_fill_uuids(struct fwu_mdata_object *mobj, char *uuids[]) mdata->version = FWU_MDATA_VERSION; mdata->active_index = active_bank; mdata->previous_active_index = previous_bank; + mdata->metadata_size = mobj->size; + mdata->desc_offset = sizeof(struct fwu_mdata); + + for (i = 0; i < MAX_BANKS; i++) + mdata->bank_state[i] = i < mobj->banks ? + BANK_ACCEPTED : BANK_INVALID; + + mdata->fw_desc[0].num_banks = mobj->banks; + mdata->fw_desc[0].num_images = mobj->images; + mdata->fw_desc[0].img_entry_size = sizeof(struct fwu_image_entry) + + (sizeof(struct fwu_image_bank_info) * mobj->banks); + mdata->fw_desc[0].bank_info_entry_size = + sizeof(struct fwu_image_bank_info); for (i = 0; i < mobj->images; i++) { ret = fwu_parse_fill_image_uuid(mobj, i, uuids[i]); @@ -313,6 +328,12 @@ int main(int argc, char *argv[]) return -EINVAL; } + if (banks > MAX_BANKS) { + fprintf(stderr, "Error: The number of banks must not be more than %u.\n", + MAX_BANKS); + return -EINVAL; + } + /* This command takes UUIDs * images and output file. */ if (optind + images + 1 != argc) { fprintf(stderr, "Error: UUID list or output file is not specified or too much.\n");