From patchwork Mon Apr 10 23:02:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 672040 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp495072wrx; Mon, 10 Apr 2023 16:03:45 -0700 (PDT) X-Google-Smtp-Source: AKy350YZxppC3fR4du1nZsMGJQdEThIAgydkSgynKNxVC08szc7XICMZiJDGhuoU4WbQ4cgY/+kc X-Received: by 2002:a05:6214:27ef:b0:5ad:a15b:3e6c with SMTP id jt15-20020a05621427ef00b005ada15b3e6cmr13537428qvb.48.1681167825388; Mon, 10 Apr 2023 16:03:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681167825; cv=none; d=google.com; s=arc-20160816; b=M+GKSO3vfD+L5ayt74bK5V2vfHr8kirmv6toMR7u27dMTW/eDw1wLgMzw2b9Wd1zTG KkXoiQC9R9G99SC81Psodp8VM2XzT1W12fGS2gNHOFgRiLD/MV7vdJRX0j8kB7+mXGWr f26bjjo9ACfYxispqlH46X/V2M93uxdhOfYpccr6mBMZWCqBT7JegT5mq/WTnOD/Rd6n tx5GI1U8p/oPW1i9N71bTns8jomvT7TR8psK/in6mnPUmsctGw2FKzwfMWslkapf1jqn iaK6iQHoGzeLGss0wn/M6hNJXtjVOGCV7YXGxq41h8xVYT2jtvP4vqf5QgxffXf+Hg/P +JZg== 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=8UV7U1TxN6Hapwts1/NVN5NDgnxOrgG8ZBLYWeele2c=; b=ppcnEmBiznA6JdrR5bK14AUYkEdbvOe78s5OZBVIHh8NhOSXL3K25bd/LjMhWNvNDK nejNuySvhcJ+UNW6UHFDfW+u9ra0yIQur6eq5A4OrIfvW2lqtC+hVssrvKVilDjtxixe rohY/siR6lwUTYVM5PnLz6dRt6cTHFoMekj9cbwB8XorOiMfStj7abOVcbTDrwjNc37d K8ivXHjXfoAflgOMfNAQKRpJvOujZldAnlCJcVMa/NzgkToIjAlxx5OvOuRmdueuMJ0A pg/E0zreXLd5/q+/cgmIq9WKuNe6L7M03sYzfxbvw0iDTm8Iikhzobud2hME3Y+03cvN M8Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dNCp5U1X; 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 eq6-20020ad45966000000b005bbeedd15a1si7879738qvb.584.2023.04.10.16.03.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 16:03:45 -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=dNCp5U1X; 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 13F6F85D1E; Tue, 11 Apr 2023 01:03:43 +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="dNCp5U1X"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BCC5D815D4; Tue, 11 Apr 2023 01:03:40 +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-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) (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 7942C85CD8 for ; Tue, 11 Apr 2023 01:03:35 +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=jaswinder.singh@linaro.org Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-54f6fc7943eso8755707b3.3 for ; Mon, 10 Apr 2023 16:03:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681167814; x=1683759814; 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=8UV7U1TxN6Hapwts1/NVN5NDgnxOrgG8ZBLYWeele2c=; b=dNCp5U1X2c2+7xC/lQXODWetKrcUtgQE4np6Hj6g2GHhorZONlbXQV30AXSwiajLuR UPz50QLirOCLy/yfPhVCnsOb08xRcuyf8X4RQ3U3DP6u+9Yfz1OMpZyCOg9ph84LFPV9 4kEKBIfm5cpxPCsgj5vYc7Zyd06Kc+/7Z4jEwvd7rwLb2xrhJC2vJTK0X2HQd0uA4LMo 1JXHHgSnrBaF03hk3jRlEsVrd4urOfAPAbfUoZFShuREOzCDLRQcAplV0imUYyN5wQMt liggT/FW1B1+X35JP1lXdJ3TNtTe3ZfzLT/Ovr+AFNfdMKapMiojlokBL12EevqxYWyu lbvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681167814; x=1683759814; 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=8UV7U1TxN6Hapwts1/NVN5NDgnxOrgG8ZBLYWeele2c=; b=ZRtQkFAwq3oJwkG9V1+SJkyq3hY9lEvLEVhg38pEpRjvzHYXfMBOnSKjZVU3XXM3fm DOvR/f1Zelul95Sy23b4YZB714JniTc9FtwzCAaDV/jwCUNGABhIU+4FHKps440GhF1+ G1MC/+rGNv3nFi4dandWjRZeN+WHsg7dDzaLmBv5c6lyLDHgst9zLsPRQBliZ3P+L2oe DNbBMTl6M5wgk1XfCtE0Iz1aNtRSYvIpBEnoZRd/2sYpBOMD77OsD8rQEHCvh/8Edxv5 7RDpJCcuv7deTVKDNncyRNB1+q29uxjGR4QYGa+Ig01r37ye+zeqXPScmx7yhOS+CVEq cOqw== X-Gm-Message-State: AAQBX9c8FJq4Sd7u2kCSrtTaoBvdOm/56MdSuRtGGiDVzLhj7HrA3daq eHHMJfhiafkbxAL94ctFzyMw/09hSq7kk6HG2mM= X-Received: by 2002:a81:6f54:0:b0:544:c7e0:9706 with SMTP id k81-20020a816f54000000b00544c7e09706mr6946697ywc.42.1681167813827; Mon, 10 Apr 2023 16:03:33 -0700 (PDT) Received: from jassi-desktop.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id bh30-20020a05690c039e00b0054c0ddb3611sm3108546ywb.87.2023.04.10.16.03.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 16:03:33 -0700 (PDT) From: jaswinder.singh@linaro.org To: u-boot@lists.denx.de Cc: ilias.apalodimas@linaro.org, etienne.carriere@linaro.org, trini@konsulko.com, sjg@chromium.org, sughosh.ganu@linaro.org, xypron.glpk@gmx.de, takahiro.akashi@linaro.org, michal.simek@amd.com, Masami Hiramatsu , Jassi Brar Subject: [PATCH v5 1/6] FWU: Add FWU metadata access driver for MTD storage regions Date: Mon, 10 Apr 2023 18:02:48 -0500 Message-Id: <20230410230247.72585-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410230143.72556-1-jaswinder.singh@linaro.org> References: <20230410230143.72556-1-jaswinder.singh@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 From: Masami Hiramatsu In the FWU Multi Bank Update feature, the information about the updatable images is stored as part of the metadata, on a separate region. Add a driver for reading from and writing to the metadata when the updatable images and the metadata are stored on a raw MTD region. The code is divided into core under drivers/fwu-mdata/ and some helper functions clubbed together under lib/fwu_updates/ Signed-off-by: Masami Hiramatsu Signed-off-by: Jassi Brar --- drivers/fwu-mdata/Kconfig | 15 ++ drivers/fwu-mdata/Makefile | 1 + drivers/fwu-mdata/raw_mtd.c | 272 ++++++++++++++++++++++++++++++++++++ include/fwu.h | 32 +++++ lib/fwu_updates/Makefile | 1 + lib/fwu_updates/fwu_mtd.c | 185 ++++++++++++++++++++++++ 6 files changed, 506 insertions(+) create mode 100644 drivers/fwu-mdata/raw_mtd.c create mode 100644 lib/fwu_updates/fwu_mtd.c diff --git a/drivers/fwu-mdata/Kconfig b/drivers/fwu-mdata/Kconfig index 36c4479a59..42736a5e43 100644 --- a/drivers/fwu-mdata/Kconfig +++ b/drivers/fwu-mdata/Kconfig @@ -6,6 +6,11 @@ config FWU_MDATA FWU Metadata partitions reside on the same storage device which contains the other FWU updatable firmware images. +choice + prompt "Storage Layout Scheme" + depends on FWU_MDATA + default FWU_MDATA_GPT_BLK + config FWU_MDATA_GPT_BLK bool "FWU Metadata access for GPT partitioned Block devices" select PARTITION_TYPE_GUID @@ -14,3 +19,13 @@ config FWU_MDATA_GPT_BLK help Enable support for accessing FWU Metadata on GPT partitioned block devices. + +config FWU_MDATA_MTD + bool "Raw MTD devices" + depends on MTD + help + Enable support for accessing FWU Metadata on non-partitioned + (or non-GPT partitioned, e.g. partition nodes in devicetree) + MTD devices. + +endchoice diff --git a/drivers/fwu-mdata/Makefile b/drivers/fwu-mdata/Makefile index 3fee64c10c..06c49747ba 100644 --- a/drivers/fwu-mdata/Makefile +++ b/drivers/fwu-mdata/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_FWU_MDATA) += fwu-mdata-uclass.o obj-$(CONFIG_FWU_MDATA_GPT_BLK) += gpt_blk.o +obj-$(CONFIG_FWU_MDATA_MTD) += raw_mtd.o diff --git a/drivers/fwu-mdata/raw_mtd.c b/drivers/fwu-mdata/raw_mtd.c new file mode 100644 index 0000000000..25c1aa33ec --- /dev/null +++ b/drivers/fwu-mdata/raw_mtd.c @@ -0,0 +1,272 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2023, Linaro Limited + */ + +#define LOG_CATEGORY UCLASS_FWU_MDATA + +#include +#include +#include + +#include +#include + +/* Internal helper structure to move data around */ +struct fwu_mdata_mtd_priv { + struct mtd_info *mtd; + char pri_label[50]; + char sec_label[50]; + u32 pri_offset; + u32 sec_offset; +}; + +enum fwu_mtd_op { + FWU_MTD_READ, + FWU_MTD_WRITE, +}; + +extern struct fwu_mtd_image_info fwu_mtd_images[]; + +static bool mtd_is_aligned_with_block_size(struct mtd_info *mtd, u64 size) +{ + return !do_div(size, mtd->erasesize); +} + +static int mtd_io_data(struct mtd_info *mtd, u32 offs, u32 size, void *data, + enum fwu_mtd_op op) +{ + struct mtd_oob_ops io_op = {}; + u64 lock_offs, lock_len; + size_t len; + void *buf; + int ret; + + if (!mtd_is_aligned_with_block_size(mtd, offs)) { + log_err("Offset unaligned with a block (0x%x)\n", mtd->erasesize); + return -EINVAL; + } + + lock_offs = offs; + /* This will expand erase size to align with the block size */ + lock_len = round_up(size, mtd->erasesize); + + ret = mtd_unlock(mtd, lock_offs, lock_len); + if (ret && ret != -EOPNOTSUPP) + return ret; + + if (op == FWU_MTD_WRITE) { + struct erase_info erase_op = {}; + + erase_op.mtd = mtd; + erase_op.addr = lock_offs; + erase_op.len = lock_len; + erase_op.scrub = 0; + + ret = mtd_erase(mtd, &erase_op); + if (ret) + goto lock; + } + + /* Also, expand the write size to align with the write size */ + len = round_up(size, mtd->writesize); + + buf = memalign(ARCH_DMA_MINALIGN, len); + if (!buf) { + ret = -ENOMEM; + goto lock; + } + memset(buf, 0xff, len); + + io_op.mode = MTD_OPS_AUTO_OOB; + io_op.len = len; + io_op.ooblen = 0; + io_op.datbuf = buf; + io_op.oobbuf = NULL; + + if (op == FWU_MTD_WRITE) { + memcpy(buf, data, size); + ret = mtd_write_oob(mtd, offs, &io_op); + } else { + ret = mtd_read_oob(mtd, offs, &io_op); + if (!ret) + memcpy(data, buf, size); + } + free(buf); + +lock: + mtd_lock(mtd, lock_offs, lock_len); + + return ret; +} + +static int fwu_mtd_read_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary) +{ + struct fwu_mdata_mtd_priv *mtd_priv = dev_get_priv(dev); + struct mtd_info *mtd = mtd_priv->mtd; + u32 offs = primary ? mtd_priv->pri_offset : mtd_priv->sec_offset; + + return mtd_io_data(mtd, offs, sizeof(struct fwu_mdata), mdata, FWU_MTD_READ); +} + +static int fwu_mtd_write_mdata(struct udevice *dev, struct fwu_mdata *mdata, bool primary) +{ + struct fwu_mdata_mtd_priv *mtd_priv = dev_get_priv(dev); + struct mtd_info *mtd = mtd_priv->mtd; + u32 offs = primary ? mtd_priv->pri_offset : mtd_priv->sec_offset; + + return mtd_io_data(mtd, offs, sizeof(struct fwu_mdata), mdata, FWU_MTD_WRITE); +} + +static int flash_partition_offset(struct udevice *dev, const char *part_name, fdt_addr_t *offset) +{ + ofnode node, parts_node; + fdt_addr_t size = 0; + + parts_node = ofnode_by_compatible(dev_ofnode(dev), "fixed-partitions"); + node = ofnode_by_prop_value(parts_node, "label", part_name, strlen(part_name) + 1); + if (!ofnode_valid(node)) { + log_err("Warning: Failed to find partition by label <%s>\n", part_name); + return -ENOENT; + } + + *offset = ofnode_get_addr_size_index_notrans(node, 0, &size); + + return (int)size; +} + +static int fwu_mdata_mtd_of_to_plat(struct udevice *dev) +{ + struct fwu_mdata_mtd_priv *mtd_priv = dev_get_priv(dev); + const fdt32_t *phandle_p = NULL; + struct udevice *mtd_dev; + struct mtd_info *mtd; + const char *label; + fdt_addr_t offset; + int ret, size; + u32 phandle; + ofnode bank; + int off_img; + + /* Find the FWU mdata storage device */ + phandle_p = ofnode_get_property(dev_ofnode(dev), + "fwu-mdata-store", &size); + if (!phandle_p) { + log_err("FWU meta data store not defined in device-tree\n"); + return -ENOENT; + } + + phandle = fdt32_to_cpu(*phandle_p); + + ret = device_get_global_by_ofnode(ofnode_get_by_phandle(phandle), + &mtd_dev); + if (ret) { + log_err("FWU: failed to get mtd device\n"); + return ret; + } + + mtd_probe_devices(); + + mtd_for_each_device(mtd) { + if (mtd->dev == mtd_dev) { + mtd_priv->mtd = mtd; + log_debug("Found the FWU mdata mtd device %s\n", mtd->name); + break; + } + } + if (!mtd_priv->mtd) { + log_err("Failed to find mtd device by fwu-mdata-store\n"); + return -ENODEV; + } + + /* Get the offset of primary and secondary mdata */ + ret = ofnode_read_string_index(dev_ofnode(dev), "mdata-parts", 0, &label); + if (ret) + return ret; + strcpy(mtd_priv->pri_label, label); + + ret = flash_partition_offset(mtd_dev, mtd_priv->pri_label, &offset); + if (ret <= 0) + return ret; + mtd_priv->pri_offset = offset; + + ret = ofnode_read_string_index(dev_ofnode(dev), "mdata-parts", 1, &label); + if (ret) + return ret; + strcpy(mtd_priv->sec_label, label); + + ret = flash_partition_offset(mtd_dev, mtd_priv->sec_label, &offset); + if (ret <= 0) + return ret; + mtd_priv->sec_offset = offset; + + off_img = 0; + + ofnode_for_each_subnode(bank, dev_ofnode(dev)) { + int bank_num, bank_offset, bank_size; + const char *bank_name; + ofnode image; + + ofnode_read_u32(bank, "id", &bank_num); + bank_name = ofnode_read_string(bank, "label"); + bank_size = flash_partition_offset(mtd_dev, bank_name, &offset); + if (bank_size <= 0) + return bank_size; + bank_offset = offset; + log_debug("Bank%d: %s [0x%x - 0x%x]\n", + bank_num, bank_name, bank_offset, bank_offset + bank_size); + + ofnode_for_each_subnode(image, bank) { + int image_num, image_offset, image_size; + const char *uuid; + + if (off_img == CONFIG_FWU_NUM_BANKS * + CONFIG_FWU_NUM_IMAGES_PER_BANK) { + log_err("DT provides images more than configured!\n"); + break; + } + + uuid = ofnode_read_string(image, "uuid"); + ofnode_read_u32(image, "id", &image_num); + ofnode_read_u32(image, "offset", &image_offset); + ofnode_read_u32(image, "size", &image_size); + + fwu_mtd_images[off_img].start = bank_offset + image_offset; + fwu_mtd_images[off_img].size = image_size; + fwu_mtd_images[off_img].bank_num = bank_num; + fwu_mtd_images[off_img].image_num = image_num; + strcpy(fwu_mtd_images[off_img].uuidbuf, uuid); + log_debug("\tImage%d: %s @0x%x\n\n", + image_num, uuid, bank_offset + image_offset); + off_img++; + } + } + + return 0; +} + +static int fwu_mdata_mtd_probe(struct udevice *dev) +{ + /* Ensure the metadata can be read. */ + return fwu_get_mdata(NULL); +} + +static struct fwu_mdata_ops fwu_mtd_ops = { + .read_mdata = fwu_mtd_read_mdata, + .write_mdata = fwu_mtd_write_mdata, +}; + +static const struct udevice_id fwu_mdata_ids[] = { + { .compatible = "u-boot,fwu-mdata-mtd" }, + { } +}; + +U_BOOT_DRIVER(fwu_mdata_mtd) = { + .name = "fwu-mdata-mtd", + .id = UCLASS_FWU_MDATA, + .of_match = fwu_mdata_ids, + .ops = &fwu_mtd_ops, + .probe = fwu_mdata_mtd_probe, + .of_to_plat = fwu_mdata_mtd_of_to_plat, + .priv_auto = sizeof(struct fwu_mdata_mtd_priv), +}; diff --git a/include/fwu.h b/include/fwu.h index 33b4d0b3db..edb7e9da90 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -8,6 +8,8 @@ #include #include +#include +#include #include @@ -18,6 +20,12 @@ struct fwu_mdata_gpt_blk_priv { struct udevice *blk_dev; }; +struct fwu_mtd_image_info { + u32 start, size; + int bank_num, image_num; + char uuidbuf[UUID_STR_LEN + 1]; +}; + struct fwu_mdata_ops { /** * read_mdata() - Populate the asked FWU metadata copy @@ -251,4 +259,28 @@ u8 fwu_empty_capsule_checks_pass(void); */ int fwu_trial_state_ctr_start(void); +/** + * fwu_gen_alt_info_from_mtd() - Parse dfu_alt_info from metadata in mtd + * @buf: Buffer into which the dfu_alt_info is filled + * @len: Maximum characters that can be written in buf + * @mtd: Pointer to underlying MTD device + * + * Parse dfu_alt_info from metadata in mtd. Used for setting the env. + * + * Return: 0 if OK, -ve on error + */ +int fwu_gen_alt_info_from_mtd(char *buf, size_t len, struct mtd_info *mtd); + +/** + * fwu_mtd_get_alt_num() - Mapping of fwu_plat_get_alt_num for MTD device + * @image_guid: Image GUID for which DFU alt number needs to be retrieved + * @alt_num: Pointer to the alt_num + * @mtd_dev: Name of mtd device instance + * + * To map fwu_plat_get_alt_num onto mtd based metadata implementation. + * + * Return: 0 if OK, -ve on error + */ +int fwu_mtd_get_alt_num(efi_guid_t *image_guid, u8 *alt_num, const char *mtd_dev); + #endif /* _FWU_H_ */ diff --git a/lib/fwu_updates/Makefile b/lib/fwu_updates/Makefile index 1993088e5b..c9e3c06b48 100644 --- a/lib/fwu_updates/Makefile +++ b/lib/fwu_updates/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu.o obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_gpt.o +obj-$(CONFIG_FWU_MDATA_MTD) += fwu_mtd.o diff --git a/lib/fwu_updates/fwu_mtd.c b/lib/fwu_updates/fwu_mtd.c new file mode 100644 index 0000000000..f22c8b9443 --- /dev/null +++ b/lib/fwu_updates/fwu_mtd.c @@ -0,0 +1,185 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +struct fwu_mtd_image_info +fwu_mtd_images[CONFIG_FWU_NUM_BANKS * CONFIG_FWU_NUM_IMAGES_PER_BANK]; + +static struct fwu_mtd_image_info *mtd_img_by_uuid(const char *uuidbuf) +{ + int num_images = ARRAY_SIZE(fwu_mtd_images); + + for (int i = 0; i < num_images; i++) + if (!strcmp(uuidbuf, fwu_mtd_images[i].uuidbuf)) + return &fwu_mtd_images[i]; + + return NULL; +} + +int fwu_mtd_get_alt_num(efi_guid_t *image_id, u8 *alt_num, + const char *mtd_dev) +{ + struct fwu_mtd_image_info *mtd_img_info; + char uuidbuf[UUID_STR_LEN + 1]; + fdt_addr_t offset, size = 0; + struct dfu_entity *dfu; + int i, nalt, ret; + + mtd_probe_devices(); + + uuid_bin_to_str(image_id->b, uuidbuf, UUID_STR_FORMAT_STD); + + mtd_img_info = mtd_img_by_uuid(uuidbuf); + if (!mtd_img_info) { + log_err("%s: Not found partition for image %s\n", __func__, uuidbuf); + return -ENOENT; + } + + offset = mtd_img_info->start; + size = mtd_img_info->size; + + ret = dfu_init_env_entities(NULL, NULL); + if (ret) + return -ENOENT; + + nalt = 0; + list_for_each_entry(dfu, &dfu_list, list) + nalt++; + + if (!nalt) { + log_warning("No entities in dfu_alt_info\n"); + dfu_free_entities(); + return -ENOENT; + } + + ret = -1; + for (i = 0; i < nalt; i++) { + dfu = dfu_get_entity(i); + + /* Only MTD RAW access */ + if (!dfu || dfu->dev_type != DFU_DEV_MTD || + dfu->layout != DFU_RAW_ADDR || + dfu->data.mtd.start != offset || + dfu->data.mtd.size != size) + continue; + + *alt_num = dfu->alt; + ret = 0; + break; + } + + dfu_free_entities(); + + log_debug("%s: %s -> %d\n", __func__, uuidbuf, *alt_num); + return ret; +} + +/** + * fwu_plat_get_alt_num() - Get the DFU Alt Num for the image from the platform + * @dev: FWU device + * @image_id: Image GUID for which DFU alt number needs to be retrieved + * @alt_num: Pointer to the alt_num + * + * Get the DFU alt number from the platform for the image specified by the + * image GUID. + * + * Note: This is a weak function and platforms can override this with + * their own implementation for obtaining the alt number value. + * + * Return: 0 if OK, -ve on error + */ +__weak int fwu_plat_get_alt_num(struct udevice *dev, efi_guid_t *image_id, + u8 *alt_num) +{ + return fwu_mtd_get_alt_num(image_id, alt_num, "nor1"); +} + +static int gen_image_alt_info(char *buf, size_t len, int sidx, + struct fwu_image_entry *img, struct mtd_info *mtd) +{ + char *p = buf, *end = buf + len; + int i; + + p += snprintf(p, end - p, "mtd %s", mtd->name); + if (end < p) { + log_err("%s:%d Run out of buffer\n", __func__, __LINE__); + return -E2BIG; + } + + /* + * List the image banks in the FWU mdata and search the corresponding + * partition based on partition's uuid. + */ + for (i = 0; i < CONFIG_FWU_NUM_BANKS; i++) { + struct fwu_mtd_image_info *mtd_img_info; + struct fwu_image_bank_info *bank; + char uuidbuf[UUID_STR_LEN + 1]; + u32 offset, size; + + /* Query a partition by image UUID */ + bank = &img->img_bank_info[i]; + uuid_bin_to_str(bank->image_uuid.b, uuidbuf, UUID_STR_FORMAT_STD); + + mtd_img_info = mtd_img_by_uuid(uuidbuf); + if (!mtd_img_info) { + log_err("%s: Not found partition for image %s\n", __func__, uuidbuf); + break; + } + + offset = mtd_img_info->start; + size = mtd_img_info->size; + + p += snprintf(p, end - p, "%sbank%d raw %x %x", + i == 0 ? "=" : ";", i, offset, size); + if (end < p) { + log_err("%s:%d Run out of buffer\n", __func__, __LINE__); + return -E2BIG; + } + } + + if (i == CONFIG_FWU_NUM_BANKS) + return 0; + + return -ENOENT; +} + +int fwu_gen_alt_info_from_mtd(char *buf, size_t len, struct mtd_info *mtd) +{ + struct fwu_mdata mdata; + int i, l, ret; + + ret = fwu_get_mdata(&mdata); + if (ret < 0) { + log_err("Failed to get the FWU mdata.\n"); + return ret; + } + + for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) { + ret = gen_image_alt_info(buf, len, i * CONFIG_FWU_NUM_BANKS, + &mdata.img_entry[i], mtd); + if (ret) + break; + + l = strlen(buf); + /* Replace the last ';' with '&' if there is another image. */ + if (i != CONFIG_FWU_NUM_IMAGES_PER_BANK - 1 && l) + buf[l - 1] = '&'; + len -= l; + buf += l; + } + + return ret; +} From patchwork Mon Apr 10 23:03:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 672041 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp495255wrx; Mon, 10 Apr 2023 16:04:08 -0700 (PDT) X-Google-Smtp-Source: AKy350aO1BIsJWJDnrYyLDQdBNaCXUkT9znufwc2qY4xJqeUvfNx2H4JVpkAtAsr05MEl3lZJPdO X-Received: by 2002:a05:6214:1d22:b0:5ac:1460:b149 with SMTP id f2-20020a0562141d2200b005ac1460b149mr14434989qvd.39.1681167847940; Mon, 10 Apr 2023 16:04:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681167847; cv=none; d=google.com; s=arc-20160816; b=SM9xAFLcULqecD3D5C6wdV/5jubYtu9IcAJJ/1toJEaIoI/eqV7QLdeDsfXG0awQUr FyIJVErvjaLeV2ewniDh0JawZQa/h0EMNsdJrAe0DDGDRdrFOtsYgoXvOwCxSRN1+/Hx zs/0T9l8YDykZyykO2RJ+MpyoTN95FbjMH9tU9gVX4zbYVprAYRIBaS67qtm67xM5qqI Z3uGljZpv3r1qNpdXf6nu7WEf4eCtSSJdhRmjVIfVpe9RmHoTN+IB0eF5ppBvWGwYsX3 AL/3nDWREtqS/EBKvPh+h10eqMD8H7swSvP/WzkLbR9A7gvAg7ej0HBmi5iNKEWpT25A r3aw== 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=r4E4jwLI9dP/tipJxiHApgeKaH/IdoYRLZeRiqpvu7U=; b=VUJbZ9WwTlBQgDFEPimlvpuAGds+SxjExjB8PBgyFhHlsqcU25Ev3YfURN95NJkhyT 3XnBW61ACYayhe0FGlF4guMmqlBt5TeYFz+TvKeXBYpwb9DWsrkmTEqvYKnfNbXYz8MD tuJtDgwevTTLLKd3NncFvW8BA3QEuFjEglPEvPXv99+K6klsVPm7HdYLTztgspg1LHDQ 5snPr4tneKDaESHbQf9XvkrnY6+U3Wn2R6HKPW9b0DGUPJDVmMrsbZWgUloWhPFIfDpR ABpuy89hbQgfoT7dJKcjeVBTDoTn4yBYWhYsh4o7DBjP9Gm70ancigpmHSF8vebUWApZ IJTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="SP7/V7Ln"; 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 r16-20020a056214125000b0056ebb465a7esi8494475qvv.249.2023.04.10.16.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 16:04:07 -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="SP7/V7Ln"; 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 16C7B85D37; Tue, 11 Apr 2023 01:04:06 +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="SP7/V7Ln"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A5D138339E; Tue, 11 Apr 2023 01:04:01 +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-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) (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 3021F85D6A for ; Tue, 11 Apr 2023 01:03: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=jaswinder.singh@linaro.org Received: by mail-yb1-xb29.google.com with SMTP id f188so38028489ybb.3 for ; Mon, 10 Apr 2023 16:03:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681167830; x=1683759830; 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=r4E4jwLI9dP/tipJxiHApgeKaH/IdoYRLZeRiqpvu7U=; b=SP7/V7LndmO8MEaozqKm4mk3ZVdMn4BupWM3C7HsTDyBxQpRVpCQZxYE/6m8u8Cuxr JXMxFG1UHKWwupEzo5DrU7jXVKqyhTYv63FUbyrFW+iciy4xtUe7mBE4TT1/Q3Ig/wpP gcbp7BBSsdG4MjahteJ83IyIe70tqHHK/c2Fw6TTbsE/XQObw3jlPWu98P6nBKrisTPR CeKkxkmkNOGMnesimY50LpBLB+VlOZTxh4+HzH0BQD3+gvJeehoHWkyGQGNpetDP3m5S 15I3tALzx5TGrdSXgiGj3kmeRE8HIMxHTpbGnnGgivaw4RWuFCSCbIfr0ergxrwbWgvn RrcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681167830; x=1683759830; 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=r4E4jwLI9dP/tipJxiHApgeKaH/IdoYRLZeRiqpvu7U=; b=4bPeIXl9B/FDL4TpXXcFBde5HSgQLaZ5xKY33/BzT1kR8SQM0aih+5oaaI5vLOFrmo nD4OXPJP8tEKNpvJY/hmvGzNtZwfsuqSGL3XDGHXqE5ZSQqmej4V2LAXvIiFZh3bxIKD mZmLGmLBp5kLju4zO+5866ruh2hWOXixgIpxIbRwzNMVkY7NjAZXxsZw4ElFgRzkQYA2 bDV+R47bUZYxh4SPhB3CMLZoOrPyMxNUWBSt8v01nRWSHZB50RZW/nS9555fI1NANi2W EtAN1nyjaZAgggcmVSB5GkNTTwQ6PIJ3K0EibwP32Q6NbHy1Pos3GmgByStE4gQfIwBW Y0CA== X-Gm-Message-State: AAQBX9cERZdHIj9Ue+HvqQygjtdrjp+60yhnao4E16yW7MASBU42CWd8 eCsBZ+PYoawnEWK5iZC8NCPPknhKF4MM2GyCpKk= X-Received: by 2002:a25:1c2:0:b0:b6b:edd:8772 with SMTP id 185-20020a2501c2000000b00b6b0edd8772mr7260896ybb.6.1681167830514; Mon, 10 Apr 2023 16:03:50 -0700 (PDT) Received: from jassi-desktop.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id n4-20020a2581c4000000b00b7767ca748csm3222629ybm.41.2023.04.10.16.03.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 16:03:50 -0700 (PDT) From: jaswinder.singh@linaro.org To: u-boot@lists.denx.de Cc: ilias.apalodimas@linaro.org, etienne.carriere@linaro.org, trini@konsulko.com, sjg@chromium.org, sughosh.ganu@linaro.org, xypron.glpk@gmx.de, takahiro.akashi@linaro.org, michal.simek@amd.com, Masami Hiramatsu , Jassi Brar Subject: [PATCH v5 2/6] tools: Add mkfwumdata tool for FWU metadata image Date: Mon, 10 Apr 2023 18:03:44 -0500 Message-Id: <20230410230344.72603-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410230143.72556-1-jaswinder.singh@linaro.org> References: <20230410230143.72556-1-jaswinder.singh@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 From: Masami Hiramatsu Add 'mkfwumdata' tool to generate FWU metadata image for the meta-data partition to be used in A/B Update imeplementation. Signed-off-by: Sughosh Ganu Signed-off-by: Jassi Brar Signed-off-by: Masami Hiramatsu --- doc/mkfwumdata.1 | 89 ++++++++++++ tools/Kconfig | 9 ++ tools/Makefile | 4 + tools/mkfwumdata.c | 334 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 436 insertions(+) create mode 100644 doc/mkfwumdata.1 create mode 100644 tools/mkfwumdata.c diff --git a/doc/mkfwumdata.1 b/doc/mkfwumdata.1 new file mode 100644 index 0000000000..7dd718b26e --- /dev/null +++ b/doc/mkfwumdata.1 @@ -0,0 +1,89 @@ +.\" SPDX-License-Identifier: GPL-2.0-or-later +.\" Copyright (C) 2023 Jassi Brar +.TH MKFWUMDATA 1 2023-04-10 U-Boot +.SH NAME +mkfwumdata \- create FWU metadata image +. +.SH SYNOPSIS +.SY mkfwumdata +.OP \-a activeidx +.OP \-p previousidx +.OP \-g +.BI \-i\~ imagecount +.BI \-b\~ bankcount +.I UUIDs +.I outputimage +.YS +.SY mkfwumdata +.B \-h +.YS +. +.SH DESCRIPTION +.B mkfwumdata +creates metadata info to be used with FWU. +. +.SH OPTIONS +.TP +.B \-h +Print usage information and exit. +. +.TP +.B \-a +Set +.IR activeidx +as the currently active Bank. Default is 0. +. +.TP +.B \-p +Set +.IR previousidx +as the previous active Bank. Default is +.IR activeidx "-1" +or +.IR bankcount "-1," +whichever is non-negative. +. +.TP +.B \-g +Convert the +.IR UUIDs +as GUIDs before use. +. +.TP +.B \-i +Specify there are +.IR imagecount +images in each bank. +. +.TP +.B \-b +Specify there are a total of +.IR bankcount +banks. +. +.TP +.IR UUIDs +Comma-separated list of UUIDs required to create the metadata :- +location_uuid,image_type_uuid, +. +.TP +.IR outputimage +Specify the name of the metadata image file to be created. +. +.SH BUGS +Please report bugs to the +.UR https://\:source\:.denx\:.de/\:u-boot/\:u-boot/\:issues +U-Boot bug tracker +.UE . +.SH EXAMPLES +Create a metadata image with 2 banks and 1 image/bank, BankAct=0, BankPrev=1: +.PP +.EX +.in +4 +$ \c +.B mkfwumdata \-a 0 \-p 1 \-b 2 \-i 1 \\\\\& +.in +6 +.B 17e86d77-41f9-4fd7-87ec-a55df9842de5,\\\\\& +.B 10c36d7d-ca52-b843-b7b9-f9d6c501d108,\\\\\& +.B 5a66a702-99fd-4fef-a392-c26e261a2828,a8f868a1-6e5c-4757-878d-ce63375ef2c0 \\\\\& +.B fwu-mdata.img diff --git a/tools/Kconfig b/tools/Kconfig index 539708f277..6e23f44d55 100644 --- a/tools/Kconfig +++ b/tools/Kconfig @@ -157,4 +157,13 @@ config LUT_SEQUENCE help Look Up Table Sequence +config TOOLS_MKFWUMDATA + bool "Build mkfwumdata command" + default y if FWU_MULTI_BANK_UPDATE + help + This command allows users to create a raw image of the FWU + metadata for initial installation of the FWU multi bank + update on the board. The installation method depends on + the platform. + endmenu diff --git a/tools/Makefile b/tools/Makefile index 38699b069d..1e3fce0b1c 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -250,6 +250,10 @@ HOSTLDLIBS_mkeficapsule += \ $(shell pkg-config --libs uuid 2> /dev/null || echo "-luuid") hostprogs-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule +mkfwumdata-objs := mkfwumdata.o lib/crc32.o +HOSTLDLIBS_mkfwumdata += -luuid +hostprogs-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata + # We build some files with extra pedantic flags to try to minimize things # that won't build on some weird host compiler -- though there are lots of # exceptions for files that aren't complaint. diff --git a/tools/mkfwumdata.c b/tools/mkfwumdata.c new file mode 100644 index 0000000000..43dabf3b72 --- /dev/null +++ b/tools/mkfwumdata.c @@ -0,0 +1,334 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#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 + +typedef uint8_t u8; +typedef int16_t s16; +typedef uint16_t u16; +typedef uint32_t u32; +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[] = { + {"banks", required_argument, NULL, 'b'}, + {"images", required_argument, NULL, 'i'}, + {"guid", required_argument, NULL, 'g'}, + {"active-bank", required_argument, NULL, 'a'}, + {"previous-bank", required_argument, NULL, 'p'}, + {"help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0}, +}; + +static void print_usage(void) +{ + fprintf(stderr, "Usage: mkfwumdata [options] \n"); + fprintf(stderr, "Options:\n" + "\t-i, --images Number of images\n" + "\t-b, --banks Number of banks\n" + "\t-a, --active-bank Active bank\n" + "\t-p, --previous-bank Previous active bank\n" + "\t-g, --guid Use GUID instead of UUID\n" + "\t-h, --help print a help message\n" + ); + fprintf(stderr, " UUIDs list syntax:\n" + "\t ,,\n" + "\t images uuid list syntax:\n" + "\t img_uuid_00,img_uuid_01...img_uuid_0b,\n" + "\t img_uuid_10,img_uuid_11...img_uuid_1b,\n" + "\t ...,\n" + "\t img_uuid_i0,img_uuid_i1...img_uuid_ib,\n" + "\t where 'b' and 'i' are number of banks and number\n" + "\t of images in a bank respectively.\n" + ); +} + +struct fwu_mdata_object { + size_t images; + size_t banks; + size_t size; + struct fwu_mdata *mdata; +}; + +static int previous_bank, active_bank; +static bool __use_guid; + +static struct fwu_mdata_object *fwu_alloc_mdata(size_t images, size_t banks) +{ + struct fwu_mdata_object *mobj; + + mobj = calloc(1, sizeof(*mobj)); + if (!mobj) + return NULL; + + mobj->size = sizeof(struct fwu_mdata) + + (sizeof(struct fwu_image_entry) + + sizeof(struct fwu_image_bank_info) * banks) * images; + mobj->images = images; + mobj->banks = banks; + + mobj->mdata = calloc(1, mobj->size); + if (!mobj->mdata) { + free(mobj); + return NULL; + } + + return mobj; +} + +static struct fwu_image_entry * +fwu_get_image(struct fwu_mdata_object *mobj, size_t idx) +{ + size_t offset; + + offset = sizeof(struct fwu_mdata) + + (sizeof(struct fwu_image_entry) + + sizeof(struct fwu_image_bank_info) * mobj->banks) * idx; + + return (struct fwu_image_entry *)((char *)mobj->mdata + offset); +} + +static struct fwu_image_bank_info * +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_image_entry) + + sizeof(struct fwu_image_bank_info) * mobj->banks) * img_idx + + sizeof(struct fwu_image_entry) + + sizeof(struct fwu_image_bank_info) * bnk_idx; + + return (struct fwu_image_bank_info *)((char *)mobj->mdata + offset); +} + +/** + * convert_uuid_to_guid() - convert UUID to GUID + * @buf: UUID binary + * + * UUID and GUID have the same data structure, but their binary + * formats are different due to the endianness. See lib/uuid.c. + * Since uuid_parse() can handle only UUID, this function must + * be called to get correct data for GUID when parsing a string. + * + * The correct data will be returned in @buf. + */ +static void convert_uuid_to_guid(unsigned char *buf) +{ + unsigned char c; + + c = buf[0]; + buf[0] = buf[3]; + buf[3] = c; + c = buf[1]; + buf[1] = buf[2]; + buf[2] = c; + + c = buf[4]; + buf[4] = buf[5]; + buf[5] = c; + + c = buf[6]; + buf[6] = buf[7]; + buf[7] = c; +} + +static int uuid_guid_parse(char *uuidstr, unsigned char *uuid) +{ + int ret; + + ret = uuid_parse(uuidstr, uuid); + if (ret < 0) + return ret; + + if (__use_guid) + convert_uuid_to_guid(uuid); + + return ret; +} + +static int +fwu_parse_fill_image_uuid(struct fwu_mdata_object *mobj, + size_t idx, char *uuids) +{ + struct fwu_image_entry *image = fwu_get_image(mobj, idx); + struct fwu_image_bank_info *bank; + char *p = uuids, *uuid; + int i; + + if (!image) + return -ENOENT; + + /* Image location UUID */ + uuid = strsep(&p, ","); + if (!uuid) + return -EINVAL; + + if (strcmp(uuid, "0") && + uuid_guid_parse(uuid, (unsigned char *)&image->location_uuid) < 0) + return -EINVAL; + + /* Image type UUID */ + uuid = strsep(&p, ","); + if (!uuid) + return -EINVAL; + + if (uuid_guid_parse(uuid, (unsigned char *)&image->image_type_uuid) < 0) + return -EINVAL; + + /* Fill bank image-UUID */ + for (i = 0; i < mobj->banks; i++) { + bank = fwu_get_bank(mobj, idx, i); + if (!bank) + return -ENOENT; + bank->accepted = 1; + uuid = strsep(&p, ","); + if (!uuid) + return -EINVAL; + + if (strcmp(uuid, "0") && + uuid_guid_parse(uuid, (unsigned char *)&bank->image_uuid) < 0) + return -EINVAL; + } + return 0; +} + +/* Caller must ensure that @uuids[] has @mobj->images entries. */ +static int fwu_parse_fill_uuids(struct fwu_mdata_object *mobj, char *uuids[]) +{ + struct fwu_mdata *mdata = mobj->mdata; + int i, ret; + + mdata->version = FWU_MDATA_VERSION; + mdata->active_index = active_bank; + mdata->previous_active_index = previous_bank; + + for (i = 0; i < mobj->images; i++) { + ret = fwu_parse_fill_image_uuid(mobj, i, uuids[i]); + if (ret < 0) + return ret; + } + + mdata->crc32 = crc32(0, (const unsigned char *)&mdata->version, + mobj->size - sizeof(uint32_t)); + + return 0; +} + +static int +fwu_make_mdata(size_t images, size_t banks, char *uuids[], char *output) +{ + struct fwu_mdata_object *mobj; + FILE *file; + int ret; + + mobj = fwu_alloc_mdata(images, banks); + if (!mobj) + return -ENOMEM; + + ret = fwu_parse_fill_uuids(mobj, uuids); + if (ret < 0) + goto done_make; + + file = fopen(output, "w"); + if (!file) { + ret = -errno; + goto done_make; + } + + ret = fwrite(mobj->mdata, mobj->size, 1, file); + if (ret != mobj->size) + ret = -errno; + else + ret = 0; + + fclose(file); + +done_make: + free(mobj->mdata); + free(mobj); + + return ret; +} + +int main(int argc, char *argv[]) +{ + unsigned long banks = 0, images = 0; + int c, ret; + + /* Explicitly initialize defaults */ + active_bank = 0; + __use_guid = false; + previous_bank = INT_MAX; + + do { + c = getopt_long(argc, argv, opts_short, options, NULL); + switch (c) { + case 'h': + print_usage(); + return 0; + case 'b': + banks = strtoul(optarg, NULL, 0); + break; + case 'i': + images = strtoul(optarg, NULL, 0); + break; + case 'g': + __use_guid = true; + break; + case 'p': + previous_bank = strtoul(optarg, NULL, 0); + break; + case 'a': + active_bank = strtoul(optarg, NULL, 0); + break; + } + } while (c != -1); + + if (!banks || !images) { + fprintf(stderr, "Error: The number of banks and images must not be 0.\n"); + 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"); + print_usage(); + return -ERANGE; + } + + if (previous_bank == INT_MAX) { + /* set to the earlier bank in round-robin scheme */ + previous_bank = active_bank > 0 ? active_bank - 1 : banks - 1; + } + + ret = fwu_make_mdata(images, banks, argv + optind, argv[argc - 1]); + if (ret < 0) + fprintf(stderr, "Error: Failed to parse and write image: %s\n", + strerror(-ret)); + + return ret; +} From patchwork Mon Apr 10 23:03:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 672042 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp495425wrx; Mon, 10 Apr 2023 16:04:28 -0700 (PDT) X-Google-Smtp-Source: AKy350as8sCSHers0pHWgbW4gQxvKRZnB8RxepE/O+3c7V3NazSZMGjiP0TnXT9JaPvV1CKkLRoo X-Received: by 2002:a05:6214:29cd:b0:572:636d:625f with SMTP id gh13-20020a05621429cd00b00572636d625fmr1230354qvb.33.1681167867914; Mon, 10 Apr 2023 16:04:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681167867; cv=none; d=google.com; s=arc-20160816; b=TILEqItn6rPcbjDCME+9qVK/p9LrKLJMQTaQJoAsS3P5RIGBPo3fPD04PVG0Fp3wjy S0NQgbnYfMo+lP2BDbQo0eSwYbtTmO2AMO2g0sSVczeo1I77975vm2Pm03E9ANDw6AR1 fRCsQEpriZ3Nivvj0dbaCqWXw3XFq+XmaEocJRF8EAi6v9r+pHhvBd8zHy/7XxAne4Ai BOoO+Cr5oumB07gwiLkU87XOUcCSpyanyS/P/oSTXiNvncvJXEzahlM+caPjU+L76wfd lPjKTkRTV+IOKMUqeHdnE6dNSOAiLwqhC3i5g8U7GMzqW16pktjaMJCXcxQYQhkXhxL0 rieA== 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=4fyDe/0cTHlEQ9lVYN3dBZWaoU0hi0zVBuGeGw2+mA8=; b=iMyAGIiAWj/UZlTpNMhYvxVT7YE/UXwwAdyBTVkBl47W7kZyljNYCaGlSqA+5pWv0R WD7nWpjw/1O2grV4qRJfJ3DR4UWDjL/pHIdUgwWE2aoDTuZ1cpiJsWILRUA/8B3Xb1eA iqg9ZXzR8L/lHxL9dyK30Y/k0oAU62d8uMXpYSMsP81FYc1FGZsjrjXMPyqxi+AETSg+ dZcAVykQMQh69jJ4nVzBTgSjfWsxA8HNhZoqS64JlorjdW6AOGSDLh7WwN8yieWWOxYQ 82mmxwKqtCvAbqEZ3oAwRF/fuODQ1/Vf6wBe7MX1wKH226LaO4lZtxW5yNBRqBMS19NL D5Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DsjAgkxQ; 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 jv1-20020a05621429e100b0056eb3abe4f1si8432494qvb.168.2023.04.10.16.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 16:04:27 -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=DsjAgkxQ; 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 4C54885D95; Tue, 11 Apr 2023 01:04:24 +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="DsjAgkxQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4C92885D95; Tue, 11 Apr 2023 01:04:07 +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-yw1-x1129.google.com (mail-yw1-x1129.google.com [IPv6:2607:f8b0:4864:20::1129]) (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 82D4F85CD8 for ; Tue, 11 Apr 2023 01:04:01 +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=jaswinder.singh@linaro.org Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-54c061acbc9so266406507b3.11 for ; Mon, 10 Apr 2023 16:04:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681167840; x=1683759840; 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=4fyDe/0cTHlEQ9lVYN3dBZWaoU0hi0zVBuGeGw2+mA8=; b=DsjAgkxQXmkrhKG4cm9Zxb1pAftCF6WeFxcerO0FYYh80/MCyO56sL6ym9EIYqbUvG IoO5wShlM4MwYcJq5XUCtaRYW7xGlViXgNa7PHs+cz8H1z+lWBBrhJiWXYEFYSDJCVR2 yxePSswny+9plUU+l4Bi6doFiiBNaR0ouAPkrIJ8vOWRQr4XqSon4IYS40OTaiY//bFj kutF9geetDSHlOlBRp+m8rvDy0reXgt21scbxO2hXlhmwUUd2K1oBKAVAc7tZ6XCCkdX LVE8R7Zybw7nkj918JPHONoL1GiOe82VyYPBvzg12rlWoad7kiw9xX53jmMoakW6rXFG JHig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681167840; x=1683759840; 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=4fyDe/0cTHlEQ9lVYN3dBZWaoU0hi0zVBuGeGw2+mA8=; b=ViV4UmC0AAwcU0iK8MvWz71vj69fIOIxtbfkfoNvLs758uyBqmNe2zn083AmDZ/qAR +CeaAH+JjC67EveKY9epavfFvOQkSo6GugP65VRbS5AnOH1zL4Mo84jz+JVVUzEU7BYQ 4NSkDdKJYL22lrZrukD3cR2pOG2JcsGSHVUbs5WzcY6BGbl3y/ZWi3bD14R4yXpFzDOD wl0QMwi+/RcVqel8jyUv3CKYa3T11rU3xJeI6TznuG8WHZQ7HQIjEXGWdtiZ3zlPyqQz F/F8DGsfKqbQ8955DZaKzFJww3R+IeuL2PPrBdApmWeilqCzYfzCWlxOy+BPie5RNdV+ NKXA== X-Gm-Message-State: AAQBX9eQjazLOwZODQpYbd1en77veAkD+of13hI160/pqACmW0Uz1MvA 0L4ISwxsrcKkRblaOn64ZMXu90aI4V70p8Khp/w= X-Received: by 2002:a81:4ac3:0:b0:54b:f97a:3264 with SMTP id x186-20020a814ac3000000b0054bf97a3264mr792341ywa.8.1681167840111; Mon, 10 Apr 2023 16:04:00 -0700 (PDT) Received: from jassi-desktop.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id bq7-20020a05690c060700b00545a08184cesm3090787ywb.94.2023.04.10.16.03.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 16:03:59 -0700 (PDT) From: jaswinder.singh@linaro.org To: u-boot@lists.denx.de Cc: ilias.apalodimas@linaro.org, etienne.carriere@linaro.org, trini@konsulko.com, sjg@chromium.org, sughosh.ganu@linaro.org, xypron.glpk@gmx.de, takahiro.akashi@linaro.org, michal.simek@amd.com, Jassi Brar Subject: [PATCH v5 3/6] dt: fwu: developerbox: enable fwu banks and mdata regions Date: Mon, 10 Apr 2023 18:03:55 -0500 Message-Id: <20230410230355.72619-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410230143.72556-1-jaswinder.singh@linaro.org> References: <20230410230143.72556-1-jaswinder.singh@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 From: Jassi Brar Specify Bank-0/1 and fwu metadata mtd regions. Signed-off-by: Jassi Brar --- .../synquacer-sc2a11-developerbox-u-boot.dtsi | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi b/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi index 9f9837b33b..9957646a46 100644 --- a/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi +++ b/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi @@ -21,7 +21,7 @@ #size-cells = <0>; status = "okay"; - flash@0 { + flash0: flash@0 { #address-cells = <1>; #size-cells = <1>; compatible = "jedec,spi-nor"; @@ -74,8 +74,24 @@ }; partition@500000 { - label = "Ex-OPTEE"; - reg = <0x500000 0x200000>; + label = "MDATA-Pri"; + reg = <0x500000 0x1000>; + }; + + partition@530000 { + label = "MDATA-Sec"; + reg = <0x530000 0x1000>; + }; + + /* FWU Multi bank update partitions */ + partition@600000 { + label = "FIP-Bank0"; + reg = <0x600000 0x400000>; + }; + + partition@a00000 { + label = "FIP-Bank1"; + reg = <0xa00000 0x400000>; }; }; }; @@ -102,6 +118,33 @@ optee { status = "okay"; }; + + fwu-mdata { + compatible = "u-boot,fwu-mdata-mtd"; + fwu-mdata-store = <&flash0>; + mdata-parts = "MDATA-Pri", "MDATA-Sec"; + + fwu-bank0 { + id = <0>; + label = "FIP-Bank0"; + fwu-image0 { + id = <0>; + offset = <0x0>; + size = <0x400000>; + uuid = "5a66a702-99fd-4fef-a392-c26e261a2828"; + }; + }; + fwu-bank1 { + id = <1>; + label = "FIP-Bank1"; + fwu-image0 { + id = <0>; + offset = <0x0>; + size = <0x400000>; + uuid = "a8f868a1-6e5c-4757-878d-ce63375ef2c0"; + }; + }; + }; }; }; From patchwork Mon Apr 10 23:04:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 672043 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp495500wrx; Mon, 10 Apr 2023 16:04:40 -0700 (PDT) X-Google-Smtp-Source: AKy350boepoYjkcyOO14Oi6dCv7Qv8/Lbv3TVvyHQCOAGTDisyF4BM4uOG/E35k6nQ9CF0Hm1/P8 X-Received: by 2002:ac8:7f4c:0:b0:3e3:8ee5:1629 with SMTP id g12-20020ac87f4c000000b003e38ee51629mr13948653qtk.51.1681167880165; Mon, 10 Apr 2023 16:04:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681167880; cv=none; d=google.com; s=arc-20160816; b=DijjXB47RR52744YFSz7eXrQV8/u70Ognvk+gK8LlQMIDjwJpcnoRz5Fu4YONMfWfL e2ocM5f5urn8OfZnSnoSbm7W+zwyEF2xnMUfpDxew52ryYFLWGJECS3RO94/LX4cv5cI pyCJ9PvDIfoldTQQifaJh0zBkvSlXrJ830h4hxNbFd1z890YuZBcyev3Qm0Yb6i0hkDP 26ssaEdzAx4AlRGSrq31ic9dU+Jnk1pQeK9pUu8Aj7Q0Ochzf6Besjh6DAf8zsTQp+zA s7nEGJ5cnft9+Hf2PvRc8RBXkeOlvvjlRJxvH8zYkdHILyPxuylg/y0Si+zOHu4+TkCJ 9fBg== 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=OXBn5foSwTJTJ2vmulNQTAQcFjz178bCXgid1TBmP7k=; b=PcFc0d/+kJ7m6WsDtaF4KZ5MiHoxhRxOYlHscUCzow7sAsq7bkI5hoBGm1oSAbRmXS ZqRYh/H7jlYZYwcRroasyvpxdiUSuu8SM9UNgGLxNRcYpSD9ZzX+md4ndkQuGaaDJ+2v iWQmq3vFEiSnMK9Odh+rF44tpPE28W1Imrg6ungxtoF1ZIrPkhYxUdqKDr5/lw1reyqY 5ziLRmAFBS34vZAeudyn4wivSEqeSRvmDIv/gBcpG0REDibRRl3apIKRDnc3shMGnWMP ykV9l7V0B6KbwSswtuSzoTTVbvGIhsqbXr9W0AjqjDd27xD3SBsQzC5S9N0ak2ryRlrZ mE4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nvB1picq; 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 g15-20020ac87f4f000000b003e696fefa3asi5522595qtk.487.2023.04.10.16.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 16:04:40 -0700 (PDT) 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=nvB1picq; 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 5C27685D77; Tue, 11 Apr 2023 01:04:32 +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="nvB1picq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 63A708339E; Tue, 11 Apr 2023 01:04:20 +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-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) (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 208618339E for ; Tue, 11 Apr 2023 01:04:11 +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=jaswinder.singh@linaro.org Received: by mail-yb1-xb35.google.com with SMTP id 72so6349826ybe.6 for ; Mon, 10 Apr 2023 16:04:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681167849; x=1683759849; 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=OXBn5foSwTJTJ2vmulNQTAQcFjz178bCXgid1TBmP7k=; b=nvB1picq8cH50a2nhzDZJsxPk3ZUmuVJk+OOZzynN9rYsWC2mv19vTU/UVH7hOgPJA yukwMAUJ53QRZ4FopOaX0UWa9T1O0y85TZAG1bxJIe6x1PSj8xFXcou60IZqbi3SfV6E nH2lq/OvPoGpBV+5h2fJUejtPjM4HTlmxcwGEF39M6pDaP6bIrGwIB2kGcvBccjDRZ4c CTLEJvYsb2Jf/awLKYa96sLBfyIKNZyyWeo0S7z2w7PDjGI+l102W+AuX4eK2sgg7Yew apZWFw7LY61PqrLxugOF3gIhuuCyuVgVQUebYb4OzDSmKOv0pb8D9Uo40/gXgEqTbdTU Wr9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681167849; x=1683759849; 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=OXBn5foSwTJTJ2vmulNQTAQcFjz178bCXgid1TBmP7k=; b=FwKKQUkH9aikSPBXU/UbdbYG4GpJPswzZGakfF6JD9nV2bfd2YXbaiEWNpMZ/1tNfQ khmONzCTy3/DX2410AT0f5/DeyNM1SDhJc+OqIEglfcfR0r2V2QLWi9RcT8IhnUbOHGl NlJOZB3e6CUOSvwSGEhJnbzdhLKLOCRlleWAm6zMwIPIJas48sJwfwMozxlYQ8zWbOR3 6q9GHF8wpsVe7RjEKfPHxOdR8ubwncgaCSSrxG4n0XOnBvTE0Qu6gxlVWT56HeMY6UaJ NQ80V9x3Sfylv5xobU3TsKYnu40ZTK++2acN4a0JaOMhWV5gab83u0eRbuZ4btxjOXJM BaZA== X-Gm-Message-State: AAQBX9eeQEiee4VPYveeKcb/DY/ZGA8mFmnEVn6+AshBdA3mgnuvJ6an 3cqZJ3HieMrnk1CnC7NlddxlSEkZmFklEg9BNqE= X-Received: by 2002:a25:360a:0:b0:b8b:f517:1400 with SMTP id d10-20020a25360a000000b00b8bf5171400mr6615294yba.45.1681167849235; Mon, 10 Apr 2023 16:04:09 -0700 (PDT) Received: from jassi-desktop.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id i3-20020a056902128300b00b8f09a8f4f5sm544726ybu.46.2023.04.10.16.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 16:04:08 -0700 (PDT) From: jaswinder.singh@linaro.org To: u-boot@lists.denx.de Cc: ilias.apalodimas@linaro.org, etienne.carriere@linaro.org, trini@konsulko.com, sjg@chromium.org, sughosh.ganu@linaro.org, xypron.glpk@gmx.de, takahiro.akashi@linaro.org, michal.simek@amd.com, Jassi Brar Subject: [PATCH v5 4/6] configs: move to new flash layout and boot flow Date: Mon, 10 Apr 2023 18:04:05 -0500 Message-Id: <20230410230405.72649-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410230143.72556-1-jaswinder.singh@linaro.org> References: <20230410230143.72556-1-jaswinder.singh@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 From: Jassi Brar Towards enabling FWU and supporting new firmware layout in NOR flash, make u-boot PIC and adjust uboot env offset in flash. Signed-off-by: Jassi Brar --- configs/synquacer_developerbox_defconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configs/synquacer_developerbox_defconfig b/configs/synquacer_developerbox_defconfig index 08f19a90cb..09e12b739b 100644 --- a/configs/synquacer_developerbox_defconfig +++ b/configs/synquacer_developerbox_defconfig @@ -1,12 +1,12 @@ CONFIG_ARM=y CONFIG_ARCH_SYNQUACER=y -CONFIG_TEXT_BASE=0x08200000 +CONFIG_POSITION_INDEPENDENT=y CONFIG_SYS_MALLOC_LEN=0x1000000 CONFIG_SYS_MALLOC_F_LEN=0x400 CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0xe0000000 CONFIG_ENV_SIZE=0x30000 -CONFIG_ENV_OFFSET=0x300000 +CONFIG_ENV_OFFSET=0x580000 CONFIG_ENV_SECT_SIZE=0x10000 CONFIG_DM_GPIO=y CONFIG_DEFAULT_DEVICE_TREE="synquacer-sc2a11-developerbox" From patchwork Mon Apr 10 23:04:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 672044 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp495699wrx; Mon, 10 Apr 2023 16:05:08 -0700 (PDT) X-Google-Smtp-Source: AKy350bRS7InRPDIhzSL16BgLFyIy7vyuWigUT1ZC+y4F2dCwwLYAWQd9iQpzKwqqbMWfvuijE56 X-Received: by 2002:a05:622a:407:b0:3d9:b59f:1ba9 with SMTP id n7-20020a05622a040700b003d9b59f1ba9mr15508491qtx.12.1681167908451; Mon, 10 Apr 2023 16:05:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681167908; cv=none; d=google.com; s=arc-20160816; b=RuJ9VjuAX3RcY9qHOV84uam3V6iPBCuE0yYYTzBAyrU0/HEOTeFHfxjS2fJ3rBrqck nVV/S4DgkdtqSuSMvNG6kUOt7llXMP36PL8Ul8m9pSdnTVQDbEGdSFkO+OpfrSp487f9 3UqXLvuX5LkNi+1QE4O2TifcrMnL+bvQNVIYCnQ68dFjN+hBzndO/y+9rZ2xpiYhkel8 BLwmsuNEbuYS4fPLtgnyaUKexv2mmyeg95m4ev2kb1XRqTCn4Ai6bRKOwl93naT0wwF6 ysNqpCDvRno9c/rRWtHQ5PmsvuSbOKHN70WTs0LffAJFlP1ViLold24ui8HebOnbaMGr j/Gw== 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=+LSs1reOm65vTWdIiXqwIet0FQhuLXHhZY4Va6BwhGI=; b=bWUHH898pSCW9vj+CD10fVQKhGCTgT6IJ9VhuH9mzJP4EmE/MxZEfSEvEu+/LNUNYS 0ovpc/OOM7u0JsHkE9R9mirQl7r5OFxE+lftOOrIfwba2ojQzg6OfNgUEHFipuXztA5l QisuuyZTphBVBYee7/J8EX6EZLdBHsZueRn+rsaqxK/RTQv3DbmKPx7QP9eSkJF30o5c 4tGqd+vmAMLBuRjdDRPATgRs/+xXfP2oNZKqUquFzZsZ45Jma1JofwBUxuGJkwUTIjNc ZjXq842CYhkgtskcT54lY6WftNyvDpQrbwYb0ZhLjHoe53QPlRauC3B4K0seQAt2JxFY 8phg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Pqv0WaWA; 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 s14-20020a05622a1a8e00b003e4df9434ebsi8036583qtc.604.2023.04.10.16.05.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 16:05:08 -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=Pqv0WaWA; 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 1222985D8B; Tue, 11 Apr 2023 01:05:06 +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="Pqv0WaWA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 69FBD83A35; Tue, 11 Apr 2023 01:05:01 +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-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) (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 308E185DCE for ; Tue, 11 Apr 2023 01:04:55 +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=jaswinder.singh@linaro.org Received: by mail-yb1-xb36.google.com with SMTP id v7so4757434ybi.0 for ; Mon, 10 Apr 2023 16:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681167894; x=1683759894; 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=+LSs1reOm65vTWdIiXqwIet0FQhuLXHhZY4Va6BwhGI=; b=Pqv0WaWAinBi5FV4HyrBdmCXaQwVm01i9ZfLCzl/6LATnFzt5pj4adb0VWVczXjvvk u+GvEjcX7BFnmtuSHQwTWJxERlCFPZ2/SqKg/EaHE99HJuJeT1Squzzv/L6o2+NRlnxN 3Dw5j3gSAc2ttRIWi2hAuQHpNnlSpXOX/p+gq5vBWKA602m8qthNlpT8W6873kGzDE3M s+tXb27xb7JjMUS+bPTF8ZfjfqlyxVTsY3i6SE0iu1f1G1j5Bv0OWHQ79h7nOsAjklr6 fnDfI9D/aSlaLq4QGp86ShMBTLwWipJuvjLkESVP5vq/bT5W+Bc2k8iW74s4tBl+MBVl AV9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681167894; x=1683759894; 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=+LSs1reOm65vTWdIiXqwIet0FQhuLXHhZY4Va6BwhGI=; b=6XTENpjd2UR+c03M0XW+0pPQQQaYUHe1Y98xUY5MEByWLdt0bXAqPZPkmCLNI3MTQ8 swho5Ltyt9w/AxAcAOy3/xQgAhEi5NPbtwMhaChQwsEygQLiFmoJAbRr6bgB3Axg2Ke+ nqRWDSqfaJrAxVWcODXYSpAmtW3kakMijgZGr9jjvhqnDXr99r/JjN4IsSW1RzuOI6Ic 9PP06N7cnp43wELGkCbMIDAD276SHqi1dEFMWIjLR+9vO86EmhTcCHuKajI1qH5CAHA+ eFPy1m71CiCfwCjXRb+QbhQFrn3+ZwPOA7ML9m0Bbg9CR9LukySgf34Lka6hv9H4x636 CJsw== X-Gm-Message-State: AAQBX9fkjbDDRfvUuLYtqIK/0A4yazz4sNrBJ82OAG7gq1lQ/ebKai/L ORRkcv3/BgFYTNq2FJRGxxdRN5zW/zqYz3fCBN8= X-Received: by 2002:a25:ae1f:0:b0:b6a:514e:9d85 with SMTP id a31-20020a25ae1f000000b00b6a514e9d85mr6300197ybj.10.1681167893626; Mon, 10 Apr 2023 16:04:53 -0700 (PDT) Received: from jassi-desktop.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id a140-20020a0dd892000000b0054c055b8ffcsm3110177ywe.41.2023.04.10.16.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 16:04:53 -0700 (PDT) From: jaswinder.singh@linaro.org To: u-boot@lists.denx.de Cc: ilias.apalodimas@linaro.org, etienne.carriere@linaro.org, trini@konsulko.com, sjg@chromium.org, sughosh.ganu@linaro.org, xypron.glpk@gmx.de, takahiro.akashi@linaro.org, michal.simek@amd.com, Jassi Brar Subject: [PATCH v5 5/6] fwu: DeveloperBox: add support for FWU Date: Mon, 10 Apr 2023 18:04:36 -0500 Message-Id: <20230410230436.72664-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410230143.72556-1-jaswinder.singh@linaro.org> References: <20230410230143.72556-1-jaswinder.singh@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 From: Jassi Brar Add code to support FWU_MULTI_BANK_UPDATE. The platform does not have gpt-partition storage for Banks and MetaData, rather it used SPI-NOR backed mtd regions for the purpose. Signed-off-by: Jassi Brar --- board/socionext/developerbox/Makefile | 1 + board/socionext/developerbox/developerbox.c | 8 + board/socionext/developerbox/fwu_plat.c | 37 +++++ configs/synquacer_developerbox_defconfig | 8 + doc/board/socionext/developerbox.rst | 155 +++++++++++++++++++- include/configs/synquacer.h | 10 ++ 6 files changed, 213 insertions(+), 6 deletions(-) create mode 100644 board/socionext/developerbox/fwu_plat.c diff --git a/board/socionext/developerbox/Makefile b/board/socionext/developerbox/Makefile index 4a46de995a..1acd067a7e 100644 --- a/board/socionext/developerbox/Makefile +++ b/board/socionext/developerbox/Makefile @@ -7,3 +7,4 @@ # obj-y := developerbox.o +obj-$(CONFIG_FWU_MDATA_MTD) += fwu_plat.o diff --git a/board/socionext/developerbox/developerbox.c b/board/socionext/developerbox/developerbox.c index 16e14d4f7f..ce2cccf4f0 100644 --- a/board/socionext/developerbox/developerbox.c +++ b/board/socionext/developerbox/developerbox.c @@ -20,6 +20,13 @@ #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) struct efi_fw_image fw_images[] = { +#if CONFIG_IS_ENABLED(FWU_MULTI_BANK_UPDATE) + { + .image_type_id = DEVELOPERBOX_FIP_IMAGE_GUID, + .fw_name = u"DEVELOPERBOX-FIP", + .image_index = 1, + }, +#else { .image_type_id = DEVELOPERBOX_UBOOT_IMAGE_GUID, .fw_name = u"DEVELOPERBOX-UBOOT", @@ -35,6 +42,7 @@ struct efi_fw_image fw_images[] = { .fw_name = u"DEVELOPERBOX-OPTEE", .image_index = 3, }, +#endif }; struct efi_capsule_update_info update_info = { diff --git a/board/socionext/developerbox/fwu_plat.c b/board/socionext/developerbox/fwu_plat.c new file mode 100644 index 0000000000..e5dae0ff11 --- /dev/null +++ b/board/socionext/developerbox/fwu_plat.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include +#include + +#define DFU_ALT_BUF_LEN 256 + +/* Generate dfu_alt_info from partitions */ +void set_dfu_alt_info(char *interface, char *devstr) +{ + int ret; + struct mtd_info *mtd; + + ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); + memset(buf, 0, sizeof(buf)); + + mtd_probe_devices(); + + mtd = get_mtd_device_nm("nor1"); + if (IS_ERR_OR_NULL(mtd)) + return; + + ret = fwu_gen_alt_info_from_mtd(buf, DFU_ALT_BUF_LEN, mtd); + if (ret < 0) { + log_err("Error: Failed to generate dfu_alt_info. (%d)\n", ret); + return; + } + log_debug("Make dfu_alt_info: '%s'\n", buf); + + env_set("dfu_alt_info", buf); +} diff --git a/configs/synquacer_developerbox_defconfig b/configs/synquacer_developerbox_defconfig index 09e12b739b..d09684153a 100644 --- a/configs/synquacer_developerbox_defconfig +++ b/configs/synquacer_developerbox_defconfig @@ -97,3 +97,11 @@ CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y CONFIG_EFI_CAPSULE_ON_DISK=y CONFIG_EFI_IGNORE_OSINDICATIONS=y CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y +CONFIG_EFI_SECURE_BOOT=y +CONFIG_FWU_MULTI_BANK_UPDATE=y +CONFIG_FWU_MDATA=y +CONFIG_FWU_MDATA_MTD=y +CONFIG_FWU_NUM_BANKS=2 +CONFIG_FWU_NUM_IMAGES_PER_BANK=1 +CONFIG_CMD_FWU_METADATA=y +CONFIG_TOOLS_MKFWUMDATA=y diff --git a/doc/board/socionext/developerbox.rst b/doc/board/socionext/developerbox.rst index 2d943c23be..908d3a7e6f 100644 --- a/doc/board/socionext/developerbox.rst +++ b/doc/board/socionext/developerbox.rst @@ -57,14 +57,20 @@ Installation You can install the SNI_NOR_UBOOT.fd via NOR flash writer. -Flashing the U-Boot image on DeveloperBox requires a 96boards UART mezzanine or other mezzanine which can connect to LS-UART0 port. -Connect USB cable from host to the LS-UART0 and set DSW2-7 to ON, and turn the board on again. The flash writer program will be started automatically; don’t forget to turn the DSW2-7 off again after flashing. +Flashing the U-Boot image on DeveloperBox requires a 96boards UART mezzanine +or other mezzanine which can connect to LS-UART0 port. +Connect USB cable from host to the LS-UART0 and set DSW2-7 to ON, and turn the +board on again. The flash writer program will be started automatically; +don't forget to turn the DSW2-7 off again after flashing. -*!!CAUTION!! If you failed to write the U-Boot image on wrong address, the board can be bricked. See below page if you need to recover the bricked board. See the following page for more detail* +*!!CAUTION!! If you write the U-Boot image on wrong address, the board can +be bricked. See below page if you need to recover the bricked board. See +the following page for more detail* https://www.96boards.org/documentation/enterprise/developerbox/installation/board-recovery.md.html -When the serial flasher is running correctly is will show the following boot messages shown via LS-UART0:: +When the serial flasher is running correctly is will show the following boot +messages shown via LS-UART0:: /*------------------------------------------*/ @@ -81,7 +87,144 @@ Once the flasher tool is running we are ready flash the UEFI image:: flash rawwrite 200000 100000 >> Send SPI_NOR_UBOOT.fd via XMODEM (Control-A S in minicom) << -*!!NOTE!! The flasher command parameter is different from the command for board recovery. U-Boot uses the offset 200000 (2-five-0, 2M in hex) and the size 100000 (1-five-0, 1M in hex).* +*!!NOTE!! The flasher command parameter is different from the command for +board recovery. U-Boot uses the offset 200000 (2-five-0, 2M in hex) and the +size 100000 (1-five-0, 1M in hex).* -After transferring the SPI_NOR_UBOOT.fd, turn off the DSW2-7 and reset the board. +After transferring the SPI_NOR_UBOOT.fd, turn off the DSW2-7 and +reset the board. + +Enable FWU Multi Bank Update +============================ + +DeveloperBox supports the FWU Multi Bank Update. You *MUST* update both +*SCP firmware* and *TF-A* for this feature. This will change the layout and +the boot process but you can switch back to the normal one by changing +the DSW 1-4 off. + +Configure U-Boot +---------------- + +To enable the FWU Multi Bank Update on the DeveloperBox, you need to add +following configurations to configs/synquacer_developerbox_defconfig :: + + CONFIG_FWU_MULTI_BANK_UPDATE=y + CONFIG_FWU_MDATA=y + CONFIG_FWU_MDATA_MTD=y + CONFIG_FWU_NUM_BANKS=2 + CONFIG_FWU_NUM_IMAGES_PER_BANK=1 + CONFIG_CMD_FWU_METADATA=y + +And build it:: + + cd u-boot/ + export ARCH=arm64 + export CROSS_COMPILE=aarch64-linux-gnu- + make synquacer_developerbox_defconfig + make -j `noproc` + cd ../ + +By default, the CONFIG_FWU_NUM_BANKS and CONFIG_FWU_NUM_IMAGES_PER_BANKS are +set to 2 and 1 respectively. This uses FIP (Firmware Image Package) type image +which contains TF-A, U-Boot and OP-TEE (the OP-TEE is optional.) +You can use fiptool to compose the FIP image from those firmware images. + +Rebuild SCP firmware +-------------------- + +Rebuild SCP firmware which supports FWU Multi Bank Update as below:: + + cd SCP-firmware/ + OUT=./build/product/synquacer + ROMFW_FILE=$OUT/scp_romfw/$SCP_BUILD_MODE/bin/scp_romfw.bin + RAMFW_FILE=$OUT/scp_ramfw/$SCP_BUILD_MODE/bin/scp_ramfw.bin + ROMRAMFW_FILE=scp_romramfw_release.bin + + make CC=arm-none-eabi-gcc PRODUCT=synquacer MODE=release + tr "\000" "\377" < /dev/zero | dd of=${ROMRAMFW_FILE} bs=1 count=196608 + dd if=${ROMFW_FILE} of=${ROMRAMFW_FILE} bs=1 conv=notrunc seek=0 + dd if=${RAMFW_FILE} of=${ROMRAMFW_FILE} bs=1 seek=65536 + cd ../ + +And you can get the `scp_romramfw_release.bin` file + +Rebuild OPTEE firmware +---------------------- + +Rebuild OPTEE to use in new-layout fip as below:: + + cd optee_os/ + make -j`nproc` PLATFORM=synquacer ARCH=arm \ + CROSS_COMPILE64=aarch64-linux-gnu- CFG_ARM64_core=y \ + CFG_CRYPTO_WITH_CE=y CFG_CORE_HEAP_SIZE=524288 CFG_CORE_DYN_SHM=y \ + CFG_CORE_ARM64_PA_BITS=48 CFG_TEE_CORE_LOG_LEVEL=1 CFG_TEE_TA_LOG_LEVEL=1 + cp out/arm-plat-synquacer/core/tee-pager_v2.bin ../arm-trusted-firmware/ + +The produced `tee-pager_v2.bin` is to be used while building TF-A next. + + +Rebuild TF-A and FIP +-------------------- + +Rebuild TF-A which supports FWU Multi Bank Update as below:: + + cd arm-trusted-firmware/ + make CROSS_COMPILE=aarch64-linux-gnu- -j`nproc` PLAT=synquacer \ + TRUSTED_BOARD_BOOT=1 SPD=opteed SQ_RESET_TO_BL2=1 GENERATE_COT=1 \ + MBEDTLS_DIR=../mbedtls BL32=tee-pager_v2.bin \ + BL33=../u-boot/u-boot.bin all fip fiptool + +And make a FIP image.:: + + cp build/synquacer/release/fip.bin SPI_NOR_NEWFIP.fd + tools/fiptool/fiptool update --tb-fw build/synquacer/release/bl2.bin SPI_NOR_NEWFIP.fd + +UUIDs for the FWU Multi Bank Update +----------------------------------- + +FWU multi-bank update requires some UUIDs. The DeveloperBox platform uses +following UUIDs. + + - Location UUID for the FIP image: 17e86d77-41f9-4fd7-87ec-a55df9842de5 + - Image type UUID for the FIP image: 10c36d7d-ca52-b843-b7b9-f9d6c501d108 + - Image UUID for Bank0 : 5a66a702-99fd-4fef-a392-c26e261a2828 + - Image UUID for Bank1 : a8f868a1-6e5c-4757-878d-ce63375ef2c0 + +These UUIDs are used for making a FWU metadata image. + +u-boot$ ./tools/mkfwumdata -i 1 -b 2 \ + 17e86d77-41f9-4fd7-87ec-a55df9842de5,10c36d7d-ca52-b843-b7b9-f9d6c501d108,5a66a702-99fd-4fef-a392-c26e261a2828,a8f868a1-6e5c-4757-878d-ce63375ef2c0 \ + ../devbox-fwu-mdata.img + +Create Accept & Revert capsules + +u-boot$ ./tools/mkeficapsule -A -g 7d6dc310-52ca-43b8-b7b9-f9d6c501d108 NEWFIP_accept.Cap +u-boot$ ./tools/mkeficapsule -R NEWFIP_revert.Cap + +Install via flash writer +------------------------ + +As explained in above section, the new FIP image and the FWU metadata image +can be installed via NOR flash writer. Note that the installation offsets for +the FWU multi bank update supported firmware. + +Once the flasher tool is running we are ready flash the images.:: +Write the FIP image to the Bank-0 & 1 at 6MB and 10MB offset.:: + + flash rawwrite 600000 180000 + flash rawwrite a00000 180000 + >> Send SPI_NOR_NEWFIP.fd via XMODEM (Control-A S in minicom) << + + flash rawwrite 500000 1000 + flash rawwrite 530000 1000 + >> Send devbox-fwu-mdata.img via XMODEM (Control-A S in minicom) << + +And write the new SCP firmware.:: + + flash write cm3 + >> Send scp_romramfw_release.bin via XMODEM (Control-A S in minicom) << + +At last, turn on the DSW 3-4 on the board, and reboot. +Note that if DSW 3-4 is turned off, the DeveloperBox will boot from +the original EDK2 firmware (or non-FWU U-Boot if you already installed.) diff --git a/include/configs/synquacer.h b/include/configs/synquacer.h index 8f44c6f66a..cd7359c2f8 100644 --- a/include/configs/synquacer.h +++ b/include/configs/synquacer.h @@ -40,19 +40,29 @@ /* Since U-Boot 64bit PCIe support is limited, disable 64bit MMIO support */ +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define DEFAULT_DFU_ALT_INFO +#else #define DEFAULT_DFU_ALT_INFO "dfu_alt_info=" \ "mtd nor1=u-boot.bin raw 200000 100000;" \ "fip.bin raw 180000 78000;" \ "optee.bin raw 500000 100000\0" +#endif /* GUIDs for capsule updatable firmware images */ #define DEVELOPERBOX_UBOOT_IMAGE_GUID \ EFI_GUID(0x53a92e83, 0x4ef4, 0x473a, 0x8b, 0x0d, \ 0xb5, 0xd8, 0xc7, 0xb2, 0xd6, 0x00) +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE +#define DEVELOPERBOX_FIP_IMAGE_GUID \ + EFI_GUID(0x7d6dc310, 0x52ca, 0x43b8, 0xb7, 0xb9, \ + 0xf9, 0xd6, 0xc5, 0x01, 0xd1, 0x08) +#else #define DEVELOPERBOX_FIP_IMAGE_GUID \ EFI_GUID(0x880866e9, 0x84ba, 0x4793, 0xa9, 0x08, \ 0x33, 0xe0, 0xb9, 0x16, 0xf3, 0x98) +#endif #define DEVELOPERBOX_OPTEE_IMAGE_GUID \ EFI_GUID(0xc1b629f1, 0xce0e, 0x4894, 0x82, 0xbf, \ From patchwork Mon Apr 10 23:04:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 672045 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp495842wrx; Mon, 10 Apr 2023 16:05:28 -0700 (PDT) X-Google-Smtp-Source: AKy350bu3CUukyrQN6tuoiDPLo3Y1F6w/rnXGHHsGFkTvEgcVK9AhqrVD4ehTXgbnsa1FCx+szqI X-Received: by 2002:a05:622a:1006:b0:3e6:2bba:87f3 with SMTP id d6-20020a05622a100600b003e62bba87f3mr21093307qte.47.1681167928368; Mon, 10 Apr 2023 16:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681167928; cv=none; d=google.com; s=arc-20160816; b=EX7aJgbnCQmxb3HfCQP65Jj6Kyrz8IqdTDIQhLIRmdtlnx/PSw7ekdhHuY8PZxJ/xP uTc4tMaEfoaOP7u6F6GEKotEI79OXaZ8nrFpS0JPlaUTIaDHRoPOLZYNOQrDmaaTh1dX GAM566VhdQJJjTc4MkTY2GOx0AO+/3/ODiagaAh5RxTqRAjQ+9+rFoprLRpZR8ntNZpG 3e7vtO5Khc3S7ol86BMx+GoOxiPF8xvt6qLiMkQh58NvoqUlzctj56VwoBbu64ZRSYho C+ijn7d5ir/SXV3I0hHUNycMZuzeCtKXhS1Oy0n57BZQuV7Lzz2VTmCHn+SldxlLGb6q 4ddQ== 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=I9XcgT61QsL7BxVRHbct/x5Cgqheqd71HgzZMDhiF5I=; b=IPTyz6lnbmbVYB3Pa6SrfsUf6afOuP2PcJq5Fii460lOZ3Qc5m4byTDX1Yd4Q7TWIF iVoQZZZCChPxR4a25tDM8iAz5oAyIiEcGcvP6VLePY5XYw2xMfuxVx5a0WiYTi4teQyh pEG8StMhAeQWCJgyavsziJB5v9aIzRYsZZtQBfNjnALDwYEQ7WKDLl3Ya5t4g0zr4uZl eOL7aoUvV3Xw0FSYIq5Z79u8aH1SeOgRW6QFX5wrB7LKR7ox6Dblgtzi9aV3Yo7yO2dY 937GMsEixH0IAfVkYRLGQVjP7iwTM8FvAvnwkJri4XSazfa/RDcn26UyIgYw2aU0Qkb+ zbzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="g1n/xWJJ"; 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 d126-20020a37b484000000b007487c63263bsi7720301qkf.425.2023.04.10.16.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 16:05:28 -0700 (PDT) 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="g1n/xWJJ"; 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 BDA1785D77; Tue, 11 Apr 2023 01:05:25 +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="g1n/xWJJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7437185E34; Tue, 11 Apr 2023 01:05:19 +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-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) (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 6B49485B31 for ; Tue, 11 Apr 2023 01:05:04 +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=jaswinder.singh@linaro.org Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-54c17fa9ae8so225810167b3.5 for ; Mon, 10 Apr 2023 16:05:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681167903; x=1683759903; 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=I9XcgT61QsL7BxVRHbct/x5Cgqheqd71HgzZMDhiF5I=; b=g1n/xWJJ2bMFlLW2EVq5lPWbgVOnKXzXXRYqwbcadEcoUoqqDlofcKVn5kopuizVIl la35wG7qpOHoXgvQ8z2MT+12tC0O4YNjmnPm8C1xgPsHgTZYkdqlPgICKsfNQ3rPhXQ0 zSce4vimT3eseWyiy8aktT+UqlVzhIoPD2KCzcJZhSuWz4LFrttVIu/ppB0xjPjNcW6S I7RMnYcUMwzNdunlojolUvyqscGDsr5i5B8rK/yREKLgX4tzB+ml039chnOwYIulGvEd KElRX1kwvkPh0GUd688d90kIqPj7hZnC0n5TsNvMQE9G2AnJr1ojksbAxGdwbbBibeWS 9SKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681167903; x=1683759903; 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=I9XcgT61QsL7BxVRHbct/x5Cgqheqd71HgzZMDhiF5I=; b=zY9eGnJ8nXzhtiP5e1NfROkYdnqsG1NmERwzawfNqkRsg4EQ3UXMprdHB1WSeNfFm+ VxOGZk91E0puQjsLak9IEMZUO/TJRzbQ58wuaTRKoh2fwO52cW26h1aY1yQCMWW+FAHX mG70M1vCDuD30pOTsOOBP40ygEDgW/a1JQbiXr0ghEBHPOPw/NAMItMtkYr1TivM64dK pRZIQBJsjkaj6f8LVELM2O4WdpZt6w1aZwb9J+z/T4j9nKtiqI8Pzh2eAKyVysaSxxzU xloldiv0Fm60cjZsYlap0hdKKOGAN+cEXgpwpshjqGCCBmEtoqQg1ZH9pvoPLrZw4+zX xIbw== X-Gm-Message-State: AAQBX9c5JNeCX9//ou42Q2+26L4xV5a/M402Y8RpT5ITe/AZmeF1k2Qs MkeaYP/kxd9PwmmHVigmxh3TR0+VAU0eIaW83lk= X-Received: by 2002:a0d:ddc5:0:b0:541:a166:a916 with SMTP id g188-20020a0dddc5000000b00541a166a916mr9478703ywe.36.1681167903044; Mon, 10 Apr 2023 16:05:03 -0700 (PDT) Received: from jassi-desktop.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id z35-20020a81ac63000000b005463f6ae720sm3053008ywj.68.2023.04.10.16.05.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 16:05:02 -0700 (PDT) From: jaswinder.singh@linaro.org To: u-boot@lists.denx.de Cc: ilias.apalodimas@linaro.org, etienne.carriere@linaro.org, trini@konsulko.com, sjg@chromium.org, sughosh.ganu@linaro.org, xypron.glpk@gmx.de, takahiro.akashi@linaro.org, michal.simek@amd.com, Jassi Brar Subject: [PATCH v5 6/6] fwu: provide default fwu_plat_get_bootidx Date: Mon, 10 Apr 2023 18:04:59 -0500 Message-Id: <20230410230459.72680-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230410230143.72556-1-jaswinder.singh@linaro.org> References: <20230410230143.72556-1-jaswinder.singh@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 From: Jassi Brar Just like fwu_plat_get_update_index, provide a default/weak implementation of fwu_plat_get_bootidx. So that most platforms wouldn't have to re-implement the likely case. Signed-off-by: Jassi Brar --- lib/fwu_updates/fwu.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index a24ccf567a..c9996f4d6d 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -545,6 +545,24 @@ __weak int fwu_plat_get_update_index(uint *update_idx) return ret; } +/** + * fwu_plat_get_bootidx() - Get the value of the boot index + * @boot_idx: Boot index value + * + * Get the value of the bank(partition) from which the platform + * has booted. This value is passed to U-Boot from the earlier + * stage bootloader which loads and boots all the relevant + * firmware images + */ +__weak void fwu_plat_get_bootidx(uint *boot_idx) +{ + int ret; + + ret = fwu_get_active_index(boot_idx); + if (ret < 0) + *boot_idx = 0; /* Dummy value */ +} + /** * fwu_update_checks_pass() - Check if FWU update can be done *