view rvinterf/etmsync/olddump.c @ 1023:cd6002e3aefb

doc/Freerunner-Howto: apparently some people still use SHR, so mention it too
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Tue, 03 May 2016 13:48:39 +0000
parents 461f7ee5f254
children
line wrap: on
line source

/*
 * This utility uses the old TM3 memory read command (in a synchronous manner
 * using our etmsync infrastructure) to read the memory of a GSM device running
 * a compatible fw version; it was written as an aid for reverse-engineering
 * bootloader-locked Mot C139 fw versions.
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "tm3.h"
#include "localtypes.h"
#include "exitcodes.h"

#define	CHUNK_SIZE	TM3_MEMREAD_MAX

single_op_main(argc, argv)
	char **argv;
{
	u32 addr, len, chunk;
	char buf[CHUNK_SIZE];
	FILE *outf;
	int rc;

	if (argc != 3) {
		fprintf(stderr,
		"usage: fc-olddump [options] start-addr dump-length binfile\n");
		exit(ERROR_USAGE);
	}
	addr = strtoul(argv[0], 0, 16);
	len = strtoul(argv[1], 0, 16);
	outf = fopen(argv[2], "w");
	if (!outf) {
		perror(argv[2]);
		exit(ERROR_UNIX);
	}
	while (len) {
		chunk = len;
		if (chunk > CHUNK_SIZE)
			chunk = CHUNK_SIZE;
		rc = do_memory_read_tm3(addr, buf, chunk);
		if (rc)
			exit(rc);
		fwrite(buf, 1, chunk, outf);
		putchar('.');
		fflush(stdout);
		addr += chunk;
		len -= chunk;
	}
	putchar('\n');
	fclose(outf);
	exit(0);
}