Skip to content

Commit

Permalink
Solve memory issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavosr8 committed Jul 3, 2023
1 parent 0095b14 commit aeffe67
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions port/board/afc-bpm/v3_1/payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ uint8_t payload_hpm_prepare_comp( void )
return IPMI_CC_OUT_OF_SPACE;
}

memset(hpm_page, 0xFF, sizeof(hpm_page));
memset(hpm_page, 0xFF, PAYLOAD_HPM_PAGE_SIZE);

hpm_pg_index = 0;
hpm_page_addr = 0;
Expand All @@ -393,7 +393,7 @@ uint8_t payload_hpm_upload_block( uint8_t * block, uint16_t size )
/* TODO: Check DONE pin before accessing the SPI bus, since the FPGA may be reading it in order to boot */
uint8_t remaining_bytes_start;

if ( sizeof(hpm_page) - hpm_pg_index > size ) {
if ( PAYLOAD_HPM_PAGE_SIZE - hpm_pg_index > size ) {
/* Our page is not full yet, just append the new data */
memcpy(&hpm_page[hpm_pg_index], block, size);
hpm_pg_index += size;
Expand All @@ -402,16 +402,16 @@ uint8_t payload_hpm_upload_block( uint8_t * block, uint16_t size )

} else {
/* Complete the remaining bytes on the buffer */
memcpy(&hpm_page[hpm_pg_index], block, (sizeof(hpm_page) - hpm_pg_index));
remaining_bytes_start = (sizeof(hpm_page) - hpm_pg_index);
memcpy(&hpm_page[hpm_pg_index], block, (PAYLOAD_HPM_PAGE_SIZE - hpm_pg_index));
remaining_bytes_start = (PAYLOAD_HPM_PAGE_SIZE - hpm_pg_index);

/* Program the complete page in the Flash */
flash_program_page( hpm_page_addr, &hpm_page[0], sizeof(hpm_page));
flash_program_page( hpm_page_addr, &hpm_page[0], PAYLOAD_HPM_PAGE_SIZE);

hpm_page_addr += sizeof(hpm_page);
hpm_page_addr += PAYLOAD_HPM_PAGE_SIZE;

/* Empty our buffer and reset the index */
memset(hpm_page, 0xFF, sizeof(hpm_page));
memset(hpm_page, 0xFF, PAYLOAD_HPM_PAGE_SIZE);
hpm_pg_index = 0;

/* Save the trailing bytes */
Expand All @@ -430,7 +430,7 @@ uint8_t payload_hpm_finish_upload( uint32_t image_size )
/* Check if the last page was already programmed */
if (!hpm_pg_index) {
/* Program the complete page in the Flash */
flash_program_page( hpm_page_addr, &hpm_page[0], (sizeof(hpm_page)-hpm_pg_index));
flash_program_page( hpm_page_addr, &hpm_page[0], (PAYLOAD_HPM_PAGE_SIZE-hpm_pg_index));
hpm_pg_index = 0;
hpm_page_addr = 0;

Expand Down
2 changes: 1 addition & 1 deletion port/board/afc-timing/ipmi_oem.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ IPMI_HANDLER(ipmi_oem_cmd_i2c_transfer, NETFN_CUSTOM_OEM, IPMI_OEM_CMD_I2C_TRANS

if ( read_len > 0 ) {
read_data = pvPortMalloc( read_len );
memset( read_data, read_len, 0 );
memset( read_data, 0, read_len );

if ( xI2CMasterRead( i2c_interf, i2c_addr, read_data, read_len ) == read_len ) {
rsp->data[0] = read_len;
Expand Down
16 changes: 8 additions & 8 deletions port/board/afc-timing/payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ uint8_t payload_hpm_prepare_comp( void )
return IPMI_CC_OUT_OF_SPACE;
}

memset(hpm_page, 0xFF, sizeof(hpm_page));
memset(hpm_page, 0xFF, PAYLOAD_HMP_PAGE_SIZE);

hpm_pg_index = 0;
hpm_page_addr = 0;
Expand All @@ -396,7 +396,7 @@ uint8_t payload_hpm_upload_block( uint8_t * block, uint16_t size )
/* TODO: Check DONE pin before accessing the SPI bus, since the FPGA may be reading it in order to boot */
uint8_t remaining_bytes_start;

if ( sizeof(hpm_page) - hpm_pg_index > size ) {
if ( PAYLOAD_HMP_PAGE_SIZE - hpm_pg_index > size ) {
/* Our page is not full yet, just append the new data */
memcpy(&hpm_page[hpm_pg_index], block, size);
hpm_pg_index += size;
Expand All @@ -405,16 +405,16 @@ uint8_t payload_hpm_upload_block( uint8_t * block, uint16_t size )

} else {
/* Complete the remaining bytes on the buffer */
memcpy(&hpm_page[hpm_pg_index], block, (sizeof(hpm_page) - hpm_pg_index));
remaining_bytes_start = (sizeof(hpm_page) - hpm_pg_index);
memcpy(&hpm_page[hpm_pg_index], block, (PAYLOAD_HMP_PAGE_SIZE - hpm_pg_index));
remaining_bytes_start = (PAYLOAD_HMP_PAGE_SIZE - hpm_pg_index);

/* Program the complete page in the Flash */
flash_program_page( hpm_page_addr, &hpm_page[0], sizeof(hpm_page));
flash_program_page( hpm_page_addr, &hpm_page[0], PAYLOAD_HMP_PAGE_SIZE);

hpm_page_addr += sizeof(hpm_page);
hpm_page_addr += PAYLOAD_HMP_PAGE_SIZE;

/* Empty our buffer and reset the index */
memset(hpm_page, 0xFF, sizeof(hpm_page));
memset(hpm_page, 0xFF, PAYLOAD_HMP_PAGE_SIZE);
hpm_pg_index = 0;

/* Save the trailing bytes */
Expand All @@ -433,7 +433,7 @@ uint8_t payload_hpm_finish_upload( uint32_t image_size )
/* Check if the last page was already programmed */
if (!hpm_pg_index) {
/* Program the complete page in the Flash */
flash_program_page( hpm_page_addr, &hpm_page[0], (sizeof(hpm_page)-hpm_pg_index));
flash_program_page( hpm_page_addr, &hpm_page[0], (PAYLOAD_HMP_PAGE_SIZE-hpm_pg_index));
hpm_pg_index = 0;
hpm_page_addr = 0;

Expand Down

0 comments on commit aeffe67

Please sign in to comment.