-
Notifications
You must be signed in to change notification settings - Fork 3k
FlashIAP: Fix problem of programming source buffer not aligned to 4 #6864
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,10 +107,18 @@ int FlashIAP::program(const void *buffer, uint32_t addr, uint32_t size) | |
_mutex->lock(); | ||
while (size) { | ||
uint32_t current_sector_size = flash_get_sector_size(&_flash, addr); | ||
bool unaligned_src = (((size_t) buf / sizeof(uint32_t) * sizeof(uint32_t)) != (size_t) buf); | ||
chunk = std::min(current_sector_size - (addr % current_sector_size), size); | ||
if (chunk < page_size) { | ||
// Need to use the internal page buffer in any of these two cases: | ||
// 1. Size is not page aligned | ||
// 2. Source buffer is not aligned to uint32_t. This is not supported by many targets (although | ||
// the pointer they accept is of uint8_t). | ||
if (unaligned_src || (chunk < page_size)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts on just copying to the internal buffer for all program calls? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not very efficient. I suspect that the vast majority of calls will have both buffer and size aligned. |
||
chunk = std::min(chunk, page_size); | ||
memcpy(_page_buf, buf, chunk); | ||
memset(_page_buf + chunk, 0xFF, page_size - chunk); | ||
if (chunk < page_size) { | ||
memset(_page_buf + chunk, 0xFF, page_size - chunk); | ||
} | ||
prog_buf = _page_buf; | ||
prog_size = page_size; | ||
} else { | ||
|
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 exactly is this importing? This is the first time I've ever seen a system file simply called "algorithm".
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.
It is actually used quite a lot. It imports the std::min and std::max functions.