flashwrite.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
3  * 2018 Inria
4  * 2018 Freie Universität Berlin
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
11 #pragma once
12 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 #include "riotboot/slot.h"
66 #include "periph/flashpage.h"
67 
71 #ifndef CONFIG_RIOTBOOT_FLASHWRITE_RAW
72 #define CONFIG_RIOTBOOT_FLASHWRITE_RAW 1
73 #endif
74 
78 #if CONFIG_RIOTBOOT_FLASHWRITE_RAW
79 
80 #if (FLASHPAGE_WRITE_BLOCK_SIZE < 4)
81 #define RIOTBOOT_FLASHPAGE_BUFFER_SIZE 4
82 #else
83 #define RIOTBOOT_FLASHPAGE_BUFFER_SIZE FLASHPAGE_WRITE_BLOCK_SIZE
84 #endif
85 
86 #else /* CONFIG_RIOTBOOT_FLASHWRITE_RAW */
87 
88 #define RIOTBOOT_FLASHPAGE_BUFFER_SIZE FLASHPAGE_SIZE
89 
90 #endif /* !CONFIG_RIOTBOOT_FLASHWRITE_RAW */
91 
95 #define RIOTBOOT_FLASHPAGE_BUFFER_ATTRS \
96  __attribute__((aligned(FLASHPAGE_WRITE_BLOCK_ALIGNMENT)))
97 
105 typedef struct {
107  size_t offset;
108  unsigned flashpage;
115 #if CONFIG_RIOTBOOT_FLASHWRITE_RAW || DOXYGEN
122 #endif
124 
128 #define RIOTBOOT_FLASHWRITE_SKIPLEN sizeof(RIOTBOOT_MAGIC)
129 
147  size_t offset);
148 
164  int target_slot)
165 {
166  /* initialize state, but skip "RIOT" */
167  return riotboot_flashwrite_init_raw(state, target_slot,
169 }
170 
186  const uint8_t *bytes, size_t len, bool more);
195 
208  const uint8_t *bytes, size_t len);
209 
221 {
222  return riotboot_flashwrite_finish_raw(state, (const uint8_t *)"RIOT",
224 }
225 
240 
251 
260 
272 int riotboot_flashwrite_verify_sha256(const uint8_t *sha256_digest,
273  size_t img_size, int target_slot);
274 
275 #ifdef __cplusplus
276 }
277 #endif
Low-level flash page peripheral driver interface.
#define RIOTBOOT_FLASHPAGE_BUFFER_ATTRS
Extra attributes required for the firmware intermediate buffer.
Definition: flashwrite.h:95
static int riotboot_flashwrite_init(riotboot_flashwrite_t *state, int target_slot)
Initialize firmware update (riotboot version)
Definition: flashwrite.h:163
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:128
#define RIOTBOOT_FLASHPAGE_BUFFER_SIZE
Intermediate buffer size for firmware image data.
Definition: flashwrite.h:81
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:220
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:105
size_t offset
update is at this position
Definition: flashwrite.h:107
unsigned flashpage
update is at this flashpage
Definition: flashwrite.h:108
int target_slot
update targets this slot
Definition: flashwrite.h:106