From patchwork Mon Feb 12 07:47:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 772039 Delivered-To: patch@linaro.org Received: by 2002:adf:9dca:0:b0:33b:4db1:f5b3 with SMTP id q10csp2000886wre; Sun, 11 Feb 2024 23:50:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEuhw0I4zk5IXOWk+2VfJKW4t3gukeKUuQGYORoTOcIDUDnpMUK/jCKbzPW07K7gRHzcK3n X-Received: by 2002:aa7:d5c2:0:b0:560:cae:53f7 with SMTP id d2-20020aa7d5c2000000b005600cae53f7mr4193104eds.35.1707724230239; Sun, 11 Feb 2024 23:50:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707724230; cv=none; d=google.com; s=arc-20160816; b=Hg04mlQJaf8Oq3SUT979wFkSQ0Yl9z0D843g2ZKYaeoQUJJStKdCOvI1+ojO4y1t/g zYMA6nexlsWGUUswVVpRE+T/S6CyFTRP51VIsI6nZ0egCsMjm2x/3Pj86NpFXlEm4Oy7 Rw3OUYO03G7rbrCsfc1WmIkGloFEzj0JQAqcDSuX4BElLmLbvLO2rAppM9uv/T178TVM wHWcpBQxnm4dk7Z1N6DlJ32gBljjlNLL5FPcTR3I/KXlDILNkEi6+WVeYjaSa4blm3n3 OvAljvaj+FIlWKCM/XmQRWc9gB5ZernoLLaiGVUBYWazmMLf8eufeyUF4dG0U+SHpczs 5zyg== 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=EfSSKdCkctdxO/j7gdeAOVwiMZKei5VnyHFdUh0Su8M=; fh=VgvH5y+8QqoDHLgS8ZqmSn7UsvteKWCjtDmGhOlsE20=; b=j8HBO0jsnDTLo29iTEZ75uVjFbClp82V5MQ+nlThHQGQOapKm+Y3CXljsjn75dQ4If +6zkVw8XHv4pzM3aq+EYKPfDA5Tw3d0v1/m+zzhHwOsyOcFcK9HfKqfY77jk4q3Vs8ty /Rp01b+O7xvM0zOe+zWE2JW7tvR56jCF6lJOfqBT7P38tIMa07Hvm32DB2YHxg+fD5Ei 4gECrWoEX+scccUTS+8kVAZlhLRbFI7aoOjEbZaRKkDBHtPzjtkwHWS9VxtS7yXBbCqn gzffpJ1XOJbfC7rGKwRLT4GT7SJuXHSuVQD8qpvWRL0uE/7JkBZNpBKlGkZdayCAfVY7 96qQ==; darn=linaro.org ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org X-Forwarded-Encrypted: i=1; AJvYcCUJKZ82yDEL9DxVZHdtiT+N0ph8TrgnDGK/J0thdYMnVshOaPpPOiV6RaVadcw8xFd3q1c9xen6ZmSPIVFZDyVTboCNeul47c5Lj4Eq6EKMm2loW1Hjvz2QusRC91YwJiYSW80imxN7wXzBeRvm16HT5Z4y87/GHn135ueYvL/5bK+l7JIDXZ0LALDRvw+djDMjRlVorWqFjcSXk3D72o1QQV0e+qQ3Y8pALgv4+UibD9Cf+Q2mPGl9EeR966lV7tCX/iQoR7tggNCG3zF4WqPRmW9UBpa6TG2VZ1XEow+i3efE0508af+jzvZgBEVcWghiJ9tcItXypMiQQu/8sPQXKGQenP3sjsilaUTG13/j8WFbslAV12Vbw8sp3OIDbk5hWIpodSjFBqmqasubb5GOueP5UvK9MUaN5thM9pACUNh6iZQyDXh6r5ERIHKmyfUxO3509Ps2N6Oq0mynhlXHUEfUO68yZYmysBrrvuXi0zy1h2fDP3KLApu+TBVutRFPLlRmBjGQlQE+moGkmFLUih89kEjeiKd+jKp/ltLU2J0rdktMn/c5Er7V+3U5zKyJOeaMovC+GUSlPd70EiKO03GLafBsx4lioSGOfv8taiIMCH+wVIUqLs0toT5vpTZbsN7co8A2GgWfDl1mpXSNCIT814XfSaZh1Hz2CTiulOixks82Kg//z+u7yoG0Ai4KadHVeFInxr18LAR9yewfAsFK34bc6cYTHxbK36hoygQcQnlCh9kRmjyg304oZ6uJHAay/RFHDt6r5oWrEHBMWTMJ/+2A5DDwzkrCaeNEmrI2yYZ0vvvTfqO4uf0dgePIsJ4PFdDUUyIeZrJtViF6hm+MUWftKrxL482+Baft7Ck= 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 w12-20020aa7cb4c000000b005615b840203si2517353edt.513.2024.02.11.23.50.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 23:50:30 -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; 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=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 B07F887ECA; Mon, 12 Feb 2024 08:48:41 +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 9B0AF87F03; Mon, 12 Feb 2024 08:48:40 +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 49B7187808 for ; Mon, 12 Feb 2024 08:48:38 +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 55B3ADA7; Sun, 11 Feb 2024 23:49:19 -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 898693F762; Sun, 11 Feb 2024 23:48:34 -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 , Michal Simek , Jassi Brar , Sughosh Ganu Subject: [PATCH v2 17/21] tools: mkfwumdata: migrate to metadata version 2 Date: Mon, 12 Feb 2024 13:17:08 +0530 Message-Id: <20240212074712.3657076-18-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240212074712.3657076-1-sughosh.ganu@linaro.org> References: <20240212074712.3657076-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 --- Changes since V1: * Compute location of struct fwu_fw_store_desc using pointer arithmetic. tools/mkfwumdata.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/tools/mkfwumdata.c b/tools/mkfwumdata.c index 9732a8ddc5..fb847e3a78 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; @@ -220,11 +222,26 @@ fwu_parse_fill_image_uuid(struct fwu_mdata_object *mobj, static int fwu_parse_fill_uuids(struct fwu_mdata_object *mobj, char *uuids[]) { struct fwu_mdata *mdata = mobj->mdata; + struct fwu_fw_store_desc *fw_desc; int i, ret; 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; + + fw_desc = (struct fwu_fw_store_desc *)((u8 *)mdata + sizeof(*mdata)); + fw_desc->num_banks = mobj->banks; + fw_desc->num_images = mobj->images; + fw_desc->img_entry_size = sizeof(struct fwu_image_entry) + + (sizeof(struct fwu_image_bank_info) * mobj->banks); + fw_desc->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 +330,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");