Skip to content
Snippets Groups Projects
Commit 0f8e851e authored by Jens Gehrlein's avatar Jens Gehrlein Committed by Stefan Roese
Browse files

CFI: increase performance of function find_sector()


Tested on TQM5200S-BD with Samsung K8P2815UQB

Signed-off-by: default avatarJens Gehrlein <sew_s@tqs.de>
Signed-off-by: default avatarStefan Roese <sr@denx.de>
parent a7292871
No related branches found
No related tags found
No related merge requests found
...@@ -774,17 +774,26 @@ static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c) ...@@ -774,17 +774,26 @@ static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c)
} }
} }
/* loop through the sectors from the highest address when the passed /*
* address is greater or equal to the sector address we have a match * Loop through the sector table starting from the previously found sector.
* Searches forwards or backwards, dependent on the passed address.
*/ */
static flash_sect_t find_sector (flash_info_t * info, ulong addr) static flash_sect_t find_sector (flash_info_t * info, ulong addr)
{ {
flash_sect_t sector; static flash_sect_t saved_sector = 0; /* previously found sector */
flash_sect_t sector = saved_sector;
for (sector = info->sector_count - 1; sector >= 0; sector--) { while ((info->start[sector] < addr)
if (addr >= info->start[sector]) && (sector < info->sector_count - 1))
break; sector++;
} while ((info->start[sector] > addr) && (sector > 0))
/*
* also decrements the sector in case of an overshot
* in the first loop
*/
sector--;
saved_sector = sector;
return sector; return sector;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment