[PATCH] test: cmd: mbr: Remove unreachable code

2023-11-07 Thread Alexander Gendin
Fix Coverity (CID 467404): Control flow issues (DEADCODE).
Fix code indentation.

Reported-by: Coverity (CID 467404)
Signed-off-by: Alexander Gendin 
---
 test/cmd/mbr.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/test/cmd/mbr.c b/test/cmd/mbr.c
index 5d7402154d..46b78e706c 100644
--- a/test/cmd/mbr.c
+++ b/test/cmd/mbr.c
@@ -205,16 +205,14 @@ static unsigned build_mbr_parts(char *buf, size_t 
buf_size, unsigned num_parts)
bytes_remaining -= cur_str_size;
 
}
-   else if (num_parts == 5) {
-   cur_str_size = sizeof(mbr_parts_p5);
-   if (cur_str_size + 1 > bytes_remaining)
-   return 1;
-   strcat(cur_buf, mbr_parts_p5);
-   bytes_remaining -= cur_str_size;
+   else if (num_parts == 5) {
+   cur_str_size = sizeof(mbr_parts_p5);
+   if (cur_str_size + 1 > bytes_remaining)
+   return 1;
+   strcat(cur_buf, mbr_parts_p5);
+   bytes_remaining -= cur_str_size;
 
-   }
-   else if (num_parts > 5)
-   return 1;
+   }
}
}
}
-- 
2.41.0


Re: [tom.r...@gmail.com: Fwd: New Defects reported by Coverity Scan for Das U-Boot]

2023-11-07 Thread Alexander Gendin
On Mon, Nov 06, 2023 at 03:27:52PM -0500, Tom Rini  wrote:

> Hey all,
> 
> Here's the latest report. I _think_ I passed the right options to
> get_maintainer.pl such that it would only look far enough back in git to
> find the likely authors (along with listed maintainers of the files).
> 
> -- Forwarded message -
> From: 
> Date: Mon, Nov 6, 2023 at 2:58 PM
> Subject: New Defects reported by Coverity Scan for Das U-Boot
> To: 
> 
> Hi,
> 
> Please find the latest report on new defect(s) introduced to Das
> U-Boot found with Coverity Scan.
> 
> 13 new defect(s) introduced to Das U-Boot found with Coverity Scan.
> 5 defect(s), reported by Coverity Scan earlier, were marked fixed in
> the recent build analyzed by Coverity Scan.
> 
> New defect(s) Reported-by: Coverity Scan
> Showing 13 of 13 defect(s)
> 
> <...skipped...>
> *** CID 467404:  Control flow issues  (DEADCODE)
> /test/cmd/mbr.c: 217 in build_mbr_parts()
> 211 return 1;
> 212 strcat(cur_buf, mbr_parts_p5);
> 213 bytes_remaining -= cur_str_size;
> 214
> 215 }
> 216 else if (num_parts > 5)
> >>> CID 467404:  Control flow issues  (DEADCODE)
> >>> Execution cannot reach this statement: "return 1U;".
> 217 return 1;
> 218 }
> 219 }
> 220 }
> 221
> 222 cur_str_size = sizeof(mbr_parts_tail);
> <...skipped...>
> 
> -- 
> Tom

Hi Tom,

Thanks for the report.

The patch to fix CID 467404 has been sent to the mailing list.

Regards,
Alex

-- 

[PATCH] test: cmd: mbr: Fix Smatch static checker warning

2024-02-02 Thread Alexander Gendin
This patch fixes Smatch static checker warning:
test/cmd/mbr.c:243 mbr_test_run()
warn: sizeof(NUMBER)?

Reported-by: Dan Carpenter 
Signed-off-by: Alexander Gendin 
---
 test/cmd/mbr.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/test/cmd/mbr.c b/test/cmd/mbr.c
index 46b78e706c..235b363290 100644
--- a/test/cmd/mbr.c
+++ b/test/cmd/mbr.c
@@ -240,7 +240,11 @@ static int mbr_test_run(struct unit_test_state *uts)
ut_assert(ofnode_valid(node));
ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false));
 
-   mbr_parts_max = sizeof('\0') + 2 +
+   /*
+* 1 byte for null character
+* 2 reserved bytes
+*/
+   mbr_parts_max = 1 + 2 +
strlen(mbr_parts_header) +
strlen(mbr_parts_p1) +
strlen(mbr_parts_p2) +
-- 
2.41.0


[PATCH] drivers: misc: Kconfig: Fix SPL_FS_LOADER prompt

2023-11-20 Thread Alexander Gendin
Both FS_LOADER and SPL_FS_LOADER have the same menu prompt.
To avoid confusion, make prompt for SPL_FS_LOADER different.

Signed-off-by: Alexander Gendin 
---
 drivers/misc/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 97057de8bf..ed7ecedd3a 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -615,7 +615,7 @@ config FS_LOADER
  ie. the FPGA device.
 
 config SPL_FS_LOADER
