comparison loadtools/flconf.c @ 506:0dd2c87c1b63

fc-loadtool flash support overhaul
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 28 May 2019 05:12:47 +0000
parents
children
comparison
equal deleted inserted replaced
505:7bf0d909c87e 506:0dd2c87c1b63
1 /*
2 * This module handles flash configuration for fc-loadtool
3 */
4
5 #include <sys/types.h>
6 #include <ctype.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 /* the following variables describe our selected flash config */
15
16 int flash_global_config;
17 struct flash_bank_info flash_bank_info[2];
18
19 /* global configurations selected via hw parameter files */
20
21 static struct global_cfg_kw {
22 char *kw;
23 int code;
24 } global_cfg_keywords[] = {
25 {"single-4M", FLASH_GLOBAL_CFG_SINGLE_4M},
26 {"single-8M", FLASH_GLOBAL_CFG_SINGLE_8M},
27 {"dual-8M", FLASH_GLOBAL_CFG_DUAL_8M},
28 /* backward compatibility with old hw param files */
29 {"cfi-4M", FLASH_GLOBAL_CFG_SINGLE_4M},
30 {"cfi-8M", FLASH_GLOBAL_CFG_SINGLE_8M},
31 {"k5a32xx_t", FLASH_GLOBAL_CFG_SINGLE_4M},
32 {"pl129n", FLASH_GLOBAL_CFG_DUAL_8M},
33 {"28f640w30b", FLASH_GLOBAL_CFG_SINGLE_8M},
34 {0, 0} /* array terminator */
35 };
36
37 /* called from hwparam.c config file parser */
38 void
39 set_flash_config(arg, filename_for_errs, lineno_for_errs)
40 char *arg;
41 char *filename_for_errs;
42 int lineno_for_errs;
43 {
44 char *cp, *np, *ep;
45 struct global_cfg_kw *tp;
46 int bank, nbanks;
47 struct flash_bank_info *bi;
48 uint32_t align_size;
49
50 if (flash_global_config) {
51 fprintf(stderr, "%s line %d: duplicate flash setting\n",
52 filename_for_errs, lineno_for_errs);
53 exit(1);
54 }
55 for (cp = arg; isspace(*cp); cp++)
56 ;
57 if (!*cp || *cp == '#') {
58 too_few_arg: fprintf(stderr,
59 "%s line %d: flash setting: too few arguments\n",
60 filename_for_errs, lineno_for_errs);
61 exit(1);
62 }
63 for (np = cp; *cp && !isspace(*cp); cp++)
64 ;
65 if (*cp)
66 *cp++ = '\0';
67 for (tp = global_cfg_keywords; tp->kw; tp++)
68 if (!strcmp(tp->kw, np))
69 break;
70 if (!tp->kw) {
71 fprintf(stderr,
72 "%s line %d: unknown flash config \"%s\"\n",
73 filename_for_errs, lineno_for_errs, np);
74 exit(1);
75 }
76 flash_global_config = tp->code;
77
78 /* now initialize flash_bank_info (base addresses) */
79 switch (flash_global_config) {
80 case FLASH_GLOBAL_CFG_SINGLE_4M:
81 nbanks = 1;
82 align_size = 0x400000;
83 break;
84 case FLASH_GLOBAL_CFG_SINGLE_8M:
85 nbanks = 1;
86 align_size = 0x800000;
87 break;
88 case FLASH_GLOBAL_CFG_DUAL_8M:
89 nbanks = 2;
90 align_size = 0x800000;
91 break;
92 default:
93 fprintf(stderr,
94 "BUG in set_flash_config(): invalid global config\n");
95 abort();
96 }
97 for (bank = 0; bank < nbanks; bank++) {
98 while (isspace(*cp))
99 cp++;
100 if (!*cp || *cp == '#')
101 goto too_few_arg;
102 for (np = cp; *cp && !isspace(*cp); cp++)
103 ;
104 if (*cp)
105 *cp++ = '\0';
106 bi = flash_bank_info + bank;
107 bi->base_addr = strtoul(np, &ep, 16);
108 if (*ep) {
109 fprintf(stderr,
110 "%s line %d: syntax error (base addr expected after flash config name)\n",
111 filename_for_errs, lineno_for_errs);
112 exit(1);
113 }
114 /* check alignment */
115 if (bi->base_addr & (align_size - 1)) {
116 fprintf(stderr,
117 "%s line %d: flash bank %d base addr is not aligned to the bank size (0x%lx)\n",
118 filename_for_errs, lineno_for_errs, bank,
119 (u_long) align_size);
120 exit(1);
121 }
122 }
123 while (isspace(*cp))
124 cp++;
125 if (*cp && *cp != '#') {
126 fprintf(stderr,
127 "%s line %d: flash setting: too many arguments\n",
128 filename_for_errs, lineno_for_errs);
129 exit(1);
130 }
131 }