comparison 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
comparison
equal deleted inserted replaced
54:50b652bc3a4f 55:278052b6afda
1 /*
2 * In this module we are going to implement the flash operation commands
3 * of fc-loadtool.
4 */
5
6 #include <sys/types.h>
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <string.h>
10 #include <strings.h>
11 #include <stdlib.h>
12 #include "flash.h"
13
14 /* S{29,71}PL129N device description */
15
16 static struct flash_region_desc pl129n_ce1_regions[] = {
17 /* 4 sectors of 64 KiB each at the beginning, then 256 KiB sectors */
18 {0x10000, 4},
19 {0x40000, 31},
20 {0, 0} /* array terminator */
21 };
22
23 static struct flash_region_desc pl129n_ce2_regions[] = {
24 /* the other way around now */
25 {0x40000, 31},
26 {0x10000, 4},
27 {0, 0} /* array terminator */
28 };
29
30 static struct flash_bank_desc pl129n_banks[2] = {
31 {pl129n_ce1_regions, 0xFFFC0000},
32 {pl129n_ce2_regions, 0xFFFC0000}
33 };
34
35 /* list of supported flash devices */
36
37 struct flash_device_desc flash_device_list[] = {
38 {"pl129n", pl129n_banks, 2},
39 {0, 0, 0} /* array terminator */
40 };
41
42 /* the following variables describe our selected flash device */
43
44 struct flash_device_desc *selected_flash_device;
45 struct flash_bank_info flash_bank_info[2];
46
47 /* called from hwparam.c config file parser */
48 void
49 set_flash_device(arg, filename_for_errs, lineno_for_errs)
50 char *arg;
51 char *filename_for_errs;
52 int lineno_for_errs;
53 {
54 char *cp, *np, *ep;
55 struct flash_device_desc *tp;
56 int bank;
57
58 if (selected_flash_device) {
59 fprintf(stderr, "%s line %d: duplicate flash setting\n",
60 filename_for_errs, lineno_for_errs);
61 exit(1);
62 }
63 for (cp = arg; isspace(*cp); cp++)
64 ;
65 if (!*cp || *cp == '#') {
66 too_few_arg: fprintf(stderr,
67 "%s line %d: flash setting: too few arguments\n",
68 filename_for_errs, lineno_for_errs);
69 exit(1);
70 }
71 for (np = cp; *cp && !isspace(*cp); cp++)
72 ;
73 if (*cp)
74 *cp++ = '\0';
75 for (tp = flash_device_list; tp->name; tp++)
76 if (!strcmp(tp->name, np))
77 break;
78 if (!tp->name) {
79 fprintf(stderr,
80 "%s line %d: unknown flash device \"%s\"\n",
81 filename_for_errs, lineno_for_errs, np);
82 exit(1);
83 }
84 selected_flash_device = tp;
85
86 /* now initialize flash_bank_info */
87 for (bank = 0; bank < selected_flash_device->nbanks; bank++) {
88 while (isspace(*cp))
89 cp++;
90 if (!*cp || *cp == '#')
91 goto too_few_arg;
92 for (np = cp; *cp && !isspace(*cp); cp++)
93 ;
94 if (*cp)
95 *cp++ = '\0';
96 flash_bank_info[bank].base_addr = strtoul(np, &ep, 16);
97 if (*ep) {
98 fprintf(stderr,
99 "%s line %d: syntax error (base addr expected after flash device type)\n",
100 filename_for_errs, lineno_for_errs);
101 exit(1);
102 }
103 /* the rest comes from the flash device type */
104 flash_bank_info[bank].bank_desc =
105 selected_flash_device->bank_desc + bank;
106 /* TODO: call function to init total_size and nsectors */
107 }
108 while (isspace(*cp))
109 cp++;
110 if (*cp && *cp != '#') {
111 fprintf(stderr,
112 "%s line %d: flash setting: too many arguments\n",
113 filename_for_errs, lineno_for_errs);
114 exit(1);
115 }
116 }