-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
main: redesign boot_out.txt writing #5536
Conversation
New design: * capture output to a vstr * compare the complete vstr to boot_out.txt * rewrite if not a complete match This is resilient against future changes to the automatic text written to boot_out.txt. This also fixes rewriting boot_out.txt in the case where boot.py prints something. Perhaps it also saves a bit of code space. Some tricks: * no need to close a file in read mode * no need to switch on/off USB write access, going down to the oofatfs layer doesn't check it anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if a write goes past the end of the vstr
? Does it just discard the overflow?
How did you test? The easiest way I found to test whether a rewrite happened or not was to lengthen the 1 second delay to 10 seconds. I had a code.py
that blinked board.LED
, so I knew when it started.
The allocation is increased, until it fails. This means you could now MemoryError yourself if
I temporarily had code that turned the LED red during the 1 second delay before writing out the file. After changing boot.py to output something else and hitting reset, I would get the red LED once but not the next time I hit reset. |
That's a bit of a pathological case, but I think the exception should be caught if possible so you don't get no output, which is what would happen. |
If it's hard to catch the MemoryError, then you could just truncate the output after some relatively small amount (a few thousand chars), and add an ellipsis or something. |
Now this boot.py: ```py for i in range(1000): print(i) ``` creates a 512-byte boot_out.txt that ends ``` 88 89 ... ```
Now this boot.py: for i in range(1000):
print(i) creates a 512-byte boot_out.txt that ends
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it! Thanks for fixing this well.
Back in adafruit#5536 I modified how boot_out.txt got written. However, I broke USB enumeration in the safe-mode case. This fixes it so that a safe-mode board still connects on USB with all defaults. (tested on a macropad)
New design:
This is resilient against future changes to the automatic text written to boot_out.txt.
This also fixes rewriting boot_out.txt in the case where boot.py prints something.
Perhaps it also saves a bit of code space. Some tricks:
This is a possible alternative to