Loading...
Searching...
No Matches
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
63extern "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
106typedef struct {
108 size_t offset;
109 unsigned flashpage;
116#if CONFIG_RIOTBOOT_FLASHWRITE_RAW || DOXYGEN
123#endif
125
129#define RIOTBOOT_FLASHWRITE_SKIPLEN sizeof(RIOTBOOT_MAGIC)
130
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
241
252
261
273int riotboot_flashwrite_verify_sha256(const uint8_t *sha256_digest,
274 size_t img_size, int target_slot);
275
276#ifdef __cplusplus
277}
278#endif
279
280#endif /* RIOTBOOT_FLASHWRITE_H */
Low-level flash page peripheral driver interface.
#define RIOTBOOT_FLASHPAGE_BUFFER_ATTRS
Extra attributes required for the firmware intermediate buffer.
Definition flashwrite.h:96
static int riotboot_flashwrite_init(riotboot_flashwrite_t *state, int target_slot)
Initialize firmware update (riotboot version)
Definition flashwrite.h:164
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:129
#define RIOTBOOT_FLASHPAGE_BUFFER_SIZE
Intermediate buffer size for firmware image data.
Definition flashwrite.h:89
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:221
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:106
size_t offset
update is at this position
Definition flashwrite.h:108
unsigned flashpage
update is at this flashpage
Definition flashwrite.h:109
int target_slot
update targets this slot
Definition flashwrite.h:107