-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Initial support for flashing EXST .hex files to External Flash. #1565
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
Conversation
Parsing `0800` was ok, but parsing `97CE` was not. The sign was not correctly handled, this uses `>>> 0` to force unsigned result. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#%3E%3E%3E_(Zero-fill_right_shift)
Not sure why you would need to have a zero fill when using .hex files to flash - .hex files allow for the target address of non-contiguos blocks to be explicitly set, so unless you need the space in between two blocks to be 0, just specifying the first block, beginning at its start address, and then the second block, also beginning at its start address, will work with .hex files. |
src/js/protocols/stm32usbdfu.js
Outdated
| console.log('Using transfer size: ' + self.transferSize); | ||
| self.clearStatus(function () { | ||
| self.upload_procedure(1); | ||
| if (typeof chipInfo.internal_flash != "undefined") { |
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.
Should be a non-coercing not equals.
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.
done
src/js/protocols/stm32usbdfu.js
Outdated
| }); | ||
| }); | ||
| } | ||
| } else if (typeof chipInfo.external_flash != "undefined") { |
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.
Should be a non-coercing not equals.
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.
done
yes, the zero fill is needed because the 0's are used for exst hash calculation. I didnt see any other command line arguments to objcopy that allow the gap to be set, it would also require additional code in the hex parser anyway, iirc. |
The .hex file parser in the Betaflight configurator can already handle non-contiguos blocks - that's how it is possible to update the firmware without resetting the configuration. |
|
@mikeller yes I know it does non-continguous blocks. I had a good look at the code and step-debugged through a lot of it to see how it dealt with hex data sections, etc. However that is not the issue here. The issue is that the EXST hash is computed on the firmware BINARY, minus the last 64 byte block, this binary contains 0's as defined by the linker script. However, when you use objcopy to generate a hex file from the patched .elf file it does not output the area between the end of firmware and the start of the hash block. Since the configurator will erase pages as needed, based on the addresses in the hex file and sector boundaries of the flash, and these erased pages on NAND flash have a default value of 0xFF when read, the hash computed from the content on flash won't match the hash at the end of the firmware block. To me the simplest solution is to generate a .hex file have the same binary content as the .bin file. |
|
@mikeller with regards to use of "typeof" it seems kinda weird that in the same file, Initially the way I had it was to use |
|
@hydra: You misunderstood me. All I meant you to do was to change the |
|
Looking at the use of I'm the sort of guy that has to go and look up what coercing means as far as javascript goes, but I've noticed that we've got some code that has been unmodified since baseflight-configurator We're using Looks like all the |
|
There's the difference:
The type system in JavaScript, and the Type checking with If you want to get into the nitty gritty of JavaScript, I can recommend Douglas Crockford's presentations on it: https://www.youtube.com/watch?v=JxAXlJEmNMg |
|
will fix this up in the morning. thanks for feedback and info. |
In this case, it's invalid if the HEX file doesn't contain any data in the address range of the chip to flash.
ok done.
agreed! LGTM! |
Now I'm working on a PR that uses this, and both are different. If I remove the |
you must use Since this PR checks the same object for two properties and results in false for the first expression and true for the second one when flashing an EXST target we can be sure that all versions of the expression work OK. i.e. For this PR, both the original expression, the second version and the current expression all work fine. I'm happy to use any of the expressions so far, but like @mikeller I often err on the side of strictness when it comes to languages that do type coercion so that the reader of the code can clearly see the intent. |
src/js/protocols/stm32usbdfu.js
Outdated
| } | ||
| } | ||
|
|
||
| if (erase_pages.length == 0) { |
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.
Same deal here, should be ===.
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.
done
| case 0x04: // extended linear address record | ||
| extended_linear_address = (parseInt(content.substr(0, 2), 16) << 24) | parseInt(content.substr(2, 2), 16) << 16; | ||
| // input address is UNSIGNED | ||
| extended_linear_address = ((parseInt(content.substr(0, 2), 16) << 24) | parseInt(content.substr(2, 2), 16) << 16) >>> 0; |
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.
Not sure why you are adding the >>> 0 here?
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.
Byte overflow? not sure on the right term. I checked with the binary he has posted:
Did console.log of extended_linear_address when it was set.
Hex conversion is what windows calculator says.
Old way: -1748107264 FFFF FFFF 97CE 0000
New way: 2546860032 97CE 0000
I got suggested this when I looked for 'uint32 javascript' so it seems reasonable.
https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32
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.
yes, it's because all bitwise operators in JS are 32 bit signed. The >>> 0 forces the result to UNSIGNED.
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.
Heh, signed bitwise operators, who wouldn't want those.
|
ready for merge now? |
| case 0x04: // extended linear address record | ||
| extended_linear_address = (parseInt(content.substr(0, 2), 16) << 24) | parseInt(content.substr(2, 2), 16) << 16; | ||
| // input address is UNSIGNED | ||
| extended_linear_address = ((parseInt(content.substr(0, 2), 16) << 24) | parseInt(content.substr(2, 2), 16) << 16) >>> 0; |
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.
Heh, signed bitwise operators, who wouldn't want those.
Tested with hex files generated firmware from betaflight/betaflight#8679
All existing .hex files generated by the build are not suitable for flashing using the configurator as they don't have the zero fill. This issue wasn't known about until the code in this PR was written and tested.
Instructions for use:
Notes:
Video here:
https://youtu.be/jyFupDg1biQ