view loadtools/chainload.c @ 619:f82551c77e58

libserial-newlnx: ASYNC_LOW_LATENCY patch reverted Reports from Das Signal indicate that loadtools performance on Debian is about the same as on Slackware, and that including or omitting the ASYNC_LOW_LATENCY patch from Serg makes no difference. Because the patch in question does not appear to be necessary, it is being reverted until and unless someone other than Serg reports an actual real-world system on which loadtools operation times are slowed compared to the Mother's Slackware reference and on which Slackware-like performance can be restored by setting the ASYNC_LOW_LATENCY flag.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 27 Feb 2020 01:09:48 +0000
parents 02bdb2f366bc
children bf840c984113
line wrap: on
line source

/*
 * This module implements the chain-loading of XRAM images via loadagent.
 */

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

struct srecreader xramimage;

extern struct baudrate *current_baud_rate;
extern struct baudrate *xram_run_baudrate;
extern int xram_jtag_mode;

static void
make_ml_arg(rec, buf)
	u_char *rec;
	char *buf;
{
	register int i, len;
	register char *s;

	len = rec[0] + 1;
	s = buf;
	for (i = 0; i < len; i++) {
		sprintf(s, "%02X", rec[i]);
		s += 2;
	}
	*s = '\0';
}

perform_chain_load()
{
	int resp;
	unsigned long rec_count;
	char *argv[3], srecarg[516];
	time_t start_time, finish_time;
	unsigned duration, mm, ss;

	if (open_srec_file(&xramimage) < 0)
		exit(1);
	argv[0] = "ML";
	argv[1] = srecarg;
	argv[2] = 0;
	for (rec_count = 0; ; ) {
		if (read_s_record(&xramimage) < 0)
			exit(1);
		switch (xramimage.record_type) {
		case '0':
			if (xramimage.lineno == 1)
				continue;
			fprintf(stderr,
		"%s: S0 record found in line %d (expected in line 1 only)\n",
				xramimage.filename, xramimage.lineno);
			exit(1);
		case '3':
		case '7':
			if (s3s7_get_addr_data(&xramimage) < 0)
				exit(1);
			break;
		default:
			fprintf(stderr,
				"%s line %d: S%c record type not supported\n",
				xramimage.filename, xramimage.lineno,
				xramimage.record_type);
			exit(1);
		}
		if (xramimage.record_type == '7') {
			time(&finish_time);
			break;
		}
		/* must be S3 */
		if (xramimage.datalen < 1) {
			fprintf(stderr,
				"%s line %d: S3 record has zero data length\n",
				xramimage.filename, xramimage.lineno);
			exit(1);
		}
		if (!rec_count) {
			printf("Each \'.\' is 100 S-records\n");
			time(&start_time);
		}
		make_ml_arg(xramimage.record, srecarg);
		tpinterf_make_cmd(argv);
		if (tpinterf_send_cmd())
			exit(1);
		if (tpinterf_pass_output(1))
			exit(1);
		rec_count++;
		if (rec_count % 100 == 0) {
			putchar('.');
			fflush(stdout);
		}
	}
	/* got S7 */
	fclose(xramimage.openfile);
	if (!rec_count) {
		fprintf(stderr,
		"%s line %d: S7 without any preceding S3 data records\n",
			xramimage.filename, xramimage.lineno);
		exit(1);
	}
	putchar('\n');	/* newline after the dots */
	duration = finish_time - start_time;
	mm = duration / 60;
	ss = duration - mm * 60;
	printf("XRAM image transferred in %um%us\n", mm, ss);
	if (xram_run_baudrate != current_baud_rate) {
		resp = loadagent_switch_baud(xram_run_baudrate);
		if (resp)
			exit(1);
	}
	if (xram_jtag_mode) {
		printf(
      "Leaving target in loadagent for JTAG; image start address is 0x%08lX\n",
			(u_long) xramimage.addr);
		exit(0);
	}
	printf("Sending jump command\n");
	sprintf(srecarg, "%lX", (u_long) xramimage.addr);
	argv[0] = "jump";
	tpinterf_make_cmd(argv);
	if (tpinterf_send_cmd())
		exit(1);
	printf("Sent \"%s %s\": XRAM image should now be running!\n",
		argv[0], argv[1]);
	return(0);
}