view loadtools/romdump.c @ 969:8cf7d41f2821

doc/User-phone-tools: document -e addition to fcup-smsend[mult]
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 01 Sep 2023 18:37:54 +0000
parents 464a531122ab
children
line wrap: on
line source

/*
 * This module contains the main() function for fc-dspromdump.
 */

#include <sys/types.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "../libserial/baudrate.h"
#include "srecreader.h"

char *target_ttydev;

char default_dspdump_image[] = "/opt/freecalypso/target-bin/dspdump.srec";

extern struct srecreader iramimage;
extern struct baudrate *current_baud_rate;
extern void (*default_exit)();

extern struct baudrate *find_baudrate_by_name();

static struct baudrate *romdump_baudrate;
static char *output_filename;
static FILE *outfile;

static
dump_receiver(line)
	char *line;
{
	if (!strncmp(line, "DSP dump:", 9) || !strncmp(line, "ERROR:", 6))
		puts(line);
	fprintf(outfile, "%s\n", line);
	return(1);
}

main(argc, argv)
	char **argv;
{
	extern char *optarg;
	extern int optind;
	int c;
	struct baudrate *br;
	char *targv[2];

	while ((c = getopt(argc, argv, "a:b:B:c:C:h:H:i:P:t:")) != EOF)
		switch (c) {
		case 'a':
			iramimage.filename = optarg;
			continue;
		case 'b':
			set_romload_baudrate(optarg);
			continue;
		case 'B':
			br = find_baudrate_by_name(optarg);
			if (!br)
				exit(1);	/* error msg already printed */
			romdump_baudrate = br;
			continue;
		case 'c':
			set_compalstage_short(optarg);
			continue;
		case 'C':
			set_compalstage_fullpath(optarg);
			continue;
		case 'h':
			read_hwparam_file_shortname(optarg);
			continue;
		case 'H':
			read_hwparam_file_fullpath(optarg);
			continue;
		case 'i':
			set_beacon_interval(optarg);
			continue;
		case 'P':
			if (find_bootctrl_entry(optarg) < 0)
				exit(1);	/* error msg already printed */
			continue;
		case 't':
			set_romload_timeout(optarg);
			continue;
		case '?':
		default:
usage:			fprintf(stderr,
			"usage: fc-dspromdump [options] ttyport output-file\n");
			exit(1);
		}
	if (argc - optind != 2)
		goto usage;
	target_ttydev = argv[optind];
	output_filename = argv[optind+1];
	if (!iramimage.filename)
		iramimage.filename = default_dspdump_image;

	open_serial_port(target_ttydev);
	pwon_if_needed();
	perform_compal_stage();
	perform_romload();
	/* dspdump target program should be running now */
	if (tpinterf_pass_output(1) < 0)
		exit(1);
	if (romdump_baudrate && romdump_baudrate != current_baud_rate) {
		c = loadagent_switch_baud(romdump_baudrate);
		if (c)
			exit(1);
	}
	outfile = fopen(output_filename, "w");
	if (!outfile) {
		perror(output_filename);
		exit(1);
	}
	printf("Requesting DSP ROM dump\n");
	targv[0] = "fulldump";
	targv[1] = 0;
	tpinterf_make_cmd(targv);
	if (tpinterf_send_cmd() < 0)
		exit(1);
	c = tpinterf_capture_output(2, dump_receiver);
	fclose(outfile);
	if (c < 0)
		exit(1);
	default_exit(0);
}