FreeCalypso > hg > freecalypso-sw
view loadtools/ltflash.c @ 56:d98137625c0d
fc-loadtool flash: total_size logic implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 23 Jun 2013 20:50:41 +0000 |
parents | 278052b6afda |
children | 1f9302b6f342 |
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; struct flash_bank_info *bi; 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'; bi = flash_bank_info + bank; bi->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 */ bi->bank_desc = selected_flash_device->bank_desc + bank; compute_flash_totsize_nsecs(bank); if (count_ones(bi->total_size) != 1) { fprintf(stderr, "fc-loadtool internal bug: flash bank %d size for %s is not a power of 2\n", bank, selected_flash_device->name); exit(1); } if (bi->base_addr & (bi->total_size - 1)) { fprintf(stderr, "%s line %d: flash bank %d base addr is not aligned to the bank size (0x%lx)\n", filename_for_errs, lineno_for_errs, bank, (u_long) bi->total_size); exit(1); } } 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); } }