I met similar problem on different compiler (CodeWarrior for Power Architecture). The problem was that the break on line 626 was compiled as return, so the if statement was skipped. It was some compiler optimization. For myself the following modification to the _io_flashx_find_correct_sectors() worked:
void _io_flashx_find_correct_sectors
(
/* [IN] The device handle */
MQX_FILE_PTR fd_ptr,
/* [IN] The linear address within the file */
_mqx_uint location,
/* [IN/OUT] The HW start block for the write */
_mqx_uint _PTR_ start_block_ptr,
/* [IN/OUT] The start sector in the start_block */
_mqx_uint _PTR_ start_sector_ptr,
/* [IN/OUT] The offset within the first sector */
_mqx_uint _PTR_ offset_ptr,
/* [IN/OUT] The relative sector number within the file */
_mqx_uint _PTR_ file_sector_ptr
)
{ /* Body */
IO_FLASHX_STRUCT_PTR dev_ptr = (IO_FLASHX_STRUCT_PTR) fd_ptr->DEV_PTR->DRIVER_INIT_PTR;
IO_FLASHX_FILE_STRUCT_PTR file_ptr = (IO_FLASHX_FILE_STRUCT_PTR) fd_ptr->DEV_DATA_PTR;
FLASHX_BLOCK_INFO_STRUCT_PTR b;
volatile FLASHX_BLOCK_INFO_STRUCT_PTR b_temp;
_mem_size sfa; /* start file address */
_mem_size bsa, bea; /* block start address, block end address */
*file_sector_ptr = 0;
*start_block_ptr = 0;
if (file_ptr->FILE_BLOCK == NULL) {
sfa = 0;
}
else {
sfa = file_ptr->FILE_BLOCK->START_ADDR;
}
/* Go through all blocks in HW map and find the first one that matches */
for (b = dev_ptr->HW_BLOCK; b->NUM_SECTORS != 0; b++)
{
bsa = dev_ptr->BASE_ADDR + b->START_ADDR;
bea = bsa + b->NUM_SECTORS * b->SECTOR_SIZE - 1;
b_temp = b;
if ((sfa >= bsa) && (sfa <= bea))
{
break; /* start address of the file is inside the block */
}
*start_block_ptr += 1;
}
if (b_temp->NUM_SECTORS != 0) {
/* Rebase location so that is counts from the beginning of this block */
location += sfa - bsa;
/* We are at the beginning of the file, seek to the location */
for (b = b_temp ; b->NUM_SECTORS != 0; b++)
{
if (b->NUM_SECTORS * b->SECTOR_SIZE > location)
{
*start_sector_ptr = location / b->SECTOR_SIZE;
*offset_ptr = location % b->SECTOR_SIZE;
/* recreate the location back, perhaps we will decrement the value */
location -= sfa - bsa;
*file_sector_ptr += location / b->SECTOR_SIZE;
break;
}
location -= b->SECTOR_SIZE * b->NUM_SECTORS;
*file_sector_ptr += b->NUM_SECTORS;
*start_block_ptr += 1;
}
}
} /* Endbody */
Can you try to build MQX 3.8.1 libs with the modificaiton above and tell if this modification helps or not ?