changeset 15:36e65605d16a

bootutil: add c155-analyze-boot
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 10 Jun 2023 05:35:37 +0000
parents 09c18549921b
children 6b0d533046e5
files .hgignore bootutil/Makefile bootutil/c155_main.c
diffstat 3 files changed, 68 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sat Jun 10 05:09:38 2023 +0000
+++ b/.hgignore	Sat Jun 10 05:35:37 2023 +0000
@@ -11,3 +11,4 @@
 ^bootmatch/fc_patched_boot\.c$
 
 ^bootutil/c139-analyze-boot$
+^bootutil/c155-analyze-boot$
--- a/bootutil/Makefile	Sat Jun 10 05:09:38 2023 +0000
+++ b/bootutil/Makefile	Sat Jun 10 05:35:37 2023 +0000
@@ -1,9 +1,10 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	c139-analyze-boot
+PROGS=	c139-analyze-boot 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
+C155ANB_OBJS=	c155_boot.o c155_main.o do_match.o
 
 INSTALL_PREFIX=	/opt/freecalypso
 
@@ -14,6 +15,9 @@
 c139-analyze-boot:	${C139ANB_OBJS}
 	${CC} ${CFLAGS} -o $@ ${C139ANB_OBJS}
 
+c155-analyze-boot:	${C155ANB_OBJS}
+	${CC} ${CFLAGS} -o $@ ${C155ANB_OBJS}
+
 c11x_lockable.o:	../bootmatch/c11x_lockable.c
 	${CC} ${CFLAGS} -c -o $@ $<
 
@@ -26,6 +30,9 @@
 c139_nolock.o:	../bootmatch/c139_nolock.c
 	${CC} ${CFLAGS} -c -o $@ $<
 
+c155_boot.o:	../bootmatch/c155_boot.c
+	${CC} ${CFLAGS} -c -o $@ $<
+
 fc_patched_boot.o:	../bootmatch/fc_patched_boot.c
 	${CC} ${CFLAGS} -c -o $@ $<
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bootutil/c155_main.c	Sat Jun 10 05:35:37 2023 +0000
@@ -0,0 +1,59 @@
+/*
+ * This C module is the main for c155-analyze-boot utility.
+ */
+
+#include <sys/types.h>
+#include <sys/file.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include "../bootmatch/bootmatch.h"
+
+extern struct bootmatch bootmatch_c155[];
+
+#define	LENGTH_OF_INTEREST	0x2000
+
+static u_char image[LENGTH_OF_INTEREST];
+
+static void
+read_bin_file(filename)
+	char *filename;
+{
+	int fd;
+	struct stat st;
+
+	fd = open(filename, O_RDONLY);
+	if (fd < 0) {
+		perror(filename);
+		exit(1);
+	}
+	fstat(fd, &st);
+	if (!S_ISREG(st.st_mode)) {
+		fprintf(stderr, "error: %s is not a regular file\n", filename);
+		exit(1);
+	}
+	if (st.st_size < LENGTH_OF_INTEREST) {
+		fprintf(stderr, "error: %s is too short\n", filename);
+		exit(1);
+	}
+	read(fd, image, LENGTH_OF_INTEREST);
+	close(fd);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s flashdump.bin\n", argv[0]);
+		exit(1);
+	}
+	read_bin_file(argv[1]);
+	if (check_for_match(image, bootmatch_c155))
+		puts("ok");
+	else
+		puts("unknown");
+	exit(0);
+}