[U-Boot] [PATCH 1/2] itest: make memory access work under sandbox

itest accesses memory, and hence must map/unmap it. Without doing so, it accesses invalid addresses and crashes.
Signed-off-by: Stephen Warren swarren@wwwdotorg.org --- common/cmd_itest.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/common/cmd_itest.c b/common/cmd_itest.c index 76af62b46ee2..596341c9635a 100644 --- a/common/cmd_itest.c +++ b/common/cmd_itest.c @@ -15,6 +15,9 @@ #include <common.h> #include <config.h> #include <command.h> +#include <mapmem.h> + +#include <asm/io.h>
#define EQ 0 #define NE 1 @@ -49,16 +52,24 @@ static const op_tbl_t op_table [] = { static long evalexp(char *s, int w) { long l = 0; - long *p; + unsigned long addr; + void *buf;
/* if the parameter starts with a * then assume is a pointer to the value we want */ if (s[0] == '*') { - p = (long *)simple_strtoul(&s[1], NULL, 16); + addr = simple_strtoul(&s[1], NULL, 16); + buf = map_physmem(addr, w, MAP_WRBACK); + if (!buf) { + puts("Failed to map physical memory\n"); + return 0; + } switch (w) { - case 1: return((long)(*(unsigned char *)p)); - case 2: return((long)(*(unsigned short *)p)); - case 4: return(*p); + case 1: l = (long)(*(unsigned char *)buf); + case 2: l = (long)(*(unsigned short *)buf); + case 4: l = (long)(*(unsigned long *)buf); } + unmap_physmem(buf, w); + return l; } else { l = simple_strtoul(s, NULL, 16); }

In my patch series to replace fs/fat with "ff.c", I enhanced ff.c to optimize file reading, so that reads of contiguous clusters are submitted to the IO device as a single read. This test attempts to torture-test edge-cases of that enhancement.
BTW, the only way I found to validate that this script actually does create non-contiguous files was to manually inspect the FAT bitmap in a hex dump of the FAT image. hdparm --fibmap doesn't work on loop-mounted filesystems. filefrag -v -e seems to lie about files being contiguous when they aren't.
Signed-off-by: Stephen Warren swarren@wwwdotorg.org --- test/fs/fat-noncontig-test.sh | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 test/fs/fat-noncontig-test.sh
diff --git a/test/fs/fat-noncontig-test.sh b/test/fs/fat-noncontig-test.sh new file mode 100755 index 000000000000..8153708bbf78 --- /dev/null +++ b/test/fs/fat-noncontig-test.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +odir=sandbox +img=${odir}/fat.img +mnt=/mnt/tmp +fill=/dev/urandom +testfn=noncontig.img +mnttestfn=${mnt}/${testfn} +crcaddr=0 +loadaddr=1000 + +make O=${odir} -s sandbox_defconfig && make O=${odir} -s -j8 + +if [ ! -f ${img} ]; then + fallocate -l 40M ${img} + mkfs -t fat ${img} + + sudo mount -o loop,uid=$(id -u) ${img} ${mnt} + + for ((sects=8; sects < 512; sects += 8)); do + fn=${mnt}/keep-${sects}.img + dd if=${fill} of=${fn} bs=512 count=${sects} >/dev/null 2>&1 + fn=${mnt}/remove-${sects}.img + dd if=${fill} of=${fn} bs=512 count=${sects} >/dev/null 2>&1 + done + + rm -f ${mnt}/remove-*.img + + # 511 deliberately to trigger a file size that's not a multiple of the + # sector size (ignoring sizes that are multiples of both). + dd if=${fill} of=${mnttestfn} bs=511 >/dev/null 2>&1 + + sudo umount ${mnt} +fi + +sudo mount -o ro,loop,uid=$(id -u) ${img} ${mnt} +crc=0x`crc32 ${mnttestfn}` +sudo umount ${mnt} + +crc=`printf %02x%02x%02x%02x \ + $((${crc} & 0xff)) \ + $(((${crc} >> 8) & 0xff)) \ + $(((${crc} >> 16) & 0xff)) \ + $((${crc} >> 24))` + +./sandbox/u-boot << EOF +host bind 0 ${img} +load host 0:0 ${loadaddr} ${testfn} +crc32 ${loadaddr} $filesize ${crcaddr} +if itest.l *${crcaddr} != ${crc}; then echo FAILURE; else echo PASS; fi +reset +EOF

