view miscprog/cinitdump.c @ 343:917e05f03ad2

fluid-mnf/serial.c: <assert.h> no longer needed
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 13 Mar 2020 05:40:23 +0000
parents e493fcff28ab
children
line wrap: on
line source

/*
 * This program dumps the cinit section records from a firmware image
 * sans symbols, given just the cinit start address and knowing the
 * record structure.
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>

FILE *inf;
u_long offset;

u_long
get_word()
{
	u_char bytes[4];
	u_long word;

	fread(bytes, 1, 4, inf);
	word = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
	printf("%8lx:\t%08lx\n", offset, word);
	offset += 4;
	return word;
}

main(argc, argv)
	char **argv;
{
	u_long len, count;

	if (argc != 3) {
		fprintf(stderr, "usage: %s filename start-addr\n", argv[0]);
		exit(1);
	}
	inf = fopen(argv[1], "r");
	if (!inf) {
		perror(argv[1]);
		exit(1);
	}
	offset = strtoul(argv[2], 0, 0);
	fseek(inf, offset, SEEK_SET);

	for (;;) {
		len = get_word();
		if (!len)
			break;
		len = (len + 3) & ~3;
		get_word();	/* bss address */
		for (count = 0; count < len; count += 4)
			get_word();
		putchar('\n');
	}
	exit(0);
}