Skip to content

Commit e07c5c2

Browse files
committed
Fix check of boot_out.txt contents
1 parent a8b69f2 commit e07c5c2

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

main.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -667,24 +667,26 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
667667
// This saves wear and tear on the flash and also prevents filesystem damage if power is lost
668668
// during the write, which may happen due to bobbling the power connector or weak power.
669669

670-
static const size_t NUM_CHARS_TO_COMPARE = 160;
670+
// + 1 to check that there aren't extra characters beyond the version info.
671+
const size_t constant_string_length = strlen(MICROPY_FULL_VERSION_INFO) + strlen(CIRCUITPY_BOARD_INFO) + 1;
671672
if (!have_boot_py && f_open(fs, boot_output_file, CIRCUITPY_BOOT_OUTPUT_FILE, FA_READ) == FR_OK) {
672673

673-
char file_contents[NUM_CHARS_TO_COMPARE];
674+
char file_contents[constant_string_length];
674675
UINT chars_read = 0;
675-
f_read(boot_output_file, file_contents, NUM_CHARS_TO_COMPARE, &chars_read);
676+
f_read(boot_output_file, file_contents, constant_string_length, &chars_read);
676677
f_close(boot_output_file);
677678
skip_boot_output =
678-
// + 2 accounts for \r\n.
679-
chars_read == strlen(MICROPY_FULL_VERSION_INFO) + 2 &&
680-
strncmp(file_contents, MICROPY_FULL_VERSION_INFO, strlen(MICROPY_FULL_VERSION_INFO)) == 0;
679+
chars_read == strlen(MICROPY_FULL_VERSION_INFO) + strlen(CIRCUITPY_BOARD_INFO) &&
680+
strncmp(file_contents, MICROPY_FULL_VERSION_INFO, strlen(MICROPY_FULL_VERSION_INFO)) == 0 &&
681+
strncmp(file_contents + strlen(MICROPY_FULL_VERSION_INFO),
682+
CIRCUITPY_BOARD_INFO, strlen(CIRCUITPY_BOARD_INFO)) == 0;
681683
}
682684

683685
if (!skip_boot_output) {
684-
// Wait 1.5 seconds before opening CIRCUITPY_BOOT_OUTPUT_FILE for write,
686+
// Wait 1 second before opening CIRCUITPY_BOOT_OUTPUT_FILE for write,
685687
// in case power is momentary or will fail shortly due to, say a low, battery.
686688
if (common_hal_mcu_processor_get_reset_reason() == RESET_REASON_POWER_ON) {
687-
mp_hal_delay_ms(1500);
689+
mp_hal_delay_ms(1000);
688690
}
689691
// USB isn't up, so we can write the file.
690692
filesystem_set_internal_writable_by_usb(false);
@@ -694,12 +696,9 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
694696
// since boot.py might change it back to writable.
695697
filesystem_set_internal_writable_by_usb(true);
696698

697-
// Write version info to boot_out.txt.
699+
// Write version info and board ID to boot_out.txt.
698700
mp_hal_stdout_tx_str(MICROPY_FULL_VERSION_INFO);
699-
// Write the board ID (board directory and ID on circuitpython.org)
700-
mp_hal_stdout_tx_str("\r\n" "Board ID:");
701-
mp_hal_stdout_tx_str(CIRCUITPY_BOARD_ID);
702-
mp_hal_stdout_tx_str("\r\n");
701+
mp_hal_stdout_tx_str(CIRCUITPY_BOARD_INFO);
703702
}
704703
#endif
705704

py/makeversionhdr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ def make_version_header(filename):
9898
).date()
9999

100100
# Generate the file with the git and version info
101-
file_data = """\
102-
// This file was generated by py/makeversionhdr.py
101+
file_data = r"""// This file was generated by py/makeversionhdr.py
103102
#define MICROPY_GIT_TAG "%s"
104103
#define MICROPY_GIT_HASH "%s"
105104
#define MICROPY_BUILD_DATE "%s"
@@ -108,6 +107,7 @@ def make_version_header(filename):
108107
#define MICROPY_VERSION_MICRO (%s)
109108
#define MICROPY_VERSION_STRING "%s"
110109
#define MICROPY_FULL_VERSION_INFO ("Adafruit CircuitPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME)
110+
#define CIRCUITPY_BOARD_INFO ("\r\n" "Board ID:" CIRCUITPY_BOARD_ID "\r\n")
111111
""" % (
112112
git_tag,
113113
git_hash,

0 commit comments

Comments
 (0)