-   bool "Enable loader driver for file system"
+   bool "Enable loader driver for file system in SPL"
depends on SPL
help
  This is file system generic loader which can be used to load
-- 
2.41.0


[PATCH] cmd: mbr: Allow 4 MBR partitions without need for extended

2023-10-06 Thread Alexander Gendin
Current code allows up to 3 MBR partitions without extended one.
If more than 3 partitions are required, then extended partition(s)
must be used.
This commit allows up to 4 primary MBR partitions without the
need for extended partition.

Add mbr test unit. In order to use the test, mmc1.img file of size
12 MiB or greater is required in the same directory as u-boot.
Running mbr test is only supported in sandbox mode.

Signed-off-by: Alex Gendin 
---
 disk/part_dos.c   |   2 +-
 include/test/suites.h |   1 +
 test/cmd/Makefile |   1 +
 test/cmd/mbr.c| 440 ++
 test/cmd_ut.c |   4 +
 5 files changed, 447 insertions(+), 1 deletion(-)
 create mode 100644 test/cmd/mbr.c

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 3337438437..567ead7511 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -466,7 +466,7 @@ int layout_mbr_partitions(struct disk_partition *p, int 
count,
ext = &p[i];
}
 
-   if (count < 4)
+   if (count <= 4)
return 0;
 
if (!ext) {
diff --git a/include/test/suites.h b/include/test/suites.h
index 1c7dc65966..51acbe47b2 100644
--- a/include/test/suites.h
+++ b/include/test/suites.h
@@ -45,6 +45,7 @@ int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[]);
 int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_log(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]);
+int do_ut_mbr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_mem(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_optee(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_overlay(struct cmd_tbl *cmdtp, int flag, int argc,
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index 6e3d7e919e..2f251e07b4 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_CMD_PINMUX) += pinmux.o
 obj-$(CONFIG_CMD_PWM) += pwm.o
 obj-$(CONFIG_CMD_SEAMA) += seama.o
 ifdef CONFIG_SANDBOX
+obj-$(CONFIG_CMD_MBR) += mbr.o
 obj-$(CONFIG_CMD_READ) += rw.o
 obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
 obj-$(CONFIG_ARM_FFA_TRANSPORT) += armffa.o
diff --git a/test/cmd/mbr.c b/test/cmd/mbr.c
new file mode 100644
index 00..bedcef0638
--- /dev/null
+++ b/test/cmd/mbr.c
@@ -0,0 +1,440 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for mbr command
+ *
+ * Copyright 2023 Matrox Video
+ * Written by Alex Gendin 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+/*
+ * Test requirements:
+ * mmc1.img - File size needs to be at least 12 MiB
+ *
+ * Command to create mmc1.img:
+ * $ dd if=/dev/zero of=mmc1.img bs=12M count=1
+ *
+ * Place mmc1.img into the same directory as sandboxed u-boot
+ *
+ * To run this test manually:
+ * $ ./u-boot -Tc 'ut mbr'
+ */
+
+static char * mbr_parts_header = "setenv mbr_parts '";
+static char * mbr_parts_p1 = 
"uuid_disk=0x12345678;name=p1,start=8M,bootable,size=1M,id=0x0e";
+static char * mbr_parts_p2 = ";name=p2,size=1M,id=0x0e";
+static char * mbr_parts_p3 = ";name=p3,size=1M,id=0x0e";
+static char * mbr_parts_p4 = ";name=p4,size=1M,id=0x0e";
+static char * mbr_parts_p5 = 
";name=[ext],size=2M,id=0x05;name=p5,size=1M,id=0x0e";
+static char * mbr_parts_tail = "'";
+
+/*
+ * One MBR partition
+01b0  00 00 00 00 00 00 00 00  78 56 34 12 00 00 80 05  |xV4.|
+01c0  05 01 0e 25 24 01 00 40  00 00 00 08 00 00 00 00  |...%$..@|
+01d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ||
+01e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ||
+01f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..U.|
+*/
+static unsigned mbr_cmp_start = 0x1B8;
+static unsigned mbr_cmp_size = 0x48;
+static unsigned char mbr_parts_ref_p1[] = {
+0x78, 0x56, 0x34, 0x12, 0x00, 
0x00, 0x80, 0x05,
+0x05, 0x01, 0x0e, 0x25, 0x24, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x08, 0x00, 
0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x55, 0xaa
+};
+
+/*
+ * Two MBR partitions
+01b0  00 00 00 00 00 00 00 00  78 56 34 12 00 00 80 05  |xV4.|
+01c0  05 01 0e 25 24 01 00 40  00 00 00 08 00 00 00 25  |...%$..@...%|
+01d0  25 01 0e 46 05 01 00 48  00 00 00 08 00 00 00 00  |%..F...H|
+01e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ||
+01f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..U.|
+*/
+static unsigned char mbr_parts_ref_p2[] = {
+ 

[PATCH v2] cmd: mbr: Allow 4 MBR partitions without need for extended

2023-10-08 Thread Alexander Gendin
KF_FIXED, dev)
@@ -328,8 +344,8 @@ static int dm_test_blk_foreach(struct unit_test_state *uts)
found = 0;
blk_foreach_probe(BLKF_REMOVABLE, dev)
found |= 1 << dectoul(&dev->name[3], NULL);
-   ut_asserteq(3, found);
-   ut_asserteq(2, blk_count_devices(BLKF_REMOVABLE));
+   ut_asserteq(0x43, found);
+   ut_asserteq(3, blk_count_devices(BLKF_REMOVABLE));
 
return 0;
 }
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index 82932a662b..1d9149a3f6 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -433,7 +433,6 @@ def setup_cedit_file(cons):
 u_boot_utils.run_and_log(
 cons, f'{expo_tool} -e {inhname} -l {infname} -o {outfname}')
 
-
 @pytest.mark.buildconfigspec('ut_dm')
 def test_ut_dm_init(u_boot_console):
 """Initialize data for ut dm tests."""
@@ -463,6 +462,12 @@ def test_ut_dm_init(u_boot_console):
 fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x20, '2MB')
 fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x10, '1MB')
 
