openwrt/package/utils/fitblk/src/fitblk.c
Daniel Golle ddcc8f9f4e package: add fitblk util to release /dev/fit* devices
Add minimalistic tool to allow releasing /dev/fit* devices which is
needed on sysupgrade when using the fitblk driver.
The package is hidden in menuconfig, it should only be selected by
adding it to the default package selection of boards using it.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2024-02-15 19:06:36 +00:00

46 lines
814 B
C

// SPDX-License-Identifier: GPL-2.0-only
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/fitblk.h>
static int fitblk_release(char *device)
{
int fd, ret;
fd = open(device, O_RDONLY);
if (fd == -1)
return errno;
ret = ioctl(fd, FITBLK_RELEASE, NULL);
close(fd);
if (ret == -1)
return errno;
return 0;
}
int main(int argc, char *argp[])
{
int ret;
if (argc != 2) {
fprintf(stderr, "Release uImage.FIT sub-image block device\n");
fprintf(stderr, "Syntax: %s /dev/fitXXX\n", argp[0]);
return -EINVAL;
}
ret = fitblk_release(argp[1]);
if (ret)
fprintf(stderr, "fitblk: error releasing %s: %s\n", argp[1],
strerror(ret));
else
fprintf(stderr, "fitblk: %s released\n", argp[1]);
return ret;
}