@@ -132,14 +132,14 @@ int riotboot_flashwrite_putbytes(riotboot_flashwrite_t *state,
132132 flashpage_avail -= to_copy ;
133133 if ((!flashpage_avail ) || (!more )) {
134134#if CONFIG_RIOTBOOT_FLASHWRITE_RAW /* Guards access to state::firstblock_buf */
135- void * addr = flashpage_addr (state -> flashpage );
136135 if (!state -> offset ) {
137136 /* Skip flashing the first block, store it for later to flash it
138137 * during the flashwrite_finish function, when payload contains the boot header */
139138 memcpy (state -> firstblock_buf ,
140139 state -> flashpage_buf , RIOTBOOT_FLASHPAGE_BUFFER_SIZE );
141140 }
142141 else {
142+ void * addr = flashpage_addr (state -> flashpage );
143143 flashpage_write ((uint8_t * )addr + flashpage_pos ,
144144 state -> flashpage_buf ,
145145 RIOTBOOT_FLASHPAGE_BUFFER_SIZE );
@@ -209,18 +209,14 @@ int riotboot_flashwrite_finish_raw(riotboot_flashwrite_t *state,
209209 uint8_t * slot_start = (uint8_t * )riotboot_slot_get_hdr (state -> target_slot );
210210 const uint8_t * data = bytes ;
211211 size_t remaining = len ;
212- size_t to_copy ;
212+ size_t to_copy = MIN ( remaining , sizeof ( state -> flashpage_buf )) ;
213213
214214 if (!state -> skip_len ) {
215215#if IS_ACTIVE (CONFIG_RIOTBOOT_FLASHWRITE_RAW )
216216 /* If there is a skip_len, the first block contains the header and must be
217217 * re-flashed to include the magic number and checksum. */
218- to_copy = MIN (remaining , sizeof (state -> firstblock_buf ));
219218 memcpy (state -> firstblock_buf , data , to_copy );
220- flashpage_write (slot_start , state -> firstblock_buf ,
221- RIOTBOOT_FLASHPAGE_BUFFER_SIZE );
222- data += to_copy ;
223- remaining -= to_copy ;
219+ memcpy (state -> flashpage_buf , state -> firstblock_buf , sizeof (state -> flashpage_buf ));
224220#endif
225221 }
226222 while (remaining ) {
0 commit comments