FreeCalypso > hg > freecalypso-sw
view loadtools/ltflash.c @ 55:278052b6afda
loadtools: started laying the foundation for flash support
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 23 Jun 2013 20:13:59 +0000 |
parents | |
children | d98137625c0d |
line wrap: on
line source
/* * In this module we are going to implement the flash operation commands * of fc-loadtool. */ #include <sys/types.h> #include <stdio.h> #include <stdint.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "flash.h" /* S{29,71}PL129N device description */ static struct flash_region_desc pl129n_ce1_regions[] = { /* 4 sectors of 64 KiB each at the beginning, then 256 KiB sectors */ {0x10000, 4}, {0x40000, 31}, {0, 0} /* array terminator */ }; static struct flash_region_desc pl129n_ce2_regions[] = { /* the other way around now */ {0x40000, 31}, {0x10000, 4}, {0, 0} /* array terminator */ }; static struct flash_bank_desc pl129n_banks[2] = { {pl129n_ce1_regions, 0xFFFC0000}, {pl129n_ce2_regions, 0xFFFC0000} }; /* list of supported flash devices */ struct flash_device_desc flash_device_list[] = { {"pl129n", pl129n_banks, 2}, {0, 0, 0} /* array terminator */ }; /* the following variables describe our selected flash device */ struct flash_device_desc *selected_flash_device; struct flash_bank_info flash_bank_info[2]; /* called from hwparam.c config file parser */ void set_flash_device(arg, filename_for_errs, lineno_for_errs) char *arg; char *filename_for_errs; int lineno_for_errs; { char *cp, *np, *ep; struct flash_device_desc *tp; int bank; if (selected_flash_device) { fprintf(stderr, "%s line %d: duplicate flash 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: flash setting: too few arguments\n", filename_for_errs, lineno_for_errs); exit(1); } for (np = cp; *cp && !isspace(*cp); cp++) ; if (*cp) *cp++ = '\0'; for (tp = flash_device_list; tp->name; tp++) if (!strcmp(tp->name, np)) break; if (!tp->name) { fprintf(stderr, "%s line %d: unknown flash device \"%s\"\n", filename_for_errs, lineno_for_errs, np); exit(1); } selected_flash_device = tp; /* now initialize flash_bank_info */ for (bank = 0; bank < selected_flash_device->nbanks; bank++) { while (isspace(*cp)) cp++; if (!*cp || *cp == '#') goto too_few_arg; for (np = cp; *cp && !isspace(*cp); cp++) ; if (*cp) *cp++ = '\0'; flash_bank_info[bank].base_addr = strtoul(np, &ep, 16); if (*ep) { fprintf(stderr, "%s line %d: syntax error (base addr expected after flash device type)\n", filename_for_errs, lineno_for_errs); exit(1); } /* the rest comes from the flash device type */ flash_bank_info[bank].bank_desc = selected_flash_device->bank_desc + bank; /* TODO: call function to init total_size and nsectors */ } while (isspace(*cp)) cp++; if (*cp && *cp != '#') { fprintf(stderr, "%s line %d: flash setting: too many arguments\n", filename_for_errs, lineno_for_errs); exit(1); } }