-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check firmware prior to writing, disclaimer updates in readme, functi…
…onal-test script (#20) Changes here add: * A safeguard to make it less possible to write invalid (bricking) firmware to the device * Disclaimer in readme warning about the potentially unwanted side-effects of reading from the device * A functional test script to run prior to making any pushes or releases (sadly specific to my development environment)
- Loading branch information
1 parent
9ae9864
commit 66f46f2
Showing
4 changed files
with
182 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# TOOL=sinowealth-kb-tool | ||
TOOL="cargo run --" | ||
FILE_PREFIX="private/test-$(date +'%Y%m%dT%H%M%S')" | ||
PART="nuphy-air60" | ||
|
||
EXPECTED_BOOTLOADER_MD5="3e0ebd0c440af5236d7ff8872343f85d" | ||
|
||
FILE_DEFAULT="$FILE_PREFIX-read.hex" | ||
FILE_BOOTLOADER="$FILE_PREFIX-read-bootloader.hex" | ||
FILE_FULL="$FILE_PREFIX-read-full.hex" | ||
FILE_CUSTOM="$FILE_PREFIX-read-custom.hex" | ||
FILE_OVERRIDE="$FILE_PREFIX-read-override.hex" | ||
FILE_POST_WRITE="$FILE_PREFIX-post-write.hex" | ||
|
||
function reboot_device () { | ||
echo "Turning off port..." | ||
uhubctl -a off -p 1 -l 65-1 | ||
sleep 1 | ||
echo "Turning on port..." | ||
uhubctl -a on -p 1 -l 65-1 | ||
echo "Waiting..." | ||
sleep 5 | ||
} | ||
|
||
function get_md5 () { | ||
MD5SUM=($(md5sum "$1")) | ||
echo $MD5SUM | ||
} | ||
|
||
function get_md5_from_hex () { | ||
objcopy --input-target=ihex --output-target=binary "$1" "${1%.hex}.bin" | ||
MD5SUM=$(get_md5 "${1%.hex}.bin") | ||
echo $MD5SUM | ||
} | ||
|
||
echo "Initial reboot..." | ||
reboot_device | ||
|
||
echo "Standard read..." | ||
$TOOL read --part "$PART" "$FILE_DEFAULT" | ||
|
||
reboot_device | ||
|
||
echo "Bootloader read..." | ||
$TOOL read --part "$PART" -b "$FILE_BOOTLOADER" | ||
|
||
reboot_device | ||
|
||
echo "Full read..." | ||
$TOOL read --part "$PART" --full "$FILE_FULL" | ||
|
||
reboot_device | ||
|
||
echo "Custom read..." | ||
$TOOL read \ | ||
--flash_size 61440 \ | ||
--bootloader_size 4096 \ | ||
--page_size 2048 \ | ||
--vendor_id 0x05ac \ | ||
--product_id 0x024f \ | ||
"$FILE_CUSTOM" | ||
|
||
reboot_device | ||
|
||
echo "Override read..." | ||
$TOOL read \ | ||
--part "$PART" \ | ||
--vendor_id 0x05ac \ | ||
--product_id 0x024f \ | ||
"$FILE_OVERRIDE" | ||
|
||
reboot_device | ||
|
||
READ_MD5=$(get_md5_from_hex "$FILE_DEFAULT") | ||
READ_BOOTLOADER_MD5=$(get_md5_from_hex "$FILE_BOOTLOADER") | ||
READ_FULL_MD5=$(get_md5_from_hex "$FILE_FULL") | ||
READ_CUSTOM_MD5=$(get_md5_from_hex "$FILE_CUSTOM") | ||
READ_OVERRIDE_MD5=$(get_md5_from_hex "$FILE_OVERRIDE") | ||
|
||
echo "Checking bootloader checksum" | ||
if [[ "$READ_BOOTLOADER_MD5" != "$EXPECTED_BOOTLOADER_MD5" ]]; then | ||
echo "MD5 mismatch $READ_BOOTLOADER_MD5 != $EXPECTED_BOOTLOADER_MD5" | ||
exit 1 | ||
fi | ||
|
||
echo "Checking custom checksum" | ||
if [[ "$READ_CUSTOM_MD5" != "$READ_MD5" ]]; then | ||
echo "MD5 mismatch $READ_CUSTOM_MD5 != $READ_MD5" | ||
exit 1 | ||
fi | ||
|
||
echo "Checking override checksum" | ||
if [[ "$READ_OVERRIDE_MD5" != "$READ_MD5" ]]; then | ||
echo "MD5 mismatch $READ_OVERRIDE_MD5 != $READ_MD5" | ||
exit 1 | ||
fi | ||
|
||
echo "Checking standard+bootloader == full" | ||
cat "${FILE_DEFAULT%.hex}.bin" "${FILE_BOOTLOADER%.hex}.bin" > "$FILE_PREFIX-concat-full.bin" | ||
EXPECTED_FULL_MD5=$(get_md5 "$FILE_PREFIX-concat-full.bin") | ||
if [[ "$READ_FULL_MD5" != "$EXPECTED_FULL_MD5" ]]; then | ||
echo "MD5 mismatch $READ_FULL_MD5 != $EXPECTED_FULL_MD5" | ||
exit 1 | ||
fi | ||
|
||
echo "Standard write..." | ||
$TOOL write --part "$PART" "$FILE_DEFAULT" | ||
|
||
reboot_device | ||
|
||
echo "Post-write read..." | ||
$TOOL read --part "$PART" "$FILE_POST_WRITE" | ||
|
||
READ_POST_WRITE_MD5=$(get_md5_from_hex "$FILE_POST_WRITE") | ||
|
||
echo "Checking post-write checksum" | ||
if [[ "$READ_POST_WRITE_MD5" != "$READ_MD5" ]]; then | ||
echo "MD5 mismatch $READ_POST_WRITE_MD5 != $READ_MD5" | ||
exit 1 | ||
fi | ||
|
||
reboot_device | ||
|
||
echo "Passed all tests!" |