Hi Stephen,
On 2 October 2015 at 06:56, Stephen Warren swarren@wwwdotorg.org wrote:
In my patch series to replace fs/fat with "ff.c", I enhanced ff.c to optimize file reading, so that reads of contiguous clusters are submitted to the IO device as a single read. This test attempts to torture-test edge-cases of that enhancement.
BTW, the only way I found to validate that this script actually does create non-contiguous files was to manually inspect the FAT bitmap in a hex dump of the FAT image. hdparm --fibmap doesn't work on loop-mounted filesystems. filefrag -v -e seems to lie about files being contiguous when they aren't.
Signed-off-by: Stephen Warren swarren@wwwdotorg.org
test/fs/fat-noncontig-test.sh | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 test/fs/fat-noncontig-test.sh
diff --git a/test/fs/fat-noncontig-test.sh b/test/fs/fat-noncontig-test.sh new file mode 100755 index 000000000000..8153708bbf78 --- /dev/null +++ b/test/fs/fat-noncontig-test.sh @@ -0,0 +1,52 @@ +#!/bin/bash
Can you add a comment explaining what this test does?
Also I get this:
mount: mount point /mnt/tmp does not exist umount: /mnt/tmp: not found mount: mount point /mnt/tmp does not exist /usr/bin/crc32: No such file or directory umount: /mnt/tmp: not found
so does it need some extra steps?
+odir=sandbox +img=${odir}/fat.img +mnt=/mnt/tmp +fill=/dev/urandom +testfn=noncontig.img +mnttestfn=${mnt}/${testfn} +crcaddr=0 +loadaddr=1000
+make O=${odir} -s sandbox_defconfig && make O=${odir} -s -j8
+if [ ! -f ${img} ]; then
- fallocate -l 40M ${img}
- mkfs -t fat ${img}
- sudo mount -o loop,uid=$(id -u) ${img} ${mnt}
- for ((sects=8; sects < 512; sects += 8)); do
fn=${mnt}/keep-${sects}.img
dd if=${fill} of=${fn} bs=512 count=${sects} >/dev/null 2>&1
fn=${mnt}/remove-${sects}.img
dd if=${fill} of=${fn} bs=512 count=${sects} >/dev/null 2>&1
- done
- rm -f ${mnt}/remove-*.img
- # 511 deliberately to trigger a file size that's not a multiple of the
- # sector size (ignoring sizes that are multiples of both).
- dd if=${fill} of=${mnttestfn} bs=511 >/dev/null 2>&1
- sudo umount ${mnt}
+fi
+sudo mount -o ro,loop,uid=$(id -u) ${img} ${mnt} +crc=0x`crc32 ${mnttestfn}` +sudo umount ${mnt}
+crc=`printf %02x%02x%02x%02x \
- $((${crc} & 0xff)) \
- $(((${crc} >> 8) & 0xff)) \
- $(((${crc} >> 16) & 0xff)) \
- $((${crc} >> 24))`
+./sandbox/u-boot << EOF +host bind 0 ${img} +load host 0:0 ${loadaddr} ${testfn} +crc32 ${loadaddr} $filesize ${crcaddr} +if itest.l *${crcaddr} != ${crc}; then echo FAILURE; else echo PASS; fi +reset
+EOF
1.9.1
Regards, Simon

On 2 October 2015 at 06:56, Stephen Warren swarren@wwwdotorg.org wrote:
itest accesses memory, and hence must map/unmap it. Without doing so, it accesses invalid addresses and crashes.
Signed-off-by: Stephen Warren swarren@wwwdotorg.org
common/cmd_itest.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
participants (2)
-
Simon Glass
-
Stephen Warren