FreeCalypso > hg > freecalypso-sw
changeset 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 | 50b652bc3a4f |
children | d98137625c0d |
files | loadtools/Makefile loadtools/clmain.c loadtools/flash.h loadtools/hwparam.c loadtools/hwparamstubs.c loadtools/ltflash.c loadtools/sertool.c |
diffstat | 7 files changed, 180 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/loadtools/Makefile Sun Jun 23 05:47:17 2013 +0000 +++ b/loadtools/Makefile Sun Jun 23 20:13:59 2013 +0000 @@ -6,16 +6,17 @@ INSTBIN=/usr/local/bin INSTSCR=/usr/local/share/freecalypso -IRAM_OBJS= defpath.o hexdecode.o hwparam.o romload.o sercomm.o sertool.o \ - srecreader.o ttypassthru.o +IRAM_OBJS= defpath.o hexdecode.o hwparam.o hwparamstubs.o romload.o \ + sercomm.o sertool.o srecreader.o ttypassthru.o LOADTOOL_OBJS= crc32tab.o defpath.o hexdecode.o hwparam.o labaud.o \ - ltdispatch.o ltdump.o ltexit.o ltmain.o ltpassthru.o ltscript.o\ - romload.o sercomm.o srecreader.o tpinterf.o tpinterf2.o + ltdispatch.o ltdump.o ltexit.o ltflash.o ltmain.o ltpassthru.o \ + ltscript.o romload.o sercomm.o srecreader.o tpinterf.o \ + tpinterf2.o XRAM_OBJS= chainload.o clmain.o defpath.o hexdecode.o hwparam.o \ - initscript.o labaud.o romload.o sercomm.o srecreader.o \ - tpinterf.o ttypassthru.o + hwparamstubs.o initscript.o labaud.o romload.o sercomm.o \ + srecreader.o tpinterf.o ttypassthru.o all: ${PROGS}
--- a/loadtools/clmain.c Sun Jun 23 05:47:17 2013 +0000 +++ b/loadtools/clmain.c Sun Jun 23 20:13:59 2013 +0000 @@ -98,10 +98,3 @@ tty_passthru(); exit(0); } - -/* called from hwparam.c config file parser */ -/* stub needed for fc-xram to link */ -void -set_default_exit_mode() -{ -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loadtools/flash.h Sun Jun 23 20:13:59 2013 +0000 @@ -0,0 +1,39 @@ +/* this header file contains definitions for fc-loadtool flash support */ + +/* + * The following structures represent an "abstract" + * description of flash devices. + * + * A "region" is a consecutive group of erase units of the same size. + */ + +struct flash_region_desc { + uint32_t sector_size; + unsigned nsectors; +}; + +struct flash_bank_desc { + struct flash_region_desc *regions; + uint32_t prog_base_mask; +}; + +struct flash_device_desc { + char *name; + struct flash_bank_desc *bank_desc; + unsigned nbanks; +}; + +/* the following structures describe flash banks as accessible to us */ + +struct sector_info { + uint32_t start; + uint32_t size; +}; + +struct flash_bank_info { + uint32_t base_addr; + uint32_t total_size; + struct flash_bank_desc *bank_desc; + struct sector_info *sectors; + unsigned nsectors; +};
--- a/loadtools/hwparam.c Sun Jun 23 05:47:17 2013 +0000 +++ b/loadtools/hwparam.c Sun Jun 23 20:13:59 2013 +0000 @@ -13,6 +13,7 @@ extern char default_helpers_dir[]; extern void set_default_exit_mode(); +extern void set_flash_device(); char hw_init_script[128]; @@ -107,6 +108,7 @@ void (*func)(); } cmdtab[] = { {"exit-mode", set_default_exit_mode}, + {"flash", set_flash_device}, {"init-script", handle_init_script}, {"pll-config", handle_pll_config}, {"rhea-cntl", handle_rhea_cntl},
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loadtools/hwparamstubs.c Sun Jun 23 20:13:59 2013 +0000 @@ -0,0 +1,16 @@ +/* + * The exit-mode and flash settings in the hardware parameter files + * specified with -h or -H are meaningful only for fc-loadtool, but + * the same hwparam.c code is included in fc-iram and fc-xram as well. + * This module provides the stubs, allowing fc-iram and fc-xram to link. + */ + +void +set_default_exit_mode() +{ +} + +void +set_flash_device() +{ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loadtools/ltflash.c Sun Jun 23 20:13:59 2013 +0000 @@ -0,0 +1,116 @@ +/* + * 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); + } +}