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 
59 #ifndef RIOTBOOT_FLASHWRITE_H
60 #define RIOTBOOT_FLASHWRITE_H
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 #include "riotboot/slot.h"
67 #include "periph/flashpage.h"
68 
72 #ifndef CONFIG_RIOTBOOT_FLASHWRITE_RAW
73 #define CONFIG_RIOTBOOT_FLASHWRITE_RAW 1
74 #endif
75 
79 #if CONFIG_RIOTBOOT_FLASHWRITE_RAW
80 
81 #if (FLASHPAGE_WRITE_BLOCK_SIZE < 4)
82 #define RIOTBOOT_FLASHPAGE_BUFFER_SIZE 4
83 #else
84 #define RIOTBOOT_FLASHPAGE_BUFFER_SIZE FLASHPAGE_WRITE_BLOCK_SIZE
85 #endif
86 
87 #else /* CONFIG_RIOTBOOT_FLASHWRITE_RAW */
88 
89 #define RIOTBOOT_FLASHPAGE_BUFFER_SIZE FLASHPAGE_SIZE
90 
91 #endif /* !CONFIG_RIOTBOOT_FLASHWRITE_RAW */
92 
96 #define RIOTBOOT_FLASHPAGE_BUFFER_ATTRS \
97  __attribute__((aligned(FLASHPAGE_WRITE_BLOCK_ALIGNMENT)))
98 
106 typedef struct {
108  size_t offset;
109  unsigned flashpage;
116 #if CONFIG_RIOTBOOT_FLASHWRITE_RAW || DOXYGEN
117 
123 #endif
125 
129 #define RIOTBOOT_FLASHWRITE_SKIPLEN sizeof(RIOTBOOT_MAGIC)
130 
147 int riotboot_flashwrite_init_raw(riotboot_flashwrite_t *state, int target_slot,
148  size_t offset);
149 
165  int target_slot)
166 {
167  /* initialize state, but skip "RIOT" */
168  return riotboot_flashwrite_init_raw(state, target_slot,
170 }
171 
187  const uint8_t *bytes, size_t len, bool more);
196 
209  const uint8_t *bytes, size_t len);
210 
222 {
223  return riotboot_flashwrite_finish_raw(state, (const uint8_t *)"RIOT",
225 }
226 
235 
247 int riotboot_flashwrite_verify_sha256(const uint8_t *sha256_digest,
248  size_t img_size, int target_slot);
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 
254 #endif /* RIOTBOOT_FLASHWRITE_H */
riotboot_flashwrite_putbytes
int riotboot_flashwrite_putbytes(riotboot_flashwrite_t *state, const uint8_t *bytes, size_t len, bool more)
Feed bytes into the firmware writer.
RIOTBOOT_FLASHPAGE_BUFFER_SIZE
#define RIOTBOOT_FLASHPAGE_BUFFER_SIZE
Intermediate buffer size for firmware image data.
Definition: flashwrite.h:82
riotboot_flashwrite_t
firmware update state structure
Definition: flashwrite.h:106
riotboot_flashwrite_finish
static int riotboot_flashwrite_finish(riotboot_flashwrite_t *state)
Finish a firmware update (riotboot version)
Definition: flashwrite.h:221
RIOTBOOT_FLASHPAGE_BUFFER_ATTRS
#define RIOTBOOT_FLASHPAGE_BUFFER_ATTRS
Extra attributes required for the firmware intermediate buffer.
Definition: flashwrite.h:96
riotboot_flashwrite_finish_raw
int riotboot_flashwrite_finish_raw(riotboot_flashwrite_t *state, const uint8_t *bytes, size_t len)
Finish a firmware update (raw version)
riotboot_flashwrite_t::flashpage
unsigned flashpage
update is at this flashpage
Definition: flashwrite.h:109
riotboot_flashwrite_verify_sha256
int riotboot_flashwrite_verify_sha256(const uint8_t *sha256_digest, size_t img_size, int target_slot)
Verify the digest of an image.
riotboot_flashwrite_t::target_slot
int target_slot
update targets this slot
Definition: flashwrite.h:107
flashpage.h
Low-level flash page peripheral driver interface.
riotboot_flashwrite_init_raw
int riotboot_flashwrite_init_raw(riotboot_flashwrite_t *state, int target_slot, size_t offset)
Initialize firmware update (raw version)
slot.h
Slot management tools.
RIOTBOOT_FLASHWRITE_SKIPLEN
#define RIOTBOOT_FLASHWRITE_SKIPLEN
Amount of bytes to skip at initial write of first page.
Definition: flashwrite.h:129
riotboot_flashwrite_flush
int riotboot_flashwrite_flush(riotboot_flashwrite_t *state)
Force flush the buffer onto the flash.
riotboot_flashwrite_init
static int riotboot_flashwrite_init(riotboot_flashwrite_t *state, int target_slot)
Initialize firmware update (riotboot version)
Definition: flashwrite.h:164
riotboot_flashwrite_t::offset
size_t offset
update is at this position
Definition: flashwrite.h:108
riotboot_flashwrite_slotsize
size_t riotboot_flashwrite_slotsize(const riotboot_flashwrite_t *state)
Get a slot's size.