-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
suit/transport/vfs: add VFS as source for firmware updates
- Loading branch information
Showing
5 changed files
with
148 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2022 ML!PA Consulting GmbH | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
/** | ||
* @defgroup sys_suit_transport_vfs SUIT secure firmware OTA VFS transport | ||
* @ingroup sys_suit | ||
* @brief SUIT firmware VFS transport | ||
* | ||
* @{ | ||
* | ||
* @brief VFS transport backend definitions for SUIT manifests | ||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com> | ||
* | ||
*/ | ||
|
||
#ifndef SUIT_TRANSPORT_VFS_H | ||
#define SUIT_TRANSPORT_VFS_H | ||
|
||
#include "net/nanocoap.h" | ||
#include "suit.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief fetch a payload from the filesystem | ||
* | ||
* @param[in] manifest suit manifest context | ||
* @param[in] cb filesystem block callback | ||
* @param[in] ctx callback context | ||
* | ||
* @returns SUIT_OK if valid | ||
* @returns negative otherwise | ||
*/ | ||
int suit_transport_vfs_fetch(const suit_manifest_t *manifest, coap_blockwise_cb_t cb, void *ctx); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* SUIT_TRANSPORT_VFS_H */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (C) 2022 ML!PA Consulting GmbH | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup sys_suit_transport_vfs | ||
* @{ | ||
* | ||
* @fil | ||
* @brief SUIT VFS | ||
* | ||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com> | ||
* @} | ||
*/ | ||
|
||
#include <fcntl.h> | ||
#include <string.h> | ||
|
||
#include "suit/transport/vfs.h" | ||
#include "vfs.h" | ||
|
||
#define ENABLE_DEBUG 0 | ||
#include "debug.h" | ||
|
||
int suit_transport_vfs_fetch(const suit_manifest_t *manifest, coap_blockwise_cb_t cb, void *ctx) | ||
{ | ||
const char *file = &manifest->urlbuf[7]; | ||
size_t offset = 0; | ||
int res, fd; | ||
|
||
DEBUG("suit_vfs: read firmware from %s\n", file); | ||
|
||
fd = vfs_open(file, O_RDONLY, 0); | ||
if (fd < 0) { | ||
return fd; | ||
} | ||
|
||
uint8_t buf[128]; | ||
while ((res = vfs_read(fd, buf, sizeof(buf))) > 0) { | ||
size_t len = res; | ||
res = cb(ctx, offset, buf, len, 1); | ||
if (res < 0) { | ||
DEBUG("suit_vfs: write failed with %d\n", res); | ||
break; | ||
} | ||
offset += len; | ||
} | ||
|
||
if (res < 0) { | ||
DEBUG("suit_vfs: read failed with %d\n", res); | ||
} else { | ||
res = cb(ctx, offset, buf, 0, 0); | ||
} | ||
|
||
vfs_close(fd); | ||
|
||
return res; | ||
} |