increase max size of boot_out.txt

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
asdffdsa6132
 
Posts: 28
Joined: Sat Feb 18, 2023 5:00 pm

increase max size of boot_out.txt

Post by asdffdsa6132 »

hello, thanks,

i am getting "[truncated due to length]" on boot_out.txt
how can i increase the maximum size for boot_out.txt

i currenly compile my own firmware, so if there is setting/flag, please let me know,

User avatar
danhalbert
 
Posts: 4651
Joined: Tue Aug 08, 2017 12:37 pm

Re: increase max size of boot_out.txt

Post by danhalbert »

boot_out.txt was limited to a 512-byte block (so only writing one block). There are a couple of places this is done:

main.c, around line 832
vstr_init(&boot_text, 512);
supervisor/shared/micropython.c, function `mp_hal_stdout_tx_strn()`.

main.c is careful not to write boot_out.txt if the contents being written is the same as what is already there. This is to save flash wear, so it doesn't get written on each restart.

What are you interested in writing to boot_out.txt or seeing in its output? There may be alternatives to enlarging it.

User avatar
asdffdsa6132
 
Posts: 28
Joined: Sat Feb 18, 2023 5:00 pm

Re: increase max size of boot_out.txt

Post by asdffdsa6132 »

i keep running out of gc free memory.
at first, i used mpycross to create test.mpy into CIRCUITPYHON/lib/
then i had to start compiling firmware so i can use use frozen mpy.

boot.py imports the frozen test.mpy
from test.py, i use print() foroutput to boot_out.txt

sure, i could write some code to use a log file, but extra code using extra memory.
and print() is dead simple, no need to import libraries, and very important for debugging.

and that bring up another question,
let's say i have a text file i want to store in the firmware,
from a frozen mpy, how can i access the file.

User avatar
danhalbert
 
Posts: 4651
Joined: Tue Aug 08, 2017 12:37 pm

Re: increase max size of boot_out.txt

Post by danhalbert »

I'm a little confused: why are you importing the test program from boot.py instead of code.py? Is it something that has to happen at boot time?

you could also use microcontroller.nvm to log text or binary data, or alarm.sleep_memory, which is volatile but exists across CircuitPython VM startups.

There is no way to freeze a data file. You can write Python code that has data in it, such as a long bytes b'...'.

If you could explain the use case in more detail we might have more suggestions.

User avatar
asdffdsa6132
 
Posts: 28
Joined: Sat Feb 18, 2023 5:00 pm

Re: increase max size of boot_out.txt

Post by asdffdsa6132 »

"If you could explain the use case in more detail we might have more suggestions."
sure, thanks for asking.
i am using Adafruit NeoPixel Trinkey M0 with samd21e18 as a secuity device of my own design.

i have two small text files.
01.bek - required to boot windows laptop locked with bitlocker
[redacted].key - required to login to keepass.

i have already crypted both files, using my own algorithm and store them as you mentioned, as variable of type bytearray in test.py
when i compile the firmware, the test.py get compiled into a frozen module named test.mpy

so the sequence of events is:
1. plug in trinkey
2. firmware boots with contains the frozen test.mpy
3. boot.py runs, basically, does not really do anything much

Code: Select all

storage.remount("/", readonly=False, disable_concurrent_write_protection=True)
storage.enable_usb_drive()
import test
test.doitnow()
and this is what test.doitnow() does:
1. using the two cap touch buttons, i type in a morse code sequence.
2. that sequence is used as part of a key to decrypt the bytearrays
3. create the two files mentioned above with decrypted content.

now, when i boot my laptop,
1. i type the morse code sequence, the .bek file is created.
2. windows sees that file and then asks for a bitlocker password.
3. windows continues to boot.
4. i type in another morse code sequence and the .key file is created.
3. i run keepass, it knows to find 01.key on the trinkey, i type in keepass password and keepass runs.
4. live long and prosper!

User avatar
danhalbert
 
Posts: 4651
Joined: Tue Aug 08, 2017 12:37 pm

Re: increase max size of boot_out.txt

Post by danhalbert »

That is an interesting technique. I only have one idea here: since CIRCUITPY is already writable, you can do something like:

Code: Select all

# ... after remount
def log_error(msg):
    # open in append mode
    with open("errors.txt", "a") as error_output: 
        print("something", file=error_output)
and call `log_error()` when you find some error; it will append `msg` to errors.txt. This is small and you don't have to worry about the size of boot_out.txt anymore.

User avatar
asdffdsa6132
 
Posts: 28
Joined: Sat Feb 18, 2023 5:00 pm

Re: increase max size of boot_out.txt

Post by asdffdsa6132 »

thanks, that one idea is just what i needed.
it makes sense now, i have not groked how frozen mpy interact with boot.py, code.py and CIRCUITPY

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”