|
@@ -116,7 +116,7 @@ static struct environment environment = {
|
|
.flag_scheme = FLAG_NONE,
|
|
.flag_scheme = FLAG_NONE,
|
|
};
|
|
};
|
|
|
|
|
|
-static int HaveRedundEnv = 0;
|
|
|
|
|
|
+static int have_redund_env;
|
|
|
|
|
|
static unsigned char active_flag = 1;
|
|
static unsigned char active_flag = 1;
|
|
/* obsolete_flag must be 0 to efficiently set it on NOR flash without erasing */
|
|
/* obsolete_flag must be 0 to efficiently set it on NOR flash without erasing */
|
|
@@ -1239,7 +1239,7 @@ static int flash_io(int mode)
|
|
}
|
|
}
|
|
|
|
|
|
if (mode == O_RDWR) {
|
|
if (mode == O_RDWR) {
|
|
- if (HaveRedundEnv) {
|
|
|
|
|
|
+ if (have_redund_env) {
|
|
/* switch to next partition for writing */
|
|
/* switch to next partition for writing */
|
|
dev_target = !dev_current;
|
|
dev_target = !dev_current;
|
|
/* dev_target: fd_target, erase_target */
|
|
/* dev_target: fd_target, erase_target */
|
|
@@ -1264,7 +1264,7 @@ static int flash_io(int mode)
|
|
DEVNAME(dev_current), strerror(errno));
|
|
DEVNAME(dev_current), strerror(errno));
|
|
}
|
|
}
|
|
|
|
|
|
- if (HaveRedundEnv) {
|
|
|
|
|
|
+ if (have_redund_env) {
|
|
if (fsync(fd_target) &&
|
|
if (fsync(fd_target) &&
|
|
!(errno == EINVAL || errno == EROFS)) {
|
|
!(errno == EINVAL || errno == EROFS)) {
|
|
fprintf(stderr,
|
|
fprintf(stderr,
|
|
@@ -1330,7 +1330,7 @@ int fw_env_open(struct env_opts *opts)
|
|
/* read environment from FLASH to local buffer */
|
|
/* read environment from FLASH to local buffer */
|
|
environment.image = addr0;
|
|
environment.image = addr0;
|
|
|
|
|
|
- if (HaveRedundEnv) {
|
|
|
|
|
|
+ if (have_redund_env) {
|
|
redundant = addr0;
|
|
redundant = addr0;
|
|
environment.crc = &redundant->crc;
|
|
environment.crc = &redundant->crc;
|
|
environment.flags = &redundant->flags;
|
|
environment.flags = &redundant->flags;
|
|
@@ -1351,7 +1351,7 @@ int fw_env_open(struct env_opts *opts)
|
|
crc0 = crc32(0, (uint8_t *)environment.data, ENV_SIZE);
|
|
crc0 = crc32(0, (uint8_t *)environment.data, ENV_SIZE);
|
|
|
|
|
|
crc0_ok = (crc0 == *environment.crc);
|
|
crc0_ok = (crc0 == *environment.crc);
|
|
- if (!HaveRedundEnv) {
|
|
|
|
|
|
+ if (!have_redund_env) {
|
|
if (!crc0_ok) {
|
|
if (!crc0_ok) {
|
|
fprintf(stderr,
|
|
fprintf(stderr,
|
|
"Warning: Bad CRC, using default environment\n");
|
|
"Warning: Bad CRC, using default environment\n");
|
|
@@ -1644,14 +1644,14 @@ static int parse_config(struct env_opts *opts)
|
|
#ifdef DEVICE2_ENVSECTORS
|
|
#ifdef DEVICE2_ENVSECTORS
|
|
ENVSECTORS(1) = DEVICE2_ENVSECTORS;
|
|
ENVSECTORS(1) = DEVICE2_ENVSECTORS;
|
|
#endif
|
|
#endif
|
|
- HaveRedundEnv = 1;
|
|
|
|
|
|
+ have_redund_env = 1;
|
|
#endif
|
|
#endif
|
|
#endif
|
|
#endif
|
|
rc = check_device_config(0);
|
|
rc = check_device_config(0);
|
|
if (rc < 0)
|
|
if (rc < 0)
|
|
return rc;
|
|
return rc;
|
|
|
|
|
|
- if (HaveRedundEnv) {
|
|
|
|
|
|
+ if (have_redund_env) {
|
|
rc = check_device_config(1);
|
|
rc = check_device_config(1);
|
|
if (rc < 0)
|
|
if (rc < 0)
|
|
return rc;
|
|
return rc;
|
|
@@ -1664,7 +1664,7 @@ static int parse_config(struct env_opts *opts)
|
|
}
|
|
}
|
|
|
|
|
|
usable_envsize = CUR_ENVSIZE - sizeof(uint32_t);
|
|
usable_envsize = CUR_ENVSIZE - sizeof(uint32_t);
|
|
- if (HaveRedundEnv)
|
|
|
|
|
|
+ if (have_redund_env)
|
|
usable_envsize -= sizeof(char);
|
|
usable_envsize -= sizeof(char);
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
@@ -1706,7 +1706,7 @@ static int get_config(char *fname)
|
|
}
|
|
}
|
|
fclose(fp);
|
|
fclose(fp);
|
|
|
|
|
|
- HaveRedundEnv = i - 1;
|
|
|
|
|
|
+ have_redund_env = i - 1;
|
|
if (!i) { /* No valid entries found */
|
|
if (!i) { /* No valid entries found */
|
|
errno = EINVAL;
|
|
errno = EINVAL;
|
|
return -1;
|
|
return -1;
|