Skip to content

Commit b93c219

Browse files
committed
fix: address PR review comments
- Add page-boundary and length validation in steami_flash_write_config - Fix steami_flash_get_size returning absolute address instead of relative size - Separate bad-parameters error from flash-write failure in TASK_WRITE_CONFIG - Update doc to reflect actual 28-byte max payload via I2C protocol - Document fixed 31-byte frame layout for WRITE_CONFIG command
1 parent a954f62 commit b93c219

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

source/board/steami/steami32.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,11 @@ void process_task()
440440
if( task_rx_len >= 3 ){
441441
uint16_t offset = ((uint16_t)task_rx[0] << 8) | task_rx[1];
442442
uint16_t len = task_rx[2];
443-
if( len <= task_rx_len - 3 && steami_flash_write_config(offset, task_rx + 3, len) ){
443+
if( len > task_rx_len - 3 ){
444+
error_status_bad_parameter(&status_error);
445+
steami_uart_write_string("ERROR Bad config write parameters.\n");
446+
}
447+
else if( steami_flash_write_config(offset, task_rx + 3, len) ){
444448
steami_uart_write_string("Config written.\n");
445449
}
446450
else{

source/board/steami/steami_flash.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ uint32_t steami_flash_get_size(){
138138

139139
for(uint16_t i = 0; i < STEAMI_FLASH_MAX_DATA_SIZE; ++i){
140140
if( data[i] == 0xFF ){
141-
return STEAMI_FLASH_FILE_ADDR + offset + i;
141+
return offset + i;
142142
}
143143
}
144144

@@ -234,9 +234,15 @@ bool steami_flash_erase_config(){
234234
}
235235

236236
bool steami_flash_write_config(uint16_t offset, uint8_t* data, uint16_t len){
237+
if( len == 0 || len > 256 ){
238+
return false;
239+
}
237240
if( offset + len > STEAMI_FLASH_CONFIG_SIZE ){
238241
return false;
239242
}
243+
if( (offset % 256) + len > 256 ){
244+
return false;
245+
}
240246

241247
steami_led_turn_on_blue();
242248

source/board/steami/steami_flash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ bool steami_flash_erase_config();
124124
*
125125
* @param offset byte offset within the config zone (0-4095)
126126
* @param data data array
127-
* @param len number of bytes to write (max 256 per call, must stay within one page)
127+
* @param len number of bytes to write (max 28 per call via I2C, must stay within one 256-byte page)
128128
* @return TRUE if successful, FALSE otherwise
129129
*/
130130
bool steami_flash_write_config(uint16_t offset, uint8_t* data, uint16_t len);

source/board/steami/steami_i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static uint16_t get_argument_byte_number(uint8_t cmd){
6969
return 2;
7070

7171
case WRITE_CONFIG:
72-
return 31;
72+
return 31; /* fixed frame: [offset_hi, offset_lo, len, data(28 bytes max)] */
7373

7474
case READ_CONFIG:
7575
return 2;

0 commit comments

Comments
 (0)