view loadtools/flcmplboot.c @ 412:bf49e348576b

fc-loadtool: flcmplboot.c (boot-reflash-hack) code started
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 17 Jun 2014 05:07:17 +0000
parents
children a2df77833c21
line wrap: on
line source

/*
 * This module contains the implementation of the flash erase-program-boot
 * hack for brickable Compal phones.
 */

#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"

static int hack_enabled;
static uint32_t boot_sector_size;
static uint32_t ram_buffer_addr;

/* called from hwparam.c config file parser */
void
set_boot_reflash_hack(arg, filename_for_errs, lineno_for_errs)
	char *arg;
	char *filename_for_errs;
	int lineno_for_errs;
{
	char *cp, *np, *ep;

	if (hack_enabled) {
		fprintf(stderr,
			"%s line %d: duplicate boot-reflash-hack setting\n",
			filename_for_errs, lineno_for_errs);
		exit(1);
	}
	for (cp = arg; isspace(*cp); cp++)
		;
	if (!*cp || *cp == '#') {
too_few_arg:	fprintf(stderr,
		"%s line %d: boot-reflash-hack setting: too few arguments\n",
			filename_for_errs, lineno_for_errs);
		exit(1);
	}
	for (np = cp; *cp && !isspace(*cp); cp++)
		;
	if (!*cp)
		goto too_few_arg;
	*cp++ = '\0';
	ram_buffer_addr = strtoul(np, &ep, 16);
	if (*ep) {
invhex:		fprintf(stderr,
			"%s line %d: syntax error (hex arguments expected)\n",
			filename_for_errs, lineno_for_errs);
		exit(1);
	}
	while (isspace(*cp))
		cp++;
	if (!*cp || *cp == '#')
		goto too_few_arg;
	for (np = cp; *cp && !isspace(*cp); cp++)
		;
	if (*cp)
		*cp++ = '\0';
	boot_sector_size = strtoul(np, &ep, 16);
	if (*ep)
		goto invhex;
	while (isspace(*cp))
		cp++;
	if (*cp && *cp != '#') {
		fprintf(stderr,
		"%s line %d: boot-reflash-hack setting: too many arguments\n",
			filename_for_errs, lineno_for_errs);
		exit(1);
	}
	hack_enabled = 1;
}