blob: 059ba6098cea79699b60e4ddc1939698779df5b5 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// SPDX-License-Identifier: GPL-2.0-only
2#include <stdio.h>
3#include <errno.h>
4#include <fcntl.h>
5#include <string.h>
6#include <unistd.h>
7#include <sys/ioctl.h>
8#include <linux/fitblk.h>
9
10static int fitblk_release(char *device)
11{
12 int fd, ret;
13
14 fd = open(device, O_RDONLY);
15 if (fd == -1)
16 return errno;
17
18 ret = ioctl(fd, FITBLK_RELEASE, NULL);
19 close(fd);
20
21 if (ret == -1)
22 return errno;
23
24 return 0;
25}
26
27int main(int argc, char *argp[])
28{
29 int ret;
30
31 if (argc != 2) {
32 fprintf(stderr, "Release uImage.FIT sub-image block device\n");
33 fprintf(stderr, "Syntax: %s /dev/fitXXX\n", argp[0]);
34 return -EINVAL;
35 }
36
37 ret = fitblk_release(argp[1]);
38 if (ret)
39 fprintf(stderr, "fitblk: error releasing %s: %s\n", argp[1],
40 strerror(ret));
41 else
42 fprintf(stderr, "fitblk: %s released\n", argp[1]);
43
44 return ret;
45}