diff --git a/drivers/include/drivers/internal/SFDP.h b/drivers/include/drivers/internal/SFDP.h index ab0931b082..be94b8f0bd 100644 --- a/drivers/include/drivers/internal/SFDP.h +++ b/drivers/include/drivers/internal/SFDP.h @@ -129,7 +129,7 @@ int sfdp_detect_erase_types_inst_and_size(uint8_t *bptbl_ptr, sfdp_hdr_info &sfd * * @return Region number */ -int sfdp_find_addr_region(bd_size_t offset, const sfdp_hdr_info &sfdp_info); +int sfdp_find_addr_region(bd_addr_t offset, const sfdp_hdr_info &sfdp_info); /** Finds the largest Erase Type of the Region to which the offset belongs to * diff --git a/drivers/source/SFDP.cpp b/drivers/source/SFDP.cpp index b83ecd7537..1450305195 100644 --- a/drivers/source/SFDP.cpp +++ b/drivers/source/SFDP.cpp @@ -373,9 +373,9 @@ int sfdp_detect_erase_types_inst_and_size(uint8_t *bptbl_ptr, sfdp_hdr_info &sfd return 0; } -int sfdp_find_addr_region(bd_size_t offset, const sfdp_hdr_info &sfdp_info) +int sfdp_find_addr_region(bd_addr_t offset, const sfdp_hdr_info &sfdp_info) { - if ((offset > sfdp_info.bptbl.device_size_bytes) || (sfdp_info.smptbl.region_cnt == 0)) { + if ((offset >= sfdp_info.bptbl.device_size_bytes) || (sfdp_info.smptbl.region_cnt == 0)) { return -1; } @@ -383,10 +383,10 @@ int sfdp_find_addr_region(bd_size_t offset, const sfdp_hdr_info &sfdp_info) return 0; } - for (int idx = sfdp_info.smptbl.region_cnt - 2; idx >= 0; idx--) { + for (int idx = 0; idx < sfdp_info.smptbl.region_cnt; idx++) { - if (offset > sfdp_info.smptbl.region_high_boundary[idx]) { - return (idx + 1); + if (offset <= sfdp_info.smptbl.region_high_boundary[idx]) { + return idx; } } return -1;