aboutsummaryrefslogtreecommitdiff
path: root/testing/DMBootloader/generate_cmd_erase_random_pages.sh
diff options
context:
space:
mode:
authorJan Sucan <sucanjan@fit.cvut.cz>2019-06-04 14:34:27 +0200
committerJan Sucan <sucanjan@fit.cvut.cz>2019-06-04 14:34:27 +0200
commitdc8703206e3f0f69605c56d0e1127f7e17f3476a (patch)
tree166823a741dc420c10d54250cb53d1e3a6b74faf /testing/DMBootloader/generate_cmd_erase_random_pages.sh
Initial commit
Diffstat (limited to 'testing/DMBootloader/generate_cmd_erase_random_pages.sh')
-rw-r--r--testing/DMBootloader/generate_cmd_erase_random_pages.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/testing/DMBootloader/generate_cmd_erase_random_pages.sh b/testing/DMBootloader/generate_cmd_erase_random_pages.sh
new file mode 100644
index 0000000..3b29969
--- /dev/null
+++ b/testing/DMBootloader/generate_cmd_erase_random_pages.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+# Generates the YUP commands for DMBootloader for erasing random pages
+
+MIN_PAGE=1
+MAX_PAGE=992
+PAGE_COUNT=16
+OUTDIR=4_erase_random_pages
+MEMIMAGE=3_cmd_read_all_pages/memory_image
+
+tmp_cmd=${OUTDIR}/0_erase
+mkdir $tmp_cmd
+cp $MEMIMAGE $tmp_cmd
+
+for i in $(seq 1 $PAGE_COUNT); do
+ # The same page numbers can possibly be generated
+ virtual_page=$(( $RANDOM % $MAX_PAGE ))
+
+ d=${OUTDIR}/${i}_erase
+ mkdir ${d}
+
+ o=${d}/1_cmd
+ r=${d}/1_reply
+ m_base=${OUTDIR}/$(( $i - 1 ))_erase/memory_image
+ m=${d}/memory_image
+
+ # Generate erase command and gradually construct images of virtual
+ # address space with the random pages erased
+ ./create_dmbootloader_cmd.sh erase $virtual_page $o
+ # Each Erase command must complete with success
+ printf '\x00' >$r
+ # Memory image for this Erase command will be based on the memory image for the previous command
+ cp $m_base $m
+ { dd if=/dev/zero bs=1 count=512 | tr '\000' '\377' | \
+ dd bs=1 of=$m seek=$(( $virtual_page * 512)) conv=notrunc; } 2>/dev/null
+
+ echo "Generated $(( $i )) / $(( $PAGE_COUNT ))"
+done
+
+rm -rf $tmp_cmd
+
+exit 0