diff options
Diffstat (limited to 'external')
29 files changed, 991 insertions, 4 deletions
diff --git a/external/Makefile.check b/external/Makefile.check index 9147421..b5266ae 100644 --- a/external/Makefile.check +++ b/external/Makefile.check @@ -1,6 +1,6 @@ # -*-Makefile-*- -TOOL=gard ffspart +TOOL=gard ffspart pflash CHECK_TOOL=$(patsubst %,check-%,$(TOOL)) TOOL_COVERAGE=$(patsubst %,%-coverage,$(TOOL)) TOOL_TEST_CLEAN=$(patsubst %,%-test-clean,$(TOOL)) diff --git a/external/pflash/.gitignore b/external/pflash/.gitignore index edec7db..223b639 100644 --- a/external/pflash/.gitignore +++ b/external/pflash/.gitignore @@ -3,3 +3,4 @@ common libflash make_version.sh pflash +test/test.sh diff --git a/external/pflash/Makefile b/external/pflash/Makefile index 0b3a2a6..e931f29 100644 --- a/external/pflash/Makefile +++ b/external/pflash/Makefile @@ -4,6 +4,14 @@ include ../../external/common/rules.mk all: links arch_links $(EXE) +#Rebuild version.o so that the the version always matches +#what the test suite will get from ./make_version.sh +check: version.o all + $(MAKE) -C ../ffspart + @ln -sf ../../make_version.sh make_version.sh + @ln -sf ../../test/test.sh test/test.sh + @test/test-pflash + .PHONY: VERSION-always .version: VERSION-always @echo $(PFLASH_VERSION) > $@.tmp diff --git a/external/pflash/test/files/01-info.ffs b/external/pflash/test/files/01-info.ffs new file mode 100644 index 0000000..517dc47 --- /dev/null +++ b/external/pflash/test/files/01-info.ffs @@ -0,0 +1,4 @@ +ONE,0x00000300,0x00000100,EV,/dev/zero +TWO,0x00000400,0x00000100,EF,/dev/zero +THREE,0x00000500,0x00000100,EF,/dev/zero +FOUR,0x00000600,0x00000100,EF,/dev/zero diff --git a/external/pflash/test/files/02-erase.ffs b/external/pflash/test/files/02-erase.ffs new file mode 100644 index 0000000..7efcd71 --- /dev/null +++ b/external/pflash/test/files/02-erase.ffs @@ -0,0 +1,4 @@ +ONE,0x00000300,0x00000100,EV,/dev/urandom +TWO,0x00000400,0x00000100,EF,/dev/urandom +THREE,0x00000500,0x00000100,EF,/dev/urandom +FOUR,0x00000600,0x00000100,EF,/dev/urandom diff --git a/external/pflash/test/files/03-erase-parts.ffs b/external/pflash/test/files/03-erase-parts.ffs new file mode 100644 index 0000000..7efcd71 --- /dev/null +++ b/external/pflash/test/files/03-erase-parts.ffs @@ -0,0 +1,4 @@ +ONE,0x00000300,0x00000100,EV,/dev/urandom +TWO,0x00000400,0x00000100,EF,/dev/urandom +THREE,0x00000500,0x00000100,EF,/dev/urandom +FOUR,0x00000600,0x00000100,EF,/dev/urandom diff --git a/external/pflash/test/files/04-program-rand.ffs b/external/pflash/test/files/04-program-rand.ffs new file mode 100644 index 0000000..7efcd71 --- /dev/null +++ b/external/pflash/test/files/04-program-rand.ffs @@ -0,0 +1,4 @@ +ONE,0x00000300,0x00000100,EV,/dev/urandom +TWO,0x00000400,0x00000100,EF,/dev/urandom +THREE,0x00000500,0x00000100,EF,/dev/urandom +FOUR,0x00000600,0x00000100,EF,/dev/urandom diff --git a/external/pflash/test/files/05-bad-numbers.ffs b/external/pflash/test/files/05-bad-numbers.ffs new file mode 100644 index 0000000..7efcd71 --- /dev/null +++ b/external/pflash/test/files/05-bad-numbers.ffs @@ -0,0 +1,4 @@ +ONE,0x00000300,0x00000100,EV,/dev/urandom +TWO,0x00000400,0x00000100,EF,/dev/urandom +THREE,0x00000500,0x00000100,EF,/dev/urandom +FOUR,0x00000600,0x00000100,EF,/dev/urandom diff --git a/external/pflash/test/make-check-test b/external/pflash/test/make-check-test new file mode 100755 index 0000000..7f00948 --- /dev/null +++ b/external/pflash/test/make-check-test @@ -0,0 +1 @@ +make -C external/pflash/ check diff --git a/external/pflash/test/results/00-usage.err b/external/pflash/test/results/00-usage.err new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/external/pflash/test/results/00-usage.err diff --git a/external/pflash/test/results/00-usage.out b/external/pflash/test/results/00-usage.out new file mode 100644 index 0000000..3b54f45 --- /dev/null +++ b/external/pflash/test/results/00-usage.out @@ -0,0 +1,107 @@ +Open-Power Flash tool VERSION +Usage: ./pflash [options] commands... + + Options: + -a address, --address=address + Specify the start address for erasing, reading + or flashing + + -s size, --size=size + Specify the size in bytes for erasing, reading + or flashing + + -P part_name, --partition=part_name + Specify the partition whose content is to be erased + programmed or read. This is an alternative to -a and -s + if both -P and -s are specified, the smallest of the + two will be used + + -f, --force + Don't ask for confirmation before erasing or flashing + + -d, --dummy + Don't write to flash + + --direct + Bypass all safety provided to you by the kernel driver + and use the flash driver built into pflash. + If you have mtd devices and you use this command, the + system may become unstable. + If you are reading this sentence then this flag is not + what you want! Using this feature without knowing + what it does can and likely will result in a bricked + machine + + -b, --bmc + Target BMC flash instead of host flash. + Note: This carries a high chance of bricking your BMC if you + don't know what you're doing. Consider --mtd to be safe(r) + + -F filename, --flash-file filename + Target filename instead of actual flash. + + -S, --side + Side of the flash on which to operate, 0 (default) or 1 + + -T, --toc + libffs TOC on which to operate, defaults to 0. + leading 0x is required for interpretation of a hex value + + -g + Enable verbose libflash debugging + + Commands: + -4, --enable-4B + Switch the flash and controller to 4-bytes address + mode (no confirmation needed). + + -3, --disable-4B + Switch the flash and controller to 3-bytes address + mode (no confirmation needed). + + -r file, --read=file + Read flash content from address into file, use -s + to specify the size to read (or it will use the source + file size if used in conjunction with -p and -s is not + specified). When using -r together with -e or -p, the + read will be performed first + + -E, --erase-all + Erase entire flash chip + (Not supported on all chips/controllers) + + -e, --erase + Erase the specified region. If size or address are not + specified, but '--program' is used, then the file + size will be used (rounded to an erase block) and the + address defaults to 0. + + -p file, --program=file + Will program the file to flash. If the address is not + specified, it will use 0. If the size is not specified + it will use the file size. Otherwise it will limit to + the specified size (whatever is smaller). If used in + conjunction with any erase command, the erase will + take place first. + + -t, --tune + Just tune the flash controller & access size + Must be used in conjuction with --direct + (Implicit for all other operations) + + -c --clear + Used to ECC clear a partition of the flash + Must be used in conjunction with -P. Will erase the + partition and then set all the ECC bits as they should be + + -i, --info + Display some information about the flash. + + --detail + Displays detailed info about a particular partition. + Accepts a numeric partition or can be used in conjuction + with the -P flag. + + -h, --help + This message. + diff --git a/external/pflash/test/results/01-info.err b/external/pflash/test/results/01-info.err new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/external/pflash/test/results/01-info.err diff --git a/external/pflash/test/results/01-info.out b/external/pflash/test/results/01-info.out new file mode 100644 index 0000000..43baf31 --- /dev/null +++ b/external/pflash/test/results/01-info.out @@ -0,0 +1,13 @@ +Flash info: +----------- +Name = FILE +Total size = 0MB Flags E:ECC, P:PRESERVED, R:READONLY +Erase granule = 0KB B:BACKUP, F:REPROVISION + +TOC@0x00000000 Partitions: +----------- +ID=00 part 0x00000000..0x00000300 (actual=0x00000300) [-----] +ID=01 ONE 0x00000300..0x00000400 (actual=0x00000100) [E----] +ID=02 TWO 0x00000400..0x00000500 (actual=0x00000100) [E---F] +ID=03 THREE 0x00000500..0x00000600 (actual=0x00000100) [E---F] +ID=04 FOUR 0x00000600..0x00000700 (actual=0x00000100) [E---F] diff --git a/external/pflash/test/results/02-erase.err b/external/pflash/test/results/02-erase.err new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/external/pflash/test/results/02-erase.err diff --git a/external/pflash/test/results/02-erase.out b/external/pflash/test/results/02-erase.out new file mode 100644 index 0000000..7d251a7 --- /dev/null +++ b/external/pflash/test/results/02-erase.out @@ -0,0 +1,105 @@ +About to erase chip ! +WARNING ! This will modify your HOST flash chip content ! +Enter "yes" to confirm:Erasing... (may take a while) + +[ ] 0% +[= ] 1% +[= ] 2% +[== ] 3% +[== ] 4% +[=== ] 5% +[=== ] 6% +[==== ] 7% +[==== ] 8% +[===== ] 9% +[===== ] 10% +[====== ] 11% +[====== ] 12% +[======= ] 13% +[======= ] 14% +[======== ] 15% +[======== ] 16% +[========= ] 17% +[========= ] 18% +[========== ] 19% +[========== ] 20% +[=========== ] 21% +[=========== ] 22% +[============ ] 23% +[============ ] 24% +[============= ] 25% +[============= ] 26% +[============== ] 27% +[============== ] 28% +[=============== ] 29% +[=============== ] 30% +[================ ] 31% +[================ ] 32% +[================= ] 33% +[================= ] 34% +[================== ] 35% +[================== ] 36% +[=================== ] 37% +[=================== ] 38% +[==================== ] 39% +[==================== ] 40% +[===================== ] 41% +[===================== ] 42% +[====================== ] 43% +[====================== ] 44% +[======================= ] 45% +[======================= ] 46% +[======================== ] 47% +[======================== ] 48% +[========================= ] 49% +[========================= ] 50% +[========================== ] 51% +[========================== ] 52% +[=========================== ] 53% +[=========================== ] 54% +[============================ ] 55% +[============================ ] 56% +[============================= ] 57% +[============================= ] 58% +[============================== ] 59% +[============================== ] 60% +[=============================== ] 61% +[=============================== ] 62% +[================================ ] 63% +[================================ ] 64% +[================================= ] 65% +[================================= ] 66% +[================================== ] 67% +[================================== ] 68% +[=================================== ] 69% +[=================================== ] 70% +[==================================== ] 71% +[==================================== ] 72% +[===================================== ] 73% +[===================================== ] 74% +[====================================== ] 75% +[====================================== ] 76% +[======================================= ] 77% +[======================================= ] 78% +[======================================== ] 79% +[======================================== ] 80% +[========================================= ] 81% +[========================================= ] 82% +[========================================== ] 83% +[========================================== ] 84% +[=========================================== ] 85% +[=========================================== ] 86% +[============================================ ] 87% +[============================================ ] 88% +[============================================= ] 89% +[============================================= ] 90% +[============================================== ] 91% +[============================================== ] 92% +[=============================================== ] 93% +[=============================================== ] 94% +[================================================ ] 95% +[================================================ ] 96% +[================================================= ] 97% +[================================================= ] 98% +[==================================================] 99% +done ! diff --git a/external/pflash/test/results/03-erase-parts.err b/external/pflash/test/results/03-erase-parts.err new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/external/pflash/test/results/03-erase-parts.err diff --git a/external/pflash/test/results/03-erase-parts.out b/external/pflash/test/results/03-erase-parts.out new file mode 100644 index 0000000..28f0b23 --- /dev/null +++ b/external/pflash/test/results/03-erase-parts.out @@ -0,0 +1,106 @@ +About to erase 0x00000300..0x00000400 ! +WARNING ! This will modify your HOST flash chip content ! +Enter "yes" to confirm:Erasing... + +[ ] 0% +[= ] 1% +[= ] 2% +[== ] 3% +[== ] 4% +[=== ] 5% +[=== ] 6% +[==== ] 7% +[==== ] 8% +[===== ] 9% +[===== ] 10% +[====== ] 11% +[====== ] 12% +[======= ] 13% +[======= ] 14% +[======== ] 15% +[======== ] 16% +[========= ] 17% +[========= ] 18% +[========== ] 19% +[========== ] 20% +[=========== ] 21% +[=========== ] 22% +[============ ] 23% +[============ ] 24% +[============= ] 25% +[============= ] 26% +[============== ] 27% +[============== ] 28% +[=============== ] 29% +[=============== ] 30% +[================ ] 31% +[================ ] 32% +[================= ] 33% +[================= ] 34% +[================== ] 35% +[================== ] 36% +[=================== ] 37% +[=================== ] 38% +[==================== ] 39% +[==================== ] 40% +[===================== ] 41% +[===================== ] 42% +[====================== ] 43% +[====================== ] 44% +[======================= ] 45% +[======================= ] 46% +[======================== ] 47% +[======================== ] 48% +[========================= ] 49% +[========================= ] 50% +[========================== ] 51% +[========================== ] 52% +[=========================== ] 53% +[=========================== ] 54% +[============================ ] 55% +[============================ ] 56% +[============================= ] 57% +[============================= ] 58% +[============================== ] 59% +[============================== ] 60% +[=============================== ] 61% +[=============================== ] 62% +[================================ ] 63% +[================================ ] 64% +[================================= ] 65% +[================================= ] 66% +[================================== ] 67% +[================================== ] 68% +[=================================== ] 69% +[=================================== ] 70% +[==================================== ] 71% +[==================================== ] 72% +[===================================== ] 73% +[===================================== ] 74% +[====================================== ] 75% +[====================================== ] 76% +[======================================= ] 77% +[======================================= ] 78% +[======================================== ] 79% +[======================================== ] 80% +[========================================= ] 81% +[========================================= ] 82% +[========================================== ] 83% +[========================================== ] 84% +[=========================================== ] 85% +[=========================================== ] 86% +[============================================ ] 87% +[============================================ ] 88% +[============================================= ] 89% +[============================================= ] 90% +[============================================== ] 91% +[============================================== ] 92% +[=============================================== ] 93% +[=============================================== ] 94% +[================================================ ] 95% +[================================================ ] 96% +[================================================= ] 97% +[================================================= ] 98% +[==================================================] 99% +[==================================================] 100% +Updating actual size in partition header... diff --git a/external/pflash/test/results/04-program-rand.err b/external/pflash/test/results/04-program-rand.err new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/external/pflash/test/results/04-program-rand.err diff --git a/external/pflash/test/results/04-program-rand.out b/external/pflash/test/results/04-program-rand.out new file mode 100644 index 0000000..b0df327 --- /dev/null +++ b/external/pflash/test/results/04-program-rand.out @@ -0,0 +1,111 @@ +About to erase 0x00000300..0x00000400 ! +WARNING ! This will modify your HOST flash chip content ! +Enter "yes" to confirm:Erasing... + +[ ] 0% +[= ] 1% +[= ] 2% +[== ] 3% +[== ] 4% +[=== ] 5% +[=== ] 6% +[==== ] 7% +[==== ] 8% +[===== ] 9% +[===== ] 10% +[====== ] 11% +[====== ] 12% +[======= ] 13% +[======= ] 14% +[======== ] 15% +[======== ] 16% +[========= ] 17% +[========= ] 18% +[========== ] 19% +[========== ] 20% +[=========== ] 21% +[=========== ] 22% +[============ ] 23% +[============ ] 24% +[============= ] 25% +[============= ] 26% +[============== ] 27% +[============== ] 28% +[=============== ] 29% +[=============== ] 30% +[================ ] 31% +[================ ] 32% +[================= ] 33% +[================= ] 34% +[================== ] 35% +[================== ] 36% +[=================== ] 37% +[=================== ] 38% +[==================== ] 39% +[==================== ] 40% +[===================== ] 41% +[===================== ] 42% +[====================== ] 43% +[====================== ] 44% +[======================= ] 45% +[======================= ] 46% +[======================== ] 47% +[======================== ] 48% +[========================= ] 49% +[========================= ] 50% +[========================== ] 51% +[========================== ] 52% +[=========================== ] 53% +[=========================== ] 54% +[============================ ] 55% +[============================ ] 56% +[============================= ] 57% +[============================= ] 58% +[============================== ] 59% +[============================== ] 60% +[=============================== ] 61% +[=============================== ] 62% +[================================ ] 63% +[================================ ] 64% +[================================= ] 65% +[================================= ] 66% +[================================== ] 67% +[================================== ] 68% +[=================================== ] 69% +[=================================== ] 70% +[==================================== ] 71% +[==================================== ] 72% +[===================================== ] 73% +[===================================== ] 74% +[====================================== ] 75% +[====================================== ] 76% +[======================================= ] 77% +[======================================= ] 78% +[======================================== ] 79% +[======================================== ] 80% +[========================================= ] 81% +[========================================= ] 82% +[========================================== ] 83% +[========================================== ] 84% +[=========================================== ] 85% +[=========================================== ] 86% +[============================================ ] 87% +[============================================ ] 88% +[============================================= ] 89% +[============================================= ] 90% +[============================================== ] 91% +[============================================== ] 92% +[=============================================== ] 93% +[=============================================== ] 94% +[================================================ ] 95% +[================================================ ] 96% +[================================================= ] 97% +[================================================= ] 98% +[==================================================] 99% +[==================================================] 100% +About to program "FILE" at 0x00000300..0x00000400 ! +Programming & Verifying... + +[ ] 0% +[==================================================] 100% +Updating actual size in partition header... diff --git a/external/pflash/test/results/05-bad-numbers.err b/external/pflash/test/results/05-bad-numbers.err new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/external/pflash/test/results/05-bad-numbers.err diff --git a/external/pflash/test/results/05-bad-numbers.out b/external/pflash/test/results/05-bad-numbers.out new file mode 100644 index 0000000..211bd6a --- /dev/null +++ b/external/pflash/test/results/05-bad-numbers.out @@ -0,0 +1,217 @@ +Open-Power Flash tool VERSION +Usage: ./pflash [options] commands... + + Options: + -a address, --address=address + Specify the start address for erasing, reading + or flashing + + -s size, --size=size + Specify the size in bytes for erasing, reading + or flashing + + -P part_name, --partition=part_name + Specify the partition whose content is to be erased + programmed or read. This is an alternative to -a and -s + if both -P and -s are specified, the smallest of the + two will be used + + -f, --force + Don't ask for confirmation before erasing or flashing + + -d, --dummy + Don't write to flash + + --direct + Bypass all safety provided to you by the kernel driver + and use the flash driver built into pflash. + If you have mtd devices and you use this command, the + system may become unstable. + If you are reading this sentence then this flag is not + what you want! Using this feature without knowing + what it does can and likely will result in a bricked + machine + + -b, --bmc + Target BMC flash instead of host flash. + Note: This carries a high chance of bricking your BMC if you + don't know what you're doing. Consider --mtd to be safe(r) + + -F filename, --flash-file filename + Target filename instead of actual flash. + + -S, --side + Side of the flash on which to operate, 0 (default) or 1 + + -T, --toc + libffs TOC on which to operate, defaults to 0. + leading 0x is required for interpretation of a hex value + + -g + Enable verbose libflash debugging + + Commands: + -4, --enable-4B + Switch the flash and controller to 4-bytes address + mode (no confirmation needed). + + -3, --disable-4B + Switch the flash and controller to 3-bytes address + mode (no confirmation needed). + + -r file, --read=file + Read flash content from address into file, use -s + to specify the size to read (or it will use the source + file size if used in conjunction with -p and -s is not + specified). When using -r together with -e or -p, the + read will be performed first + + -E, --erase-all + Erase entire flash chip + (Not supported on all chips/controllers) + + -e, --erase + Erase the specified region. If size or address are not + specified, but '--program' is used, then the file + size will be used (rounded to an erase block) and the + address defaults to 0. + + -p file, --program=file + Will program the file to flash. If the address is not + specified, it will use 0. If the size is not specified + it will use the file size. Otherwise it will limit to + the specified size (whatever is smaller). If used in + conjunction with any erase command, the erase will + take place first. + + -t, --tune + Just tune the flash controller & access size + Must be used in conjuction with --direct + (Implicit for all other operations) + + -c --clear + Used to ECC clear a partition of the flash + Must be used in conjunction with -P. Will erase the + partition and then set all the ECC bits as they should be + + -i, --info + Display some information about the flash. + + --detail + Displays detailed info about a particular partition. + Accepts a numeric partition or can be used in conjuction + with the -P flag. + + -h, --help + This message. + +About to erase 0x00000300..0x00000400 ! +WARNING ! This will modify your HOST flash chip content ! +Enter "yes" to confirm:Erasing... + +[ ] 0% +[= ] 1% +[= ] 2% +[== ] 3% +[== ] 4% +[=== ] 5% +[=== ] 6% +[==== ] 7% +[==== ] 8% +[===== ] 9% +[===== ] 10% +[====== ] 11% +[====== ] 12% +[======= ] 13% +[======= ] 14% +[======== ] 15% +[======== ] 16% +[========= ] 17% +[========= ] 18% +[========== ] 19% +[========== ] 20% +[=========== ] 21% +[=========== ] 22% +[============ ] 23% +[============ ] 24% +[============= ] 25% +[============= ] 26% +[============== ] 27% +[============== ] 28% +[=============== ] 29% +[=============== ] 30% +[================ ] 31% +[================ ] 32% +[================= ] 33% +[================= ] 34% +[================== ] 35% +[================== ] 36% +[=================== ] 37% +[=================== ] 38% +[==================== ] 39% +[==================== ] 40% +[===================== ] 41% +[===================== ] 42% +[====================== ] 43% +[====================== ] 44% +[======================= ] 45% +[======================= ] 46% +[======================== ] 47% +[======================== ] 48% +[========================= ] 49% +[========================= ] 50% +[========================== ] 51% +[========================== ] 52% +[=========================== ] 53% +[=========================== ] 54% +[============================ ] 55% +[============================ ] 56% +[============================= ] 57% +[============================= ] 58% +[============================== ] 59% +[============================== ] 60% +[=============================== ] 61% +[=============================== ] 62% +[================================ ] 63% +[================================ ] 64% +[================================= ] 65% +[================================= ] 66% +[================================== ] 67% +[================================== ] 68% +[=================================== ] 69% +[=================================== ] 70% +[==================================== ] 71% +[==================================== ] 72% +[===================================== ] 73% +[===================================== ] 74% +[====================================== ] 75% +[====================================== ] 76% +[======================================= ] 77% +[======================================= ] 78% +[======================================== ] 79% +[======================================== ] 80% +[========================================= ] 81% +[========================================= ] 82% +[========================================== ] 83% +[========================================== ] 84% +[=========================================== ] 85% +[=========================================== ] 86% +[============================================ ] 87% +[============================================ ] 88% +[============================================= ] 89% +[============================================= ] 90% +[============================================== ] 91% +[============================================== ] 92% +[=============================================== ] 93% +[=============================================== ] 94% +[================================================ ] 95% +[================================================ ] 96% +[================================================= ] 97% +[================================================= ] 98% +[==================================================] 99% +[==================================================] 100% +About to program "FILE" at 0x00000300..0x00000400 ! +Programming & Verifying... + +[ ] 0% +[==================================================] 100% diff --git a/external/pflash/test/test-pflash b/external/pflash/test/test-pflash new file mode 100755 index 0000000..dd775bd --- /dev/null +++ b/external/pflash/test/test-pflash @@ -0,0 +1,59 @@ +#! /bin/sh + +. test/test.sh + +get_part_start() { + #We want to fail the test if the caller passed garbage + if [ "$#" -ne 2 ] || ! grep -q "$2" "$1" ; then + fail_test; + fi + grep "$2" "$1" | cut -f2 -d, | xargs printf "%d"; +} + +get_part_len() { + #We want to fail the test if the caller passed garbage + if [ "$#" -ne 2 ] || ! grep -q "$2" "$1" ; then + fail_test; + fi + grep "$2" "$1" | cut -f3 -d, | xargs printf "%d"; +} + +get_part_end() { + start=$(get_part_start "$1" "$2"); + len=$(get_part_len "$1" "$2"); + expr "$start" \+ "$len"; +} + +cmp_with_ff() { + if [ "$#" -ne 3 ] ; then + fail_test; + fi + file="$1"; + start="$2"; + len="$3"; + + blank=$(mktemp --tmpdir="$DATA_DIR" blank.pnorXXXXXX); + dd status=none if=/dev/zero bs="$len" count=1 | tr '\000' '\377' > "$blank" + cmp --bytes="$len" --ignore-initial="$start:0" "$file" "$blank"; + if [ "$?" -ne 0 ] ; then + fail_test; + fi + #fail_test; will trigger a cleanup straight away + rm $blank; +} + +#The reason for it is that this way there is a completely independant +#way of calculating checksums so if checksums fail, we can be +#confident its because libflash/libffs changed +update_checksum() { + if [ "$#" -ne 2 ] ; then + fail_test; + fi + file=$1; + part=$2; + dd if="$file" bs=1 skip="$part" count=124 status=none | perl -e 'use integer; binmode STDIN; binmode STDOUT; my $result=0; while (read STDIN, $word, 4) { $result = $result ^ unpack("N", $word); } print pack("N",$result)' | dd of="$file" seek="$(expr $part \+ 124)" bs=1 count=4 status=none conv=notrunc +} + +run_tests "test/tests/*" "test/results" "test/files" + + diff --git a/external/pflash/test/tests/00-usage b/external/pflash/test/tests/00-usage new file mode 100644 index 0000000..b83bca8 --- /dev/null +++ b/external/pflash/test/tests/00-usage @@ -0,0 +1,12 @@ +#! /bin/sh + +run_binary "./pflash" "-h" +if [ "$?" -ne 0 ] ; then + fail_test +fi + +strip_version_from_result "pflash" + +diff_with_result + +pass_test diff --git a/external/pflash/test/tests/01-info b/external/pflash/test/tests/01-info new file mode 100644 index 0000000..7d6fd52 --- /dev/null +++ b/external/pflash/test/tests/01-info @@ -0,0 +1,22 @@ +#! /bin/sh + +touch "$DATA_DIR/$CUR_TEST.pnor" + +# Don't record the output of ffspart +../ffspart/ffspart -s 0x100 -c 10 -i "$DATA_DIR/$CUR_TEST.ffs" \ + -p "$DATA_DIR/$CUR_TEST.pnor" 2>&1 >/dev/null +if [ "$?" -ne 0 ] ; then + fail_test +fi + +run_binary "./pflash" "-F $DATA_DIR/$CUR_TEST.pnor --info" +if [ "$?" -ne 0 ] ; then + fail_test +fi + +#--info will print the name of the file which will change between runs +sed -i "s|$DATA_DIR/$CUR_TEST.pnor|FILE|" "$STDOUT_OUT" + +diff_with_result + +pass_test diff --git a/external/pflash/test/tests/02-erase b/external/pflash/test/tests/02-erase new file mode 100644 index 0000000..dd00f38 --- /dev/null +++ b/external/pflash/test/tests/02-erase @@ -0,0 +1,26 @@ +#! /bin/sh + +touch "$DATA_DIR/$CUR_TEST.pnor" + +# Don't record the output of ffspart +../ffspart/ffspart -s 0x100 -c 10 -i "$DATA_DIR/$CUR_TEST.ffs" \ + -p "$DATA_DIR/$CUR_TEST.pnor" 2>&1 >/dev/null +if [ "$?" -ne 0 ] ; then + fail_test; +fi + +yes yes | run_binary "./pflash" "-F $DATA_DIR/$CUR_TEST.pnor -E" +if [ "$?" -ne 0 ] ; then + fail_test; +fi + +cmp_with_ff "$DATA_DIR/$CUR_TEST.pnor" 0 \ + "$(stat --printf="%s" "$DATA_DIR/$CUR_TEST.pnor")" + +# The test infrastructure will clean up but lets not chew unnecessarily +# though disk space +rm "$DATA_DIR/$CUR_TEST.pnor" + +diff_with_result + +pass_test diff --git a/external/pflash/test/tests/03-erase-parts b/external/pflash/test/tests/03-erase-parts new file mode 100644 index 0000000..09421bb --- /dev/null +++ b/external/pflash/test/tests/03-erase-parts @@ -0,0 +1,55 @@ +#! /bin/sh + +touch "$DATA_DIR/$CUR_TEST.pnor" + +# Don't record the output of ffspart +../ffspart/ffspart -s 0x100 -c 10 -i "$DATA_DIR/$CUR_TEST.ffs" \ + -p "$DATA_DIR/$CUR_TEST.pnor" 2>&1 >/dev/null +if [ "$?" -ne 0 ] ; then + fail_test +fi + +cp "$DATA_DIR/$CUR_TEST.pnor" "$DATA_DIR/$CUR_TEST.bk" +if [ "$?" -ne 0 ] ; then + fail_test +fi + +#Let us all take a second to appreciate the fragility of this. +#The reason we need is that pflash -e will set the actual size of the +#partition to zero, which we'll do here. Examination determined that +#it will be at byte 216 in the file +dd if=/dev/zero of="$DATA_DIR/$CUR_TEST.bk" \ + bs=1 seek=216 count=4 conv=notrunc status=none + +#176 Should be where the FFS header for partition ONE starts +update_checksum "$DATA_DIR/$CUR_TEST.bk" "176"; + +yes yes | run_binary "./pflash" "-F $DATA_DIR/$CUR_TEST.pnor -e -P ONE" +if [ "$?" -ne 0 ] ; then + fail_test; +fi + +one_start=$(get_part_start "$DATA_DIR/$CUR_TEST.ffs" "ONE"); +one_len=$(get_part_len "$DATA_DIR/$CUR_TEST.ffs" "ONE"); +one_end=$(get_part_end "$DATA_DIR/$CUR_TEST.ffs" "ONE"); +cmp_with_ff "$DATA_DIR/$CUR_TEST.pnor" "$one_start" "$one_len" + +cmp --bytes="$one_start" "$DATA_DIR/$CUR_TEST.pnor" \ + "$DATA_DIR/$CUR_TEST.bk"; +if [ "$?" -ne 0 ] ; then + fail_test; +fi + +cmp --ignore-initial="$one_end" \ + --bytes="$(expr $(stat --printf="%s" "$DATA_DIR/$CUR_TEST.pnor") - "$one_end")" \ + "$DATA_DIR/$CUR_TEST.pnor" "$DATA_DIR/$CUR_TEST.bk" +if [ "$?" -ne 0 ] ; then + fail_test; +fi +# The test infrastructure will clean up but lets no chew unnecessarily +# though disk space +rm "$DATA_DIR/$CUR_TEST.pnor" "$DATA_DIR/$CUR_TEST.bk" + +diff_with_result + +pass_test diff --git a/external/pflash/test/tests/04-program-rand b/external/pflash/test/tests/04-program-rand new file mode 100644 index 0000000..62f2f92 --- /dev/null +++ b/external/pflash/test/tests/04-program-rand @@ -0,0 +1,54 @@ +#! /bin/sh + +touch "$DATA_DIR/$CUR_TEST.pnor" + +# Don't record the output of ffspart +../ffspart/ffspart -s 0x100 -c 10 -i "$DATA_DIR/$CUR_TEST.ffs" \ + -p "$DATA_DIR/$CUR_TEST.pnor" 2>&1 >/dev/null +if [ "$?" -ne 0 ] ; then + fail_test +fi + +cp "$DATA_DIR/$CUR_TEST.pnor" "$DATA_DIR/$CUR_TEST.bk" +if [ "$?" -ne 0 ] ; then + fail_test +fi + +one_len=$(get_part_len "$DATA_DIR/$CUR_TEST.ffs" "ONE"); +one_start=$(get_part_start "$DATA_DIR/$CUR_TEST.ffs" "ONE"); +one_end=$(get_part_end "$DATA_DIR/$CUR_TEST.ffs" "ONE"); +dd if=/dev/urandom bs="$one_len" count=1 of="$DATA_DIR/random" status=none + +yes yes | run_binary "./pflash" \ + "-F $DATA_DIR/$CUR_TEST.pnor -e -P ONE -p $DATA_DIR/random" +if [ "$?" -ne 0 ] ; then + fail_test; +fi + +cmp --ignore-initial="$one_start:0" --bytes="$one_len" \ + "$DATA_DIR/$CUR_TEST.pnor" "$DATA_DIR/random" +if [ "$?" -ne 0 ] ; then + fail_test; +fi + +cmp --bytes="$one_start" "$DATA_DIR/$CUR_TEST.pnor" \ + "$DATA_DIR/$CUR_TEST.bk"; +if [ "$?" -ne 0 ] ; then + fail_test; +fi + +cmp --ignore-initial="$one_end" \ + --bytes="$(expr $(stat --printf="%s" "$DATA_DIR/$CUR_TEST.pnor") - "$one_end")" \ + "$DATA_DIR/$CUR_TEST.pnor" "$DATA_DIR/$CUR_TEST.bk" +if [ "$?" -ne 0 ] ; then + fail_test; +fi +sed -i "s|$DATA_DIR/random|FILE|" "$STDOUT_OUT" + +# The test infrastructure will clean up but lets no chew unnecessarily +# though disk space +rm "$DATA_DIR/$CUR_TEST.pnor" "$DATA_DIR/$CUR_TEST.bk" "$DATA_DIR/random" + +diff_with_result + +pass_test diff --git a/external/pflash/test/tests/05-bad-numbers b/external/pflash/test/tests/05-bad-numbers new file mode 100644 index 0000000..f84e799 --- /dev/null +++ b/external/pflash/test/tests/05-bad-numbers @@ -0,0 +1,65 @@ +#! /bin/sh + +touch "$DATA_DIR/$CUR_TEST.pnor" + +# Don't record the output of ffspart +../ffspart/ffspart -s 0x100 -c 10 -i "$DATA_DIR/$CUR_TEST.ffs" \ + -p "$DATA_DIR/$CUR_TEST.pnor" 2>&1 >/dev/null +if [ "$?" -ne 0 ] ; then + fail_test +fi + +cp "$DATA_DIR/$CUR_TEST.pnor" "$DATA_DIR/$CUR_TEST.bk" +if [ "$?" -ne 0 ] ; then + fail_test +fi + +one_len=$(get_part_len "$DATA_DIR/$CUR_TEST.ffs" "ONE"); +one_start=$(get_part_start "$DATA_DIR/$CUR_TEST.ffs" "ONE"); +one_end=$(get_part_end "$DATA_DIR/$CUR_TEST.ffs" "ONE"); +dd if=/dev/urandom bs="$one_len" count=1 of="$DATA_DIR/random" status=none + +#This should error out +run_binary "./pflash" \ + "-F $DATA_DIR/$CUR_TEST.pnor -e -a NOT_A_NUMBER -s ALSO_NOT_A_NUMBER" +if [ "$?" -eq 0 ] ; then + fail_test; +fi + +one_start_decimal=$(printf "%d" $one_start); +one_len_decimal=$(printf "%d" $one_len); +yes yes | run_binary "./pflash" \ + "-F $DATA_DIR/$CUR_TEST.pnor -e -a $one_start_decimal \ + -s $one_len_decimal -p $DATA_DIR/random" +if [ "$?" -ne 0 ] ; then + fail_test; +fi + +cmp --ignore-initial="$one_start:0" --bytes="$one_len" \ + "$DATA_DIR/$CUR_TEST.pnor" "$DATA_DIR/random" +if [ "$?" -ne 0 ] ; then + fail_test; +fi + +cmp --bytes="$one_start" "$DATA_DIR/$CUR_TEST.pnor" "$DATA_DIR/$CUR_TEST.bk"; +if [ "$?" -ne 0 ] ; then + fail_test; +fi + +cmp --ignore-initial="$one_end" \ + --bytes="$(expr $(stat --printf="%s" "$DATA_DIR/$CUR_TEST.pnor") - "$one_end")" \ + "$DATA_DIR/$CUR_TEST.pnor" "$DATA_DIR/$CUR_TEST.bk" +if [ "$?" -ne 0 ] ; then + fail_test; +fi +sed -i "s|$DATA_DIR/random|FILE|" "$STDOUT_OUT" + +# The test infrastructure will clean up but lets no chew unnecessarily +# though disk space +rm "$DATA_DIR/$CUR_TEST.pnor" "$DATA_DIR/$CUR_TEST.bk" "$DATA_DIR/random" + +strip_version_from_result "pflash" + +diff_with_result + +pass_test diff --git a/external/test/test.sh b/external/test/test.sh index f63cce5..c3bbc61 100755 --- a/external/test/test.sh +++ b/external/test/test.sh @@ -1,6 +1,6 @@ #! /bin/sh -# Copyright 2013-2014 IBM Corp. +# Copyright 2013-2017 IBM Corp. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -48,10 +48,15 @@ diff_with_result() { fi # Otherwise just diff result.out with stdout and result.err with stderr else - if ! diff -u "${RESULT}.out" "$STDOUT_OUT" ; then + #Strip carriage returns, useful for pflash which does fancy + #'progress bars'. The main reason for this is is that email + #doesn't barf at really really long lines + if ! cat "$STDOUT_OUT" | tr '\r' '\n' | \ + diff -u "${RESULT}.out" - ; then fail_test; fi - if ! diff -u "${RESULT}.err" "$STDERR_OUT" ; then + if ! cat "$STDERR_OUT" | tr '\r' '\n' | \ + diff -u "${RESULT}.err" - ; then fail_test; fi fi |