2 * Copyright (C) 2009-2012 Semihalf
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/errno.h>
31 #include <sys/ioctl.h>
32 #include <sys/types.h>
34 #include <dev/nand/nandsim.h>
44 #include "nandsim_cfgparse.h"
46 #define warn(fmt, args...) do { \
47 printf("WARNING: " fmt "\n", ##args); } while (0)
49 #define error(fmt, args...) do { \
50 printf("ERROR: " fmt "\n", ##args); } while (0)
52 #define MSG_MANDATORYKEYMISSING "mandatory key \"%s\" value belonging to " \
53 "section \"%s\" is missing!\n"
59 #define debug(fmt, args...) do { \
60 printf("NANDSIM_CONF:" fmt "\n", ##args); } while (0)
62 #define debug(fmt, args...) do {} while(0)
65 #define STRBUFSIZ 2000
67 /* Macros extracts type and type size */
68 #define TYPE(x) ((x) & 0xf8)
69 #define SIZE(x) (((x) & 0x07))
71 /* Erase/Prog/Read time max and min values */
72 #define DELAYTIME_MIN 10000
73 #define DELAYTIME_MAX 10000000
75 /* Structure holding configuration for controller. */
76 static struct sim_ctrl ctrl_conf;
77 /* Structure holding configuration for chip. */
78 static struct sim_chip chip_conf;
80 static struct nandsim_key nandsim_ctrl_keys[] = {
81 {"num_cs", 1, VALUE_UINT | SIZE_8, (void *)&ctrl_conf.num_cs, 0},
82 {"ctrl_num", 1, VALUE_UINT | SIZE_8, (void *)&ctrl_conf.num, 0},
84 {"ecc_layout", 1, VALUE_UINTARRAY | SIZE_16,
85 (void *)&ctrl_conf.ecc_layout, MAX_ECC_BYTES},
87 {"filename", 0, VALUE_STRING,
88 (void *)&ctrl_conf.filename, FILENAME_SIZE},
90 {"ecc", 0, VALUE_BOOL, (void *)&ctrl_conf.ecc, 0},
91 {NULL, 0, 0, NULL, 0},
94 static struct nandsim_key nandsim_chip_keys[] = {
95 {"chip_cs", 1, VALUE_UINT | SIZE_8, (void *)&chip_conf.num, 0},
96 {"chip_ctrl", 1, VALUE_UINT | SIZE_8, (void *)&chip_conf.ctrl_num,
98 {"device_id", 1, VALUE_UINT | SIZE_8, (void *)&chip_conf.device_id,
100 {"manufacturer_id", 1, VALUE_UINT | SIZE_8,
101 (void *)&chip_conf.manufact_id, 0},
102 {"model", 0, VALUE_STRING, (void *)&chip_conf.device_model,
104 {"manufacturer", 0, VALUE_STRING, (void *)&chip_conf.manufacturer,
106 {"page_size", 1, VALUE_UINT | SIZE_32, (void *)&chip_conf.page_size,
108 {"oob_size", 1, VALUE_UINT | SIZE_32, (void *)&chip_conf.oob_size,
110 {"pages_per_block", 1, VALUE_UINT | SIZE_32,
111 (void *)&chip_conf.pgs_per_blk, 0},
112 {"blocks_per_lun", 1, VALUE_UINT | SIZE_32,
113 (void *)&chip_conf.blks_per_lun, 0},
114 {"luns", 1, VALUE_UINT | SIZE_32, (void *)&chip_conf.luns, 0},
115 {"column_addr_cycle", 1,VALUE_UINT | SIZE_8,
116 (void *)&chip_conf.col_addr_cycles, 0},
117 {"row_addr_cycle", 1, VALUE_UINT | SIZE_8,
118 (void *)&chip_conf.row_addr_cycles, 0},
119 {"program_time", 0, VALUE_UINT | SIZE_32,
120 (void *)&chip_conf.prog_time, 0},
121 {"erase_time", 0, VALUE_UINT | SIZE_32,
122 (void *)&chip_conf.erase_time, 0},
123 {"read_time", 0, VALUE_UINT | SIZE_32,
124 (void *)&chip_conf.read_time, 0},
125 {"width", 1, VALUE_UINT | SIZE_8, (void *)&chip_conf.width, 0},
126 {"wear_out", 1, VALUE_UINT | SIZE_32, (void *)&chip_conf.wear_level,
128 {"bad_block_map", 0, VALUE_UINTARRAY | SIZE_32,
129 (void *)&chip_conf.bad_block_map, MAX_BAD_BLOCKS},
130 {NULL, 0, 0, NULL, 0},
133 static struct nandsim_section sections[] = {
134 {"ctrl", (struct nandsim_key *)&nandsim_ctrl_keys},
135 {"chip", (struct nandsim_key *)&nandsim_chip_keys},
139 static uint8_t logoutputtoint(char *, int *);
140 static uint8_t validate_chips(struct sim_chip *, int, struct sim_ctrl *, int);
141 static uint8_t validate_ctrls(struct sim_ctrl *, int);
142 static int configure_sim(const char *, struct rcfile *);
143 static int create_ctrls(struct rcfile *, struct sim_ctrl **, int *);
144 static int create_chips(struct rcfile *, struct sim_chip **, int *);
145 static void destroy_ctrls(struct sim_ctrl *);
146 static void destroy_chips(struct sim_chip *);
147 static int validate_section_config(struct rcfile *, const char *, int);
150 convert_argint(char *arg, int *value)
153 if (arg == NULL || value == NULL)
157 *value = (int)strtol(arg, NULL, 0);
158 if (*value == 0 && errno != 0) {
159 error("Cannot convert to number argument \'%s\'", arg);
166 convert_arguint(char *arg, unsigned int *value)
169 if (arg == NULL || value == NULL)
173 *value = (unsigned int)strtol(arg, NULL, 0);
174 if (*value == 0 && errno != 0) {
175 error("Cannot convert to number argument \'%s\'", arg);
181 /* Parse given ',' separated list of bytes into buffer. */
183 parse_intarray(char *array, int **buffer)
185 char *tmp, *tmpstr, *origstr;
186 unsigned int currbufp = 0, i;
187 unsigned int count = 0, from = 0, to = 0;
189 /* Remove square braces */
192 if (array[strlen(array)-1] == ']')
193 array[strlen(array)-1] = ',';
195 from = strlen(array);
196 origstr = (char *)malloc(sizeof(char) * from);
197 strcpy(origstr, array);
199 tmpstr = (char *)strtok(array, ",");
200 /* First loop checks for how big int array we need to allocate */
201 while (tmpstr != NULL) {
203 if ((tmp = strchr(tmpstr, '-')) != NULL) {
205 if (convert_arguint(tmpstr, &from) ||
206 convert_arguint(tmp, &to)) {
211 count += to - from + 1;
213 if (convert_arguint(tmpstr, &from)) {
219 tmpstr = (char *)strtok(NULL, ",");
225 /* Allocate buffer of ints */
226 tmpstr = (char *)strtok(origstr, ",");
227 *buffer = malloc(count * sizeof(int));
229 /* Second loop is just inserting converted values into int array */
230 while (tmpstr != NULL) {
232 if ((tmp = strchr(tmpstr, '-')) != NULL) {
234 from = strtol(tmpstr, NULL, 0);
235 to = strtol(tmp, NULL, 0);
236 tmpstr = strtok(NULL, ",");
237 for (i = from; i <= to; i ++)
238 (*buffer)[currbufp++] = i;
242 from = (int)strtol(tmpstr, NULL, 0);
243 (*buffer)[currbufp++] = from;
244 tmpstr = (char *)strtok(NULL, ",");
251 /* Convert logoutput strings literals into appropriate ints. */
253 logoutputtoint(char *logoutput, int *output)
257 if (strcmp(logoutput, "file") == 0)
258 out = NANDSIM_OUTPUT_FILE;
260 else if (strcmp(logoutput, "console") == 0)
261 out = NANDSIM_OUTPUT_CONSOLE;
263 else if (strcmp(logoutput, "ram") == 0)
264 out = NANDSIM_OUTPUT_RAM;
266 else if (strcmp(logoutput, "none") == 0)
267 out = NANDSIM_OUTPUT_NONE;
280 configure_sim(const char *devfname, struct rcfile *f)
282 struct sim_param sim_conf;
286 err = rc_getint(f, "sim", 0, "log_level", &tmpv);
288 if (tmpv < 0 || tmpv > 255 || err) {
289 error("Bad log level specified (%d)\n", tmpv);
292 sim_conf.log_level = tmpv;
294 rc_getstring(f, "sim", 0, "log_output", 255, (char *)&buf);
297 err = logoutputtoint((char *)&buf, &tmpv);
299 error("Log output specified in config file does not seem to "
300 "be valid (%s)!", (char *)&buf);
304 sim_conf.log_output = tmpv;
306 fd = open(devfname, O_RDWR);
308 error("could not open simulator device file (%s)!",
313 err = ioctl(fd, NANDSIM_SIM_PARAM, &sim_conf);
315 error("simulator parameters could not be modified: %s",
326 create_ctrls(struct rcfile *f, struct sim_ctrl **ctrls, int *cnt)
329 struct sim_ctrl *ctrlsptr;
331 count = rc_getsectionscount(f, "ctrl");
332 if (count > MAX_SIM_DEV) {
333 error("Too many CTRL sections specified(%d)", count);
335 } else if (count == 0) {
336 error("No ctrl sections specified");
340 ctrlsptr = (struct sim_ctrl *)malloc(sizeof(struct sim_ctrl) * count);
341 if (ctrlsptr == NULL) {
342 error("Could not allocate memory for ctrl configuration");
346 for (i = 0; i < count; i++) {
347 bzero((void *)&ctrl_conf, sizeof(ctrl_conf));
350 * ECC layout have to end up with 0xffff, so
351 * we're filling buffer with 0xff. If ecc_layout is
352 * defined in config file, values will be overridden.
354 memset((void *)&ctrl_conf.ecc_layout, 0xff,
355 sizeof(ctrl_conf.ecc_layout));
357 if (validate_section_config(f, "ctrl", i) != 0) {
362 if (parse_section(f, "ctrl", i) != 0) {
367 memcpy(&ctrlsptr[i], &ctrl_conf, sizeof(ctrl_conf));
368 /* Try to create ctrl with config parsed */
369 debug("NUM=%d\nNUM_CS=%d\nECC=%d\nFILENAME=%s\nECC_LAYOUT[0]"
370 "=%d\nECC_LAYOUT[1]=%d\n\n",
371 ctrlsptr[i].num, ctrlsptr[i].num_cs, ctrlsptr[i].ecc,
372 ctrlsptr[i].filename, ctrlsptr[i].ecc_layout[0],
373 ctrlsptr[i].ecc_layout[1]);
381 destroy_ctrls(struct sim_ctrl *ctrls)
388 create_chips(struct rcfile *f, struct sim_chip **chips, int *cnt)
390 struct sim_chip *chipsptr;
393 count = rc_getsectionscount(f, "chip");
394 if (count > (MAX_CTRL_CS * MAX_SIM_DEV)) {
395 error("Too many chip sections specified(%d)", count);
397 } else if (count == 0) {
398 error("No chip sections specified");
402 chipsptr = (struct sim_chip *)malloc(sizeof(struct sim_chip) * count);
403 if (chipsptr == NULL) {
404 error("Could not allocate memory for chip configuration");
408 for (i = 0; i < count; i++) {
409 bzero((void *)&chip_conf, sizeof(chip_conf));
412 * Bad block map have to end up with 0xffff, so
413 * we're filling array with 0xff. If bad block map is
414 * defined in config file, values will be overridden.
416 memset((void *)&chip_conf.bad_block_map, 0xff,
417 sizeof(chip_conf.bad_block_map));
419 if (validate_section_config(f, "chip", i) != 0) {
424 if (parse_section(f, "chip", i) != 0) {
429 memcpy(&chipsptr[i], &chip_conf, sizeof(chip_conf));
431 /* Try to create chip with config parsed */
432 debug("CHIP:\nNUM=%d\nCTRL_NUM=%d\nDEVID=%d\nMANID=%d\n"
433 "PAGE_SZ=%d\nOOBSZ=%d\nREAD_T=%d\nDEVMODEL=%s\n"
434 "MAN=%s\nCOLADDRCYCLES=%d\nROWADDRCYCLES=%d\nCHWIDTH=%d\n"
435 "PGS/BLK=%d\nBLK/LUN=%d\nLUNS=%d\nERR_RATIO=%d\n"
436 "WEARLEVEL=%d\nISWP=%d\n\n\n\n",
437 chipsptr[i].num, chipsptr[i].ctrl_num,
438 chipsptr[i].device_id, chipsptr[i].manufact_id,
439 chipsptr[i].page_size, chipsptr[i].oob_size,
440 chipsptr[i].read_time, chipsptr[i].device_model,
441 chipsptr[i].manufacturer, chipsptr[i].col_addr_cycles,
442 chipsptr[i].row_addr_cycles, chipsptr[i].width,
443 chipsptr[i].pgs_per_blk, chipsptr[i].blks_per_lun,
444 chipsptr[i].luns, chipsptr[i].error_ratio,
445 chipsptr[i].wear_level, chipsptr[i].is_wp);
453 destroy_chips(struct sim_chip *chips)
460 parse_config(char *cfgfname, const char *devfname)
463 unsigned int chipsectionscnt, ctrlsectionscnt, i;
465 struct sim_chip *chips;
466 struct sim_ctrl *ctrls;
468 err = rc_open(cfgfname, "r", &f);
470 error("could not open configuration file (%s)", cfgfname);
474 /* First, try to configure simulator itself. */
475 if (configure_sim(devfname, f) != EX_OK) {
480 debug("SIM CONFIGURED!\n");
481 /* Then create controllers' configs */
482 if (create_ctrls(f, &ctrls, &ctrlsectionscnt) != 0) {
486 debug("CTRLS CONFIG READ!\n");
488 /* Then create chips' configs */
489 if (create_chips(f, &chips, &chipsectionscnt) != 0) {
490 destroy_ctrls(ctrls);
494 debug("CHIPS CONFIG READ!\n");
496 if (validate_ctrls(ctrls, ctrlsectionscnt) != 0) {
497 destroy_ctrls(ctrls);
498 destroy_chips(chips);
500 return (EX_SOFTWARE);
502 if (validate_chips(chips, chipsectionscnt, ctrls,
503 ctrlsectionscnt) != 0) {
504 destroy_ctrls(ctrls);
505 destroy_chips(chips);
507 return (EX_SOFTWARE);
511 fd = open(devfname, O_RDWR);
513 error("could not open simulator device file (%s)!",
516 destroy_chips(chips);
517 destroy_ctrls(ctrls);
521 debug("SIM CONFIG STARTED!\n");
523 /* At this stage, both ctrls' and chips' configs should be valid */
524 for (i = 0; i < ctrlsectionscnt; i++) {
525 err = ioctl(fd, NANDSIM_CREATE_CTRL, &ctrls[i]);
528 error("Controller#%d already created\n",
530 else if (err == EINVAL)
531 error("Incorrect controler number (%d)\n",
534 error("Could not created controller#%d\n",
536 /* Errors during controller creation stops parsing */
539 destroy_ctrls(ctrls);
540 destroy_chips(chips);
543 debug("CTRL#%d CONFIG STARTED!\n", i);
546 for (i = 0; i < chipsectionscnt; i++) {
547 err = ioctl(fd, NANDSIM_CREATE_CHIP, &chips[i]);
550 error("Chip#%d for controller#%d already "
551 "created\n", chips[i].num,
553 else if (err == EINVAL)
554 error("Incorrect chip number (%d:%d)\n",
555 chips[i].num, chips[i].ctrl_num);
557 error("Could not create chip (%d:%d)\n",
558 chips[i].num, chips[i].ctrl_num);
559 error("Could not start chip#%d\n", i);
560 destroy_chips(chips);
561 destroy_ctrls(ctrls);
567 debug("CHIPS CONFIG STARTED!\n");
571 destroy_chips(chips);
572 destroy_ctrls(ctrls);
577 * Function tries to get appropriate value for given key, convert it to
578 * array of ints (of given size), and perform all the necessary checks and
582 get_argument_intarray(const char *sect_name, int sectno,
583 struct nandsim_key *key, struct rcfile *f)
585 char strbuf[STRBUFSIZ];
590 getres = rc_getstring(f, sect_name, sectno, key->keyname, STRBUFSIZ,
594 if (key->mandatory != 0) {
595 error(MSG_MANDATORYKEYMISSING, key->keyname,
599 /* Non-mandatory key, not present -- skip */
602 cnt = parse_intarray((char *)&strbuf, &intbuf);
603 cnt = (cnt <= key->maxlength) ? cnt : key->maxlength;
605 for (i = 0; i < cnt; i++) {
606 if (SIZE(key->valuetype) == SIZE_8)
607 *((uint8_t *)(key->field) + i) =
609 else if (SIZE(key->valuetype) == SIZE_16)
610 *((uint16_t *)(key->field) + i) =
613 *((uint32_t *)(key->field) + i) =
621 * Function tries to get appropriate value for given key, convert it to
622 * int of certain length.
625 get_argument_int(const char *sect_name, int sectno, struct nandsim_key *key,
631 getres = rc_getint(f, sect_name, sectno, key->keyname, &val);
634 if (key->mandatory != 0) {
635 error(MSG_MANDATORYKEYMISSING, key->keyname,
640 /* Non-mandatory key, not present -- skip */
643 if (SIZE(key->valuetype) == SIZE_8)
644 *(uint8_t *)(key->field) = (uint8_t)val;
645 else if (SIZE(key->valuetype) == SIZE_16)
646 *(uint16_t *)(key->field) = (uint16_t)val;
648 *(uint32_t *)(key->field) = (uint32_t)val;
652 /* Function tries to get string value for given key */
654 get_argument_string(const char *sect_name, int sectno,
655 struct nandsim_key *key, struct rcfile *f)
657 char strbuf[STRBUFSIZ];
660 getres = rc_getstring(f, sect_name, sectno, key->keyname, STRBUFSIZ,
664 if (key->mandatory != 0) {
665 error(MSG_MANDATORYKEYMISSING, key->keyname,
669 /* Non-mandatory key, not present -- skip */
672 strncpy(key->field, (char *)&strbuf, (size_t)(key->maxlength - 1));
676 /* Function tries to get on/off value for given key */
678 get_argument_bool(const char *sect_name, int sectno, struct nandsim_key *key,
683 getres = rc_getbool(f, sect_name, sectno, key->keyname, &val);
685 if (key->mandatory != 0) {
686 error(MSG_MANDATORYKEYMISSING, key->keyname,
690 /* Non-mandatory key, not present -- skip */
693 *(uint8_t *)key->field = (uint8_t)val;
698 parse_section(struct rcfile *f, const char *sect_name, int sectno)
700 struct nandsim_key *key;
701 struct nandsim_section *sect = (struct nandsim_section *)§ions;
708 if (strcmp(sect->name, sect_name) == 0)
715 debug("->Section: %s, Key: %s, type: %d, size: %d",
716 sect_name, key->keyname, TYPE(key->valuetype),
717 SIZE(key->valuetype)/2);
719 switch (TYPE(key->valuetype)) {
721 /* Single int value */
722 getres = get_argument_int(sect_name, sectno, key, f);
728 case VALUE_UINTARRAY:
730 getres = get_argument_intarray(sect_name,
739 getres = get_argument_string(sect_name, sectno, key,
747 /* Boolean value (true/false/on/off/yes/no) */
748 getres = get_argument_bool(sect_name, sectno, key,
756 } while ((++key)->keyname != NULL);
762 validate_chips(struct sim_chip *chips, int chipcnt,
763 struct sim_ctrl *ctrls, int ctrlcnt)
765 int cchipcnt, i, width, j, id, max;
768 for (chipcnt -= 1; chipcnt >= 0; chipcnt--) {
769 if (chips[chipcnt].num >= MAX_CTRL_CS) {
770 error("chip no. too high (%d)!!\n",
775 if (chips[chipcnt].ctrl_num >= MAX_SIM_DEV) {
776 error("controller no. too high (%d)!!\n",
777 chips[chipcnt].ctrl_num);
781 if (chips[chipcnt].width != 8 &&
782 chips[chipcnt].width != 16) {
783 error("invalid width:%d for chip#%d",
784 chips[chipcnt].width, chips[chipcnt].num);
788 /* Check if page size is > 512 and if its power of 2 */
789 if (chips[chipcnt].page_size < 512 ||
790 (chips[chipcnt].page_size &
791 (chips[chipcnt].page_size - 1)) != 0) {
792 error("invalid page size:%d for chip#%d at ctrl#%d!!"
793 "\n", chips[chipcnt].page_size,
795 chips[chipcnt].ctrl_num);
799 /* Check if controller no. ctrl_num is configured */
800 for (i = 0, id = -1; i < ctrlcnt && id == -1; i++)
801 if (ctrls[i].num == chips[chipcnt].ctrl_num)
804 if (i == ctrlcnt && id == -1) {
805 error("Missing configuration for controller %d"
806 " (at least one chip is connected to it)",
807 chips[chipcnt].ctrl_num);
811 * Controller is configured -> check oob_size
815 max = ctrls[id].ecc_layout[0];
816 while (i < MAX_ECC_BYTES &&
817 ctrls[id].ecc_layout[i] != 0xffff) {
819 if (ctrls[id].ecc_layout[i] > max)
820 max = ctrls[id].ecc_layout[i];
824 if (chips[chipcnt].oob_size < (unsigned)i) {
825 error("OOB size for chip#%d at ctrl#%d is "
826 "smaller than ecc layout length!",
828 chips[chipcnt].ctrl_num);
832 if (chips[chipcnt].oob_size < (unsigned)max) {
833 error("OOB size for chip#%d at ctrl#%d is "
834 "smaller than maximal ecc position in "
835 "defined layout!", chips[chipcnt].num,
836 chips[chipcnt].ctrl_num);
843 if ((chips[chipcnt].erase_time < DELAYTIME_MIN ||
844 chips[chipcnt].erase_time > DELAYTIME_MAX) &&
845 chips[chipcnt].erase_time != 0) {
846 error("Invalid erase time value for chip#%d at "
849 chips[chipcnt].ctrl_num);
853 if ((chips[chipcnt].prog_time < DELAYTIME_MIN ||
854 chips[chipcnt].prog_time > DELAYTIME_MAX) &&
855 chips[chipcnt].prog_time != 0) {
856 error("Invalid prog time value for chip#%d at "
859 chips[chipcnt].ctrl_num);
863 if ((chips[chipcnt].read_time < DELAYTIME_MIN ||
864 chips[chipcnt].read_time > DELAYTIME_MAX) &&
865 chips[chipcnt].read_time != 0) {
866 error("Invalid read time value for chip#%d at "
869 chips[chipcnt].ctrl_num);
873 /* Check if chips attached to the same controller, have same width */
874 for (i = 0; i < ctrlcnt; i++) {
876 for (j = 0; j < cchipcnt; j++) {
877 if (chips[j].ctrl_num == i) {
879 width = chips[j].width;
881 if (width != chips[j].width) {
882 error("Chips attached to "
883 "ctrl#%d have different "
896 validate_ctrls(struct sim_ctrl *ctrl, int ctrlcnt)
898 for (ctrlcnt -= 1; ctrlcnt >= 0; ctrlcnt--) {
899 if (ctrl[ctrlcnt].num > MAX_SIM_DEV) {
900 error("Controller no. too high (%d)!!\n",
904 if (ctrl[ctrlcnt].num_cs > MAX_CTRL_CS) {
905 error("Too many CS (%d)!!\n", ctrl[ctrlcnt].num_cs);
908 if (ctrl[ctrlcnt].ecc != 0 && ctrl[ctrlcnt].ecc != 1) {
909 error("ECC is set to neither 0 nor 1 !\n");
917 static int validate_section_config(struct rcfile *f, const char *sect_name,
920 struct nandsim_key *key;
921 struct nandsim_section *sect;
925 for (match = 0, sect = (struct nandsim_section *)§ions;
926 sect != NULL; sect++) {
927 if (strcmp(sect->name, sect_name) == 0) {
936 keys_tbl = rc_getkeys(f, sect_name, sectno);
937 if (keys_tbl == NULL)
940 for (i = 0; keys_tbl[i] != NULL; i++) {
944 if (strcmp(keys_tbl[i], key->keyname) == 0) {
948 } while ((++key)->keyname != NULL);
951 error("Invalid key in config file: %s\n", keys_tbl[i]);