Skip to content
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

Fix BootloaderCDC flashing over 32k #170

Merged
merged 1 commit into from
Mar 23, 2021
Merged

Fix BootloaderCDC flashing over 32k #170

merged 1 commit into from
Mar 23, 2021

Conversation

exp
Copy link
Contributor

@exp exp commented Mar 22, 2021

When loading the bytes from the USB serial stream that represent the current position in words, BootloaderCDC uses a trick which is too clever for GCC in order to populate a u32 and double the integer value.

In my testing, when the size of the flashed item exceeds 32k, the asm generated by avr-gcc (both v5 and v10) incorrectly manipulates the u32, leading to its upper 2 bytes being set to 0xFF. This then fails the Address < BOOT_START_ADDR test in IsPageAddressValid.

This PR adds an explicit u32 cast to the function calls, leading to avr-gcc treating the u32 correctly and populating all 4 bytes.

Disclaimer: I am not familiar with AVR ASM and have based this on functional testing as well as an approximate analysis.

Without the explicit cast, avr-gcc generates incorrect asm which sets
only the lower bytes of the u32, leading the upper bytes to be set to
0xFFFF when the input value has MSB set. This results in flashing past
32k bytes failing. Explicit casting corrects this behaviour in testing.
@NicoHood
Copy link
Contributor

From my experience this cast looks correct and required. I guess that most USB MCUs tested simply do not have that much space, so the issue never popped up.

@abcminiuser
Copy link
Owner

Oops - yes, with the shift it will implicitly up-cast the uint8_t to a uint16_t, but no further. Thanks!

@abcminiuser abcminiuser merged commit cfbbbb4 into abcminiuser:master Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants