Skip to content

Commit 73840f8

Browse files
committed
Improve boot_out.txt truncation
* write any partial message * instead of "..." show a sensible (translatable) message This does slightly lower the amount of data that can be printed, and makes the exact amount dependent on the language. However, if boot.py intentionally needs to produce larger amounts of output, it can deliberately mount the filesystem in RW mode and perform any writes needed. In that case it's up to the boot.py to choose an appropriate way to limit the number of writes if needed for the application.
1 parent 5f43a63 commit 73840f8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,10 @@ msgid ""
24102410
"You pressed the reset button during boot. Press again to exit safe mode."
24112411
msgstr ""
24122412

2413+
#: supervisor/shared/micropython.c
2414+
msgid "[truncated due to length]"
2415+
msgstr ""
2416+
24132417
#: py/objtype.c
24142418
msgid "__init__() should return None"
24152419
msgstr ""

supervisor/shared/micropython.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,15 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) {
6262
#ifdef CIRCUITPY_BOOT_OUTPUT_FILE
6363
if (boot_output != NULL) {
6464
// Ensure boot_out.txt is capped at 1 filesystem block and ends with a newline
65-
if (len + boot_output->len > 508) {
66-
vstr_add_str(boot_output, "...\n");
65+
#define TRUNCATED translate("[truncated due to length]")
66+
size_t truncated_message_len = decompress_length(TRUNCATED);
67+
size_t maxlen = 512 - truncated_message_len; // includes trailing '\0' so we do not need to account for trailing newline '\n' in vstr_add_byte
68+
if (len + boot_output->len > maxlen) {
69+
size_t remaining_len = maxlen - boot_output->len;
70+
vstr_add_strn(boot_output, str, remaining_len);
71+
char buf[truncated_message_len];
72+
vstr_add_str(boot_output, decompress(TRUNCATED, buf));
73+
vstr_add_byte(boot_output, '\n');
6774
boot_output = NULL;
6875
} else {
6976
vstr_add_strn(boot_output, str, len);

0 commit comments

Comments
 (0)