2 * (C) Copyright 2000-2008
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Guennadi Liakhovetski, DENX Software Engineering, lg@denx.de.
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
33 #include <sys/types.h>
34 #include <sys/ioctl.h>
40 # include <linux/mtd/mtd.h>
42 # define __user /* nothing */
43 # include <mtd/mtd-user.h>
48 #define CMD_GETENV "fw_printenv"
49 #define CMD_SETENV "fw_setenv"
51 #define min(x, y) ({ \
52 typeof(x) _min1 = (x); \
53 typeof(y) _min2 = (y); \
54 (void) (&_min1 == &_min2); \
55 _min1 < _min2 ? _min1 : _min2; })
58 char devname[16]; /* Device name */
59 ulong devoff; /* Device offset */
60 ulong env_size; /* environment size */
61 ulong erase_size; /* device erase size */
62 ulong env_sectors; /* number of environment sectors */
63 uint8_t mtd_type; /* type of the MTD device */
66 static struct envdev_s envdevices[2] =
69 .mtd_type = MTD_ABSENT,
71 .mtd_type = MTD_ABSENT,
74 static int dev_current;
76 #define DEVNAME(i) envdevices[(i)].devname
77 #define DEVOFFSET(i) envdevices[(i)].devoff
78 #define ENVSIZE(i) envdevices[(i)].env_size
79 #define DEVESIZE(i) envdevices[(i)].erase_size
80 #define ENVSECTORS(i) envdevices[(i)].env_sectors
81 #define DEVTYPE(i) envdevices[(i)].mtd_type
83 #define CFG_ENV_SIZE ENVSIZE(dev_current)
85 #define ENV_SIZE getenvsize()
87 struct env_image_single {
88 uint32_t crc; /* CRC32 over data bytes */
92 struct env_image_redundant {
93 uint32_t crc; /* CRC32 over data bytes */
94 unsigned char flags; /* active or obsolete */
107 unsigned char *flags;
109 enum flag_scheme flag_scheme;
112 static struct environment environment = {
113 .flag_scheme = FLAG_NONE,
116 static int HaveRedundEnv = 0;
118 static unsigned char active_flag = 1;
119 /* obsolete_flag must be 0 to efficiently set it on NOR flash without erasing */
120 static unsigned char obsolete_flag = 0;
123 #define XMK_STR(x) #x
124 #define MK_STR(x) XMK_STR(x)
126 static char default_environment[] = {
127 #if defined(CONFIG_BOOTARGS)
128 "bootargs=" CONFIG_BOOTARGS "\0"
130 #if defined(CONFIG_BOOTCOMMAND)
131 "bootcmd=" CONFIG_BOOTCOMMAND "\0"
133 #if defined(CONFIG_RAMBOOTCOMMAND)
134 "ramboot=" CONFIG_RAMBOOTCOMMAND "\0"
136 #if defined(CONFIG_NFSBOOTCOMMAND)
137 "nfsboot=" CONFIG_NFSBOOTCOMMAND "\0"
139 #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
140 "bootdelay=" MK_STR (CONFIG_BOOTDELAY) "\0"
142 #if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0)
143 "baudrate=" MK_STR (CONFIG_BAUDRATE) "\0"
145 #ifdef CONFIG_LOADS_ECHO
146 "loads_echo=" MK_STR (CONFIG_LOADS_ECHO) "\0"
148 #ifdef CONFIG_ETHADDR
149 "ethaddr=" MK_STR (CONFIG_ETHADDR) "\0"
151 #ifdef CONFIG_ETH1ADDR
152 "eth1addr=" MK_STR (CONFIG_ETH1ADDR) "\0"
154 #ifdef CONFIG_ETH2ADDR
155 "eth2addr=" MK_STR (CONFIG_ETH2ADDR) "\0"
157 #ifdef CONFIG_ETH3ADDR
158 "eth3addr=" MK_STR (CONFIG_ETH3ADDR) "\0"
160 #ifdef CONFIG_ETHPRIME
161 "ethprime=" CONFIG_ETHPRIME "\0"
164 "ipaddr=" MK_STR (CONFIG_IPADDR) "\0"
166 #ifdef CONFIG_SERVERIP
167 "serverip=" MK_STR (CONFIG_SERVERIP) "\0"
170 "autoload=" CFG_AUTOLOAD "\0"
172 #ifdef CONFIG_ROOTPATH
173 "rootpath=" MK_STR (CONFIG_ROOTPATH) "\0"
175 #ifdef CONFIG_GATEWAYIP
176 "gatewayip=" MK_STR (CONFIG_GATEWAYIP) "\0"
178 #ifdef CONFIG_NETMASK
179 "netmask=" MK_STR (CONFIG_NETMASK) "\0"
181 #ifdef CONFIG_HOSTNAME
182 "hostname=" MK_STR (CONFIG_HOSTNAME) "\0"
184 #ifdef CONFIG_BOOTFILE
185 "bootfile=" MK_STR (CONFIG_BOOTFILE) "\0"
187 #ifdef CONFIG_LOADADDR
188 "loadaddr=" MK_STR (CONFIG_LOADADDR) "\0"
190 #ifdef CONFIG_PREBOOT
191 "preboot=" CONFIG_PREBOOT "\0"
193 #ifdef CONFIG_CLOCKS_IN_MHZ
194 "clocks_in_mhz=" "1" "\0"
196 #if defined(CONFIG_PCI_BOOTDELAY) && (CONFIG_PCI_BOOTDELAY > 0)
197 "pcidelay=" MK_STR (CONFIG_PCI_BOOTDELAY) "\0"
199 #ifdef CONFIG_EXTRA_ENV_SETTINGS
200 CONFIG_EXTRA_ENV_SETTINGS
202 "\0" /* Termimate struct environment data with 2 NULs */
205 static int flash_io (int mode);
206 static char *envmatch (char * s1, char * s2);
207 static int env_init (void);
208 static int parse_config (void);
210 #if defined(CONFIG_FILE)
211 static int get_config (char *);
213 static inline ulong getenvsize (void)
215 ulong rc = CFG_ENV_SIZE - sizeof (long);
223 * Search the environment for a variable.
224 * Return the value, if found, or NULL, if not found.
226 char *fw_getenv (char *name)
233 for (env = environment.data; *env; env = nxt + 1) {
236 for (nxt = env; *nxt; ++nxt) {
237 if (nxt >= &environment.data[ENV_SIZE]) {
238 fprintf (stderr, "## Error: "
239 "environment not terminated\n");
243 val = envmatch (name, env);
252 * Print the current definition of one, or more, or all
253 * environment variables
255 int fw_printenv (int argc, char *argv[])
264 if (argc == 1) { /* Print all env variables */
265 for (env = environment.data; *env; env = nxt + 1) {
266 for (nxt = env; *nxt; ++nxt) {
267 if (nxt >= &environment.data[ENV_SIZE]) {
268 fprintf (stderr, "## Error: "
269 "environment not terminated\n");
274 printf ("%s\n", env);
279 if (strcmp (argv[1], "-n") == 0) {
284 fprintf (stderr, "## Error: "
285 "`-n' option requires exactly one argument\n");
292 for (i = 1; i < argc; ++i) { /* print single env variables */
293 char *name = argv[i];
296 for (env = environment.data; *env; env = nxt + 1) {
298 for (nxt = env; *nxt; ++nxt) {
299 if (nxt >= &environment.data[ENV_SIZE]) {
300 fprintf (stderr, "## Error: "
301 "environment not terminated\n");
305 val = envmatch (name, env);
308 fputs (name, stdout);
316 fprintf (stderr, "## Error: \"%s\" not defined\n", name);
325 * Deletes or sets environment variables. Returns -1 and sets errno error codes:
327 * EINVAL - need at least 1 argument
328 * EROFS - certain variables ("ethaddr", "serial#") cannot be
329 * modified or deleted
332 int fw_setenv (int argc, char *argv[])
350 * search if variable with this name already exists
352 for (nxt = env = environment.data; *env; env = nxt + 1) {
353 for (nxt = env; *nxt; ++nxt) {
354 if (nxt >= &environment.data[ENV_SIZE]) {
355 fprintf (stderr, "## Error: "
356 "environment not terminated\n");
361 if ((oldval = envmatch (name, env)) != NULL)
366 * Delete any existing definition
370 * Ethernet Address and serial# can be set only once
372 if ((strcmp (name, "ethaddr") == 0) ||
373 (strcmp (name, "serial#") == 0)) {
374 fprintf (stderr, "Can't overwrite \"%s\"\n", name);
379 if (*++nxt == '\0') {
384 if ((*env == '\0') && (*nxt == '\0'))
397 * Append new definition at the end
399 for (env = environment.data; *env || *(env + 1); ++env);
400 if (env > environment.data)
404 * "name" + "=" + "val" +"\0\0" > CFG_ENV_SIZE - (env-environment)
406 len = strlen (name) + 2;
407 /* add '=' for first arg, ' ' for all others */
408 for (i = 2; i < argc; ++i) {
409 len += strlen (argv[i]) + 1;
411 if (len > (&environment.data[ENV_SIZE] - env)) {
413 "Error: environment overflow, \"%s\" deleted\n",
417 while ((*env = *name++) != '\0')
419 for (i = 2; i < argc; ++i) {
422 *env = (i == 2) ? '=' : ' ';
423 while ((*++env = *val++) != '\0');
426 /* end is marked with double '\0' */
434 *environment.crc = crc32 (0, (uint8_t *) environment.data, ENV_SIZE);
436 /* write environment back to flash */
437 if (flash_io (O_RDWR)) {
438 fprintf (stderr, "Error: can't write fw_env to flash\n");
446 * Test for bad block on NAND, just returns 0 on NOR, on NAND:
449 * < 0 - failed to test
451 static int flash_bad_block (int fd, uint8_t mtd_type, loff_t *blockstart)
453 if (mtd_type == MTD_NANDFLASH) {
454 int badblock = ioctl (fd, MEMGETBADBLOCK, blockstart);
457 perror ("Cannot read bad block mark");
463 fprintf (stderr, "Bad block at 0x%llx, "
464 "skipping\n", *blockstart);
474 * Read data from flash at an offset into a provided buffer. On NAND it skips
475 * bad blocks but makes sure it stays within ENVSECTORS (dev) starting from
476 * the DEVOFFSET (dev) block. On NOR the loop is only run once.
478 static int flash_read_buf (int dev, int fd, void *buf, size_t count,
479 off_t offset, uint8_t mtd_type)
481 size_t blocklen; /* erase / write length - one block on NAND,
483 size_t processed = 0; /* progress counter */
484 size_t readlen = count; /* current read length */
485 off_t top_of_range; /* end of the last block we may use */
486 off_t block_seek; /* offset inside the current block to the start
488 loff_t blockstart; /* running start of the current block -
489 MEMGETBADBLOCK needs 64 bits */
493 * Start of the first block to be read, relies on the fact, that
494 * erase sector size is always a power of 2
496 blockstart = offset & ~(DEVESIZE (dev) - 1);
498 /* Offset inside a block */
499 block_seek = offset - blockstart;
501 if (mtd_type == MTD_NANDFLASH) {
503 * NAND: calculate which blocks we are reading. We have
504 * to read one block at a time to skip bad blocks.
506 blocklen = DEVESIZE (dev);
509 * To calculate the top of the range, we have to use the
510 * global DEVOFFSET (dev), which can be different from offset
512 top_of_range = (DEVOFFSET (dev) & ~(blocklen - 1)) +
513 ENVSECTORS (dev) * blocklen;
515 /* Limit to one block for the first read */
516 if (readlen > blocklen - block_seek)
517 readlen = blocklen - block_seek;
520 top_of_range = offset + count;
523 /* This only runs once on NOR flash */
524 while (processed < count) {
525 rc = flash_bad_block (fd, mtd_type, &blockstart);
526 if (rc < 0) /* block test failed */
529 if (blockstart + block_seek + readlen > top_of_range) {
530 /* End of range is reached */
532 "Too few good blocks within range\n");
536 if (rc) { /* block is bad */
537 blockstart += blocklen;
542 * If a block is bad, we retry in the next block at the same
543 * offset - see common/env_nand.c::writeenv()
545 lseek (fd, blockstart + block_seek, SEEK_SET);
547 rc = read (fd, buf + processed, readlen);
549 fprintf (stderr, "Read error on %s: %s\n",
550 DEVNAME (dev), strerror (errno));
554 fprintf (stderr, "Read 0x%x bytes at 0x%llx\n",
555 rc, blockstart + block_seek);
557 processed += readlen;
558 readlen = min (blocklen, count - processed);
560 blockstart += blocklen;
567 * Write count bytes at offset, but stay within ENVSETCORS (dev) sectors of
568 * DEVOFFSET (dev). Similar to the read case above, on NOR we erase and write
569 * the whole data at once.
571 static int flash_write_buf (int dev, int fd, void *buf, size_t count,
572 off_t offset, uint8_t mtd_type)
575 struct erase_info_user erase;
576 size_t blocklen; /* length of NAND block / NOR erase sector */
577 size_t erase_len; /* whole area that can be erased - may include
579 size_t erasesize; /* erase / write length - one block on NAND,
581 size_t processed = 0; /* progress counter */
582 size_t write_total; /* total size to actually write - excludinig
584 off_t erase_offset; /* offset to the first erase block (aligned)
586 off_t block_seek; /* offset inside the erase block to the start
588 off_t top_of_range; /* end of the last block we may use */
589 loff_t blockstart; /* running start of the current block -
590 MEMGETBADBLOCK needs 64 bits */
593 blocklen = DEVESIZE (dev);
595 /* Erase sector size is always a power of 2 */
596 top_of_range = (DEVOFFSET (dev) & ~(blocklen - 1)) +
597 ENVSECTORS (dev) * blocklen;
599 erase_offset = offset & ~(blocklen - 1);
601 /* Maximum area we may use */
602 erase_len = top_of_range - erase_offset;
604 blockstart = erase_offset;
605 /* Offset inside a block */
606 block_seek = offset - erase_offset;
609 * Data size we actually have to write: from the start of the block
610 * to the start of the data, then count bytes of data, and to the
613 write_total = (block_seek + count + blocklen - 1) & ~(blocklen - 1);
616 * Support data anywhere within erase sectors: read out the complete
617 * area to be erased, replace the environment image, write the whole
620 if (write_total > count) {
621 data = malloc (erase_len);
624 "Cannot malloc %u bytes: %s\n",
625 erase_len, strerror (errno));
629 rc = flash_read_buf (dev, fd, data, write_total, erase_offset,
631 if (write_total != rc)
634 /* Overwrite the old environment */
635 memcpy (data + block_seek, buf, count);
638 * We get here, iff offset is block-aligned and count is a
639 * multiple of blocklen - see write_total calculation above
644 if (mtd_type == MTD_NANDFLASH) {
646 * NAND: calculate which blocks we are writing. We have
647 * to write one block at a time to skip bad blocks.
649 erasesize = blocklen;
651 erasesize = erase_len;
654 erase.length = erasesize;
656 /* This only runs once on NOR flash */
657 while (processed < write_total) {
658 rc = flash_bad_block (fd, mtd_type, &blockstart);
659 if (rc < 0) /* block test failed */
662 if (blockstart + erasesize > top_of_range) {
663 fprintf (stderr, "End of range reached, aborting\n");
667 if (rc) { /* block is bad */
668 blockstart += blocklen;
672 erase.start = blockstart;
673 ioctl (fd, MEMUNLOCK, &erase);
675 if (ioctl (fd, MEMERASE, &erase) != 0) {
676 fprintf (stderr, "MTD erase error on %s: %s\n",
682 if (lseek (fd, blockstart, SEEK_SET) == -1) {
684 "Seek error on %s: %s\n",
685 DEVNAME (dev), strerror (errno));
690 printf ("Write 0x%x bytes at 0x%llx\n", erasesize, blockstart);
692 if (write (fd, data + processed, erasesize) != erasesize) {
693 fprintf (stderr, "Write error on %s: %s\n",
694 DEVNAME (dev), strerror (errno));
698 ioctl (fd, MEMLOCK, &erase);
700 processed += blocklen;
702 blockstart += blocklen;
705 if (write_total > count)
712 * Set obsolete flag at offset - NOR flash only
714 static int flash_flag_obsolete (int dev, int fd, off_t offset)
718 /* This relies on the fact, that obsolete_flag == 0 */
719 rc = lseek (fd, offset, SEEK_SET);
721 fprintf (stderr, "Cannot seek to set the flag on %s \n",
725 rc = write (fd, &obsolete_flag, sizeof (obsolete_flag));
727 perror ("Could not set obsolete flag");
732 static int flash_write (int fd_current, int fd_target, int dev_target)
736 switch (environment.flag_scheme) {
739 case FLAG_INCREMENTAL:
740 (*environment.flags)++;
743 *environment.flags = active_flag;
746 fprintf (stderr, "Unimplemented flash scheme %u \n",
747 environment.flag_scheme);
752 printf ("Writing new environment at 0x%lx on %s\n",
753 DEVOFFSET (dev_target), DEVNAME (dev_target));
755 rc = flash_write_buf (dev_target, fd_target, environment.image,
756 CFG_ENV_SIZE, DEVOFFSET (dev_target),
757 DEVTYPE(dev_target));
761 if (environment.flag_scheme == FLAG_BOOLEAN) {
762 /* Have to set obsolete flag */
763 off_t offset = DEVOFFSET (dev_current) +
764 offsetof (struct env_image_redundant, flags);
766 printf ("Setting obsolete flag in environment at 0x%lx on %s\n",
767 DEVOFFSET (dev_current), DEVNAME (dev_current));
769 flash_flag_obsolete (dev_current, fd_current, offset);
775 static int flash_read (int fd)
777 struct mtd_info_user mtdinfo;
780 rc = ioctl (fd, MEMGETINFO, &mtdinfo);
782 perror ("Cannot get MTD information");
786 if (mtdinfo.type != MTD_NORFLASH && mtdinfo.type != MTD_NANDFLASH) {
787 fprintf (stderr, "Unsupported flash type %u\n", mtdinfo.type);
791 DEVTYPE(dev_current) = mtdinfo.type;
793 rc = flash_read_buf (dev_current, fd, environment.image, CFG_ENV_SIZE,
794 DEVOFFSET (dev_current), mtdinfo.type);
796 return (rc != CFG_ENV_SIZE) ? -1 : 0;
799 static int flash_io (int mode)
801 int fd_current, fd_target, rc, dev_target;
803 /* dev_current: fd_current, erase_current */
804 fd_current = open (DEVNAME (dev_current), mode);
805 if (fd_current < 0) {
807 "Can't open %s: %s\n",
808 DEVNAME (dev_current), strerror (errno));
812 if (mode == O_RDWR) {
814 /* switch to next partition for writing */
815 dev_target = !dev_current;
816 /* dev_target: fd_target, erase_target */
817 fd_target = open (DEVNAME (dev_target), mode);
820 "Can't open %s: %s\n",
821 DEVNAME (dev_target),
827 dev_target = dev_current;
828 fd_target = fd_current;
831 rc = flash_write (fd_current, fd_target, dev_target);
834 if (close (fd_target)) {
836 "I/O error on %s: %s\n",
837 DEVNAME (dev_target),
843 rc = flash_read (fd_current);
847 if (close (fd_current)) {
849 "I/O error on %s: %s\n",
850 DEVNAME (dev_current), strerror (errno));
858 * s1 is either a simple 'name', or a 'name=value' pair.
859 * s2 is a 'name=value' pair.
860 * If the names match, return the value of s2, else NULL.
863 static char *envmatch (char * s1, char * s2)
869 if (*s1 == '\0' && *(s2 - 1) == '=')
875 * Prevent confusion if running from erased flash memory
877 static int env_init (void)
887 struct env_image_single *single;
888 struct env_image_redundant *redundant;
890 if (parse_config ()) /* should fill envdevices */
893 addr0 = calloc (1, CFG_ENV_SIZE);
896 "Not enough memory for environment (%ld bytes)\n",
901 /* read environment from FLASH to local buffer */
902 environment.image = addr0;
906 environment.crc = &redundant->crc;
907 environment.flags = &redundant->flags;
908 environment.data = redundant->data;
911 environment.crc = &single->crc;
912 environment.flags = NULL;
913 environment.data = single->data;
917 if (flash_io (O_RDONLY))
920 crc0 = crc32 (0, (uint8_t *) environment.data, ENV_SIZE);
921 crc0_ok = (crc0 == *environment.crc);
922 if (!HaveRedundEnv) {
925 "Warning: Bad CRC, using default environment\n");
926 memcpy(environment.data, default_environment, sizeof default_environment);
929 flag0 = *environment.flags;
932 addr1 = calloc (1, CFG_ENV_SIZE);
935 "Not enough memory for environment (%ld bytes)\n",
942 * have to set environment.image for flash_read(), careful -
943 * other pointers in environment still point inside addr0
945 environment.image = addr1;
946 if (flash_io (O_RDONLY))
949 /* Check flag scheme compatibility */
950 if (DEVTYPE(dev_current) == MTD_NORFLASH &&
951 DEVTYPE(!dev_current) == MTD_NORFLASH) {
952 environment.flag_scheme = FLAG_BOOLEAN;
953 } else if (DEVTYPE(dev_current) == MTD_NANDFLASH &&
954 DEVTYPE(!dev_current) == MTD_NANDFLASH) {
955 environment.flag_scheme = FLAG_INCREMENTAL;
957 fprintf (stderr, "Incompatible flash types!\n");
961 crc1 = crc32 (0, (uint8_t *) redundant->data, ENV_SIZE);
962 crc1_ok = (crc1 == redundant->crc);
963 flag1 = redundant->flags;
965 if (crc0_ok && !crc1_ok) {
967 } else if (!crc0_ok && crc1_ok) {
969 } else if (!crc0_ok && !crc1_ok) {
971 "Warning: Bad CRC, using default environment\n");
972 memcpy (environment.data, default_environment,
973 sizeof default_environment);
976 switch (environment.flag_scheme) {
978 if (flag0 == active_flag &&
979 flag1 == obsolete_flag) {
981 } else if (flag0 == obsolete_flag &&
982 flag1 == active_flag) {
984 } else if (flag0 == flag1) {
986 } else if (flag0 == 0xFF) {
988 } else if (flag1 == 0xFF) {
994 case FLAG_INCREMENTAL:
995 if ((flag0 == 255 && flag1 == 0) ||
998 else if ((flag1 == 255 && flag0 == 0) ||
1001 else /* flags are equal - almost impossible */
1005 fprintf (stderr, "Unknown flag scheme %u \n",
1006 environment.flag_scheme);
1012 * If we are reading, we don't need the flag and the CRC any
1013 * more, if we are writing, we will re-calculate CRC and update
1014 * flags before writing out
1017 environment.image = addr1;
1018 environment.crc = &redundant->crc;
1019 environment.flags = &redundant->flags;
1020 environment.data = redundant->data;
1023 environment.image = addr0;
1024 /* Other pointers are already set */
1032 static int parse_config ()
1036 #if defined(CONFIG_FILE)
1037 /* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */
1038 if (get_config (CONFIG_FILE)) {
1040 "Cannot parse config file: %s\n", strerror (errno));
1044 strcpy (DEVNAME (0), DEVICE1_NAME);
1045 DEVOFFSET (0) = DEVICE1_OFFSET;
1046 ENVSIZE (0) = ENV1_SIZE;
1047 DEVESIZE (0) = DEVICE1_ESIZE;
1048 ENVSECTORS (0) = DEVICE1_ENVSECTORS;
1050 strcpy (DEVNAME (1), DEVICE2_NAME);
1051 DEVOFFSET (1) = DEVICE2_OFFSET;
1052 ENVSIZE (1) = ENV2_SIZE;
1053 DEVESIZE (1) = DEVICE2_ESIZE;
1054 ENVSECTORS (1) = DEVICE2_ENVSECTORS;
1058 if (stat (DEVNAME (0), &st)) {
1060 "Cannot access MTD device %s: %s\n",
1061 DEVNAME (0), strerror (errno));
1065 if (HaveRedundEnv && stat (DEVNAME (1), &st)) {
1067 "Cannot access MTD device %s: %s\n",
1068 DEVNAME (1), strerror (errno));
1074 #if defined(CONFIG_FILE)
1075 static int get_config (char *fname)
1082 fp = fopen (fname, "r");
1086 while (i < 2 && fgets (dump, sizeof (dump), fp)) {
1087 /* Skip incomplete conversions and comment strings */
1091 rc = sscanf (dump, "%s %lx %lx %lx %lx",
1102 /* Default - 1 sector */
1109 HaveRedundEnv = i - 1;
1110 if (!i) { /* No valid entries found */