aboutsummaryrefslogtreecommitdiff
path: root/testing/DMBootloader/create_dmbootloader_cmd.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/create_dmbootloader_cmd.sh
Initial commit
Diffstat (limited to 'testing/DMBootloader/create_dmbootloader_cmd.sh')
-rw-r--r--testing/DMBootloader/create_dmbootloader_cmd.sh49
1 files changed, 49 insertions, 0 deletions
diff --git a/testing/DMBootloader/create_dmbootloader_cmd.sh b/testing/DMBootloader/create_dmbootloader_cmd.sh
new file mode 100644
index 0000000..4bb17b6
--- /dev/null
+++ b/testing/DMBootloader/create_dmbootloader_cmd.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+# Generates the Erase, Read, and Write YUP commands for DMBootloader.
+# Write command is generated with random data of the page.
+
+cmd_write_header()
+{
+ little_endian=$(printf "%04X\n" $2 | sed 's,^\(..\)\(..\)$,\2\1,')
+
+ printf '\x'$1 >"$file"
+ printf '\x'$(echo $little_endian | cut -c1-2) >>"$3"
+ printf '\x'$(echo $little_endian | cut -c3-4) >>"$3"
+}
+
+usage()
+{
+ {
+ echo "Usage: $0 CMD PAGE_NUMBER OUT_FILE"
+ echo " CMD write, read, or erase"
+ echo " PAGE_NUMBER 16-bit page number"
+ echo " OUT_FILE file to which the command's binary data will be written"
+ } >&2
+ exit 1
+}
+
+[ $# -ne 3 ] && usage
+
+cmd=$1
+page_num=$2
+file="${3}"
+
+case "$cmd" in
+ write)
+ cmd_write_header 00 $page_num "$file"
+ ;;
+ read)
+ cmd_write_header 02 $page_num "$file"
+ ;;
+ erase)
+ cmd_write_header 01 $page_num "$file"
+ ;;
+ *)
+ echo "Unknown command requested" >&2
+ usage
+esac
+
+[ "$1" = "write" ] && dd if=/dev/urandom of="$file" bs=1 count=512 seek=3 2>/dev/null
+
+exit 0