+mmc_dev = 6
+fn = os.path.join(u_boot_console.config.source_dir, f'mmc{mmc_dev}.img')
+data = b'\x00' * (12 * 1024 * 1024)
+with open(fn, 'wb') as fh:
+fh.write(data)
+
 @pytest.mark.buildconfigspec('cmd_bootflow')
 def test_ut_dm_init_bootstd(u_boot_console):
 """Initialise data for bootflow tests"""
-- 
2.41.0


On Sat, Oct 07, 2023 at 05:10:02PM -0600, Simon Glass  wrote:
> Hi Alexander,
> 
> On Fri, 6 Oct 2023 at 21:58, Alexander Gendin  wrote:
> >
> > Current code allows up to 3 MBR partitions without extended one.
> > If more than 3 partitions are required, then extended partition(s)
> > must be used.
> > This commit allows up to 4 primary MBR partitions without the
> > need for extended partition.
> >
> > Add mbr test unit. In order to use the test, mmc1.img file of size
> > 12 MiB or greater is required in the same directory as u-boot.
> > Running mbr test is only supported in sandbox mode.
> >
> > Signed-off-by: Alex Gendin 
> > ---
> >  disk/part_dos.c   |   2 +-
> >  include/test/suites.h |   1 +
> >  test/cmd/Makefile |   1 +
> >  test/cmd/mbr.c| 440 ++
> >  test/cmd_ut.c |   4 +
> >  5 files changed, 447 insertions(+), 1 deletion(-)
> >  create mode 100644 test/cmd/mbr.c
> 
> This looks OK apart from one thing...also I have a few suggestions /
> questions below.
> 
> >
> > diff --git a/disk/part_dos.c b/disk/part_dos.c
> > index 3337438437..567ead7511 100644
> > --- a/disk/part_dos.c
> > +++ b/disk/part_dos.c
> > @@ -466,7 +466,7 @@ int layout_mbr_partitions(struct disk_partition *p, int 
> > count,
> > ext = &p[i];
> > }
> >
> > -   if (count < 4)
> > +   if (count <= 4)
> > return 0;
> >
> > if (!ext) {
> > diff --git a/include/test/suites.h b/include/test/suites.h
> > index 1c7dc65966..51acbe47b2 100644
> > --- a/include/test/suites.h
> > +++ b/include/test/suites.h
> > @@ -45,6 +45,7 @@ int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, 
> > char *const argv[]);
> >  int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
> > argv[]);
> >  int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
> > argv[]);
> >  int do_ut_log(struct cmd_tbl *cmdtp, int flag, int argc, char * const 
> > argv[]);
> > +int do_ut_mbr(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
> > argv[]);
> >  int do_ut_mem(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
> > argv[]);
> >  int do_ut_optee(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
> > argv[]);
> >  int do_ut_overlay(struct cmd_tbl *cmdtp, int flag, int argc,
> > diff --git a/test/cmd/Makefile b/test/cmd/Makefile
> > index 6e3d7e919e..2f251e07b4 100644
> > --- a/test/cmd/Makefile
> > +++ b/test/cmd/Makefile
> > @@ -23,6 +23,7 @@ obj-$(CONFIG_CMD_PINMUX) += pinmux.o
> >  obj-$(CONFIG_CMD_PWM) += pwm.o
> >  obj-$(CONFIG_CMD_SEAMA) += seama.o
> >  ifdef CONFIG_SANDBOX
> > +obj-$(CONFIG_CMD_MBR) += mbr.o
> >  obj-$(CONFIG_CMD_READ) += rw.o
> >  obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
> >  obj-$(CONFIG_ARM_FFA_TRANSPORT) += armffa.o
> > diff --git a/test/cmd/mbr.c b/test/cmd/mbr.c
> > new file mode 100644
> > index 00..bedcef0638
> > --- /dev/null
> > +++ b/test/cmd/mb