From patchwork Mon Jan 9 01:06:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 640553 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp1903709pvb; Sun, 8 Jan 2023 17:06:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXsu2OQ+KnoIsbLJJusskR5gUSJGPmTYi+EP80O97JnGRyBofQLNHlQCU/FUQ2cRLYumi0qp X-Received: by 2002:a9d:5604:0:b0:67f:e4ff:2996 with SMTP id e4-20020a9d5604000000b0067fe4ff2996mr32180059oti.12.1673226414864; Sun, 08 Jan 2023 17:06:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673226414; cv=none; d=google.com; s=arc-20160816; b=gdzw62g4UxN8RmI7+LParqqL2gYVd81EsRaNDVUE1gMSYKQcl38iD2jFb+Hpv0XQBX zzaHb596Sv1GCCpCM2J8M5HE2y1wZG6vfic9rEStLLXEQnSwpxRm46mhAJn0vs6SK6Dx fjXBnvV7ivTkOp+AUbXX0OdFKR27bZFwDxpQUm8xUmnZjXT7ycA37gkCUwP+LZ3RHYR7 iezEZKR/E27zOYpZMII0T5ugbvuJ0iyDKbC92SGWPbk3csqxliM9B9IcoxMAOIs8b5yt JoYl/skjO7tzc3raY1V+6vlRfg51HPzR9pyD34Xyzvh5oMZqE/hjQO07w3y8qE4KkPPI iQlQ== 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=/ZAQ5zqws6ceae8ZmqG3wPDftxDEtnQ7miJCwDDx09c=; b=uFCsYNl2jzNYs3olUBGkwrMdb3rj4qHbXzK60CTjBC1J/RfQd0Wpy2ba0Hb+VEBNBk PL1CV9fRD73xBfVIirYbkih8PWVvsb3nzmpjVml58j+fQXIVuwGAPRtGEqLS3ThG8lAt GaEbCVNnXjanjJn6RJJbHvMp6TrSqsW3vAfd0mJQUtyD23gdfokYw6Rl5+pgKvlQhStR p7v1d6jQaSXppAlA/bSMTithTV4zXOZhz2mIwNfT+4xFjyRA0VeOdNEjS+N/jE9PZAME T1xjphIaov62dMS6D3HmNbP2O/CtDFN4OGqdm8STRgh+bySimaqVVS+QNk/SJ4SQGQcu DnzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AR7bSDXZ; 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 w2-20020a9d77c2000000b0066c7b890c56si7321135otl.189.2023.01.08.17.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 17:06:54 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AR7bSDXZ; 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 CFB0A8549A; Mon, 9 Jan 2023 02:06:52 +0100 (CET) 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="AR7bSDXZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D008D8549C; Mon, 9 Jan 2023 02:06:50 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) (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 91D468537F for ; Mon, 9 Jan 2023 02:06:47 +0100 (CET) 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-x12f.google.com with SMTP id o8so4226456ilo.1 for ; Sun, 08 Jan 2023 17:06:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=/ZAQ5zqws6ceae8ZmqG3wPDftxDEtnQ7miJCwDDx09c=; b=AR7bSDXZamUHB1FuDH6g3d7tAYZ4w3vNhvfe8z8UQMzKuK8aY1w1P9GiJuSM+lrqJF u8uYp4kyl5EZswyCtdWwYaz0sOvuU3ABKhihYxbWpKW25qD5oC+gLxlUJDEW7INz6e66 F3+MZczsBt6zEacEg30AxMXkQYoyS+vhyjO8K9VRDmkmph2OroQESLxp/NF80Mo5jT2k vlehIfwvSZBBujW50+c1My/G0WgIP1yXV41sMP7fPG/yzvGnRdBirVBuUk9yYvDkUCts meF4CCT5Fk1aLDRkHhSQcuqYOady+KED4yB1ri4rXUJq9vuFvxyATFl9JD/4YqFfpCIT tJzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=/ZAQ5zqws6ceae8ZmqG3wPDftxDEtnQ7miJCwDDx09c=; b=o83NL0GjwG/q/cGJbIIZOIEVQvFLQyGcE1gGskHgw+kbp0njbYMeyYsXFWCgagVX8j XTtoNHfAkBdyVWuF7gdx1cocG6qypdzWFi/9syS8qLR7kItKZYH/M/UEahYDT8/1yIcT shqdk4P4FBp3RNMU6LUKsG1mImYt5x1uHqTXUw2iQzAdWEMdcFQta90z2nUszN6mZF4A TXF4Ycmp3Vb27pZMBSqVZPMaLA1Hug86ezLWo1x4A699zK8yUzbzcj/mtrxFDxUW+dBr 1uo5o8tMgaynv1A7E/TxgFpsbRWr1dC5QVRfSCb5vtd8DS96e08QN8XGEM+eecm/g/SO i9Qg== X-Gm-Message-State: AFqh2kqNsczKcNC759pBuQPN8HzGVXVotVM8gxqjn4PTAlGl5vBVclZZ gsE2UqA8bLslHumBVO4nkY1wH4OZ4p0= X-Received: by 2002:a05:6e02:13f2:b0:30d:9f9c:cd35 with SMTP id w18-20020a056e0213f200b0030d9f9ccd35mr2928676ilj.21.1673226405851; Sun, 08 Jan 2023 17:06:45 -0800 (PST) Received: from jassi-Alienware-x17-R2.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id p32-20020a056638192000b0039e89ea68f9sm465328jal.135.2023.01.08.17.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 17:06:45 -0800 (PST) From: Jassi Brar X-Google-Original-From: Jassi Brar 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, Jassi Brar Subject: [PATCHv3 1/5] FWU: Add FWU metadata access driver for MTD storage regions Date: Sun, 8 Jan 2023 19:06:42 -0600 Message-Id: <20230109010642.578484-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230109010601.578439-1-jaswinder.singh@linaro.org> References: <20230109010601.578439-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.6 at phobos.denx.de X-Virus-Status: Clean From: Sughosh Ganu 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: Sughosh Ganu Signed-off-by: Jassi Brar --- drivers/fwu-mdata/Kconfig | 15 +++ drivers/fwu-mdata/Makefile | 1 + drivers/fwu-mdata/raw_mtd.c | 201 ++++++++++++++++++++++++++++++++++++ 3 files changed, 217 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..edd28b4525 --- /dev/null +++ b/drivers/fwu-mdata/raw_mtd.c @@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2023, Linaro Limited + */ + +#define LOG_CATEGORY UCLASS_FWU_MDATA + +#include +#include +#include +#include + +#include +#include + +/* Internal helper structure to move data around */ +struct fwu_mdata_mtd_priv { + struct mtd_info *mtd; + u32 pri_offset; + u32 sec_offset; +}; + +enum fwu_mtd_op { + FWU_MTD_READ, + FWU_MTD_WRITE, +}; + +#define FWU_MDATA_PRIMARY true +#define FWU_MDATA_SECONDARY false + +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); +} + +/** + * fwu_mdata_mtd_of_to_plat() - Translate from DT to fwu mdata device + */ +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; + int ret, size; + u32 phandle; + + /* 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 -ENOENT; + } + + /* Get the offset of primary and seconday mdata */ + ret = ofnode_read_u32_index(dev_ofnode(dev), "mdata-offsets", 0, + &mtd_priv->pri_offset); + if (ret) + return ret; + ret = ofnode_read_u32_index(dev_ofnode(dev), "mdata-offsets", 1, + &mtd_priv->sec_offset); + if (ret) + return ret; + + 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 Jan 9 01:06:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 640554 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp1903823pvb; Sun, 8 Jan 2023 17:07:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXuulHmfmotT/xm9XQbufoAEtsOEiqE4ISxpKZX+V0aaRrmjGwie+HmKYJcia4ed+MA3jdAc X-Received: by 2002:a05:6870:d393:b0:150:14a3:6556 with SMTP id k19-20020a056870d39300b0015014a36556mr22383151oag.51.1673226431861; Sun, 08 Jan 2023 17:07:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673226431; cv=none; d=google.com; s=arc-20160816; b=R0idyfeoLqE5KGEpqD1iAAKGBJroSNsZgAYVT1a0gUz4xqLUOMJXgtk8I22p6uKe9w e5wlU85aVf2itpx4bqAUqL4gREi2rJuSj1fUO31fUXjpLfC2rhNRjeFF7dQku+t4r/FB p8ck/Xdn2JrYeYgXH9oe+xcGnHkqW8um6T7mNTPjHlqbOLeL8brr7Ul5sVh8lWSQFe9v TByUol7rA9HAOG+ze0C6s216S0GvGYrn0H1Lx/ew7pKDoMy40x8wYPgn4cU1iq6kd0F0 4AdtSUxphF9TvJfV7vBrOk9WhVGIJfBXmtu8DJh/3qjMY5S57uYdmf3wR7x270OicLGw 2FOw== 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=v1WlK9ZSrEstNPg0dX6at0UABI80US4aHUxGa3j5XWk=; b=QGgz93kV+tuWHJHntDvEDx5ZZJlyDdUzxE619EgFUY7VPGN74KkfC51tfeVG9N17th rBQp2RfJTAGZw6nija2pz43NaW5vhK/JeHG0tFfzgomBEeGFqpCnmLus3NM6/i/H+4rC RYNcd8MyDA/Pf3OrubVmdVQM44XuXTGbb23ivH0PeU+wfMS0XC5yonAl+uZNn0oJE+6v nJDvK0lhnRT/qZxZ1iWqbehHdqnMzniu4bhIyAwiZtbB7bTa0LmPSmlibTC2ipt9wcGF Br5ki1Oc6ZYDfeWzKw0wH2bwvS9Kco1fz0b4tDoohr65vtQ3fLJ1gHJkqlIoqVLH8xdb IBOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AdhA5nlZ; 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 e2-20020a4ac3c2000000b004ec437a6117si6528517ooq.37.2023.01.08.17.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 17:07:11 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AdhA5nlZ; 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 ABE74854F4; Mon, 9 Jan 2023 02:07:09 +0100 (CET) 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="AdhA5nlZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D8A34854B1; Mon, 9 Jan 2023 02:07:07 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) (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 5D5CE85548 for ; Mon, 9 Jan 2023 02:07:00 +0100 (CET) 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-x12d.google.com with SMTP id y2so4219875ily.5 for ; Sun, 08 Jan 2023 17:07:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=v1WlK9ZSrEstNPg0dX6at0UABI80US4aHUxGa3j5XWk=; b=AdhA5nlZ7kPYSrfvqoqNATQ6iTmvrddu8MBWYE2g8b55DVgv7izgZYrMJlfdKKVNaB np9rusuTqNyIqankjF6HD9qnkRvsJC/zByHWy7xBuVZLQ2aFZ5KEZowuwz36aqOG1RJe 2d2LXED/CudOvWS0Stkv/XgbSwDIvzuI22b6yTp8qWcOa+O2wEMWwDMvLskdfAK5ma+p LrGA5cYNtRnEtZvh5wPSTkUMshpW8SQN7TQ3iKmQWX4FNdVct8Frwtbf1ekxX74zsWED VoUtDgtZcL0wE+QMBLuFQ0YxQHyOW9+wl0Gj2Q+7Uxj8SboDT5VGLVVErPVp2DCobQHb tDZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=v1WlK9ZSrEstNPg0dX6at0UABI80US4aHUxGa3j5XWk=; b=ejxgAGES+Hr0bi66Iy+aENWO6akpNPN3rYb2FI0h92R8Tmf0AXfKYETYl7OYMNQ+0z 3gokLq1s7uLJ7d56tfMzuLl2V8oAAtGpBakckIHklSlxZumV4cZ6jGPx49CXJS2nxNkr /7USMTWne59CO/8b6BlBeAskARm8n6Tfm5Ktq0xE5JD+M87R4CvO8FUMmOzXJ83Io5tG NVnP0T2Wrt21+BjqGpB3pIceXSeAxTpMkHZyqRV/M00bMAgulc8z5CKPijBVM6FXevJI x5QOxdGEtYTmAZ8VtmZ1MKiWVAsTtliGkoAQ8+J9hqTo1Vr/ES/KC3CKG0gAw9DvIa9Y 0MjQ== X-Gm-Message-State: AFqh2kpmKdYMXeZ320bRfF2ri5Fw6YwiqQ6kXlTEj1TmMxIkHNVfMnO1 3xcC/PVzZPxtkMwLKWqeloi0Wjc5v9w= X-Received: by 2002:a05:6e02:58a:b0:303:8c18:1283 with SMTP id c10-20020a056e02058a00b003038c181283mr42511704ils.31.1673226418472; Sun, 08 Jan 2023 17:06:58 -0800 (PST) Received: from jassi-Alienware-x17-R2.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id c32-20020a023f60000000b0038a01eba60fsm2385315jaf.69.2023.01.08.17.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 17:06:58 -0800 (PST) From: Jassi Brar X-Google-Original-From: Jassi Brar 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, Jassi Brar Subject: [PATCHv3 2/5] FWU: mtd: Add helper functions for accessing FWU metadata Date: Sun, 8 Jan 2023 19:06:54 -0600 Message-Id: <20230109010654.578506-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230109010601.578439-1-jaswinder.singh@linaro.org> References: <20230109010601.578439-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.6 at phobos.denx.de X-Virus-Status: Clean From: Sughosh Ganu Add helper functions needed for accessing the FWU metadata which contains information on the updatable images. Signed-off-by: Sughosh Ganu Signed-off-by: Jassi Brar --- include/fwu.h | 27 ++++++ lib/fwu_updates/Makefile | 1 + lib/fwu_updates/fwu_mtd.c | 172 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 lib/fwu_updates/fwu_mtd.c diff --git a/include/fwu.h b/include/fwu.h index ea25aca2cd..2edfa72caf 100644 --- a/include/fwu.h +++ b/include/fwu.h @@ -8,6 +8,7 @@ #include #include +#include #include @@ -251,4 +252,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 charaters 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..1895b8fab3 --- /dev/null +++ b/lib/fwu_updates/fwu_mtd.c @@ -0,0 +1,172 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +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; + ofnode node, parts_node; + fdt_addr_t offset, size; + char uuidbuf[UUID_STR_LEN + 1]; + + mtd_probe_devices(); + mtd = get_mtd_device_nm(mtd_dev); + + /* Find partition node under given MTD device. */ + parts_node = ofnode_by_compatible(mtd_get_ofnode(mtd), + "fixed-partitions"); + + uuid_bin_to_str(image_id->b, uuidbuf, UUID_STR_FORMAT_STD); + node = ofnode_by_prop_value(parts_node, "uuid", uuidbuf, + sizeof(uuidbuf)); + if (!ofnode_valid(node)) { + log_warning("Warning: Failed to find partition by image UUID\n"); + return -ENOENT; + } + + offset = ofnode_get_addr_size_index_notrans(node, 0, &size); + if (offset == FDT_ADDR_T_NONE || !size) + return -ENOENT; + + 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(); + + 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; + const char *suuid; + ofnode node, parts_node; + char uuidbuf[UUID_STR_LEN + 1]; + char *p = buf, *end = buf + len; + + /* Find partition node under given MTD device. */ + parts_node = ofnode_by_compatible(mtd_get_ofnode(mtd), + "fixed-partitions"); + if (!ofnode_valid(parts_node)) + return -ENOENT; + + /* Check the media UUID if exist. */ + suuid = ofnode_read_string(parts_node, "uuid"); + if (suuid) { + log_debug("Got location uuid %s\n", suuid); + uuid_bin_to_str(img->location_uuid.b, uuidbuf, UUID_STR_FORMAT_STD); + if (strcasecmp(suuid, uuidbuf)) + log_warning("Warning: Location UUID does not match!\n"); + } + + 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_image_bank_info *bank; + fdt_addr_t 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); + node = ofnode_by_prop_value(parts_node, "uuid", uuidbuf, + sizeof(uuidbuf)); + if (!ofnode_valid(node)) { + log_err("Failed to find partition by image UUID\n"); + break; + } + + offset = ofnode_get_addr_size_index_notrans(node, 0, &size); + if (offset == FDT_ADDR_T_NONE || !size) + break; + + p += snprintf(p, end - p, "%sbank%d raw %lx %lx", + i == 0 ? "=" : ";", i, (unsigned long)offset, + (unsigned long)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_debug("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 Jan 9 01:07:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 640555 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp1903872pvb; Sun, 8 Jan 2023 17:07:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXtfSy06AQmL/MLdn822eKiOXlLjlWU1YQl2WsCXce4MFbyGrtsIz0+34TjSUJT18fAbku7G X-Received: by 2002:a05:6830:55:b0:670:61f7:6457 with SMTP id d21-20020a056830005500b0067061f76457mr32213214otp.29.1673226442741; Sun, 08 Jan 2023 17:07:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673226442; cv=none; d=google.com; s=arc-20160816; b=dBnk1J81IT8Q43elnXWr9VZ9tMMpBodoEM1ehwKPTX7J/esP4YTIQC2gcLsRYUS/Uo I5kYyOCL7CBaXYwKe1qth+GcDB6c5p4p8gJwYr65vk7UFyO0tWcXQp3q/uIoQxhkr4GS K+DcDi4zo055sNX3Y63E4Y9sK8a7Caxxk4YpCW2Ei7WY+WR/hmHkwsEpXatMHSpxN5iU w8v4Nk2LROamB/G1Poj1GDooXx8B7xKrhDG/RNVotQAhJBvdV8dtxihakaWfliqW3I/D nQG4KblzAWfrQ2k4JTr4IUIEKQppCXYQwCUvx6GEL/llRV8oEok+Ggt+AZua2mbyMRO4 XU+Q== 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=9yLezMasoQ4AoEqXOvGtZB63zneL/bwFkAHf5U/QudQ=; b=MdHm8y16sacrWbTbc8N02R4G4m0hExBaY2NwPXY+NnYO2fmuWRqhh2XMI+Nm6zDtWq OXB6ufb39tqdtXv/ttifLLsx+tOtnnPU/pRQXSfSrOO0GNSNPJ1NQZzb5blt8LU4A2Mk JCMgBHnMkk/GF6zU11c8KDF4EbPQKd3NIA7XOOXK4daDp3bZygP/LRAF4CUHT2xsWwzu PtXLfpELPVU94sfJGB9raxycRnqED+7BZvHVsLTb+0qGzsRaaFNpKSqpop0IjaWFs7dW y4FlEGFiPkO+lLPzqGHPIcRpmS4dXK0sU1tyZ9wWdtzip0ozHBusma9bpD2puywTzCkA FFVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=B4TuMak7; 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 s38-20020a0568302aa600b00661e60b4e67si6991048otu.212.2023.01.08.17.07.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 17:07:22 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=B4TuMak7; 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 254A78555D; Mon, 9 Jan 2023 02:07:20 +0100 (CET) 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="B4TuMak7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 172F185520; Mon, 9 Jan 2023 02:07:11 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) (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 CC3288544F for ; Mon, 9 Jan 2023 02:07:07 +0100 (CET) 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-x12f.google.com with SMTP id o13so4208231ilc.7 for ; Sun, 08 Jan 2023 17:07:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=9yLezMasoQ4AoEqXOvGtZB63zneL/bwFkAHf5U/QudQ=; b=B4TuMak74UIH+KD4FT1/fzPpDlJpRQzt6JWqdhCd9sAUEzkEeaJ/qCqCqFhzEGIlQ6 gKU+q4YdWKv6oxZLhiww+yp+dND95DliOnuqCumskn5PeSSwZeVr8GCrINgvTNO7M/EX H9ldesEnCiyqbB8p2LBP8R4O+KGlf6IVFPrEfKG6bDgbp4r5iJD+knGBbX5JNuvvtQAk w3oXGEiPrpsx4Nr0ykrALUd82/SWeg2WUQkm3gE9ct7nn+FlPxwHymMn2FS4nrdJigKJ BSzSELMx+6+zUKlYrDZqBKtH76kjzkl9LUlQKrXL0fZOZRGziyY7nr9It7gfq5CnUJII 4hnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=9yLezMasoQ4AoEqXOvGtZB63zneL/bwFkAHf5U/QudQ=; b=P8G8mxbRTnHJyr5aqdLZhe0lHF7qAi7C5l0ocFgZjQ7igdKzALWLMnU/nILglkmv6l gM17xq7e/0QkxQuUgbCctAInoaVOb5lNEaATF3Mvj8FQB14+L+WITh7ybfwYiG6jXJEF gMG4Nv14qX/FFE3hGSjbp+ua7Yw65ly3mW6FGAT7BfCTa0GmkR0bpjKEXKcTNMpf8VEX zfBYiklLoklsKaFl1aYfI3WwGYoAmldakbATOoS6L+t+WGmAWO37XH9kvbTKS3fpT1bI y9chcigQH54AkgwevWYOa+Lv95gJ9xSu2mCj00hMA2wnsH3tbk2f5TvINxmCp3KuLQ4e 4xTg== X-Gm-Message-State: AFqh2kpKgOgwyvmFjgXOz09wpAVm+IImRtZ31oLR0P7QBzgdft+RTcy3 izAJEITnlGLFD1YPQ8lB5JJJsPpbIag= X-Received: by 2002:a92:c98e:0:b0:304:c91b:4a5c with SMTP id y14-20020a92c98e000000b00304c91b4a5cmr39192717iln.24.1673226426187; Sun, 08 Jan 2023 17:07:06 -0800 (PST) Received: from jassi-Alienware-x17-R2.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id g5-20020a05663810e500b0037556012c63sm2321899jae.132.2023.01.08.17.07.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 17:07:05 -0800 (PST) From: Jassi Brar X-Google-Original-From: Jassi Brar 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, Jassi Brar Subject: [PATCHv3 3/5] dt: fwu: developerbox: enable fwu banks and mdata regions Date: Sun, 8 Jan 2023 19:07:02 -0600 Message-Id: <20230109010702.578523-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230109010601.578439-1-jaswinder.singh@linaro.org> References: <20230109010601.578439-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.6 at phobos.denx.de X-Virus-Status: Clean Specify Bank-0/1 and fwu metadata mtd regions. Signed-off-by: Jassi Brar Acked-by: Ilias Apalodimas --- .../synquacer-sc2a11-developerbox-u-boot.dtsi | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi b/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi index 7a56116d6f..62eee0aaf0 100644 --- a/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi +++ b/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi @@ -23,7 +23,7 @@ active_clk_edges; chipselect_num = <1>; - spi-flash@0 { + spi_flash: spi-flash@0 { #address-cells = <1>; #size-cells = <1>; compatible = "jedec,spi-nor"; @@ -36,6 +36,7 @@ compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>; + uuid = "17e86d77-41f9-4fd7-87ec-a55df9842de5"; partition@0 { label = "BootStrap-BL1"; @@ -79,6 +80,19 @@ label = "Ex-OPTEE"; reg = <0x500000 0x200000>; }; + + /* FWU Multi bank update partitions */ + partition@600000 { + label = "FIP-Bank0"; + reg = <0x600000 0x400000>; + uuid = "5a66a702-99fd-4fef-a392-c26e261a2828"; + }; + + partition@a00000 { + label = "FIP-Bank1"; + reg = <0xa00000 0x400000>; + uuid = "a8f868a1-6e5c-4757-878d-ce63375ef2c0"; + }; }; }; }; @@ -104,6 +118,12 @@ optee { status = "okay"; }; + + fwu-mdata { + compatible = "u-boot,fwu-mdata-mtd"; + fwu-mdata-store = <&spi_flash>; + mdata-offsets = <0x500000 0x530000>; + }; }; }; From patchwork Mon Jan 9 01:07:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 640556 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp1903945pvb; Sun, 8 Jan 2023 17:07:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXtGbU+iiU2Sw4ffWkNa8+e329XB4s/xmoUZr8EdcsjUXErTjwFAkLp/tp9iXnDp+Lwv/ROM X-Received: by 2002:a05:6870:7d0e:b0:15a:db00:7816 with SMTP id os14-20020a0568707d0e00b0015adb007816mr1151648oab.21.1673226455999; Sun, 08 Jan 2023 17:07:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673226455; cv=none; d=google.com; s=arc-20160816; b=izujl1cbwmJuy2Dmz/zsATrB0uEcPW7rPpjkkd0dPFSHDrIyJFxr8/F2h6OEt8NcgI 7e6P4lDEes6TrXI6fmiA1A4EwcNlcl/YPvPnpWWmllg0A9/nGXTcI9bSvoeMNT4uW8XN f5MMBB7S1IyflYjeOxPltNGSA30pb90cML4AbaleyPvFl7tKfnN7N/nV9k05cTv65SC3 Q5tFoxtQKZfd4q1DnFbMVVg800oUyKdMCaNVDHORfoLgGoRXqwtqYVRBzUkDTRBpwpff 7A3EQyJodTYg2C+HtISEYVKBTvKYdq8OOu8oawU1NmMDtotSatmzo9tedsKX6EB5dWsh oUCA== 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=2jXnZobeq7ovfl7VOLBJDNZpQvcNG1FgOQAJU29Ovzs=; b=IywgKTZX20KCUjfKTPNufnCcq6vt+gFglnw9XVdR7HQq8gJ19VT/xQiAD7rG5EP5Jm iosW+QkXbjj2mx6VOJEL0Gvj5nX/Eiu/pj9cxr9R9HiGxrQf2J39V+DfSfbZB/FeJ/Y+ IOtW9/a51twWWw2NXTqRZWnqEQ8k4aQyyF1Hq6EBFs05xfSrlmauaQnS8saib4g1yGI2 d4UfWUdzSE6+Pal3vOIam9zpYYB9KOm9WCzLflqGwFX5qJUOPSzbU+8yFYt6GuAh0uAD 3vvfcuWDCbHGcRcWyllBog6rK3Lgt1gw0jLJ8Jet8Iyv4Q2H2x2dq5SrEIt+Y67tsnMV 7ZBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FxVB8ZZm; 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 q37-20020a056871082500b0014366f5b79esi6568277oap.205.2023.01.08.17.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 17:07:35 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FxVB8ZZm; 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 E11CC854BF; Mon, 9 Jan 2023 02:07:25 +0100 (CET) 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="FxVB8ZZm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C528A85602; Mon, 9 Jan 2023 02:07:22 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) (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 7C2C085548 for ; Mon, 9 Jan 2023 02:07:15 +0100 (CET) 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-x136.google.com with SMTP id a9so3594698ilp.6 for ; Sun, 08 Jan 2023 17:07:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=2jXnZobeq7ovfl7VOLBJDNZpQvcNG1FgOQAJU29Ovzs=; b=FxVB8ZZmHnprnpK/7RoSATd4uVSB8m/5f5V3X8Ozsb+JkGPxEZgdDDjgz37ooKFDtY SQzfxLzT1JycJLlsUlTylBKlddE1SPzdIHxEkmtektGQIfmGtRLdcbgEnKGAGIo6Nsfr JzwmuvR1Qs8pdpUl+9dPegckDRen8f8mfD/l1d7/zKxHm2z0CdAopjX9Kx2NmqdraDa4 DC+xcDzS0W/fUiWEXCAShseGDX7a+/5bDJq5465UcUNVPVcLuBRYVhKrRhrhvn3xjjZZ BdAe8IqfWK/JmMiCUSLeRtu68EUlPk//HhvXPOHCUzumlj0AARKUY6+9ZCagE0ObeKtq kaYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=2jXnZobeq7ovfl7VOLBJDNZpQvcNG1FgOQAJU29Ovzs=; b=qY+2XMV11mIf4PZEZ23KLxFF1GB4r+W9Woii7/+MbyHIHzyT1iFyYHU9TbxmjY9Oul DRw0awlKf3T5yUUAr5yOZefceseDI1ElRq1dad6+niIij5V5IbV0I2faMCZ4u2HTyKdP IxUDZGuWTe/ezicNpaKyYF6V1UcGvDkQdVNek6Pbr9G327U3nAZ7VL8sJyEeOnUe2RfE wRDxMr+IEXVGOvTJhIzCtl18vP1zJHnm//fW1CCQSnYcNxXWtUMG1ljOSpSnb+Fh2Q9j CQHHh0JYOelkROPZhi4Xup69iiwPUWU/mfa9QltKdRwt0rJDebReMzwOD5Z6w7DWaNsx 5o/w== X-Gm-Message-State: AFqh2ko57fP8cw+5nSSK3eh9x9f16+jn8BN4WV4QCGfKKQpzqNWV9Djb YmliTQc1B7ZAQTLygH8f31G3XXYgHxw= X-Received: by 2002:a92:1941:0:b0:30c:5c54:c25a with SMTP id e1-20020a921941000000b0030c5c54c25amr11663499ilm.14.1673226433706; Sun, 08 Jan 2023 17:07:13 -0800 (PST) Received: from jassi-Alienware-x17-R2.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id e18-20020a921e12000000b0030d7c4bc3aesm2318423ile.72.2023.01.08.17.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 17:07:13 -0800 (PST) From: Jassi Brar X-Google-Original-From: Jassi Brar 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, Jassi Brar Subject: [PATCHv3 4/5] fwu: DeveloperBox: add support for FWU Date: Sun, 8 Jan 2023 19:07:09 -0600 Message-Id: <20230109010709.578546-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230109010601.578439-1-jaswinder.singh@linaro.org> References: <20230109010601.578439-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.6 at phobos.denx.de X-Virus-Status: Clean 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 | 13 ++- doc/board/socionext/developerbox.rst | 96 +++++++++++++++++++++ include/configs/synquacer.h | 10 +++ 6 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 board/socionext/developerbox/fwu_plat.c diff --git a/board/socionext/developerbox/Makefile b/board/socionext/developerbox/Makefile index 4a46de995a..9b80ee38e7 100644 --- a/board/socionext/developerbox/Makefile +++ b/board/socionext/developerbox/Makefile @@ -7,3 +7,4 @@ # obj-y := developerbox.o +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu_plat.o diff --git a/board/socionext/developerbox/developerbox.c b/board/socionext/developerbox/developerbox.c index 6415c90c1c..2123914f21 100644 --- a/board/socionext/developerbox/developerbox.c +++ b/board/socionext/developerbox/developerbox.c @@ -20,6 +20,13 @@ #if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) struct efi_fw_image fw_images[] = { +#if defined(CONFIG_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 f69b873a36..b1085a388e 100644 --- a/configs/synquacer_developerbox_defconfig +++ b/configs/synquacer_developerbox_defconfig @@ -1,10 +1,11 @@ CONFIG_ARM=y CONFIG_ARCH_SYNQUACER=y -CONFIG_TEXT_BASE=0x08200000 +CONFIG_POSITION_INDEPENDENT=y +CONFIG_SYS_TEXT_BASE=0 CONFIG_SYS_MALLOC_LEN=0x1000000 CONFIG_SYS_MALLOC_F_LEN=0x400 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" @@ -96,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..be872aa79d 100644 --- a/doc/board/socionext/developerbox.rst +++ b/doc/board/socionext/developerbox.rst @@ -85,3 +85,99 @@ Once the flasher tool is running we are ready flash the UEFI image:: 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 synqucer_developerbox_defconfig + make -j `noproc` + cd ../ + +By default, the CONFIG_FWU_NUM_BANKS and COFNIG_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_EMB_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 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 \ + SPD=opteed SQ_RESET_TO_BL2=1 GENERATE_COT=1 MBEDTLS_DIR=../mbedtls \ + 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. + +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 0x600000 offset.:: + + flash rawwrite 600000 180000 + >> Send SPI_NOR_NEWFIP.fd 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 63d897d090..c798a23bed 100644 --- a/include/configs/synquacer.h +++ b/include/configs/synquacer.h @@ -41,19 +41,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 Jan 9 01:07:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 640557 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp1904006pvb; Sun, 8 Jan 2023 17:07:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXvkLKBQL7BxjPa4I6Z428IzK0sRhN2uuvFZNX2vYEuM+7iM1nFQvh3zwfh64DsypNCU/Lgz X-Received: by 2002:a05:6830:1652:b0:670:6328:f4bb with SMTP id h18-20020a056830165200b006706328f4bbmr31820334otr.24.1673226468387; Sun, 08 Jan 2023 17:07:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673226468; cv=none; d=google.com; s=arc-20160816; b=X9xwJ1qQn8g3eoKhyJp4QJ58Q6H0hyvBZj0mqOjd6TkTNLQqTziwqaW5opuze6Hynm IxU6LH/kKBR+MUTsq0fPRDyz5jeAyqgKhG6ptSUY3a+jC90F9QBiM9pRj34jljMnisDG IvCZhzRUjeUU3sxlOqHnEItZGWtwIufwOfnowGJxAR3PAWI+MHT94fHk1c0mwqtN2B9k nScDqfcWFDGPF47LI0buYYW5Mn46JURt/Tops+dwo0SpUQNYNVX02+Y5iGgMp1Reg1R+ orHJrx36njA/GA1mMDoAE9aCaqDsTIv+sz93AAhImdJG1Pei/6iry6IIq0GZhBcCLeVB dE6w== 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=m3TsJxEgofguXr786SP01F8KbiytxLj72Zy+gO227vE=; b=k2uwl/bcYODdFD6kCXv5XvNdqFQj0GabYwI/lrfe1wMuS9ayQY8yVqVO3d8x/fqZ8M v9BO7IuNmP3FyBFV9IXl0tsQGkjlePkr4KxkNts01M8wfA1co9gaa9/ydf2Yl/Er6xoo S4WCzp7uv4AL+KDSb6eqAoaiIjnbBlpwt9/shES+G8T7T+Z/1jEjELYfRbJuAYvouhQn bPasuGUHtXiZzHdNVODw4xD07w6bJqZnD8zGQscOTfjWW19Ila8HjJ8jM4uQanySeKsQ u2C/zOvXVtkLJONSWBIO5P/CP6z94XSiFFApDUKBo3SyYoVhmRP3149g3ssxVBuSYmM+ SMLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lNe7er9q; 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 s20-20020a056830439400b00670723eeb81si8702125otv.320.2023.01.08.17.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 17:07:48 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lNe7er9q; 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 91A728560A; Mon, 9 Jan 2023 02:07:32 +0100 (CET) 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="lNe7er9q"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6D9968546C; Mon, 9 Jan 2023 02:07:29 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) (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 74C7285603 for ; Mon, 9 Jan 2023 02:07:22 +0100 (CET) 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-xd2f.google.com with SMTP id d123so3877770iof.6 for ; Sun, 08 Jan 2023 17:07:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=m3TsJxEgofguXr786SP01F8KbiytxLj72Zy+gO227vE=; b=lNe7er9qeltKP1NPNImgXsApnmidiH36td1zxEkymntfLbfuy6wcbWH7f55mp6O21S aX36TyX8WQm6bu5eoP9BOEXHbgdzH3Q01Y1lJfrj6Z0aXrx1l5rLGT8xOazCd5udfgMW 9htfpguT5YACwlA9bgiafpIesMYssr5SlWPzFAHHHYzExxKx4dgrNAhDx532EfbZl+Cq mQNzqeFi6jiI/PB6WZZ9Plm599Ah3dANwEU8U+wnZi1ADFgKzkuDX/FYSd7ne6C/GM20 HPR1Y/9PitIEENE1Pqv4nna1Z+3qesZnZMkKzXVDnjetvR3hIvmCTwJhXLnByjIaBBEr 0E2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=m3TsJxEgofguXr786SP01F8KbiytxLj72Zy+gO227vE=; b=7l4Quxz7wEj/uuCCZs83m8lIfpnKgyLSFRK4HdBHV6uZr1dwTBcRkkP6wNPlj6ag/j 5lvI5cihCmIZQM51sWlAyZRrYBXu5x3KG5lI/aMUDp1Bw5ZiQpvZTcMSFYdf4ybVR5Cn MJR7VxlLMlmsJTt9+8u9tsEDUJO6RfBxYTa0sxKMs2Ue+J3S3utDJz6jARB8OLj+2MlR fx2M3PF2ivYJERouaKErEZ4Js17gn2y0B17FV5e0+PU3bXVMXqc5xs96DOyJuy5htPwa rtzmXbJWnszF3nNWyB2nydRyfHPNHudb1KOAhoDUl9hzj6pUkj4eUM9w216tt8Wiq5Yq Qc9Q== X-Gm-Message-State: AFqh2kqszalVTgIC9TdZeZPdQ53t5Ou3v5Sq1G0+ZGKx7Z0RNiGShLCk GyTw39nB4rE9R0PwcSorDVwq7j2eTTM= X-Received: by 2002:a05:6602:314e:b0:6bc:d712:c30f with SMTP id m14-20020a056602314e00b006bcd712c30fmr41829439ioy.6.1673226440700; Sun, 08 Jan 2023 17:07:20 -0800 (PST) Received: from jassi-Alienware-x17-R2.. (wnpgmb0311w-ds01-45-177-228.dynamic.bellmts.net. [206.45.177.228]) by smtp.gmail.com with ESMTPSA id k15-20020a02334f000000b0039d71c46577sm1292314jak.21.2023.01.08.17.07.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 17:07:20 -0800 (PST) From: Jassi Brar X-Google-Original-From: Jassi Brar 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, Masami Hiramatsu , Jassi Brar Subject: [PATCHv3 5/5] tools: Add mkfwumdata tool for FWU metadata image Date: Sun, 8 Jan 2023 19:07:17 -0600 Message-Id: <20230109010717.578564-1-jaswinder.singh@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230109010601.578439-1-jaswinder.singh@linaro.org> References: <20230109010601.578439-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.6 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 | 326 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 339 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 26be0a7ba2..024d6c8eca 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -255,6 +255,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..e0b6702039 --- /dev/null +++ b/tools/mkfwumdata.c @@ -0,0 +1,326 @@ +// 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: Endianess 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\t img_uuid_00,img_uuid_01...img_uuid_0b,\n" + "\t\t img_uuid_10,img_uuid_11...img_uuid_1b,\n" + "\t\t ...,\n" + "\t\t img_uuid_i0,img_uuid_i1...img_uuid_ib,\n" + "\t\t where 'b' and 'i' are number of banks and numbder of images in a bank respectively.\n" + ); +} + +static int active_bank = 0; +static int previous_bank = INT_MAX; /* unset */ +static bool __use_guid = false; + +struct fwu_mdata_object { + size_t images; + size_t banks; + size_t size; + struct fwu_mdata *mdata; +}; + +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; +} + +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); +} + +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. + */ +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; +} + +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; +} + +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. */ +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; +} + +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; + + 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; +}