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