view rvinterf/etmsync/memdump.c @ 497:74610c4f10f7

target-utils: added 10 ms delay at the end of abb_power_off() The deosmification of the ABB access code (replacement of osmo_delay_ms() bogus delays with correctly-timed ones, which are significantly shorter) had one annoying side effect: when executing the poweroff command from any of the programs, one last '=' prompt character was being sent (and received by the x86 host) as the Calypso board powers off. With delays being shorter now, the abb_power_off() function was returning and the standalone program's main loop was printing its prompt before the Iota chip fully executed the switch-off sequence! I thought about inserting an endless tight loop at the end of the abb_power_off() function, but the implemented solution of a 10 ms delay is a little nicer IMO because if the DEVOFF operation doesn't happen for some reason in a manual hacking scenario, there won't be an artificial blocker in the form of a tight loop keeping us from further poking around.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 25 May 2019 20:44:05 +0000
parents e40bb5a6c6b9
children
line wrap: on
line source

/*
 * This utility uses one of TI's Test Mode memory read commands (either TM3 or
 * ETM) in a synchronous manner (using our etmsync infrastructure) to read the
 * memory of a GSM device running a compatible fw version.  It supplants
 * the former fc-olddump tool.
 */

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

int use_etm;

extern char *socket_pathname;
extern char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;

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

	if (argc != 3) {
		fprintf(stderr,
		"usage: fc-memdump [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);
	}
	if (use_etm)
		maxchunk = MAX_MEMREAD_BYTES;
	else
		maxchunk = TM3_MEMREAD_MAX;
	while (len) {
		chunk = len;
		if (chunk > maxchunk)
			chunk = maxchunk;
		if (use_etm)
			rc = do_memory_read(addr, buf, chunk);
		else
			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);
}

main(argc, argv)
	char **argv;
{
	extern int optind;
	extern char *optarg;
	int c, sopt = 0;

	while ((c = getopt(argc, argv, "B:el:p:s:w:")) != EOF)
		switch (c) {
		case 'B':
			rvinterf_Bopt = optarg;
			continue;
		case 'e':
			use_etm++;
			continue;
		case 'l':
			rvinterf_lopt = optarg;
			continue;
		case 'p':
			rvinterf_ttyport = optarg;
			continue;
		case 's':
			socket_pathname = optarg;
			sopt++;
			continue;
		case 'w':
			rvinterf_wopt = optarg;
			continue;
		case '?':
		default:
			/* error msg already printed */
			exit(ERROR_USAGE);
		}
	if (rvinterf_ttyport) {
		if (sopt) {
			fprintf(stderr,
			"%s error: -p and -s options are mutually exclusive\n",
				argv[0]);
			exit(ERROR_USAGE);
		}
		launch_rvinterf(1);
	} else {
		if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) {
			fprintf(stderr,
"%s error: -B, -l and -w options are meaningful only when launching rvinterf\n",
				argv[0]);
			exit(ERROR_USAGE);
		}
		connect_local_socket();
	}

	return single_op_main(argc - optind, argv + optind);
}