diff options
author | John Klug <john.klug@multitech.com> | 2017-04-10 12:26:19 -0500 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2017-04-10 12:26:19 -0500 |
commit | 851eb02635f7dfbf20864cb8e9b01d59ad07ec45 (patch) | |
tree | cca2fa67d1fda64cc26bf30bde5ec82721a10ea1 /recipes-bsp | |
parent | 35b6b59cc3aabc1cd062aed3f7298e12d914ce98 (diff) | |
download | meta-multitech-851eb02635f7dfbf20864cb8e9b01d59ad07ec45.tar.gz meta-multitech-851eb02635f7dfbf20864cb8e9b01d59ad07ec45.tar.bz2 meta-multitech-851eb02635f7dfbf20864cb8e9b01d59ad07ec45.zip |
Fix MAC address in default environment
Diffstat (limited to 'recipes-bsp')
-rw-r--r-- | recipes-bsp/multitech/u-boot-linux-utils/crc_erase.patch | 99 | ||||
-rw-r--r-- | recipes-bsp/multitech/u-boot-linux-utils/uboot_mac.patch | 169 | ||||
-rw-r--r-- | recipes-bsp/multitech/u-boot-linux-utils_0.0.1.bb | 7 |
3 files changed, 174 insertions, 101 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 deleted file mode 100644 index 5d78703..0000000 --- a/recipes-bsp/multitech/u-boot-linux-utils/crc_erase.patch +++ /dev/null @@ -1,99 +0,0 @@ -# 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..94f18ed 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,27 @@ 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"); -+ if (!crc1_ok && !crc2_ok && env1->crc == 0xffffffff && -+ (env1->flags == 0xff) && (env2->flags == 0xff) && (env2->crc == 0xffffffff)) { -+ 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 +369,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); diff --git a/recipes-bsp/multitech/u-boot-linux-utils/uboot_mac.patch b/recipes-bsp/multitech/u-boot-linux-utils/uboot_mac.patch new file mode 100644 index 0000000..5b92f35 --- /dev/null +++ b/recipes-bsp/multitech/u-boot-linux-utils/uboot_mac.patch @@ -0,0 +1,169 @@ +commit de3ea4470a6da4c01bfff9377649324747c1e3c9 +Author: John Klug <john.klug@multitech.com> +Date: Mon Apr 10 12:16:08 2017 -0500 + + Add MAC address in default environment and add clearenv functionality. + +diff --git a/src/u_boot.c b/src/u_boot.c +index e240475..7eea5e9 100644 +--- a/src/u_boot.c ++++ b/src/u_boot.c +@@ -36,6 +36,12 @@ + + #include "u_boot.h" + ++ ++#define DUMMY_MAC "00:00:00:00:00:00" ++#define MACNAME "ethaddr" ++ ++#define EMPTY_CRC 0xf9137807 ++ + static int tokcmp(const char *cmd, const char *pattern) { + int len = strlen(cmd); + if (len > strlen(pattern)) { +@@ -64,6 +70,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) { +@@ -166,7 +174,7 @@ static int cmd_setenv(struct environment *env, int argc, char **argv) + var = env->data; + while (*var) { + if (!strncmp(var, name, name_len) && var[name_len] == '=') { +- dbg("found variable (%s) at %lld", var, (long long int) var); ++ dbg("found variable (%s) at %p", var, var); + + cp = next_var(var); + while (*cp) { +@@ -213,7 +221,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 (to be stored): 0x%08X", env->crc); + env->flags = 0; + + tmp = write_uboot_env(MTD_ENV1, env); +@@ -238,7 +246,7 @@ static void print_version(const char *name) { + } + + static void usage(FILE *out) { +- fprintf(out, "Usage: u-boot { printenv [ name ] | setenv name [ value ] }\n"); ++ fprintf(out, "Usage: u-boot { printenv [ name ] | setenv name [ value ] | clearenv }\n"); + fprintf(out, "\n"); + } + +@@ -252,6 +260,7 @@ int main(int argc, char *argv[]) { + struct environment *env2; + uint32_t crc1_ok; + uint32_t crc2_ok; ++ uint32_t crc1_calc, crc2_calc; + + if (argc <= 1) { + usage(stderr); +@@ -301,12 +310,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) { ++ crc1_calc = crc32(0, (uint8_t *) env1->data, sizeof(env1->data)); ++ if (crc1_calc == 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,crc1_calc); ++ if ((env1->crc != 0xffffffff) || (crc1_calc != EMPTY_CRC)) ++ error("crc does not match on env1"); ++ else ++ dbg("uninitialized env1"); ++ + crc1_ok = 0; + } + +@@ -315,20 +330,64 @@ 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) { ++ crc2_calc = crc32(0, (uint8_t *) env2->data, sizeof(env2->data)); ++ if (crc2_calc == 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,crc2_calc); ++ if ((env2->crc != 0xffffffff) || (crc2_calc != EMPTY_CRC) ) ++ 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"); ++ if (!crc1_ok && !crc2_ok && (env1->crc == 0xffffffff) && ++ (env2->crc == 0xffffffff) && (crc1_calc == EMPTY_CRC) && ++ (crc2_calc == EMPTY_CRC) ) { ++ int mp_fd = open(MAC_PATH, O_RDONLY); ++ int len,retval; ++ char *p; ++ ++ fputs("WARNING: Flash is in initial state, so use defaults\n",stderr); + env = env1; + env->flags = 0; + memcpy(env->data, DEFAULT_ENV, sizeof(DEFAULT_ENV)); ++ /* Now need to find the MAC address */ ++ if (mp_fd == -1) { ++ perror("Cannot open: " MAC_PATH); ++ exit(1); ++ } ++ ++ len = sizeof DUMMY_MAC - 1; /* remove null from count */ ++ p = malloc(len); ++ retval = read(mp_fd,p,len); ++ dbg("Mac read of %d returned %d",len,retval); ++ if(retval != len) { ++ if(retval == -1) { ++ perror("Failed to read: " MAC_PATH); ++ exit(1); ++ } ++ if (retval != len) { ++ fprintf(stderr,"%s: Only read %d characters of %d for the MAC address\n", ++ MAC_PATH,retval,len); ++ fprintf(stderr,"%s: Read %*.*s\n",MAC_PATH,retval,retval,p); ++ exit(1); ++ } ++ } ++ len = sizeof(DEFAULT_ENV); ++ memcpy(env->data + len - 1, MACNAME, sizeof MACNAME); ++ len += sizeof MACNAME - 1; ++ env->data[len-1] = '='; ++ memcpy(env->data + len, p, sizeof DUMMY_MAC - 1); ++ len += sizeof DUMMY_MAC; ++ env->data[len-1] = 0; ++ env->data[len] = 0; ++ } else if (!crc1_ok && !crc2_ok) { ++ error("both environments are bad: not loading DEFAULT_ENV"); ++ exit(1); + } else if (crc1_ok && !crc2_ok) { + env = env1; + } else if (!crc1_ok && crc2_ok) { +@@ -353,6 +412,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); diff --git a/recipes-bsp/multitech/u-boot-linux-utils_0.0.1.bb b/recipes-bsp/multitech/u-boot-linux-utils_0.0.1.bb index 36510f8..0d5f2dc 100644 --- a/recipes-bsp/multitech/u-boot-linux-utils_0.0.1.bb +++ b/recipes-bsp/multitech/u-boot-linux-utils_0.0.1.bb @@ -4,14 +4,17 @@ SECTION = "console/utils" PRIORITY = "optional" LICENSE = "GPLv2" LIC_FILES_CHKSUM = "file://COPYING;md5=94d55d512a9ba36caa9b7df079bae19f" -PR = "r0" +PR = "r3" DEPENDS = "mtd-utils" # tag 0.0.1 SRCREV = "9c154405c2d01648f41c6a72bcc96f9865c4f07c" -SRC_URI = "git://git.multitech.net/u-boot-linux-utils.git;protocol=git" +SRC_URI = "git://git.multitech.net/u-boot-linux-utils.git;protocol=git \ + file://uboot_mac.patch \ + file://uboot_configure.patch" + S = "${WORKDIR}/git" inherit autotools |