flash: more flash write_image bugfixes
Remove/fix lots of bugs in handling of non-contigious sections and out of order sections. Fix a gaffe introduced in previous commit to src/flash/nor/core.c Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
This commit is contained in:
parent
0d8f60e28f
commit
7e33f87b3d
|
@ -602,14 +602,11 @@ int flash_write_unlock(struct target *target, struct image *image,
|
||||||
while ((run_address + run_size - 1 < c->base + c->size - 1)
|
while ((run_address + run_size - 1 < c->base + c->size - 1)
|
||||||
&& (section_last + 1 < image->num_sections))
|
&& (section_last + 1 < image->num_sections))
|
||||||
{
|
{
|
||||||
if (sections[section_last + 1]->base_address < (run_address + run_size))
|
/* sections are sorted */
|
||||||
|
assert(sections[section_last + 1]->base_address >= c->base);
|
||||||
|
if (sections[section_last + 1]->base_address >= (c->base + c->size))
|
||||||
{
|
{
|
||||||
LOG_DEBUG("section %d out of order "
|
/* Done with this bank */
|
||||||
"(surprising, but supported)",
|
|
||||||
section_last + 1);
|
|
||||||
/* REVISIT this can break with autoerase ...
|
|
||||||
* clobbering data after it's written.
|
|
||||||
*/
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -631,8 +628,6 @@ int flash_write_unlock(struct target *target, struct image *image,
|
||||||
* flash programming could fail due to alignment issues
|
* flash programming could fail due to alignment issues
|
||||||
* attempt to rebuild a consecutive buffer for the flash loader */
|
* attempt to rebuild a consecutive buffer for the flash loader */
|
||||||
pad_bytes = (sections[section_last + 1]->base_address) - (run_address + run_size);
|
pad_bytes = (sections[section_last + 1]->base_address) - (run_address + run_size);
|
||||||
if ((run_address + run_size + pad_bytes) > (c->base + c->size))
|
|
||||||
break;
|
|
||||||
padding[section_last] = pad_bytes;
|
padding[section_last] = pad_bytes;
|
||||||
run_size += sections[++section_last]->size;
|
run_size += sections[++section_last]->size;
|
||||||
run_size += pad_bytes;
|
run_size += pad_bytes;
|
||||||
|
@ -641,16 +636,7 @@ int flash_write_unlock(struct target *target, struct image *image,
|
||||||
LOG_INFO("Padding image section %d with %d bytes", section_last-1, pad_bytes);
|
LOG_INFO("Padding image section %d with %d bytes", section_last-1, pad_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fit the run into bank constraints */
|
assert (run_address + run_size - 1 <= c->base + c->size - 1);
|
||||||
if (run_address + run_size - 1 > c->base + c->size - 1)
|
|
||||||
{
|
|
||||||
/* REVISIT isn't this superfluous, given the while()
|
|
||||||
* loop conditions above??
|
|
||||||
*/
|
|
||||||
LOG_WARNING("writing %d bytes only - as image section is %d bytes and bank is only %d bytes", \
|
|
||||||
(int)(c->base + c->size - run_address), (int)(run_size), (int)(c->size));
|
|
||||||
run_size = c->base + c->size - run_address;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we're applying any sector automagic, then pad this
|
/* If we're applying any sector automagic, then pad this
|
||||||
* (maybe-combined) segment to the end of its last sector.
|
* (maybe-combined) segment to the end of its last sector.
|
||||||
|
@ -691,8 +677,12 @@ int flash_write_unlock(struct target *target, struct image *image,
|
||||||
* #¤%#"%¤% we have to figure out the section # from the sorted
|
* #¤%#"%¤% we have to figure out the section # from the sorted
|
||||||
* list of pointers to sections to invoke image_read_section()...
|
* list of pointers to sections to invoke image_read_section()...
|
||||||
*/
|
*/
|
||||||
int t_section_num = (sections[section] - image->sections) / sizeof(struct imageection);
|
intptr_t diff = (intptr_t)sections[section] - (intptr_t)image->sections;
|
||||||
|
int t_section_num = diff / sizeof(struct imageection);
|
||||||
|
|
||||||
|
LOG_DEBUG("image_read_section: section = %d, t_section_num = %d, section_offset = %d, buffer_size = %d, size_read = %d",
|
||||||
|
(int)section,
|
||||||
|
(int)t_section_num, (int)section_offset, (int)buffer_size, (int)size_read);
|
||||||
if ((retval = image_read_section(image, t_section_num, section_offset,
|
if ((retval = image_read_section(image, t_section_num, section_offset,
|
||||||
size_read, buffer + buffer_size, &size_read)) != ERROR_OK || size_read == 0)
|
size_read, buffer + buffer_size, &size_read)) != ERROR_OK || size_read == 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue