mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
9d350f08c0
Sometimes we want to roll-back to a previous firmware version. To do so we need a higher riotbot version numbers still. Add an update command to the riotboot_gen_hdr tool so that an existing firmware image can be re-rolled out with a new version number.
61 lines
1.1 KiB
C
61 lines
1.1 KiB
C
/*
|
|
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
* License v2. See the file LICENSE for more details.
|
|
*/
|
|
|
|
/**
|
|
* @file
|
|
* @brief Common tools for RIOT images header generation
|
|
*
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
|
*/
|
|
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
|
|
int to_file(const char *filename, const void *buf, size_t len)
|
|
{
|
|
int fd;
|
|
|
|
if (strcmp("-", filename)) {
|
|
fd = open(filename, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
|
|
}
|
|
else {
|
|
fd = STDOUT_FILENO;
|
|
}
|
|
|
|
if (fd > 0) {
|
|
ssize_t res = write(fd, buf, len);
|
|
close(fd);
|
|
return res == (ssize_t)len;
|
|
}
|
|
else {
|
|
return fd;
|
|
}
|
|
}
|
|
|
|
int from_file(const char *filename, void *buf, size_t len)
|
|
{
|
|
int fd;
|
|
|
|
if (strcmp("-", filename)) {
|
|
fd = open(filename, O_RDONLY, 0);
|
|
}
|
|
else {
|
|
fd = STDIN_FILENO;
|
|
}
|
|
|
|
if (fd > 0) {
|
|
ssize_t res = read(fd, buf, len);
|
|
close(fd);
|
|
return res;
|
|
}
|
|
else {
|
|
return fd;
|
|
}
|
|
}
|