Add Wi-Fi OTA partition migration support
This commit is contained in:
1 parent
69681a2db6
commit
9844982b00
20 files changed
+1637
-62
No files matched your search
+96
-14
@@ -319,6 +319,37 @@ require(rak_usb, "build_flags", "FORCE_GPS_ALIVE")
|
||||
# replace each with that exact board's Full target.
|
||||
init_project_context >/dev/null
|
||||
|
||||
# ESP32 and nRF52 standalone room servers receive the same lean LoRa-OTA
|
||||
# sibling as repeaters. Sensor roles stay on their ordinary recipe so this
|
||||
# cannot accidentally become a blanket no-external-sensors policy.
|
||||
while IFS='|' read -r room_env room_ota_env; do
|
||||
is_supported_build_env "$room_ota_env" \
|
||||
|| fail "$room_ota_env was not registered as a room-server LoRa OTA target"
|
||||
[ "$(get_pio_build_env "$room_ota_env")" = "$room_env" ] \
|
||||
|| fail "$room_ota_env did not retain its room-server PlatformIO recipe"
|
||||
[ "$(get_reduced_lora_ota_target "$room_env")" = "$room_ota_env" ] \
|
||||
|| fail "$room_env did not resolve its reduced room-server OTA sibling"
|
||||
(
|
||||
BUILD_PROFILE_FOR_TARGET=standard
|
||||
ESP32_FULL_BUILD=0
|
||||
is_lora_ota_build "$room_ota_env" \
|
||||
|| fail "$room_ota_env did not enable LoRa OTA"
|
||||
)
|
||||
done <<'ROOM_OTA_SPECS'
|
||||
Heltec_v3_room_server|Heltec_v3_room_server_lora_ota_no_external_sensors
|
||||
RAK_3401_room_server|RAK_3401_room_server_lora_ota_no_external_sensors
|
||||
ROOM_OTA_SPECS
|
||||
print_release_firmware_targets get-room-server-firmwares-to-build | grep -Fx \
|
||||
RAK_3401_room_server_lora_ota_no_external_sensors >/dev/null \
|
||||
|| fail "room-server release resolution omitted its portable LoRa OTA target"
|
||||
for sensor_ota_env in \
|
||||
Heltec_v3_sensor_lora_ota_no_external_sensors \
|
||||
RAK_3401_sensor_lora_ota_no_external_sensors; do
|
||||
if is_supported_build_env "$sensor_ota_env"; then
|
||||
fail "$sensor_ota_env was incorrectly generated from a sensor role"
|
||||
fi
|
||||
done
|
||||
|
||||
# KISS inherits board OTA flags, not the application OTA implementation.
|
||||
for kiss_env in "${SUPPORTED_PIO_ENVS[@]}"; do
|
||||
is_kiss_modem_target "$kiss_env" || continue
|
||||
@@ -561,16 +592,20 @@ unset PLATFORMIO_BUILD_FLAGS PLATFORMIO_BUILD_UNFLAGS \
|
||||
PLATFORMIO_BUILD_SRC_FILTER
|
||||
|
||||
# An environment that includes only the tiny OTA inflater still needs the C++
|
||||
# protocol implementation when build.sh overlays LoRa OTA.
|
||||
reduced_nrf_ota_env=RAK_3401_repeater_lora_ota_no_external_sensors
|
||||
reduced_nrf_pio_env=$(get_pio_build_env "$reduced_nrf_ota_env")
|
||||
PLATFORMIO_BUILD_SRC_FILTER=""
|
||||
PLATFORMIO_EXTRA_SCRIPTS=""
|
||||
apply_nrf52_lora_ota_build_recipe "$reduced_nrf_ota_env" "$reduced_nrf_pio_env"
|
||||
if ! pio_env_option_contains "$reduced_nrf_pio_env" build_src_filter "helpers/ota/*.cpp" \
|
||||
&& [[ "$PLATFORMIO_BUILD_SRC_FILTER" != *"helpers/ota/*.cpp"* ]]; then
|
||||
fail "$reduced_nrf_ota_env omitted the OTA C++ implementation"
|
||||
fi
|
||||
# protocol implementation when build.sh overlays LoRa OTA. Room servers use
|
||||
# the same nRF52 overlay as repeaters.
|
||||
for reduced_nrf_ota_env in \
|
||||
RAK_3401_repeater_lora_ota_no_external_sensors \
|
||||
RAK_3401_room_server_lora_ota_no_external_sensors; do
|
||||
reduced_nrf_pio_env=$(get_pio_build_env "$reduced_nrf_ota_env")
|
||||
PLATFORMIO_BUILD_SRC_FILTER=""
|
||||
PLATFORMIO_EXTRA_SCRIPTS=""
|
||||
apply_nrf52_lora_ota_build_recipe "$reduced_nrf_ota_env" "$reduced_nrf_pio_env"
|
||||
if ! pio_env_option_contains "$reduced_nrf_pio_env" build_src_filter "helpers/ota/*.cpp" \
|
||||
&& [[ "$PLATFORMIO_BUILD_SRC_FILTER" != *"helpers/ota/*.cpp"* ]]; then
|
||||
fail "$reduced_nrf_ota_env omitted the OTA C++ implementation"
|
||||
fi
|
||||
done
|
||||
unset PLATFORMIO_BUILD_SRC_FILTER PLATFORMIO_EXTRA_SCRIPTS
|
||||
|
||||
# The bounded AsyncTCP task stack belongs to every ESP32 Full profile, including
|
||||
@@ -727,26 +762,40 @@ for logging_target in Station_G2_companion_radio_full RAK_4631_companion_radio_f
|
||||
verify_full_logging_contract "$logging_target" 0 off 1 yes no
|
||||
done
|
||||
|
||||
# Synthetic inventory: one ESP32 target qualified for expanded Full and one
|
||||
# nRF52 target which must attempt complete LoRa OTA in its current partition.
|
||||
# Synthetic inventory: ESP32 and nRF52 repeater/room-server targets with the
|
||||
# same lean OTA policy. The sensor deliberately has no lean sibling.
|
||||
SUPPORTED_PIO_ENVS=(
|
||||
esp_repeater
|
||||
esp_repeater_lora_ota_no_external_sensors
|
||||
esp_room_server
|
||||
esp_room_server_lora_ota_no_external_sensors
|
||||
nrf_repeater
|
||||
nrf_repeater_lora_ota_no_external_sensors
|
||||
nrf_room_server
|
||||
nrf_room_server_lora_ota_no_external_sensors
|
||||
nrf_qspi_repeater
|
||||
nrf_qspi_repeater_lora_ota_no_external_sensors
|
||||
nrf_qspi_room_server
|
||||
nrf_qspi_room_server_lora_ota_no_external_sensors
|
||||
nrf_sensor
|
||||
)
|
||||
PIO_ENV_PLATFORM_BY_NAME[esp_repeater]=ESP32_PLATFORM
|
||||
PIO_ENV_PLATFORM_BY_NAME[esp_repeater_lora_ota_no_external_sensors]=ESP32_PLATFORM
|
||||
PIO_ENV_PLATFORM_BY_NAME[esp_room_server]=ESP32_PLATFORM
|
||||
PIO_ENV_PLATFORM_BY_NAME[esp_room_server_lora_ota_no_external_sensors]=ESP32_PLATFORM
|
||||
PIO_ENV_PLATFORM_BY_NAME[nrf_repeater]=NRF52_PLATFORM
|
||||
PIO_ENV_PLATFORM_BY_NAME[nrf_repeater_lora_ota_no_external_sensors]=NRF52_PLATFORM
|
||||
PIO_ENV_PLATFORM_BY_NAME[nrf_room_server]=NRF52_PLATFORM
|
||||
PIO_ENV_PLATFORM_BY_NAME[nrf_room_server_lora_ota_no_external_sensors]=NRF52_PLATFORM
|
||||
PIO_ENV_PLATFORM_BY_NAME[nrf_qspi_repeater]=NRF52_PLATFORM
|
||||
PIO_ENV_PLATFORM_BY_NAME[nrf_qspi_repeater_lora_ota_no_external_sensors]=NRF52_PLATFORM
|
||||
PIO_ENV_PLATFORM_BY_NAME[nrf_qspi_room_server]=NRF52_PLATFORM
|
||||
PIO_ENV_PLATFORM_BY_NAME[nrf_qspi_room_server_lora_ota_no_external_sensors]=NRF52_PLATFORM
|
||||
PIO_ENV_PLATFORM_BY_NAME[nrf_sensor]=NRF52_PLATFORM
|
||||
PIO_ENV_QSPI_OTA_BY_NAME[nrf_qspi_repeater_lora_ota_no_external_sensors]=1
|
||||
PIO_ENV_QSPI_OTA_BY_NAME[nrf_qspi_room_server_lora_ota_no_external_sensors]=1
|
||||
PIO_ENV_FULL_BUILD_BY_NAME[esp_repeater]=1
|
||||
PIO_ENV_FULL_BUILD_BY_NAME[esp_room_server]=1
|
||||
|
||||
RESOLVED_BUILD_TARGETS=(esp_repeater)
|
||||
configure_effective_build_profile build-firmware >/dev/null
|
||||
@@ -756,6 +805,16 @@ configure_effective_build_profile build-firmware >/dev/null
|
||||
esp_repeater_lora_ota_no_external_sensors ] \
|
||||
|| fail "ESP32 reduced fallback was not resolved"
|
||||
|
||||
BUILD_PROFILE_OVERRIDE=auto
|
||||
BUILD_PROFILE_EXPLICIT=0
|
||||
RESOLVED_BUILD_TARGETS=(esp_room_server)
|
||||
configure_effective_build_profile build-firmware >/dev/null
|
||||
[ "$BUILD_PROFILE_EFFECTIVE" = full ] || fail "ESP32 room server auto did not prefer Full"
|
||||
[ "$AUTO_PREFER_FULL_BUILD" = 1 ] || fail "ESP32 room-server Full pass was not scheduled"
|
||||
[ "$AUTO_REDUCED_FALLBACK_TARGET" = \
|
||||
esp_room_server_lora_ota_no_external_sensors ] \
|
||||
|| fail "ESP32 room-server reduced fallback was not resolved"
|
||||
|
||||
BUILD_PROFILE_OVERRIDE=auto
|
||||
BUILD_PROFILE_EXPLICIT=0
|
||||
RESOLVED_BUILD_TARGETS=(nrf_repeater)
|
||||
@@ -768,6 +827,18 @@ configure_effective_build_profile build-firmware >/dev/null
|
||||
[ "$AUTO_PUBLISH_REDUCED_SECOND_PASS" = 1 ] \
|
||||
|| fail "internal-flash nRF52 reduced second artifact was not scheduled"
|
||||
|
||||
BUILD_PROFILE_OVERRIDE=auto
|
||||
BUILD_PROFILE_EXPLICIT=0
|
||||
RESOLVED_BUILD_TARGETS=(nrf_room_server)
|
||||
configure_effective_build_profile build-firmware >/dev/null
|
||||
[ "${RESOLVED_BUILD_TARGETS[0]}" = \
|
||||
nrf_room_server_lora_ota_no_external_sensors ] \
|
||||
|| fail "nRF52 room-server complete OTA pass did not select the OTA identity"
|
||||
[ "$AUTO_COMPLETE_FIRST_PASS" = 1 ] \
|
||||
|| fail "nRF52 room-server complete first pass was not scheduled"
|
||||
[ "$AUTO_PUBLISH_REDUCED_SECOND_PASS" = 1 ] \
|
||||
|| fail "internal-flash nRF52 room-server reduced second artifact was not scheduled"
|
||||
|
||||
BUILD_PROFILE_OVERRIDE=auto
|
||||
BUILD_PROFILE_EXPLICIT=0
|
||||
RESOLVED_BUILD_TARGETS=(nrf_qspi_repeater)
|
||||
@@ -777,6 +848,15 @@ configure_effective_build_profile build-firmware >/dev/null
|
||||
[ "$AUTO_PUBLISH_REDUCED_SECOND_PASS" = 0 ] \
|
||||
|| fail "external-storage nRF52 incorrectly scheduled a redundant artifact"
|
||||
|
||||
BUILD_PROFILE_OVERRIDE=auto
|
||||
BUILD_PROFILE_EXPLICIT=0
|
||||
RESOLVED_BUILD_TARGETS=(nrf_qspi_room_server)
|
||||
configure_effective_build_profile build-firmware >/dev/null
|
||||
[ "$AUTO_COMPLETE_FIRST_PASS" = 1 ] \
|
||||
|| fail "external-storage nRF52 room-server complete first pass was not scheduled"
|
||||
[ "$AUTO_PUBLISH_REDUCED_SECOND_PASS" = 0 ] \
|
||||
|| fail "external-storage nRF52 room-server incorrectly scheduled a redundant artifact"
|
||||
|
||||
BUILD_PROFILE_OVERRIDE=auto
|
||||
BUILD_PROFILE_EXPLICIT=0
|
||||
RESOLVED_BUILD_TARGETS=(nrf_sensor)
|
||||
@@ -784,9 +864,9 @@ configure_effective_build_profile build-firmware >/dev/null
|
||||
[ "$BUILD_PROFILE_EFFECTIVE" = auto ] \
|
||||
|| fail "nRF52 sensor did not retain its ordinary auto profile"
|
||||
[ "$AUTO_COMPLETE_FIRST_PASS" = 0 ] \
|
||||
|| fail "non-repeater nRF52 target incorrectly scheduled OTA profile passes"
|
||||
|| fail "nRF52 sensor incorrectly scheduled OTA profile passes"
|
||||
[ "$AUTO_PUBLISH_REDUCED_SECOND_PASS" = 0 ] \
|
||||
|| fail "non-repeater nRF52 target incorrectly scheduled two artifacts"
|
||||
|| fail "nRF52 sensor incorrectly scheduled two artifacts"
|
||||
|
||||
# Ordinary USB-loggable roles compile their historical logging profile into
|
||||
# the canonical artifact. LoRa OTA repeaters, KISS, and BLE keep their distinct
|
||||
@@ -1018,6 +1098,8 @@ verify_reduced_sensor_flags() {
|
||||
|
||||
verify_reduced_sensor_flags \
|
||||
RAK_3401_repeater_lora_ota_no_external_sensors 1
|
||||
verify_reduced_sensor_flags \
|
||||
RAK_3401_room_server_lora_ota_no_external_sensors 1
|
||||
verify_reduced_sensor_flags \
|
||||
Heltec_t114_repeater_lora_ota_no_external_sensors 0
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <helpers/ESP32PartitionMigrationPolicy.h>
|
||||
|
||||
namespace policy = mesh::esp32_partition_migration;
|
||||
|
||||
TEST(Esp32PartitionMigrationPolicy, AcceptsOnlyTheKnownLegacyV4Layout) {
|
||||
EXPECT_TRUE(policy::isLegacyLayout(policy::kLegacyLayout));
|
||||
EXPECT_TRUE(policy::canMigrate(policy::kRequiredFlashBytes,
|
||||
policy::kLegacyLayout));
|
||||
EXPECT_TRUE(policy::canMigrate(policy::kRequiredFlashBytes + 1,
|
||||
policy::kLegacyLayout));
|
||||
EXPECT_FALSE(policy::canMigrate(policy::kRequiredFlashBytes - 1,
|
||||
policy::kLegacyLayout));
|
||||
|
||||
policy::PartitionGeometry shifted = policy::kLegacyLayout;
|
||||
shifted.spiffs_address += policy::kSectorBytes;
|
||||
EXPECT_FALSE(policy::isLegacyLayout(shifted));
|
||||
EXPECT_FALSE(policy::canMigrate(policy::kRequiredFlashBytes, shifted));
|
||||
}
|
||||
|
||||
TEST(Esp32PartitionMigrationPolicy, ExpandedLayoutRetainsAndGrowsSpiffs) {
|
||||
EXPECT_TRUE(policy::isExpandedLayout(policy::kExpandedLayout));
|
||||
EXPECT_EQ(0x9000U, policy::kExpandedLayout.nvs_address);
|
||||
EXPECT_EQ(policy::kLegacyLayout.nvs_size, policy::kExpandedLayout.nvs_size);
|
||||
EXPECT_EQ(policy::kLegacyLayout.otadata_address,
|
||||
policy::kExpandedLayout.otadata_address);
|
||||
EXPECT_LT(policy::kLegacyLayout.spiffs_address,
|
||||
policy::kExpandedLayout.spiffs_address);
|
||||
EXPECT_GE(policy::kExpandedLayout.spiffs_size,
|
||||
policy::kLegacyLayout.spiffs_size);
|
||||
EXPECT_EQ(policy::kExpandedLayout.app1_address + policy::kExpandedLayout.app1_size,
|
||||
policy::kExpandedLayout.spiffs_address);
|
||||
}
|
||||
|
||||
TEST(Esp32PartitionMigrationPolicy, GenericPlansAcceptStableEightAndSixteenMiBLayouts) {
|
||||
EXPECT_EQ(&policy::kTarget8MB, policy::targetForFlash(8U * 1024U * 1024U));
|
||||
EXPECT_EQ(&policy::kTarget16MB, policy::targetForFlash(16U * 1024U * 1024U));
|
||||
EXPECT_EQ(nullptr, policy::targetForFlash(4U * 1024U * 1024U));
|
||||
EXPECT_TRUE(policy::isTargetLayout(8U * 1024U * 1024U,
|
||||
policy::kExpanded8MBLayout));
|
||||
EXPECT_TRUE(policy::canMigrateGeneric(8U * 1024U * 1024U,
|
||||
policy::kLegacyLayout));
|
||||
EXPECT_TRUE(policy::canMigrateGeneric(16U * 1024U * 1024U,
|
||||
policy::kLegacyLayout));
|
||||
|
||||
policy::PartitionGeometry moved_metadata = policy::kLegacyLayout;
|
||||
moved_metadata.nvs_address += policy::kSectorBytes;
|
||||
EXPECT_FALSE(policy::canMigrateGeneric(8U * 1024U * 1024U,
|
||||
moved_metadata));
|
||||
|
||||
policy::PartitionGeometry out_of_bounds = policy::kLegacyLayout;
|
||||
out_of_bounds.app1_address = 8U * 1024U * 1024U - policy::kSectorBytes;
|
||||
EXPECT_FALSE(policy::canMigrateGeneric(8U * 1024U * 1024U,
|
||||
out_of_bounds));
|
||||
}
|
||||
|
||||
TEST(Esp32PartitionMigrationPolicy, GeneratedTablePrefixContainsAllSixEntriesAndMd5) {
|
||||
EXPECT_EQ(0xE0U, policy::kExpandedPartitionTablePrefixBytes);
|
||||
EXPECT_EQ(0xAA, policy::kExpandedPartitionTablePrefix[0]);
|
||||
EXPECT_EQ(0x50, policy::kExpandedPartitionTablePrefix[1]);
|
||||
EXPECT_EQ(0xAA, policy::kExpandedPartitionTablePrefix[0xA0]);
|
||||
EXPECT_EQ(0x50, policy::kExpandedPartitionTablePrefix[0xA1]);
|
||||
EXPECT_EQ(0xEB, policy::kExpandedPartitionTablePrefix[0xC0]);
|
||||
EXPECT_EQ(0xEB, policy::kExpandedPartitionTablePrefix[0xC1]);
|
||||
EXPECT_EQ(policy::kExpandedPartitionTablePrefixBytes,
|
||||
policy::kExpanded8MBPartitionTablePrefixBytes);
|
||||
EXPECT_EQ(0x33, policy::kExpanded8MBPartitionTablePrefix[0x4A]);
|
||||
EXPECT_EQ(0x34, policy::kExpanded8MBPartitionTablePrefix[0x66]);
|
||||
EXPECT_EQ(0x67, policy::kExpanded8MBPartitionTablePrefix[0x86]);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
"""Contract checks for the shared ESP32 Wi-Fi partition migrator."""
|
||||
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
HEADER = ROOT / "src/helpers/ESP32PartitionMigrationPolicy.h"
|
||||
SOURCE = ROOT / "examples/esp32_partition_migrator/main.cpp"
|
||||
PROFILE = ROOT / "variants/heltec_v4/platformio.ini"
|
||||
MIGRATOR_BOARD = ROOT / "boards/heltec_v4_migrator.json"
|
||||
XIAO_PROFILE = ROOT / "variants/xiao_s3_wio/platformio.ini"
|
||||
XIAO_MIGRATOR_BOARD = ROOT / "boards/seeed_xiao_esp32s3_migrator.json"
|
||||
PARTITIONS = Path.home() / ".platformio/packages/framework-arduinoespressif32/tools/partitions/default_16MB.csv"
|
||||
PARTITIONS_8MB = Path.home() / ".platformio/packages/framework-arduinoespressif32/tools/partitions/default_8MB.csv"
|
||||
GENERATOR = Path.home() / ".platformio/packages/framework-arduinoespressif32/tools/gen_esp32part.py"
|
||||
|
||||
|
||||
class HeltecV4PartitionMigratorTest(unittest.TestCase):
|
||||
def test_profile_is_a_small_legacy_slot_image_with_its_own_wifi_uploader(self):
|
||||
profile = PROFILE.read_text(encoding="utf-8")
|
||||
start = profile.index("[env:heltec_v4_partition_migrator]")
|
||||
section = profile[start:]
|
||||
self.assertIn("board = heltec_v4_migrator", section)
|
||||
self.assertIn("board_build.partitions = default.csv", section)
|
||||
self.assertIn("+<../examples/esp32_partition_migrator>", section)
|
||||
self.assertIn("file://arch/esp32/AsyncElegantOTA", section)
|
||||
|
||||
xiao_profile = XIAO_PROFILE.read_text(encoding="utf-8")
|
||||
self.assertIn("[env:xiao_s3_partition_migrator]", xiao_profile)
|
||||
self.assertIn("board = seeed_xiao_esp32s3_migrator", xiao_profile)
|
||||
self.assertIn("[env:xiao_s3_partition_legacy_seed]", xiao_profile)
|
||||
self.assertIn("board_build.partitions = default.csv", xiao_profile)
|
||||
xiao_board = XIAO_MIGRATOR_BOARD.read_text(encoding="utf-8")
|
||||
self.assertIn('"flash_size": "8MB"', xiao_board)
|
||||
|
||||
def test_migration_stages_identity_and_self_copies_before_table_switch(self):
|
||||
source = SOURCE.read_text(encoding="utf-8")
|
||||
self.assertIn("bool stageLegacyIdentity()", source)
|
||||
self.assertIn("bool restoreStagedIdentity()", source)
|
||||
self.assertIn("/identity/_main.id", source)
|
||||
self.assertIn('Preferences migration_nvs', source)
|
||||
self.assertIn('kMigrationIdentityPendingKey[] = "id-pending"', source)
|
||||
self.assertIn("migration::canMigrateGeneric", source)
|
||||
self.assertIn("migration::isTargetLayout", source)
|
||||
self.assertIn("migration::targetForFlash", source)
|
||||
self.assertIn("copyAndVerify(*running", source)
|
||||
self.assertIn("plan->layout.app0_address", source)
|
||||
self.assertIn("running->size > plan->layout.app0_size", source)
|
||||
migration_body = source[source.index("void runMigration()") :]
|
||||
self.assertLess(migration_body.index("stageLegacyIdentity()"),
|
||||
migration_body.index("copyAndVerify(*running"))
|
||||
self.assertLess(migration_body.index("esp_ota_set_boot_partition(&target_app0)"),
|
||||
migration_body.index("publishExpandedPartitionTable(*plan)"))
|
||||
setup_body = source[source.index("void setup()") :]
|
||||
self.assertIn("restoreStagedIdentity()", setup_body)
|
||||
self.assertIn("AsyncElegantOTA.begin(&server)", source)
|
||||
self.assertIn("MeshCore-Migrate", source)
|
||||
self.assertIn("DRAM_ATTR esp_partition_t copy_destination", source)
|
||||
self.assertIn("partition_table_flash_hooks.region_protected = partitionTableRegionProtected", source)
|
||||
self.assertIn("chip->os_func = &partition_table_flash_hooks", source)
|
||||
self.assertIn("esp_flash_erase_region(chip", source)
|
||||
self.assertIn("esp_flash_write(chip", source)
|
||||
self.assertNotIn("#include <esp_flash_internal.h>", source)
|
||||
|
||||
board = MIGRATOR_BOARD.read_text(encoding="utf-8")
|
||||
self.assertIn('"-DARDUINO_USB_CDC_ON_BOOT=0"', board)
|
||||
|
||||
def test_embedded_partition_prefixes_match_arduino_default_targets(self):
|
||||
self.assertTrue(PARTITIONS.is_file(), "Arduino partition CSV is required")
|
||||
self.assertTrue(PARTITIONS_8MB.is_file(), "Arduino 8 MiB partition CSV is required")
|
||||
self.assertTrue(GENERATOR.is_file(), "Arduino partition generator is required")
|
||||
text = HEADER.read_text(encoding="utf-8")
|
||||
block = text[text.index("kExpandedPartitionTablePrefix[]"):
|
||||
text.index("};", text.index("kExpandedPartitionTablePrefix[]"))]
|
||||
embedded = bytes(int(value, 16) for value in re.findall(r"0x([0-9A-F]{2})", block))
|
||||
self.assertEqual(0xE0, len(embedded))
|
||||
with tempfile.TemporaryDirectory(prefix="meshcore-v4-partition-") as directory:
|
||||
generated = Path(directory) / "default16.bin"
|
||||
subprocess.run([sys.executable, str(GENERATOR), str(PARTITIONS), str(generated)],
|
||||
check=True, capture_output=True, text=True)
|
||||
self.assertEqual(embedded, generated.read_bytes()[:len(embedded)])
|
||||
generated_8mb = Path(directory) / "default8.bin"
|
||||
subprocess.run([sys.executable, str(GENERATOR), str(PARTITIONS_8MB), str(generated_8mb)],
|
||||
check=True, capture_output=True, text=True)
|
||||
start_8mb = text.index("kExpanded8MBPartitionTablePrefix[]")
|
||||
block_8mb = text[start_8mb:text.index("};", start_8mb)]
|
||||
embedded_8mb = bytes(int(value, 16)
|
||||
for value in re.findall(r"0x([0-9A-F]{2})", block_8mb))
|
||||
self.assertEqual(embedded_8mb, generated_8mb.read_bytes()[:len(embedded_8mb)])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user