Debian Codegraph @

tools/src/checksum.c

raw symbols SCIP
1 /*
2 * Copyright 2010-2011 Christian Lamparter <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <error.h>
21 #include <string.h>
22 #include <errno.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26
27 #include "carlfw.h"
28
29 #include "compiler.h"
30
31 static void checksum_help(void)
32 {
33 fprintf(stderr, "Usage:\n");
34 fprintf(stderr, "\tchecksum FW-FILE\n");
35
36 fprintf(stderr, "\nDescription:\n");
37 fprintf(stderr, "\tThis simple utility adds/updates various "
38 "checksums.\n");
39
40 fprintf(stderr, "\nParameteres:\n");
41 fprintf(stderr, "\t 'FW-FILE' = firmware name\n");
42 fprintf(stderr, "\n");
43 }
44
45 int main(int argc, char *args[])
46 {
47 struct carlfw *fw = NULL;
48 int err = 0;
49
50 if (argc != 2) {
51 err = -EINVAL;
52 goto out;
53 }
54
55 fw = carlfw_load(args[1]);
56 if (IS_ERR_OR_NULL(fw)) {
57 err = PTR_ERR(fw);
58 fprintf(stderr, "Failed to open file \"%s\" (%d).\n",
59 args[1], err);
60 goto out;
61 }
62
63 /*
64 * No magic here, The checksum descriptor is added/update
65 * automatically in a subroutine of carlfw_store().
66 *
67 * This tools serves as a skeleton/example.
68 */
69 err = carlfw_store(fw);
70 if (err) {
71 fprintf(stderr, "Failed to apply checksum (%d).\n", err);
72 goto out;
73 }
74
75 out:
76 switch (err) {
77 case 0:
78 fprintf(stdout, "checksum applied.\n");
79 break;
80 case -EINVAL:
81 checksum_help();
82 break;
83 default:
84 break;
85 }
86
87 carlfw_release(fw);
88 return err ? EXIT_FAILURE : EXIT_SUCCESS;
89 }