Skip to content

Fix boot_out.txt contents check #5535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,24 +667,26 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
// This saves wear and tear on the flash and also prevents filesystem damage if power is lost
// during the write, which may happen due to bobbling the power connector or weak power.

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

char file_contents[NUM_CHARS_TO_COMPARE];
char file_contents[constant_string_length];
UINT chars_read = 0;
f_read(boot_output_file, file_contents, NUM_CHARS_TO_COMPARE, &chars_read);
f_read(boot_output_file, file_contents, constant_string_length, &chars_read);
f_close(boot_output_file);
skip_boot_output =
// + 2 accounts for \r\n.
chars_read == strlen(MICROPY_FULL_VERSION_INFO) + 2 &&
strncmp(file_contents, MICROPY_FULL_VERSION_INFO, strlen(MICROPY_FULL_VERSION_INFO)) == 0;
chars_read == strlen(MICROPY_FULL_VERSION_INFO) + strlen(CIRCUITPY_BOARD_INFO) &&
strncmp(file_contents, MICROPY_FULL_VERSION_INFO, strlen(MICROPY_FULL_VERSION_INFO)) == 0 &&
strncmp(file_contents + strlen(MICROPY_FULL_VERSION_INFO),
CIRCUITPY_BOARD_INFO, strlen(CIRCUITPY_BOARD_INFO)) == 0;
}

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

// Write version info to boot_out.txt.
// Write version info and board ID to boot_out.txt.
mp_hal_stdout_tx_str(MICROPY_FULL_VERSION_INFO);
// Write the board ID (board directory and ID on circuitpython.org)
mp_hal_stdout_tx_str("\r\n" "Board ID:");
mp_hal_stdout_tx_str(CIRCUITPY_BOARD_ID);
mp_hal_stdout_tx_str("\r\n");
mp_hal_stdout_tx_str(CIRCUITPY_BOARD_INFO);
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions py/makeversionhdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ def make_version_header(filename):
).date()

# Generate the file with the git and version info
file_data = """\
// This file was generated by py/makeversionhdr.py
file_data = r"""// This file was generated by py/makeversionhdr.py
#define MICROPY_GIT_TAG "%s"
#define MICROPY_GIT_HASH "%s"
#define MICROPY_BUILD_DATE "%s"
Expand All @@ -108,6 +107,7 @@ def make_version_header(filename):
#define MICROPY_VERSION_MICRO (%s)
#define MICROPY_VERSION_STRING "%s"
#define MICROPY_FULL_VERSION_INFO ("Adafruit CircuitPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME)
#define CIRCUITPY_BOARD_INFO ("\r\n" "Board ID:" CIRCUITPY_BOARD_ID "\r\n")
""" % (
git_tag,
git_hash,
Expand Down