diff options
author | John Klug <john.klug@multitech.com> | 2017-04-06 11:56:23 -0500 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2017-04-24 11:43:22 -0500 |
commit | cff3a694b8b95686002295831f3cf4d72b748274 (patch) | |
tree | 1824483ef96f7d663bf202bb8ab1db7f98f2e09a /recipes-bsp | |
parent | cef89f77e21f1b865bd288870f62795ef17cc8c8 (diff) | |
download | meta-multitech-atmel-cff3a694b8b95686002295831f3cf4d72b748274.tar.gz meta-multitech-atmel-cff3a694b8b95686002295831f3cf4d72b748274.tar.bz2 meta-multitech-atmel-cff3a694b8b95686002295831f3cf4d72b748274.zip |
patch to prevent inadvertant erasure of environment and allow deliberate erasure
Diffstat (limited to 'recipes-bsp')
-rw-r--r-- | recipes-bsp/multitech/u-boot-linux-utils/crc_erase.patch | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/recipes-bsp/multitech/u-boot-linux-utils/crc_erase.patch b/recipes-bsp/multitech/u-boot-linux-utils/crc_erase.patch new file mode 100644 index 0000000..67cd5ef --- /dev/null +++ b/recipes-bsp/multitech/u-boot-linux-utils/crc_erase.patch @@ -0,0 +1,97 @@ +# Print out the CRC's if debugging. +# Prevent the erasure of the environment. +# Allow the deliberate erasure of the environment with the +# clearenv command. +diff --git a/src/u_boot.c b/src/u_boot.c +index e240475..f10eaa3 100644 +--- a/src/u_boot.c ++++ b/src/u_boot.c +@@ -64,6 +64,8 @@ static int write_uboot_env(const char *device, struct environment *env) + error("mtd_erase_all %s failed", device); + return -1; + } ++ if(env == NULL) ++ return 0; + + fd = open(device, O_WRONLY); + if (fd < 0) { +@@ -213,7 +215,7 @@ static int cmd_setenv(struct environment *env, int argc, char **argv) + } + + env->crc = crc32(0, (uint8_t *) env->data, sizeof(env->data)); +- dbg("crc: 0x%08X", env->crc); ++ dbg("Calculated crc: 0x%08X", env->crc); + env->flags = 0; + + tmp = write_uboot_env(MTD_ENV1, env); +@@ -252,6 +254,7 @@ int main(int argc, char *argv[]) { + struct environment *env2; + uint32_t crc1_ok; + uint32_t crc2_ok; ++ uint32_t mycrc; + + if (argc <= 1) { + usage(stderr); +@@ -301,12 +304,18 @@ int main(int argc, char *argv[]) { + error("read_uboot_env failed"); + return 1; + } +- dbg("env1 crc: 0x%08X", env1->crc); ++ dbg("env1 stored crc: 0x%08X", env1->crc); + dbg("env1 flags: %d", env1->flags); +- if (crc32(0, (uint8_t *) env1->data, sizeof(env1->data)) == env1->crc) { ++ mycrc = crc32(0, (uint8_t *) env1->data, sizeof(env1->data)); ++ if (mycrc == env1->crc) { + crc1_ok = 1; + } else { +- error("crc does not match on primary env"); ++ dbg("env1 stored crc 0x%x, calculated crc 0x%x",env1->crc,mycrc); ++ if(env1->flags != 255) ++ error("crc does not match on env1"); ++ else ++ dbg("uninitialized env1"); ++ + crc1_ok = 0; + } + +@@ -315,20 +324,26 @@ int main(int argc, char *argv[]) { + error("read_uboot_env failed"); + return 1; + } +- dbg("env2 crc: 0x%08X", env2->crc); ++ dbg("env2 stored crc: 0x%08X", env2->crc); + dbg("env2 flags: %d", env2->flags); +- if (crc32(0, (uint8_t *) env2->data, sizeof(env2->data)) == env2->crc) { ++ mycrc = crc32(0, (uint8_t *) env2->data, sizeof(env2->data)); ++ if (mycrc == env2->crc) { + crc2_ok = 1; + } else { +- error("crc does not match on redundant env"); ++ dbg("env2 stored crc 0x%x, calculated crc 0x%x",env2->crc,mycrc); ++ if(env2->flags != 255) ++ error("crc does not match on env2"); ++ else ++ dbg("uninitialized env2"); + crc2_ok = 0; + } + + if (!crc1_ok && !crc2_ok) { +- error("both environments are bad: loading DEFAULT_ENV"); ++ error("both environments are bad: not loading DEFAULT_ENV"); + env = env1; + env->flags = 0; + memcpy(env->data, DEFAULT_ENV, sizeof(DEFAULT_ENV)); ++ exit(1); + } else if (crc1_ok && !crc2_ok) { + env = env1; + } else if (!crc1_ok && crc2_ok) { +@@ -353,6 +368,9 @@ int main(int argc, char *argv[]) { + err = cmd_printenv(env, argc, argv); + } else if (!tokcmp(cmd, "setenv")) { + err = cmd_setenv(env, argc, argv); ++ } else if (!tokcmp(cmd, "clearenv")) { ++ (void)write_uboot_env(MTD_ENV1, NULL); ++ (void)write_uboot_env(MTD_ENV2, NULL); + } else { + usage(stderr); + exit(1); |