flashwrite.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2018 Kaspar Schleiser <kaspar@schleiser.de>
3  * SPDX-FileCopyrightText: 2018 Inria
4  * SPDX-FileCopyrightText: 2018 Freie Universität Berlin
5  * SPDX-License-Identifier: LGPL-2.1-only
6  */
7 
8 #pragma once
9 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 #include "riotboot/slot.h"
63 #include "periph/flashpage.h"
64 
68 #ifndef CONFIG_RIOTBOOT_FLASHWRITE_RAW
69 #define CONFIG_RIOTBOOT_FLASHWRITE_RAW 1
70 #endif
71 
75 #if CONFIG_RIOTBOOT_FLASHWRITE_RAW
76 
77 #if (FLASHPAGE_WRITE_BLOCK_SIZE < 4)
78 #define RIOTBOOT_FLASHPAGE_BUFFER_SIZE 4
79 #else
80 #define RIOTBOOT_FLASHPAGE_BUFFER_SIZE FLASHPAGE_WRITE_BLOCK_SIZE
81 #endif
82 
83 #else /* CONFIG_RIOTBOOT_FLASHWRITE_RAW */
84 
85 #define RIOTBOOT_FLASHPAGE_BUFFER_SIZE FLASHPAGE_SIZE
86 
87 #endif /* !CONFIG_RIOTBOOT_FLASHWRITE_RAW */
88 
92 #define RIOTBOOT_FLASHPAGE_BUFFER_ATTRS \
93  __attribute__((aligned(FLASHPAGE_WRITE_BLOCK_ALIGNMENT)))
94 
102 typedef struct {
104  size_t offset;
105  unsigned flashpage;
112 #if CONFIG_RIOTBOOT_FLASHWRITE_RAW || DOXYGEN
119 #endif
121 
125 #define RIOTBOOT_FLASHWRITE_SKIPLEN sizeof(RIOTBOOT_MAGIC)
126 
144  size_t offset);
145 
161  int target_slot)
162 {
163  /* initialize state, but skip "RIOT" */
164  return riotboot_flashwrite_init_raw(state, target_slot,
166 }
167 
183  const uint8_t *bytes, size_t len, bool more);
192 
205  const uint8_t *bytes, size_t len);
206 
218 {
219  return riotboot_flashwrite_finish_raw(state, (const uint8_t *)"RIOT",
221 }
222 
237 
248 
257 
269 int riotboot_flashwrite_verify_sha256(const uint8_t *sha256_digest,
270  size_t img_size, int target_slot);
271 
272 #ifdef __cplusplus
273 }
274 #endif
Low-level flash page peripheral driver interface.
#define RIOTBOOT_FLASHPAGE_BUFFER_ATTRS
Extra attributes required for the firmware intermediate buffer.
Definition: flashwrite.h:92
static int riotboot_flashwrite_init(riotboot_flashwrite_t *state, int target_slot)
Initialize firmware update (riotboot version)
Definition: flashwrite.h:160
int riotboot_flashwrite_verify_sha256(const uint8_t *sha256_digest, size_t img_size, int target_slot)
Verify the digest of an image.
int riotboot_flashwrite_invalidate(int slot)
Invalidate a slot header (riotboot version)
size_t riotboot_flashwrite_slotsize(const riotboot_flashwrite_t *state)
Get a slot's size.
int riotboot_flashwrite_init_raw(riotboot_flashwrite_t *state, int target_slot, size_t offset)
Initialize firmware update (raw version)
int riotboot_flashwrite_finish_raw(riotboot_flashwrite_t *state, const uint8_t *bytes, size_t len)
Finish a firmware update (raw version)
int riotboot_flashwrite_flush(riotboot_flashwrite_t *state)
Force flush the buffer onto the flash.
#define RIOTBOOT_FLASHWRITE_SKIPLEN
Amount of bytes to skip at initial write of first page.
Definition: flashwrite.h:125
#define RIOTBOOT_FLASHPAGE_BUFFER_SIZE
Intermediate buffer size for firmware image data.
Definition: flashwrite.h:78
int riotboot_flashwrite_invalidate_latest(void)
Invalidate the latest firmware version (riotboot version)
static int riotboot_flashwrite_finish(riotboot_flashwrite_t *state)
Finish a firmware update (riotboot version)
Definition: flashwrite.h:217
int riotboot_flashwrite_putbytes(riotboot_flashwrite_t *state, const uint8_t *bytes, size_t len, bool more)
Feed bytes into the firmware writer.
Slot management tools.
firmware update state structure
Definition: flashwrite.h:102
size_t offset
update is at this position
Definition: flashwrite.h:104
unsigned flashpage
update is at this flashpage
Definition: flashwrite.h:105
int target_slot
update targets this slot
Definition: flashwrite.h:103