From 4ea84c5dce5a96a4ed9f8c410974425ff2167721 Mon Sep 17 00:00:00 2001 From: Balamanikandan Gunasundar Date: Tue, 29 Jun 2021 12:46:11 +0530 Subject: [PATCH 1/7] cmd: nand biterr - Add support for nand biterr command The command shall be used to induce bit errors in the nand page manually. The code flips a bit in the specified offset without changing the ECC. This helps to see how the software handles the error. The patch is ported from https://patchwork.ozlabs.org/project/uboot/patch/\ 1325691123-19565-1-git-send-email-holger.brunck@keymile.com The implementation is inspired from 'mtd-utils/nand-utils/nandflipbits.c' Signed-off-by: Balamanikandan Gunasundar --- cmd/nand.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 124 insertions(+), 3 deletions(-) diff --git a/cmd/nand.c b/cmd/nand.c index df5a4b1db1..e730484d0b 100644 --- a/cmd/nand.c +++ b/cmd/nand.c @@ -17,6 +17,10 @@ * and/or modified under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. + * + * The function nand_biterror() in this file is inspired from + * mtd-utils/nand-utils/nandflipbits.c which was released under GPLv2 + * only */ #include @@ -44,6 +48,116 @@ int find_dev_and_part(const char *id, struct mtd_device **dev, u8 *part_num, struct part_info **part); #endif +#define MAX_NUM_PAGES 64 + +static int nand_biterror(struct mtd_info *mtd, ulong off, int bit) +{ + int ret = 0; + int page = 0; + ulong block_off; + u_char *datbuf[MAX_NUM_PAGES]; /* Data and OOB */ + u_char data; + int pages_per_blk = mtd->erasesize / mtd->writesize; + struct erase_info einfo; + + if (pages_per_blk > MAX_NUM_PAGES) { + printf("Too many pages in one erase block\n"); + return 1; + } + + if (bit < 0 || bit > 7) { + printf("bit position 0 to 7 is allowed\n"); + return 1; + } + + /* Allocate memory */ + memset(datbuf, 0, sizeof(datbuf)); + for (page = 0; page < pages_per_blk ; page++) { + datbuf[page] = malloc(mtd->writesize + mtd->oobsize); + if (!datbuf[page]) { + printf("No memory for page buffer\n"); + ret = -ENOMEM; + goto free_memory; + } + } + + /* Align to erase block boundary */ + block_off = off & (~(mtd->erasesize - 1)); + + /* Read out memory as first step */ + for (page = 0; page < pages_per_blk ; page++) { + struct mtd_oob_ops ops; + loff_t addr = (loff_t)block_off; + + memset(&ops, 0, sizeof(ops)); + ops.datbuf = datbuf[page]; + ops.oobbuf = datbuf[page] + mtd->writesize; + ops.len = mtd->writesize; + ops.ooblen = mtd->oobsize; + ops.mode = MTD_OPS_RAW; + ret = mtd_read_oob(mtd, addr, &ops); + if (ret < 0) { + printf("Error (%d) reading page %08lx\n", + ret, block_off); + ret = 1; + goto free_memory; + } + block_off += mtd->writesize; + } + + /* Erase the block */ + memset(&einfo, 0, sizeof(einfo)); + einfo.mtd = mtd; + /* Align to erase block boundary */ + einfo.addr = (loff_t)(off & (~(mtd->erasesize - 1))); + einfo.len = mtd->erasesize; + ret = mtd_erase(mtd, &einfo); + if (ret < 0) { + printf("Error (%d) nand_erase_nand page %08llx\n", + ret, einfo.addr); + ret = 1; + goto free_memory; + } + + /* Twist a bit in data part */ + block_off = off & (mtd->erasesize - 1); + data = datbuf[block_off / mtd->writesize][block_off % mtd->writesize]; + data ^= (1 << bit); + datbuf[block_off / mtd->writesize][block_off % mtd->writesize] = data; + + printf("Flip data at 0x%lx with xor 0x%02x (bit=%d) to value=0x%02x\n", + off, (1 << bit), bit, data); + + /* Write back twisted data and unmodified OOB */ + /* Align to erase block boundary */ + block_off = off & (~(mtd->erasesize - 1)); + for (page = 0; page < pages_per_blk; page++) { + struct mtd_oob_ops ops; + loff_t addr = (loff_t)block_off; + + memset(&ops, 0, sizeof(ops)); + ops.datbuf = datbuf[page]; + ops.oobbuf = datbuf[page] + mtd->writesize; + ops.len = mtd->writesize; + ops.ooblen = mtd->oobsize; + ops.mode = MTD_OPS_RAW; + ret = mtd_write_oob(mtd, addr, &ops); + if (ret < 0) { + printf("Error (%d) write page %08lx\n", ret, block_off); + ret = 1; + goto free_memory; + } + block_off += mtd->writesize; + } + +free_memory: + for (page = 0; page < pages_per_blk ; page++) { + if (datbuf[page]) + free(datbuf[page]); + } + return ret; +} + static int nand_dump(struct mtd_info *mtd, ulong off, int only_oob, int repeat) { @@ -733,8 +847,15 @@ static int do_nand(struct cmd_tbl *cmdtp, int flag, int argc, } if (strcmp(cmd, "biterr") == 0) { - /* todo */ - return 1; + int bit; + + if (argc != 4) + goto usage; + + off = (int)simple_strtoul(argv[2], NULL, 16); + bit = (int)simple_strtoul(argv[3], NULL, 10); + ret = nand_biterror(mtd, off, bit); + return ret; } #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK @@ -825,7 +946,7 @@ static char nand_help_text[] = "nand scrub [-y] off size | scrub.part partition | scrub.chip\n" " really clean NAND erasing bad blocks (UNSAFE)\n" "nand markbad off [...] - mark bad block(s) at offset (UNSAFE)\n" - "nand biterr off - make a bit error at offset (UNSAFE)" + "nand biterr off bit - make a bit error at offset and bit position (UNSAFE)" #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK "\n" "nand lock [tight] [status]\n" From 32cc3929a173246bf55b2a602082cabd971fc71b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= Date: Wed, 13 Oct 2021 16:00:04 +0200 Subject: [PATCH 2/7] firmware: scmi: fix struct layout for scmi_clk_rate_set_in MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First two fields are reversed compared to what is expected by the SCMI specification. Signed-off-by: Clément Léger Fixes: 60388844836 ("clk: add clock driver for SCMI agents") --- include/scmi_protocols.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/scmi_protocols.h b/include/scmi_protocols.h index 2db71697e8..ef26e72176 100644 --- a/include/scmi_protocols.h +++ b/include/scmi_protocols.h @@ -97,14 +97,14 @@ struct scmi_clk_rate_get_out { /** * struct scmi_clk_state_in - Message payload for CLOCK_RATE_SET command - * @clock_id: SCMI clock ID * @flags: Flags for the clock rate set request + * @clock_id: SCMI clock ID * @rate_lsb: 32bit LSB of the clock rate in Hertz * @rate_msb: 32bit MSB of the clock rate in Hertz */ struct scmi_clk_rate_set_in { - u32 clock_id; u32 flags; + u32 clock_id; u32 rate_lsb; u32 rate_msb; }; From b560c704d66edf30c32c2a588bc1d177750bb418 Mon Sep 17 00:00:00 2001 From: Philippe Reynes Date: Fri, 15 Oct 2021 11:28:47 +0200 Subject: [PATCH 3/7] lib: rsa: rsa-verify: also check that padding is not NULL This commit adds a check on the padding in the function rsa_verify_key to avoid using a NULL pointer. Signed-off-by: Philippe Reynes Reviewed-by: Simon Glass --- lib/rsa/rsa-verify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rsa/rsa-verify.c b/lib/rsa/rsa-verify.c index 600c93ab81..83f7564101 100644 --- a/lib/rsa/rsa-verify.c +++ b/lib/rsa/rsa-verify.c @@ -340,7 +340,7 @@ static int rsa_verify_key(struct image_sign_info *info, struct padding_algo *padding = info->padding; int hash_len; - if (!prop || !sig || !hash || !checksum) + if (!prop || !sig || !hash || !checksum || !padding) return -EIO; if (sig_len != (prop->num_bits / 8)) { From 5d39c9324418405d75c0428ab12e3267afcc8c7e Mon Sep 17 00:00:00 2001 From: Philippe Reynes Date: Fri, 15 Oct 2021 11:35:03 +0200 Subject: [PATCH 4/7] common: Kconfig.boot: add config SPL_FIT_RSASSA_PSS The padding pss is only supported on u-boot and tools since commit 2bbed3ff8c7f ("image: Use Kconfig to enable FIT_RSASSA_PSS on host") This commit adds the config SPL_FIT_RSASSA_PSS to support the padding pss in the SPL. Signed-off-by: Philippe Reynes Reviewed-by: Simon Glass --- common/Kconfig.boot | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/Kconfig.boot b/common/Kconfig.boot index 9b84a8d005..c948d58094 100644 --- a/common/Kconfig.boot +++ b/common/Kconfig.boot @@ -175,6 +175,13 @@ config SPL_FIT_SIGNATURE_MAX_SIZE device memory. Assure this size does not extend past expected storage space. +config SPL_FIT_RSASSA_PSS + bool "Support rsassa-pss signature scheme of FIT image contents in SPL" + depends on SPL_FIT_SIGNATURE + help + Enable this to support the pss padding algorithm as described + in the rfc8017 (https://tools.ietf.org/html/rfc8017) in SPL. + config SPL_LOAD_FIT bool "Enable SPL loading U-Boot as a FIT (basic fitImage features)" select SPL_FIT From 70a9f4d25b4383c22b74a6a4354927644392debb Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Fri, 22 Oct 2021 17:05:47 +0200 Subject: [PATCH 5/7] lib: uuid: fix the test on RNG device presence Correct the test on RNG device presence,when ret is equal to 0, before to call dm_rng_read function. Without this patch the RNG device is not used when present (when ret == 0) or a data abort occurs in dm_rng_read when CONFIG_DM_RNG is activated but the RNG device is not present in device tree (ret != 0 and devp = NULL). Fixes: 92fdad28cfdf ("lib: uuid: use RNG device if present") CC: Matthias Brugger CC: Torsten Duwe Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- lib/uuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/uuid.c b/lib/uuid.c index 67267c66a3..e4703dce2b 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -257,7 +257,7 @@ void gen_rand_uuid(unsigned char *uuid_bin) if (IS_ENABLED(CONFIG_DM_RNG)) { ret = uclass_get_device(UCLASS_RNG, 0, &devp); - if (ret) { + if (!ret) { ret = dm_rng_read(devp, &randv, sizeof(randv)); if (ret < 0) randv = 0; From 73d18e352d97b5e9a3de3780d5c9117d44993c41 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 26 Oct 2021 00:37:05 +0200 Subject: [PATCH 6/7] dfu: Sort Kconfig entries alphabetically The DFU_MTD Kconfig entry is in the wrong position, move it into the correct alphabetically sorted position. No functional change. Signed-off-by: Marek Vasut Cc: Lukasz Majewski Cc: Patrice Chotard Cc: Patrick Delaunay --- drivers/dfu/Kconfig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig index 48e41bc262..8d7f13dcb0 100644 --- a/drivers/dfu/Kconfig +++ b/drivers/dfu/Kconfig @@ -38,6 +38,13 @@ config DFU_MMC help This option enables using DFU to read and write to MMC based storage. +config DFU_MTD + bool "MTD back end for DFU" + depends on DM_MTD + depends on CMD_MTDPARTS + help + This option enables using DFU to read and write to on any MTD device. + config DFU_NAND bool "NAND back end for DFU" depends on CMD_MTDPARTS @@ -72,13 +79,6 @@ config DFU_SF_PART This option enables the support of "part" and "partubi" target in SPI flash DFU back end. -config DFU_MTD - bool "MTD back end for DFU" - depends on DM_MTD - depends on CMD_MTDPARTS - help - This option enables using DFU to read and write to on any MTD device. - config DFU_VIRT bool "VIRTUAL flash back end for DFU" help From 28ab12ad145d92de13baf679c8e3733be99ee95e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 26 Oct 2021 00:41:59 +0200 Subject: [PATCH 7/7] env: superfluous check before free() Free() checks if its argument in NULL. There is no need for the caller to do the same. Signed-off-by: Heinrich Schuchardt --- env/flash.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/env/flash.c b/env/flash.c index ebee9069e4..473e82454d 100644 --- a/env/flash.c +++ b/env/flash.c @@ -210,8 +210,7 @@ static int env_flash_save(void) perror: flash_perror(rc); done: - if (saved_data) - free(saved_data); + free(saved_data); /* try to re-protect */ flash_sect_protect(1, (ulong)flash_addr, end_addr); flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new); @@ -298,8 +297,7 @@ static int env_flash_save(void) perror: flash_perror(rc); done: - if (saved_data) - free(saved_data); + free(saved_data); /* try to re-protect */ flash_sect_protect(1, (long)flash_addr, end_addr); return rc;