From 312e4ec2fe2e62c19c8f25658de218b7ef028560 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 1 Nov 2022 22:21:07 +0100 Subject: [PATCH] Added firmware hash readout --- Device.h | 1 - Framing.h | 1 + Power.h | 1 - RNode_Firmware.ino | 12 ++++++++++++ Utilities.h | 42 +++++++++++++++++++++++++++++++++++++++++- 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/Device.h b/Device.h index 612e964..f62ffc8 100644 --- a/Device.h +++ b/Device.h @@ -76,7 +76,6 @@ void device_load_signature() { } void device_load_firmware_hash() { - Serial.println("Loading hash from EEPROM"); for (uint8_t i = 0; i < DEV_HASH_LEN; i++) { dev_firmware_hash_target[i] = EEPROM.read(dev_fwhash_addr(i)); } diff --git a/Framing.h b/Framing.h index b8a8a1d..649bb1f 100644 --- a/Framing.h +++ b/Framing.h @@ -46,6 +46,7 @@ #define CMD_DEV_HASH 0x56 #define CMD_DEV_SIG 0x57 #define CMD_FW_HASH 0x58 + #define CMD_HASHES 0x60 #define CMD_UNLOCK_ROM 0x59 #define ROM_UNLOCK_BYTE 0xF8 #define CMD_RESET 0x55 diff --git a/Power.h b/Power.h index 7aa24bc..0677b47 100644 --- a/Power.h +++ b/Power.h @@ -45,7 +45,6 @@ void measure_battery() { battery_voltage = PMU.getBattVoltage()/1000.0; battery_percent = PMU.getBattPercentage()*1.0; battery_installed = PMU.isBatteryConnect(); - // auxillary_temperature = PMU.getTemp(); external_power = PMU.isVBUSPlug(); float ext_voltage = PMU.getVbusVoltage()/1000.0; float ext_current = PMU.getVbusCurrent(); diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index f608859..0a441ba 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -697,6 +697,18 @@ void serialCallback(uint8_t sbyte) { device_save_signature(); } #endif + } else if (command == CMD_HASHES) { + #if MCU_VARIANT == MCU_ESP32 + if (sbyte == 0x01) { + kiss_indicate_target_fw_hash(); + } else if (sbyte == 0x02) { + kiss_indicate_fw_hash(); + } else if (sbyte == 0x03) { + kiss_indicate_bootloader_hash(); + } else if (sbyte == 0x04) { + kiss_indicate_partition_table_hash(); + } + #endif } else if (command == CMD_FW_HASH) { #if MCU_VARIANT == MCU_ESP32 if (sbyte == FESC) { diff --git a/Utilities.h b/Utilities.h index 3b10b77..49f89a1 100644 --- a/Utilities.h +++ b/Utilities.h @@ -43,7 +43,7 @@ uint8_t boot_vector = 0x00; // TODO: Get ESP32 boot flags #endif -#if BOARD_MODEL == BOARD_RNODE_NG_20 +#if BOARD_MODEL == BOARD_RNODE_NG_20 || BOARD_RNODE_NG_21 #include #define NP_PIN 4 #define NUMPIXELS 1 @@ -635,6 +635,46 @@ void kiss_indicate_fbstate() { } serial_write(FEND); } + + void kiss_indicate_target_fw_hash() { + serial_write(FEND); + serial_write(CMD_DEV_HASH); + for (int i = 0; i < DEV_HASH_LEN; i++) { + uint8_t byte = dev_firmware_hash_target[i]; + escaped_serial_write(byte); + } + serial_write(FEND); + } + + void kiss_indicate_fw_hash() { + serial_write(FEND); + serial_write(CMD_DEV_HASH); + for (int i = 0; i < DEV_HASH_LEN; i++) { + uint8_t byte = dev_firmware_hash[i]; + escaped_serial_write(byte); + } + serial_write(FEND); + } + + void kiss_indicate_bootloader_hash() { + serial_write(FEND); + serial_write(CMD_DEV_HASH); + for (int i = 0; i < DEV_HASH_LEN; i++) { + uint8_t byte = dev_bootloader_hash[i]; + escaped_serial_write(byte); + } + serial_write(FEND); + } + + void kiss_indicate_partition_table_hash() { + serial_write(FEND); + serial_write(CMD_DEV_HASH); + for (int i = 0; i < DEV_HASH_LEN; i++) { + uint8_t byte = dev_partition_table_hash[i]; + escaped_serial_write(byte); + } + serial_write(FEND); + } #endif void kiss_indicate_fb() {