view loadtools/romdump.c @ 1012:11391cb6bdc0

patch from fixeria: doc change from SE K2x0 to K2xx Since their discovery in late 2022, Sony Ericsson K200 and K220 phones were collectively referred to as SE K2x0 in FreeCalypso documentation. However, now that SE K205 has been discovered as yet another member of the same family (same PCBA in different case), it makes more sense to refer to the whole family as SE K2xx.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 23 Sep 2024 12:23:20 +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);
}