Patrick Georgi | 5ac6a63 | 2020-10-28 17:29:38 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | set -e |
| 3 | |
Nico Huber | 819ba50 | 2023-03-07 22:59:01 +0000 | [diff] [blame] | 4 | TEMP_DIR=$(mktemp -d) |
| 5 | trap "rm -rf ${TEMP_DIR}" EXIT |
| 6 | |
Nico Huber | 4eb9748 | 2024-04-21 21:44:33 +0200 | [diff] [blame] | 7 | dd bs=$((128*1024)) count=1 </dev/urandom >"${TEMP_DIR}/rand" |
| 8 | dd bs=$((128*1024)) count=1 </dev/urandom >"${TEMP_DIR}/rand2" |
| 9 | dd bs=$((128*1024)) count=1 </dev/zero | tr '\000' '\377' >"${TEMP_DIR}/empty" |
Nico Huber | 819ba50 | 2023-03-07 22:59:01 +0000 | [diff] [blame] | 10 | |
Nico Huber | 4eb9748 | 2024-04-21 21:44:33 +0200 | [diff] [blame] | 11 | test_prog() { |
| 12 | prog="$1" |
Nico Huber | 819ba50 | 2023-03-07 22:59:01 +0000 | [diff] [blame] | 13 | |
Nico Huber | 72b30a0 | 2024-04-21 21:59:19 +0200 | [diff] [blame] | 14 | if [ "${CROSS_COMPILE}" ]; then |
| 15 | return 0 |
| 16 | fi |
| 17 | |
Nico Huber | 4eb9748 | 2024-04-21 21:44:33 +0200 | [diff] [blame] | 18 | "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -w "${TEMP_DIR}/rand" |
| 19 | "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -r "${TEMP_DIR}/bak" |
| 20 | cmp "${TEMP_DIR}/rand" "${TEMP_DIR}/bak" |
Nico Huber | 7a48031 | 2023-04-10 14:54:22 +0200 | [diff] [blame] | 21 | |
Nico Huber | 4eb9748 | 2024-04-21 21:44:33 +0200 | [diff] [blame] | 22 | "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -c M25P10 -w "${TEMP_DIR}/rand2" |
| 23 | "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -c M25P10 -v "${TEMP_DIR}/rand2" |
| 24 | |
| 25 | "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -c M25P10 -E |
| 26 | "${prog}" -p dummy:emulate=M25P10.RES,image="${TEMP_DIR}/image" -c M25P10 -v "${TEMP_DIR}/empty" |
| 27 | } |
| 28 | |
Nico Huber | 3d2f212 | 2024-04-21 21:54:15 +0200 | [diff] [blame] | 29 | if [ "${MAKECMD=make}" ]; then |
| 30 | ${MAKECMD} clean |
| 31 | eval ${MAKECMD} -j${CPUS:-$(nproc)} CC="\"${CC:-ccache cc}\"" ${MAKEARGS-CONFIG_EVERYTHING=yes} |
| 32 | test_prog ./flashprog |
| 33 | fi |
Nico Huber | 4eb9748 | 2024-04-21 21:44:33 +0200 | [diff] [blame] | 34 | |
Nico Huber | 3d2f212 | 2024-04-21 21:54:15 +0200 | [diff] [blame] | 35 | if [ "${MESONCMD=meson}" ]; then |
| 36 | eval ${MESONCMD} setup ${MESONARGS--D programmer=all --buildtype release} "${TEMP_DIR}/build" |
| 37 | ninja ${CPUS:+-j${CPUS}} -C "${TEMP_DIR}/build" |
| 38 | test_prog "${TEMP_DIR}/build/flashprog" |
Nico Huber | c7b549e | 2023-03-19 14:27:43 +0000 | [diff] [blame] | 39 | |
| 40 | if [ "${MAKECMD}" -a ! "${CROSS_COMPILE}" ]; then |
| 41 | ./flashprog -L >"${TEMP_DIR}/flashprog.supported" |
| 42 | "${TEMP_DIR}/build/flashprog" -L >"${TEMP_DIR}/mashprog.supported" |
| 43 | diff -u "${TEMP_DIR}/flashprog.supported" "${TEMP_DIR}/mashprog.supported" |
| 44 | fi |
Nico Huber | 3d2f212 | 2024-04-21 21:54:15 +0200 | [diff] [blame] | 45 | fi |