From patchwork Mon Mar 27 21:15: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: 667401 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp1313871wrt; Mon, 27 Mar 2023 14:17:19 -0700 (PDT) X-Google-Smtp-Source: AKy350aPfcqR9+TrDI6DRqtdS5DC2ZK1vedCouVAbeu2X+LYUdOLB5CLh61UqMH7flaTOO6Qc0Ft X-Received: by 2002:a17:902:eecc:b0:1a0:6bd4:ea78 with SMTP id h12-20020a170902eecc00b001a06bd4ea78mr11433068plb.31.1679951839639; Mon, 27 Mar 2023 14:17:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679951839; cv=none; d=google.com; s=arc-20160816; b=QtVxzf3KAoWtKIeHov0903T7emfNdP9KWPQR/dRaysMUP6shY+d4zLI6xVoQZQYfhS 1zXxhWpuUlFNs8H5yodia66o5d2AZ/VgOWWdbNWF2H9Q3tIH6q4us72TuzqQA9/Qf/hS Sgt47U4HShqDF0BczejIrBU42zcesOt3z8qFWfEiwP8/PCP73ePCauEMQ4MM0b7t0CBp +oz/wSncKTduf0AgTE9vG1L5VG5/2VKOQhzMmNrg3Jf3Kcu3nMMet/VmIpFYMrFFJ7ez CMEy+yhiO5Hm/0BMpffudGaYebV/dtU6OUGIBDQ48DycYDAl78pyhkTjMhPNDVJYK7/P Of3w== 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=ZdGPHSSk0TYQNlX4M295PLnEsj3L1+X7yekc4Nc9Q8o=; b=Lt27cbzI/xGo3tER1tJzKX2L3RbmztzqqrXSzGYm2onPFkAInbIMPtEi6b5e+OKNxN eJHwZyo8GiKD3FdlI43/1OrD1NyMh7JTE3I/n2zl88JrG1z/2uOc4F6LzG8bNmafO1KT hWST8Rg4TEd5EMFCV2/r4jAUFODz1SwnW5Xs5JECVJinetgKIpLLf2kZD8n+n4iQorHM ZI8XCMGXCBHddn21ptulFm3IMiWJuYxqN1Dh11V2oZs7Y7IqXxw8dKYUjxRGycQnon13 WRE2StRfLddNQLQL7EPeL/dvvYe8TqoYY3kscz1rAKfD+WaoAHztNHgMdUmbhM3VUpkS xHxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GpcrngLT; 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=QUARANTINE dis=NONE) header.from=gmail.com 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 kr16-20020a170903081000b001a20b5104b0si9688703plb.424.2023.03.27.14.17.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 14:17:19 -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=@gmail.com header.s=20210112 header.b=GpcrngLT; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7406685C14; Mon, 27 Mar 2023 23:17:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="GpcrngLT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DE32A85BED; Mon, 27 Mar 2023 23:17:11 +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,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) (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 37095804DB for ; Mon, 27 Mar 2023 23:17:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jassisinghbrar@gmail.com Received: by mail-il1-x132.google.com with SMTP id s7so5328364ilv.12 for ; Mon, 27 Mar 2023 14:17:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679951753; 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=ZdGPHSSk0TYQNlX4M295PLnEsj3L1+X7yekc4Nc9Q8o=; b=GpcrngLTG/KXed9726CvhfQmUr5CuNmxFtA+/KEnGS3VwNdjo6VBemuoVQ7AxjnYOl 0DBd2OwIing/qiI4vLvkhRGXjdCebSjZiP+o/vwSVAOHJxG+LY4/XMSEYqLHVXOKKKfG DfVmp2N3OVFA7DKBBM8BtaWN6JWcbEAmU/nlQQN2eZx1P8mxqkJ3GRLq5pBCPXubdcKp oVMttwUQvKQzQamGIDSf2ufN6clhzK3x4eXHhadKKDp1PYNsYbYDoP8/vgNaSbELKlrB ETIGq5U10U8d6Au9wPKbnlfSgUJsv17dVmlvWFiEeqDn1vRSXhU6VzjGFuT6I1LKYBK1 asBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679951753; 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=ZdGPHSSk0TYQNlX4M295PLnEsj3L1+X7yekc4Nc9Q8o=; b=uaZ9a+mbI+coJv0BQLd6RMn1EV7ulBNmvwaAggUR2YXvnbZcuPtXklBD/Jtn+CqKMT jTXYSqFn9cSX5bqrLyZZ2dRZFDoT2P8pls7GmOLm6GnpQMUNhodYpfOwazEykAeY67Yf IEuQUiKdBYzXiiwQ1nXuCsdF/LcPlgSZ2te2oqvkpEwTNAjoIqQTmButXRadsISDmkXx yYRtuC6RifzcC2BHpk6ktKlJM49KpQ3y3lBPB/uYP2Pen8P2egvBcOVPCok0VmifQaNh FLlweVF+3MoPPuN+/GNdHkBZhFbAwIF6sQeUveUh2qi39Pk4uKQwdjxciCwrvK+dQFp0 VS8g== X-Gm-Message-State: AAQBX9cTRWBCAXWs0XzU2lpiplp6VAWznzhsGM8z9LWKH0ywcdMnpP7h qwT9mJnz6Ps9v8lttN0Isr9ndtcBxvY= X-Received: by 2002:a92:da11:0:b0:325:b002:89b4 with SMTP id z17-20020a92da11000000b00325b00289b4mr10277188ilm.25.1679951752752; Mon, 27 Mar 2023 14:15:52 -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 cp2-20020a056638480200b00407eacc0550sm5054137jab.154.2023.03.27.14.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 14:15:52 -0700 (PDT) From: jassisinghbrar@gmail.com X-Google-Original-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 v4 1/6] FWU: Add FWU metadata access driver for MTD storage regions Date: Mon, 27 Mar 2023 16:15:48 -0500 Message-Id: <20230327211548.498919-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230327211458.498879-1-jaswinder.singh@linaro.org> References: <20230327211458.498879-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. 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 ++++++++++++++++++++++++++++++++++++ 3 files changed, 288 insertions(+) create mode 100644 drivers/fwu-mdata/raw_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..4b1a10073a --- /dev/null +++ b/drivers/fwu-mdata/raw_mtd.c @@ -0,0 +1,272 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * 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 seconday 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), +}; From patchwork Mon Mar 27 21:16:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 667417 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp1317120wrt; Mon, 27 Mar 2023 14:28:02 -0700 (PDT) X-Google-Smtp-Source: AKy350YYMg3YeAatCq6/GZfElUmOE+cROW7x4G7JX7bzznvCu6EZaSdZCfroEAAW65PWRnFjyMze X-Received: by 2002:a62:1a83:0:b0:60b:e13:a10b with SMTP id a125-20020a621a83000000b0060b0e13a10bmr12048013pfa.3.1679952482189; Mon, 27 Mar 2023 14:28:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679952482; cv=none; d=google.com; s=arc-20160816; b=No/YTjqB0jh5m8L4/oyoWkC8S0z8nLFIEN51YrLsOMeojmOvEqR7KppGkzzimlsuqI 0lAPQDp++Ky9N6yolMpGYzVW0Yo+5GfIzimME70VR2tv/zm9whLgLhwwQ6R3xlXgfUEX ai/UhzUf702knpNof/Dzo+x5eHxIIFAR5wQb38GZYl1iU8MwO//Etluo7EwCULqqMIOC xos5zuJ1FfQatFixV6vysQjBn4OcRnKmEAAdRB0fjBWqXcYf6v8aOss+nxs5tyeYivzK dvWkYyB07G5kGlGolhdkB/v+3ZZHu1jvRELz5+jJmskweYTHClaUn1ft+PDAKrsBlwoQ dCOg== 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=jSvnVnODILm8SMNl0Jw7dajkiOcOe45Gnkt3hTc/Nfk=; b=zOKyyHXkeUWLmm1BQxx27lb0ZeorT+nNdW6nctL+NIzhSPEyraxABEgdyYphgFPtNq eX/u6IjJ+qs89ptOdndWhKjOD3apml/Y3zuNAAn+OzYmOx55adFTbmEVpbyH9ibabTHu XzQGSW6DKdfIT/E/T2xQlT1GadkUzAlWMHsc1wT7qKxwhzRbaFKJovw3kohFXETQtxRx 4irtxGExh0PvdRLx1CrOSBn7zIX9VwkH5+RDq1k/kUbmRMzIFjyMcX8SVXkRBbqjOTG6 YK5TF26N0UD1cr1TH6FUzdRVAuA6by9aMz5dJ2F6x45iwErZWu30d83RoiZkZ3hipqiT hDpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mknhaWhJ; 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=QUARANTINE dis=NONE) header.from=gmail.com 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 c11-20020a624e0b000000b0062ae6345c76si8386777pfb.401.2023.03.27.14.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 14:28:02 -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=@gmail.com header.s=20210112 header.b=mknhaWhJ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3A5C385C96; Mon, 27 Mar 2023 23:26:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="mknhaWhJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 88B5283523; Mon, 27 Mar 2023 23:26:42 +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,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) (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 1922285BD0 for ; Mon, 27 Mar 2023 23:17:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jassisinghbrar@gmail.com Received: by mail-io1-xd30.google.com with SMTP id y85so4486358iof.13 for ; Mon, 27 Mar 2023 14:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679951767; 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=jSvnVnODILm8SMNl0Jw7dajkiOcOe45Gnkt3hTc/Nfk=; b=mknhaWhJm7/glw4klc3EuXOaGJcPSc2dWF3q56B9qAStrEPZylH9vNKRJHkhnwztky Lqc2L/zl2YOKatQ8ppozhtFiXhdBDOaXrRJN26iXzb/Lzbh/TxLb5z2FSf5tIaJSeraq jdcCfVETHf2BVuKWkSm1R1rs8j8ed5nidIMySyNQ4IuqLeyBo5BENk79UVGoTN3dL5ov n15icyG6UJPmp+BciIvFiekiTPcLEQ9/ivAIHEFSQAyjZfX7jIYXwNWGXHokGuCxO96/ kRB5QHW294rg1QCnJzzrU3LZve1OsgvWo9yk3GNO9RWgs8//20KWTSQOa8tX7mMXcKEc NZoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679951767; 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=jSvnVnODILm8SMNl0Jw7dajkiOcOe45Gnkt3hTc/Nfk=; b=Xuw0ojpkHGRJWVGMHV1a3yhbYv9XvqWno3eHXj1w8RjTI8oYIfB7gYpTdEGVt8ntwl HXb1XZV2GfWq8rHPGQ+4GDaE9eOowrz4VH4b0hbPR3mu+L4qb0/Y+7HUpHPb9yaz+YEL jJEAxkH0wGqy1lQoJkl5VjcDCFPYz4jjhH50+l0F6di+TeR3IWJh3HwDAnGVpv6qBmRQ ndENAVAZeRq5SkuxvmJFJkVQmXmZxCKiCrKs0eV43wDlhvdg5buqaakz7Mqe1hHlxqSD Xzf+xuQf5e8ddFjZLQP/cp/DvjucyBlx4TjnFnyWTjMtGkEGDzX7/JwWMqg59KyeXnYt KWdg== X-Gm-Message-State: AO0yUKUR5JCYcAOBDNjxgMKVnVa7COsmcs7laLSLsbGgCG/IW0KzxjJ9 30pARPZazySk6UMSIiqsUi85I3OJLZg= X-Received: by 2002:a5d:9e53:0:b0:73a:6c7f:c476 with SMTP id i19-20020a5d9e53000000b0073a6c7fc476mr10836937ioi.16.1679951767405; Mon, 27 Mar 2023 14:16:07 -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 u26-20020a02b1da000000b003a958f51423sm5629595jah.167.2023.03.27.14.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 14:16:07 -0700 (PDT) From: jassisinghbrar@gmail.com X-Google-Original-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 v4 2/6] FWU: mtd: Add helper functions for accessing FWU metadata Date: Mon, 27 Mar 2023 16:16:03 -0500 Message-Id: <20230327211603.498936-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230327211458.498879-1-jaswinder.singh@linaro.org> References: <20230327211458.498879-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 helper functions needed for accessing the FWU metadata which contains information on the updatable images. Signed-off-by: Masami Hiramatsu Signed-off-by: Jassi Brar --- include/fwu.h | 34 ++++++++ lib/fwu_updates/Makefile | 1 + lib/fwu_updates/fwu_mtd.c | 164 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 lib/fwu_updates/fwu_mtd.c diff --git a/include/fwu.h b/include/fwu.h index 33b4d0b3db..117f51c4f5 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,30 @@ 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_id, 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..c1d04e574b --- /dev/null +++ b/lib/fwu_updates/fwu_mtd.c @@ -0,0 +1,164 @@ +// 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 = sizeof(fwu_mtd_images) / sizeof(struct fwu_mtd_image_info); + + 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) +{ + int i, nalt; + int ret = -1; + struct mtd_info *mtd; + struct dfu_entity *dfu; + fdt_addr_t offset, size = 0; + char uuidbuf[UUID_STR_LEN + 1]; + struct fwu_mtd_image_info *mtd_img_info; + + mtd_probe_devices(); + mtd = get_mtd_device_nm(mtd_dev); + + 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; + + dfu_init_env_entities(NULL, NULL); + + 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; + } + + 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; +} + +static int gen_image_alt_info(char *buf, size_t len, int sidx, + struct fwu_image_entry *img, struct mtd_info *mtd) +{ + int i; + char *p = buf, *end = buf + len; + + 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 Mar 27 21:16:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 667419 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp1317299wrt; Mon, 27 Mar 2023 14:28:42 -0700 (PDT) X-Google-Smtp-Source: AK7set9R1nO2m8n8sDDyCXsTEGIcMMkzvM//zT7sGdqiE+jTdlN+invkdnjIuuCL+x/oCeHCN00M X-Received: by 2002:a17:90b:1a85:b0:23a:66:1d3a with SMTP id ng5-20020a17090b1a8500b0023a00661d3amr14823437pjb.45.1679952522610; Mon, 27 Mar 2023 14:28:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679952522; cv=none; d=google.com; s=arc-20160816; b=HULSQQ8HTZFqrcx4cIYmzG4F3N0v2ujXuBMnTxzjnYjQt8//1KZrGEOwqVaT2yRRpc u1CnbhbEPF0GPNARzwWg4NTGoMZ4Fn4LjJH8IA10RIlD2Y59q1ISe2sXbIg63xD7T8MR lWN98Uw15wt9MuNb4lUlTB3SC88bIdjaxpJ5qieh5PrKKuYwW+n9WiwYXHs2jR6pLe7G m4rJf0uNbDuU2KetPFWSrbk1GUVsNkgNgeWX4C8HWYcsyWzAMsC1M0ok8SU5SKHY8R+r p3pHIw4blxibnp9yzHheO2AokaWfyMYi8K3exLleJg7eFaOlNr4lwu1H1w1F76KswkAz +lng== 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=9EZ6zF9mfC2skdxijrSO9z8BfwPHD16I+UlLNAvw00c=; b=tr3jtFIYfLvDSxlmoKP9pFXZKSWUS3wcf0NWDjFwFIkSVcv5AGGxTowYh+pwFamz5D g2U+h5Nz+Pt+06o79HmExfirKvmeMGadiBPWRzQOVTw77Wp2JUUlBcmd37B/KAQprYHh q/OzPTVWy6XJ2kC2ZJyP27KQrkVSPsTsMZkLHkg6xpgOY1kmFrYQujuwPQS3A/Jblc2/ egRVZ3epAXgBtl6IO4GkBCwqREYBvLoe+sQ07uIZxV4XvCYLFRLTlSIxCxRs0JSJn28p CmLv7JrZ1DVdbpN48J+G7qf8d6khd4OPkNLuRYSTZWNfwOf0Uo9z4i/Ru8cBd0Y92A06 0k0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jpmgtcGu; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id t22-20020a635f16000000b0050fa785a426si17499201pgb.634.2023.03.27.14.28.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 14:28:42 -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=@gmail.com header.s=20210112 header.b=jpmgtcGu; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 78BC285A8F; Mon, 27 Mar 2023 23:27:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="jpmgtcGu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 274D185CE6; Mon, 27 Mar 2023 23:26:58 +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,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) (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 3DA2D85B78 for ; Mon, 27 Mar 2023 23:17:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jassisinghbrar@gmail.com Received: by mail-io1-xd36.google.com with SMTP id p17so4495303ioj.10 for ; Mon, 27 Mar 2023 14:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679951774; 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=9EZ6zF9mfC2skdxijrSO9z8BfwPHD16I+UlLNAvw00c=; b=jpmgtcGuG0KWSJ00T7ZvuwJIJvyD/10Dr+2KvIYRyp0kEgV95t2tdNaMKISrZA7XoC HxEIIYt2E69EvBn6Pxl+zdMcv74iMfQxf2L7JX/R8fp1vYltA3WuLrnW9YYAKKEGYVbQ ifDipnxq0OBDX8abY6y7PH+qE8m256Ko3mlON8aFOjosRfFAkTh/rcm74MZ/Gj4XS95R DbB9jiZrydoHvLDWcJTrxeAhuWgb3L/mbDOcQKqhQCfGabSHZLdamj68rzt2uDY96nS6 bCwm7NDxqMU+eG4iZXY5W1xsng/c3f7VaAr9rJOPf6qHHHHtR3OoJQFzzCAncjqz2SxK tu2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679951774; 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=9EZ6zF9mfC2skdxijrSO9z8BfwPHD16I+UlLNAvw00c=; b=zU3yTKJeFLH6dUdPxgbFu/n1H1UVm3fneuZf11WqBE/sv4/fYUB90LwKhTztiZOwfT emfnsDmMyOKcqqLLC3yRYnbNwaYhW/S77GNJ02VMnzSVUcBc1oLnS8opiPGoHs0FoaPW oY44Yeva1sl+EON8GHPE5zDWMKYSXhdvbIieXEv/Vf9TiG4R9/4Jd+yptjjfS3pCwyM2 Xw60WymxWXArzl6xUSlAoosgiOKA+aq/rKbylWIEy1VJVeFOzaaTp+Pm+l9kHn7IlKU+ igNEzrogNwxgS07nQRem2p5ILVMg/23KGl5z86RcmzyuxpuP5lU434lxTjlTjULUDI0a 7MHQ== X-Gm-Message-State: AO0yUKVf9aSLHSn4m5XCF4m6dUMOCA22n2aYNXK25tgA8TQRffgYDqFj MYwn4j6O8q57RjoKrQDZY33ES7V71BI= X-Received: by 2002:a5d:8545:0:b0:71b:3544:887 with SMTP id b5-20020a5d8545000000b0071b35440887mr9667324ios.10.1679951774580; Mon, 27 Mar 2023 14:16:14 -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 bo23-20020a056638439700b00346a98b0a76sm8933375jab.77.2023.03.27.14.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 14:16:14 -0700 (PDT) From: jassisinghbrar@gmail.com X-Google-Original-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 v4 3/6] tools: Add mkfwumdata tool for FWU metadata image Date: Mon, 27 Mar 2023 16:16:10 -0500 Message-Id: <20230327211610.498952-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230327211458.498879-1-jaswinder.singh@linaro.org> References: <20230327211458.498879-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: Masami Hiramatsu Signed-off-by: Sughosh Ganu Signed-off-by: Jassi Brar --- tools/Kconfig | 9 ++ tools/Makefile | 4 + tools/mkfwumdata.c | 334 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 347 insertions(+) create mode 100644 tools/mkfwumdata.c 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 e13effbb66..80eee71505 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -247,6 +247,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 Mar 27 21:16:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 667416 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp1317014wrt; Mon, 27 Mar 2023 14:27:39 -0700 (PDT) X-Google-Smtp-Source: AKy350aBGjgXIgpV+TiBTbRGr9rpXqlOD9VKoiA3kj3CKgWIE/dYeFByZ/v1CurjdbiRtCExeuRX X-Received: by 2002:a17:90a:18e:b0:23b:2c51:6e7 with SMTP id 14-20020a17090a018e00b0023b2c5106e7mr14060436pjc.21.1679952459291; Mon, 27 Mar 2023 14:27:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679952459; cv=none; d=google.com; s=arc-20160816; b=fNSaI8tZZfJu3Esm4gyw3x6Py43BkFd96XOycTb3n1zDXbK/BIrmJDUQAMEMUOuStN 7OuwxqQEsIQJ1tUiqrLgwZRfR7IB1jGNWI+3+IK7pLvKych3E/VP9KkmCtXHluJTVNlS WGCQuG7xP/fbTSN+z7iqaNztEw/S3kbGMEny0RQxBp/I2CpzqPVvDz8dUh6WdJgTNSYl BtABI49+dZQDIqbqhMy7780Td5xInmQMn+IGoZiZHgVmqpcahqwyUUTStc0Ecf+LsK3Y 0p9CJLowaNBEqayLYJ909eREGFpfKj0R0MQPmnqAE0y/aiAxbeCcwDd9zNiSphXRMDF4 8JsA== 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=dSCiqb+ADHCBJofDDPtkGMe/hlu6JUpOsKaLKWvMf7ebLKNkvcJuvuvD7dTSBC0YX8 PaExEm3JR+AuTaO8PCWVwCVd3Dj1kLmuobHMZ2rnMu6UuJ6R3dc7ZE0vSSLHRLN7J+ck KAdmMklTqGWc4S8j2g2yhys63bXfEuxKidEKzRD/SSiR6xJYmoFY5zkAflldRDAx2Qq0 8eFqD6MK12SuQXh1hOLT330J9X+bPB/m9C700QK1lqV1mIvB1zJigV12O4IXjfEFnuT1 MQtWUitsNZSo1hWmuqjWYnPMwmIhvy02bmcZRX4WMzAx8uPNtCzij/xBOQIHJy3Q9U+N pW2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pngGxvf0; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id s17-20020a632151000000b0050bee8d3e4bsi27807431pgm.691.2023.03.27.14.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 14:27:39 -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=@gmail.com header.s=20210112 header.b=pngGxvf0; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7729481E3E; Mon, 27 Mar 2023 23:26:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="pngGxvf0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9137685C66; Mon, 27 Mar 2023 23:26:41 +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,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) (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 8143C85C7B for ; Mon, 27 Mar 2023 23:17:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jassisinghbrar@gmail.com Received: by mail-io1-xd33.google.com with SMTP id e13so4521681ioc.0 for ; Mon, 27 Mar 2023 14:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679951783; 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=pngGxvf0vHRRHHNKhP87RI1dyx74YYNQYduI+FhMchMeG1k1lD4EyOcF8lnNsesYs7 6ZI0JluQLClMmVA9Rg1zv5T2h0fPP0nFRHNVXLhSUcvE73yp9gYvjKVvb11mx0biCBel WkhFsjWKvqy4E8BWtLFJKOoFJzizhGxwGHPBaoZ2FKEgCZSaAVl4B43NxrWqtdDZXq6l MBxSCZmDu8Y2cqeow6W4RF4pCHE4tWfm2gxftLv0wiN9UijRo47LZAO7p+VrQyoI0zib OtImlpq/k98SyFWM19j4g5RLMU4xWT3bgA1XEqgfafGetR79BOJzDwcY4QBsi18GGzB8 EbyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679951783; 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=xb3vWui8EMbG8676a0iNcSqlzCFml1sg2JGBaKrqrB7y3xMA2hGIMiC9A0v/qQ57Ez +IdGTyXTD3DbsB/rrZbEFrP6lsViVUe4xWE6UqMll+boXHp0rcLaOx5YIIr7z1n+mx/7 5qmmQerJFRIqf6Bb2dEGpmfh+HE4C5cYg0RiQoHPWHQ+YcTvK755T8dsSkIZcr68SdSX 2rvkHTwVi5l2fWTCUgkZ+Ia/fVrm0mhpqow4A5Vj62h7Kdh5uv0B2kTjcZLYJQV/Z115 xGdcJDlXCOhfBJ3VhOkTvxlqFJTfLHEU19C/KUME6fubHLbFDsHUHLLV3U9h1xlXEnhK snxg== X-Gm-Message-State: AO0yUKXVIoOcOGtF98geDOmblafsy1R3Z5sZfbnmNj/UqUNByCmN1GfG O1JtY2WXQxXgX52VEjtp8tg2AGH3bQY= X-Received: by 2002:a05:6602:228a:b0:758:917b:c313 with SMTP id d10-20020a056602228a00b00758917bc313mr10032182iod.13.1679951782761; Mon, 27 Mar 2023 14:16:22 -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 t8-20020a056638348800b004061eb055dcsm7682340jal.140.2023.03.27.14.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 14:16:22 -0700 (PDT) From: jassisinghbrar@gmail.com X-Google-Original-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 v4 4/6] dt: fwu: developerbox: enable fwu banks and mdata regions Date: Mon, 27 Mar 2023 16:16:19 -0500 Message-Id: <20230327211619.498967-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230327211458.498879-1-jaswinder.singh@linaro.org> References: <20230327211458.498879-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 Mar 27 21:16:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 667415 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp1316790wrt; Mon, 27 Mar 2023 14:26:48 -0700 (PDT) X-Google-Smtp-Source: AKy350aC1cYX6C4gOKHt4TwVpTWY2jVwk6sPcpG0FViUwWfCQrxsgVywac7qyFirc3xVlSABbI0P X-Received: by 2002:a17:90b:3ec2:b0:234:409:9752 with SMTP id rm2-20020a17090b3ec200b0023404099752mr13749587pjb.25.1679952408075; Mon, 27 Mar 2023 14:26:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679952408; cv=none; d=google.com; s=arc-20160816; b=Lw9tUPSo376dYRLxF5BLPWXuQ526QRdTaFZN0QzEWrZFORqJftNYFiz0pnr7CIekEr I0pKLuaM5fYDVKOuKuw13fK20FVhMWWw4J6Qyvw94mr2YepDZukAGcWoPanqKT60cXV0 x5XbFOVNUIBcEokKBDxidN7SQmyaVsCfFQI7PrL2PZmrvd0pkR2789KfooxYONLpYBBZ pxyBezspMrznp6gF31Pv78JaP+bc1Wm5ZsXe/d4X7hM7M4TBg6uQuh4nZNFRA5JQAmRe vW1AXr8gtaU9KFGORyZAxUleEDTs1LJ6Kt0F38fRB/Y7wHRJz76GnB/j0ma/LIqS6ZUt Bg9A== 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=XGfAzsNyjGbPFoO7/jTxhrmXxqsx/Mt4GKu3+bTYtGPQVBhEMyuaq84yrXO/p7IZHG O8FmclOcF6WN7nfFRMWoQ7b+BPGI8j6Db+4Sz/TgcKFrnuF/PzaIN1QgjEbBSa9nil0o TpaoF++nmMbqmwf1/eJ7UWlb6Sq8Ki2tC7iJOJoa7+evA4+AitZ671lbyjKzMAaYvQTW iTFijoJQI3iyd/NLHYICKzVQGCWR9p7t5SfobLJo1IQ4VeBciPkkCtwo6nDcpdZOxomV EosjQeOpYoHgYHe95grqDqSLb/BWE5WTm8Dqdbj6BFwDvMk6E7ggTTOSHOrO89YOgZyR TXnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=b0RSOwm1; 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=QUARANTINE dis=NONE) header.from=gmail.com 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 f7-20020a17090a638700b00233fdfd70fdsi6714289pjj.18.2023.03.27.14.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 14:26:48 -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=@gmail.com header.s=20210112 header.b=b0RSOwm1; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 713B385B70; Mon, 27 Mar 2023 23:26:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="b0RSOwm1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A78DB844BF; Mon, 27 Mar 2023 23:26:37 +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,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) (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 868DB85C66 for ; Mon, 27 Mar 2023 23:17:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jassisinghbrar@gmail.com Received: by mail-il1-x12c.google.com with SMTP id j6so5335400ilr.7 for ; Mon, 27 Mar 2023 14:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679951790; 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=b0RSOwm1bFafeyuGP7kc950VT9uH2i//ig06evDFG2dWxGOYOWgYs5gKyq//qd2ca7 biaOphqIQsprb5jWgZfbjybb0O5VgZwJ/mrYvm61JmaPn3OdjlB+zw0rEhi67B2CM798 vRFz+ZrMBUzDPtED2ApljWjsJhtyDNXMisa1bIn4sQ0QboWQJC/bEfT0ORIv3PInUXoC U5zb6ja6mf6E3sDwsFqeZTnH1BE5TJGrU+rh2RsQdqkTm1jvN9UAuRifD8HgfHS9vNA/ NShQwnWLSGHPpiTStLcxv3hhmSrfQhKSYgRK84aU4J5/niPa40WGhPvNg5bhB2D8kw0u 5x6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679951790; 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=4HIMFrC0x/fLyonr6fWJI6MN9Hy7BtwvcgU53gTg5JwSttBR5ifGwKh2C2QuLe2Wjn Rfa/XX8urxE163cSUwhHVeVydhs9jyPXAv8MedOgWrT+NfxgxyxWl8j6RPlLzWRFP1BT y4kEzzU+jvZq27l+IXbcc56m0ssG6uTWA1VjaltpraKyJYu/zN0jf2ymIYevGzNmbo1A e3pWotShCv9IDRYV+CaCsuac8ONTSYyHE1svRA4D54/5Dy5GiBXfyFqJy1ucJTzpDec6 QQCUxXdOd04l63aMx2sTvLw6srK6yZGwr18tRWTNqErSYepkNESjEId6IW18v5GBXdXI CpHg== X-Gm-Message-State: AAQBX9ef+7+aeP2Z8e+wu2HBr5OK7oT0KI0bAUNLlY++at3I4uYj2b0F kavaUUMBiVktgrt9rmA2z2u6A4ovM6A= X-Received: by 2002:a05:6e02:78a:b0:314:20e6:133c with SMTP id q10-20020a056e02078a00b0031420e6133cmr3724145ils.3.1679951789883; Mon, 27 Mar 2023 14:16:29 -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 n10-20020a056e02100a00b003261422fdbcsm446834ilj.80.2023.03.27.14.16.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 14:16:29 -0700 (PDT) From: jassisinghbrar@gmail.com X-Google-Original-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 v4 5/6] configs: move to new flash layout and boot flow Date: Mon, 27 Mar 2023 16:16:25 -0500 Message-Id: <20230327211625.498983-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230327211458.498879-1-jaswinder.singh@linaro.org> References: <20230327211458.498879-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 Mar 27 21:16:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 667418 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp1317210wrt; Mon, 27 Mar 2023 14:28:21 -0700 (PDT) X-Google-Smtp-Source: AK7set8Y1tk9mdV283jHK0/qRTGEh90AB6dVQg5Vws7Zlg9jOkqTF3jkU6yuybBmxlwqvcpwqJC1 X-Received: by 2002:a05:6a20:2d9e:b0:de:5082:c9e9 with SMTP id bf30-20020a056a202d9e00b000de5082c9e9mr11558580pzb.27.1679952501525; Mon, 27 Mar 2023 14:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679952501; cv=none; d=google.com; s=arc-20160816; b=NOLnbmCl/G2RqpVGHkJAM4emsH9jeXb1B7vYPmQA1c3rHTBp+NoQ9OUe0yz6LZTjAy 78/UnPetY93D2JwI4iP4/1UgMVl8wtVYn/Z0aGmuSLecadiq8FdvPYrnO/CG5cHtqbFq y+GL2t7Frg02B8nfP5yEvunwToOVaKTyhr6I6NHBdrBJyNV+9Avdol86GlJuhbyGT5E4 Xqc/PEzD5v6lbniOPZyiDCTXgTrzwRwhuUByu8wLlX0rHWYnb/IOo/r//HqdCmBAzd3S FmnGMpHYkBAQufPA8WVGRXGBH5JhDshue87JQ+DzdXHzsd1+6AHgG+ehIud3ZsddHNml sh6A== 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=hiBaU5XGhz16Bb+xEdfhydaumNs87L7GCXbVi++4I/4=; b=xbaD+CqrOBkkuOepVkIt+1SVrlXVRyPCxTfNjuzYk2DTdueoHA0UG5Y0jGzkzze5Eg sY1rO9aOZucrqp1kGehfyyDyXoyZRrOACN02BPQBx8rvZqglVKixrE3k8iAfrgSk8XJg pBLB8ITRVPWgD/OhLd5rufplL7bE8RndMT03A4tAqz3uWraE38It+bltkw3EUlhwk86X UVU6wyY58FtCzlx7Sg0cVv2ii9GEIYU0/dIkdCsg2dO76nTcjljpCcph8blky9EwHLii ke0o9dai/KEVO1yUhXjc8SGJe/kTAftBSmWQC2Wf55XKWd694PzCY6JD4Z7HgMmTv5u8 GA0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gXIVaHj2; 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=QUARANTINE dis=NONE) header.from=gmail.com 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 j64-20020a638b43000000b00513234112b9si8695873pge.901.2023.03.27.14.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 14:28:21 -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=@gmail.com header.s=20210112 header.b=gXIVaHj2; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CE97085B78; Mon, 27 Mar 2023 23:26:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="gXIVaHj2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3B16985A83; Mon, 27 Mar 2023 23:26:52 +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,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) (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 A382A85C96 for ; Mon, 27 Mar 2023 23:17:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jassisinghbrar@gmail.com Received: by mail-il1-x130.google.com with SMTP id v5so2773868ilj.4 for ; Mon, 27 Mar 2023 14:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679951804; 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=hiBaU5XGhz16Bb+xEdfhydaumNs87L7GCXbVi++4I/4=; b=gXIVaHj2oPTzFReaTIEF8bKs6Jyev5N1Vf2O2G6QPKcTMPNoPL/SyIhT2qhhaVyxR0 p9AMZmuCfyPyiXdISjgjbYUoF5n0UVySj8zwe5vauH+b3123oqs9QUviM8LX1QEDVFIT VBrxeF1HMVrNcZYp50nVF0c90zxUX3FI+oR8d3YT1VyT0BHKgr+TqxTWgOU2/Qy+TLi5 GceAv6x6XIrzFn35ZwuwU0a8Oi5Yt6nJD/cC/nZGqXHpNn9AF58qxIB7v4yI73dDxv4o LUDpBKGg1xvF7TCNyaq1xqI5xoejj6/vHJmYJ/ZFYNEBTW4giJvuhW12LxZE/b91jOam M8UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679951804; 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=hiBaU5XGhz16Bb+xEdfhydaumNs87L7GCXbVi++4I/4=; b=a9HE1J4XoAMoYfqKADW4rWRp8ZWI2vw1pJQnXj8QDPIrxSnklO9ehqfY7x8P+c3rRk +XE7Pyeen9qRLGvqEQJfE63944hdMJ8C9Ots2n5JNPLgldp43/pziBCsdcEFTSho+aac Gh8uOUrXv9RoT25c5Xt77qNx48ADX7jNEEgarmeC93ba/8ax9jNgO3kMfMqab1dmhBJ9 OIsXWv2Wf6yEq5DAcSuT3IWITg1+z5iVAPRXTdJ+x3Ch3EI2kvDSQYIjP2une2Rt596x abGY39bdif+sfu2fn5/WgdA/pOH4pv+0sndNJxxe971NtUiaARinqpZLwjuU4AtyX9nK mX0w== X-Gm-Message-State: AAQBX9ckw4dME5VCGUmuSFDskBlHbVsi8PVT3T/WQ88INSDnDKMmySLD KE1AU9aNDULWFYMaPGkxTbarrcUxRr8= X-Received: by 2002:a05:6e02:681:b0:325:b220:196d with SMTP id o1-20020a056e02068100b00325b220196dmr9571707ils.13.1679951803904; Mon, 27 Mar 2023 14:16:43 -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 s7-20020a056638218700b0039e5786d7b7sm7563704jaj.18.2023.03.27.14.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 14:16:43 -0700 (PDT) From: jassisinghbrar@gmail.com X-Google-Original-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 v4 6/6] fwu: DeveloperBox: add support for FWU Date: Mon, 27 Mar 2023 16:16:40 -0500 Message-Id: <20230327211640.499001-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230327211458.498879-1-jaswinder.singh@linaro.org> References: <20230327211458.498879-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 | 57 +++++++ configs/synquacer_developerbox_defconfig | 8 + doc/board/socionext/developerbox.rst | 155 +++++++++++++++++++- include/configs/synquacer.h | 10 ++ 6 files changed, 233 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..29b258f86c --- /dev/null +++ b/board/socionext/developerbox/fwu_plat.c @@ -0,0 +1,57 @@ +// 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); +} + +int fwu_plat_get_alt_num(struct udevice __always_unused *dev, + efi_guid_t *image_id, u8 *alt_num) +{ + return fwu_mtd_get_alt_num(image_id, alt_num, "nor1"); +} + +void fwu_plat_get_bootidx(uint *boot_idx) +{ + int ret; + u32 active_idx; + u32 *bootidx = boot_idx; + + ret = fwu_get_active_index(&active_idx); + + if (ret < 0) + *bootidx = -1; + + *bootidx = active_idx; +} 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, \