view loadtools/flmain.c @ 560:641d816b1e91

loadtools/scripts: tango.config renamed to gen8.config This config is really generic for all "vanilla" targets with 8 MiB flash
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 30 Jan 2020 06:59:03 +0000
parents 211be4dc6be2
children 815c3f8bcff1
line wrap: on
line source

/*
 * This module is the main entry point for fc-loadtool flash functions
 */

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "flash.h"

extern int flash_global_config;
extern struct flash_bank_info flash_bank_info[2];

flashcmd_geom(argc, argv, bank)
	char **argv;
{
	struct flash_bank_info *bi;
	unsigned rn;

	if (argc > 2) {
		fprintf(stderr, "error: too many arguments\n");
		return(-1);
	}
	if (flash_detect(bank, 0) < 0)
		return(-1);
	bi = flash_bank_info + bank;
	printf("Detected flash device: %s\n", bi->device->name);
	if (bi->device->bank_geom[1])
		printf("Device has two banks, looking at bank %d\n", bank);
	else
		printf("Single-bank flash device\n");
	printf("Bank %d total size: 0x%lx\n", bank,
		(u_long) bi->geom->total_size);
	printf("Sectors in bank %d: %u (%u regions)\n", bank,
		bi->geom->total_sectors, bi->geom->nregions);
	for (rn = 0; rn < bi->geom->nregions; rn++)
		printf("Region %u: %u sectors of 0x%lx bytes\n", rn,
			bi->geom->regions[rn].nsectors,
			(u_long) bi->geom->regions[rn].sector_size);
	printf("Command set style: %s\n", bi->ops->cmdset_name);
	return(0);
}

flashcmd_help()
{
	return loadtool_help("flash");
}

flashcmd_id(argc, argv, bank)
	char **argv;
{
	if (argc > 2) {
		fprintf(stderr, "error: too many arguments\n");
		return(-1);
	}
	return flash_detect(bank, 1);
}

flashcmd_info(argc, argv)
	char **argv;
{
	int bank, nbanks;

	if (argc > 2) {
		fprintf(stderr, "error: too many arguments\n");
		return(-1);
	}
	switch (flash_global_config) {
	case FLASH_GLOBAL_CFG_SINGLE_4M:
		printf("Configured for a single flash bank of up to 4 MiB\n");
		nbanks = 1;
		break;
	case FLASH_GLOBAL_CFG_SINGLE_8M:
		printf("Configured for a single flash bank of up to 8 MiB\n");
		nbanks = 1;
		break;
	case FLASH_GLOBAL_CFG_DUAL_8M:
		printf("Configured for two flash banks of up to 8 MiB each\n");
		nbanks = 2;
		break;
	default:
		fprintf(stderr, "error: invalid global config\n");
		return(-1);
	}
	for (bank = 0; bank < nbanks; bank++)
		printf("Bank %d base address: %08lX\n", bank,
			(u_long) flash_bank_info[bank].base_addr);
	return(0);
}

extern int flashcmd_blankchk();
extern int flashcmd_dump2file();
extern int flashcmd_erase();
extern int flashcmd_erase_program_boot();
extern int flashcmd_progbin();
extern int flashcmd_program_m0();
extern int flashcmd_program_srec();
extern int flashcmd_quickprog();
extern int flashcmd_reset();
extern int flashcmd_sectors();
extern int flashcmd_status();
extern int flashcmd_unlock();

static struct cmdtab {
	char *cmd;
	int (*func)();
} cmdtab[] = {
	{"blankchk", flashcmd_blankchk},
	{"dump2bin", flashcmd_dump2file},
	{"dump2srec", flashcmd_dump2file},
	{"erase", flashcmd_erase},
	{"erase-program-boot", flashcmd_erase_program_boot},
	{"geom", flashcmd_geom},
	{"help", flashcmd_help},
	{"id", flashcmd_id},
	{"info", flashcmd_info},
	{"program-bin", flashcmd_progbin},
	{"program-m0", flashcmd_program_m0},
	{"program-srec", flashcmd_program_srec},
	{"quickprog", flashcmd_quickprog},
	{"reset", flashcmd_reset},
	{"sectors", flashcmd_sectors},
	{"status", flashcmd_status},
	{"unlock", flashcmd_unlock},
	{0, 0}
};

cmd_flash(argc, argv)
	char **argv;
{
	int bank;
	struct cmdtab *tp;

	if (!flash_global_config) {
		fprintf(stderr, "No flash configuration defined\n");
		return(-1);
	}
	if (argv[0][5] == '2') {
		if (flash_global_config != FLASH_GLOBAL_CFG_DUAL_8M) {
			fprintf(stderr, "No second flash bank configured\n");
			return(-1);
		}
		bank = 1;
	} else
		bank = 0;
	for (tp = cmdtab; tp->cmd; tp++)
		if (!strcmp(tp->cmd, argv[1]))
			break;
	if (!tp->func) {
		fprintf(stderr, "%s %s: unknown/unimplemented subcommand\n",
			argv[0], argv[1]);
		return(-1);
	}
	return tp->func(argc, argv, bank);
}