view target-utils/loadagent/bindump.c @ 964:a96cb97b66a2

ringtools/imy: fix duplicate definition of tdma_durations[] The bug was reported by Vadim Yanitskiy <fixeria@osmocom.org>, although the present fix is slightly different from the contributed patch: because main.c doesn't need this tdma_durations[] array at all, let's simply remove the reference to this array from main.c rather than turn it into an extern. I no longer remember my original thought flow that resulted (by mistake) in tdma_durations[] being multiply defined in main.c and durations.c. My intent might have been to define all globals in main.c and have the reference in durations.c be an extern - and I missed that extern - but without clear memory, I have no certainty. In any case, having this data array defined in the same module that fills it (durations.c) is sensible, so let's make it the new way.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 31 Aug 2023 19:38:18 +0000
parents 963d15a808eb
children
line wrap: on
line source

/*
 * Here we are going to implement a new memory dump command for use by
 * fc-loadtool, sending the dump stream to the host in binary instead of hex
 * S-records.
 *
 * We could send the entire stream continuously without any structure or
 * breaks, but if we did that, fc-loadtool would not be able to detect a slip
 * (byte loss error) in the serial stream until the end of the dump,
 * potentially minutes long.  For this reason we are taking a different
 * approach: we are going to send the dump stream in blocks of 8192 bytes,
 * with each block preceded by an 8-byte binary header.  Loadtool will know
 * and expect the same block structure, and seeing our block headers in the
 * right positions in the stream will provide assurance of synchronization.
 */

#include <sys/types.h>
#include "types.h"

void
cmd_memdump_binary(argbulk)
	char *argbulk;
{
	char *argv[3];
	u_long start, length;
	u_long addr, remlen;
	unsigned blklen, n;

	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
		return;
	if (parse_hexarg(argv[0], 8, &start) < 0) {
		printf("ERROR: arg1 must be a valid 32-bit hex address\n");
		return;
	}
	if (parse_hexarg(argv[1], 8, &length) < 0) {
	    printf("ERROR: arg2 must be a valid 32-bit hex value (length)\n");
		return;
	}
	addr = start;
	for (remlen = length; remlen; remlen -= blklen) {
		blklen = 8192;
		if (remlen < blklen)
			blklen = remlen;
		serial_out(0x55);
		serial_out(0xAA);
		serial_out(addr >> 24);
		serial_out(addr >> 16);
		serial_out(addr >> 8);
		serial_out(addr);
		serial_out(blklen >> 8);
		serial_out(blklen);
		for (n = blklen; n; n--) {
			serial_out(*(volatile u8 *)addr);
			addr++;
		}
	}
}