# HG changeset patch # User Mychaela Falconia # Date 1686376140 0 # Node ID 6b0d533046e519a3f85a5558b30a381a2ef6213b # Parent 36e65605d16a172b80c032754c402660a8ae9ebd bootutil: add c139-patch-dmagic diff -r 36e65605d16a -r 6b0d533046e5 .hgignore --- a/.hgignore Sat Jun 10 05:35:37 2023 +0000 +++ b/.hgignore Sat Jun 10 05:49:00 2023 +0000 @@ -11,4 +11,5 @@ ^bootmatch/fc_patched_boot\.c$ ^bootutil/c139-analyze-boot$ +^bootutil/c139-patch-dmagic$ ^bootutil/c155-analyze-boot$ diff -r 36e65605d16a -r 6b0d533046e5 bootutil/Makefile --- a/bootutil/Makefile Sat Jun 10 05:35:37 2023 +0000 +++ b/bootutil/Makefile Sat Jun 10 05:49:00 2023 +0000 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -PROGS= c139-analyze-boot c155-analyze-boot +PROGS= c139-analyze-boot c139-patch-dmagic c155-analyze-boot C139ANB_OBJS= c11x_lockable.o c11x_nolock.o c139_lockable.o c139_main.o \ c139_nolock.o do_match.o fc_patched_boot.o @@ -15,6 +15,9 @@ c139-analyze-boot: ${C139ANB_OBJS} ${CC} ${CFLAGS} -o $@ ${C139ANB_OBJS} +c139-patch-dmagic: c139-patch-dmagic.c + ${CC} ${CFLAGS} -o $@ $@.c + c155-analyze-boot: ${C155ANB_OBJS} ${CC} ${CFLAGS} -o $@ ${C155ANB_OBJS} diff -r 36e65605d16a -r 6b0d533046e5 bootutil/c139-patch-dmagic.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bootutil/c139-patch-dmagic.c Sat Jun 10 05:49:00 2023 +0000 @@ -0,0 +1,46 @@ +/* + * This program patches DD DD DD DD magic bytes into the given binary file + * at offset 0x2060, thereby turning a locked C11x/12x or C139/140 flash image + * into an unlocked one. + */ + +#include +#include +#include +#include +#include +#include + +static u_char magic[4] = {0xDD, 0xDD, 0xDD, 0xDD}; + +main(argc, argv) + char **argv; +{ + int fd; + struct stat st; + + if (argc != 2) { + fprintf(stderr, "usage: %s flashimage.bin\n", argv[0]); + exit(1); + } + fd = open(argv[1], O_RDWR); + if (fd < 0) { + perror(argv[1]); + exit(1); + } + fstat(fd, &st); + if (!S_ISREG(st.st_mode)) { + fprintf(stderr, "error: %s is not a regular file\n", argv[1]); + exit(1); + } + if (st.st_size < 0x2064) { + fprintf(stderr, "error: %s is too short\n", argv[1]); + exit(1); + } + lseek(fd, 0x2060, SEEK_SET); + if (write(fd, magic, 4) != 4) { + perror("error writing to file"); + exit(1); + } + exit(0); +}