aboutsummaryrefslogtreecommitdiff
path: root/test/dm/fwu_mdata.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2022-11-01 09:32:21 -0400
committerTom Rini <trini@konsulko.com>2022-11-01 09:32:21 -0400
commitc8d9ff634fc429db5acf2f5386ea937f0fef1ae7 (patch)
tree5ee0a5efa73f325b172a16db7551af87725fdb1f /test/dm/fwu_mdata.c
parenta90afc6730e6c67ad37f4c98a02891a93b4ff971 (diff)
parent75f11c3bfdcfbadad0265eda74c372e52423ae4c (diff)
Merge branch '2022-10-31-FWU-add-FWU-multi-bank-update-feature-support'
To quote the author: The patchset adds support for the FWU Multi Bank Update[1] feature. Certain aspects of the Dependable Boot[2] specification have also been implemented. The FWU multi bank update feature is used for supporting multiple sets(also called banks) of firmware image(s), allowing the platform to boot from a different bank, in case it fails to boot from the active bank. This functionality is supported by keeping the relevant information in a structure called metadata, which provides information on the images. Among other parameters, the metadata structure contains information on the currect active bank that is being used to boot image(s). Functionality is being added to work with the UEFI capsule driver in u-boot. The metadata is read to gather information on the update bank, which is the bank to which the firmware images would be flashed to. On a successful completion of the update of all components, the active bank field in the metadata is updated, to reflect the bank from which the platform will boot on the subsequent boots. Currently, the feature is being enabled on the STM32MP157C-DK2 and Synquacer boards. The DK2 board boots a FIP image from a uSD card partitioned with the GPT partioning scheme, while the Synquacer board boots a FIP image from a MTD partitioned SPI NOR flash device. This feature also requires changes in a previous stage of bootloader, which parses the metadata and selects the bank to boot the image(s) from. Support has being added in tf-a(BL2 stage) for the STM32MP157C-DK2 board to boot the active bank images. These changes have been merged to the upstream tf-a repository. The patch for adding a python test for the feature has been developed, and was sent in the version 5 of the patches[3]. However, the test script depends on adding support for the feature on MTD SPI NOR devices, and that is being done as part of the Synquacer patches. Hence these set of patches do not have the test script for the feature. That will be added through the patches for adding support for the feauture on Synquacer platform. [1] - https://developer.arm.com/documentation/den0118/a [2] - https://git.codelinaro.org/linaro/dependable-boot/mbfw/uploads/6f7ddfe3be24e18d4319e108a758d02e/mbfw.pdf [3] - https://lists.denx.de/pipermail/u-boot/2022-June/485992.html
Diffstat (limited to 'test/dm/fwu_mdata.c')
-rw-r--r--test/dm/fwu_mdata.c147
1 files changed, 147 insertions, 0 deletions
diff --git a/test/dm/fwu_mdata.c b/test/dm/fwu_mdata.c
new file mode 100644
index 0000000000..b179a65c15
--- /dev/null
+++ b/test/dm/fwu_mdata.c
@@ -0,0 +1,147 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022, Linaro Limited
+ * Copyright (c) 2022, Heinrich Schuchardt <xypron.glpk@gmx.de>
+ */
+
+#include <blk.h>
+#include <common.h>
+#include <dm.h>
+#include <fwu.h>
+#include <fwu_mdata.h>
+#include <log.h>
+#include <malloc.h>
+#include <memalign.h>
+#include <part.h>
+
+#include <dm/test.h>
+#include <test/ut.h>
+
+#include "fwu_mdata_disk_image.h"
+
+/* Block size of compressed disk image */
+#define COMPRESSED_DISK_IMAGE_BLOCK_SIZE 8
+
+static struct udevice *mmc_dev;
+static struct blk_desc *dev_desc;
+
+/* One 8 byte block of the compressed disk image */
+struct line {
+ size_t addr;
+ char *line;
+};
+
+/* Compressed disk image */
+struct compressed_disk_image {
+ size_t length;
+ struct line lines[];
+};
+
+static const struct compressed_disk_image img = FWU_MDATA_DISK_IMG;
+
+/* Decompressed disk image */
+static u8 *image;
+
+static int setup_blk_device(struct unit_test_state *uts)
+{
+ ut_assertok(uclass_get_device(UCLASS_MMC, 0, &mmc_dev));
+ ut_assertok(blk_get_device_by_str("mmc", "0", &dev_desc));
+
+ return 0;
+}
+
+static int populate_mmc_disk_image(struct unit_test_state *uts)
+{
+ u8 *buf;
+ size_t i;
+ size_t addr;
+ size_t len;
+
+ buf = malloc(img.length);
+ if (!buf)
+ return -ENOMEM;
+
+ memset(buf, 0, img.length);
+
+ for (i = 0; ; i++) {
+ if (!img.lines[i].line)
+ break;
+ addr = img.lines[i].addr;
+ len = COMPRESSED_DISK_IMAGE_BLOCK_SIZE;
+ if (addr + len > img.length)
+ len = img.length - addr;
+ memcpy(buf + addr, img.lines[i].line, len);
+ }
+ image = buf;
+
+ return 0;
+}
+
+static int write_mmc_blk_device(struct unit_test_state *uts)
+{
+ lbaint_t blkcnt;
+
+ blkcnt = BLOCK_CNT(img.length, dev_desc);
+
+ ut_asserteq(blkcnt, blk_dwrite(dev_desc, 0, blkcnt, image));
+
+ return 0;
+}
+
+static int dm_test_fwu_mdata_read(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ struct fwu_mdata mdata = { 0 };
+
+ ut_assertok(uclass_first_device_err(UCLASS_FWU_MDATA, &dev));
+ ut_assertok(setup_blk_device(uts));
+ ut_assertok(populate_mmc_disk_image(uts));
+ ut_assertok(write_mmc_blk_device(uts));
+
+ ut_assertok(fwu_get_mdata(dev, &mdata));
+
+ ut_asserteq(mdata.version, 0x1);
+
+ return 0;
+}
+DM_TEST(dm_test_fwu_mdata_read, UT_TESTF_SCAN_FDT);
+
+static int dm_test_fwu_mdata_write(struct unit_test_state *uts)
+{
+ u32 active_idx;
+ struct udevice *dev;
+ struct fwu_mdata mdata = { 0 };
+
+ ut_assertok(setup_blk_device(uts));
+ ut_assertok(populate_mmc_disk_image(uts));
+ ut_assertok(write_mmc_blk_device(uts));
+
+ ut_assertok(uclass_first_device_err(UCLASS_FWU_MDATA, &dev));
+
+ ut_assertok(fwu_get_mdata(dev, &mdata));
+
+ active_idx = (mdata.active_index + 1) % CONFIG_FWU_NUM_BANKS;
+ ut_assertok(fwu_set_active_index(active_idx));
+
+ ut_assertok(fwu_get_mdata(dev, &mdata));
+ ut_asserteq(mdata.active_index, active_idx);
+
+ return 0;
+}
+DM_TEST(dm_test_fwu_mdata_write, UT_TESTF_SCAN_FDT);
+
+static int dm_test_fwu_mdata_check(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+
+ ut_assertok(setup_blk_device(uts));
+ ut_assertok(populate_mmc_disk_image(uts));
+ ut_assertok(write_mmc_blk_device(uts));
+
+ ut_assertok(uclass_first_device_err(UCLASS_FWU_MDATA, &dev));
+
+ ut_assertok(fwu_check_mdata_validity());
+
+ return 0;
+}
+DM_TEST(dm_test_fwu_mdata_check, UT_TESTF_SCAN_FDT);