comparison bootutil/c139-patch-dmagic.c @ 16:6b0d533046e5

bootutil: add c139-patch-dmagic
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 10 Jun 2023 05:49:00 +0000
parents
children
comparison
equal deleted inserted replaced
15:36e65605d16a 16:6b0d533046e5
1 /*
2 * This program patches DD DD DD DD magic bytes into the given binary file
3 * at offset 0x2060, thereby turning a locked C11x/12x or C139/140 flash image
4 * into an unlocked one.
5 */
6
7 #include <sys/types.h>
8 #include <sys/file.h>
9 #include <sys/stat.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13
14 static u_char magic[4] = {0xDD, 0xDD, 0xDD, 0xDD};
15
16 main(argc, argv)
17 char **argv;
18 {
19 int fd;
20 struct stat st;
21
22 if (argc != 2) {
23 fprintf(stderr, "usage: %s flashimage.bin\n", argv[0]);
24 exit(1);
25 }
26 fd = open(argv[1], O_RDWR);
27 if (fd < 0) {
28 perror(argv[1]);
29 exit(1);
30 }
31 fstat(fd, &st);
32 if (!S_ISREG(st.st_mode)) {
33 fprintf(stderr, "error: %s is not a regular file\n", argv[1]);
34 exit(1);
35 }
36 if (st.st_size < 0x2064) {
37 fprintf(stderr, "error: %s is too short\n", argv[1]);
38 exit(1);
39 }
40 lseek(fd, 0x2060, SEEK_SET);
41 if (write(fd, magic, 4) != 4) {
42 perror("error writing to file");
43 exit(1);
44 }
45 exit(0);
46 }