[Skiboot] [PATCH v2 18/19] external/pflash: Add tests

Cyril Bur cyril.bur at au1.ibm.com
Fri Jul 28 16:46:36 AEST 2017


Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
 external/Makefile.check                          |   2 +-
 external/pflash/.gitignore                       |   1 +
 external/pflash/Makefile                         |   8 +
 external/pflash/test/files/01-info.ffs           |   4 +
 external/pflash/test/files/02-erase.ffs          |   4 +
 external/pflash/test/files/03-erase-parts.ffs    |   4 +
 external/pflash/test/files/04-program-rand.ffs   |   4 +
 external/pflash/test/files/05-bad-numbers.ffs    |   4 +
 external/pflash/test/make-check-test             |   1 +
 external/pflash/test/results/00-usage.err        |   0
 external/pflash/test/results/00-usage.out        | 107 +++++++++++
 external/pflash/test/results/01-info.err         |   0
 external/pflash/test/results/01-info.out         |  13 ++
 external/pflash/test/results/02-erase.err        |   0
 external/pflash/test/results/02-erase.out        | 105 +++++++++++
 external/pflash/test/results/03-erase-parts.err  |   0
 external/pflash/test/results/03-erase-parts.out  | 106 +++++++++++
 external/pflash/test/results/04-program-rand.err |   0
 external/pflash/test/results/04-program-rand.out | 111 ++++++++++++
 external/pflash/test/results/05-bad-numbers.err  |   0
 external/pflash/test/results/05-bad-numbers.out  | 217 +++++++++++++++++++++++
 external/pflash/test/test-pflash                 |  59 ++++++
 external/pflash/test/tests/00-usage              |  12 ++
 external/pflash/test/tests/01-info               |  22 +++
 external/pflash/test/tests/02-erase              |  26 +++
 external/pflash/test/tests/03-erase-parts        |  55 ++++++
 external/pflash/test/tests/04-program-rand       |  54 ++++++
 external/pflash/test/tests/05-bad-numbers        |  65 +++++++
 external/test/test.sh                            |  11 +-
 29 files changed, 991 insertions(+), 4 deletions(-)
 create mode 100644 external/pflash/test/files/01-info.ffs
 create mode 100644 external/pflash/test/files/02-erase.ffs
 create mode 100644 external/pflash/test/files/03-erase-parts.ffs
 create mode 100644 external/pflash/test/files/04-program-rand.ffs
 create mode 100644 external/pflash/test/files/05-bad-numbers.ffs
 create mode 100755 external/pflash/test/make-check-test
 create mode 100644 external/pflash/test/results/00-usage.err
 create mode 100644 external/pflash/test/results/00-usage.out
 create mode 100644 external/pflash/test/results/01-info.err
 create mode 100644 external/pflash/test/results/01-info.out
 create mode 100644 external/pflash/test/results/02-erase.err
 create mode 100644 external/pflash/test/results/02-erase.out
 create mode 100644 external/pflash/test/results/03-erase-parts.err
 create mode 100644 external/pflash/test/results/03-erase-parts.out
 create mode 100644 external/pflash/test/results/04-program-rand.err
 create mode 100644 external/pflash/test/results/04-program-rand.out
 create mode 100644 external/pflash/test/results/05-bad-numbers.err
 create mode 100644 external/pflash/test/results/05-bad-numbers.out
 create mode 100755 external/pflash/test/test-pflash
 create mode 100644 external/pflash/test/tests/00-usage
 create mode 100644 external/pflash/test/tests/01-info
 create mode 100644 external/pflash/test/tests/02-erase
 create mode 100644 external/pflash/test/tests/03-erase-parts
 create mode 100644 external/pflash/test/tests/04-program-rand
 create mode 100644 external/pflash/test/tests/05-bad-numbers

diff --git a/external/Makefile.check b/external/Makefile.check
index 9147421d..b5266ae6 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 edec7db5..223b639e 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 0b3a2a69..e931f296 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 00000000..517dc47b
--- /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 00000000..7efcd717
--- /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 00000000..7efcd717
--- /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 00000000..7efcd717
--- /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 00000000..7efcd717
--- /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 00000000..7f009486
--- /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 00000000..e69de29b
diff --git a/external/pflash/test/results/00-usage.out b/external/pflash/test/results/00-usage.out
new file mode 100644
index 00000000..3b54f456
--- /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 00000000..e69de29b
diff --git a/external/pflash/test/results/01-info.out b/external/pflash/test/results/01-info.out
new file mode 100644
index 00000000..43baf316
--- /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 at 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 00000000..e69de29b
diff --git a/external/pflash/test/results/02-erase.out b/external/pflash/test/results/02-erase.out
new file mode 100644
index 00000000..7d251a70
--- /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 00000000..e69de29b
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 00000000..28f0b23d
--- /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 00000000..e69de29b
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 00000000..b0df327c
--- /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 00000000..e69de29b
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 00000000..211bd6a0
--- /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 00000000..dd775bda
--- /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 00000000..b83bca85
--- /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 00000000..7d6fd523
--- /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 00000000..dd00f381
--- /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 00000000..09421bbe
--- /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 00000000..62f2f920
--- /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 00000000..f84e7992
--- /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 f63cce5f..c3bbc61c 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
-- 
2.13.3



More information about the Skiboot mailing list