| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 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 |
} |