From 248c6dada5daa872014be30acb722ce18181c08d Mon Sep 17 00:00:00 2001 From: John Klug Date: Tue, 4 Apr 2017 11:08:46 -0500 Subject: Add password creation utility mts-ubpasswd --- recipes-bsp/multitech/mts-id-eeprom.inc | 2 +- recipes-bsp/multitech/mts-id-eeprom_0.2.10.bb | 3 + recipes-bsp/multitech/mts-id-eeprom_0.2.6.bb | 3 - .../u-boot/u-boot-2012.10/u-boot-2012.10-pwd.patch | 312 +++++++++++++++++++++ recipes-bsp/u-boot/u-boot_2012.10.bb | 2 + 5 files changed, 318 insertions(+), 4 deletions(-) create mode 100644 recipes-bsp/multitech/mts-id-eeprom_0.2.10.bb delete mode 100644 recipes-bsp/multitech/mts-id-eeprom_0.2.6.bb create mode 100644 recipes-bsp/u-boot/u-boot-2012.10/u-boot-2012.10-pwd.patch diff --git a/recipes-bsp/multitech/mts-id-eeprom.inc b/recipes-bsp/multitech/mts-id-eeprom.inc index 61f024d..3bef9e9 100644 --- a/recipes-bsp/multitech/mts-id-eeprom.inc +++ b/recipes-bsp/multitech/mts-id-eeprom.inc @@ -7,7 +7,7 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=94d55d512a9ba36caa9b7df079bae19f" INC_PR = "r0" DEPENDS = "mts-io" -SRCREV = "${PV}" +SRCREV = "8801af07013ddfdf517d42bb50a21ebfad621460" SRC_URI = "git://git.multitech.net/mts-id-eeprom.git;protocol=git" S = "${WORKDIR}/git" diff --git a/recipes-bsp/multitech/mts-id-eeprom_0.2.10.bb b/recipes-bsp/multitech/mts-id-eeprom_0.2.10.bb new file mode 100644 index 0000000..9c5bd5f --- /dev/null +++ b/recipes-bsp/multitech/mts-id-eeprom_0.2.10.bb @@ -0,0 +1,3 @@ +require mts-id-eeprom.inc + +PR = "${INC_PR}.1A" diff --git a/recipes-bsp/multitech/mts-id-eeprom_0.2.6.bb b/recipes-bsp/multitech/mts-id-eeprom_0.2.6.bb deleted file mode 100644 index ccf3521..0000000 --- a/recipes-bsp/multitech/mts-id-eeprom_0.2.6.bb +++ /dev/null @@ -1,3 +0,0 @@ -require mts-id-eeprom.inc - -PR = "${INC_PR}.0" diff --git a/recipes-bsp/u-boot/u-boot-2012.10/u-boot-2012.10-pwd.patch b/recipes-bsp/u-boot/u-boot-2012.10/u-boot-2012.10-pwd.patch new file mode 100644 index 0000000..5338a6a --- /dev/null +++ b/recipes-bsp/u-boot/u-boot-2012.10/u-boot-2012.10-pwd.patch @@ -0,0 +1,312 @@ +diff --git a/common/Makefile b/common/Makefile +index 973f05a..12e8c00 100644 +--- a/common/Makefile ++++ b/common/Makefile +@@ -173,7 +173,7 @@ COBJS-$(CONFIG_YAFFS2) += cmd_yaffs2.o + COBJS-$(CONFIG_CMD_SPL) += cmd_spl.o + COBJS-$(CONFIG_CMD_ZIP) += cmd_zip.o + COBJS-$(CONFIG_CMD_ZFS) += cmd_zfs.o +- ++COBJS-$(CONFIG_MTS_PASSWD) += mts_passwd.o + # others + ifdef CONFIG_DDR_SPD + SPD := y +diff --git a/common/main.c b/common/main.c +index 9507cec..249bf6e 100644 +--- a/common/main.c ++++ b/common/main.c +@@ -403,7 +403,7 @@ void main_loop (void) + } + #endif /* CONFIG_MENUKEY */ + #endif /* CONFIG_BOOTDELAY */ +- ++ mts_run_passwd_loop(); + /* + * Main Loop for Monitor Command Processing + */ +diff --git a/common/mts_passwd.c b/common/mts_passwd.c +new file mode 100644 +index 0000000..947ac3a +--- /dev/null ++++ b/common/mts_passwd.c +@@ -0,0 +1,248 @@ ++#include ++#include ++#include ++#include ++#include ++ ++#define MTS_PASSWD_ATTEMPTS (3) ++#define MTS_PASSWD_MAX_LEN (30) ++#define MTS_PASSWD_HASH_VAR "mtsp" ++#define MTS_PASSWD_SALT_VAR "mtss" ++#define MTS_PASSWD_PROMPT "Enter password : " ++ ++static ++void mts_do_reset(unsigned long delay) ++{ ++ mdelay(delay); ++ do_reset(NULL, 0, 0, NULL); ++} ++ ++/* ++ * ++ * Figure out if device is locked or not ++ * ++ */ ++static ++int mts_get_protection_status(void) ++{ ++ int rc = 0; /* UNLOCKED */ ++ char *var = NULL; ++ int len; ++ ++ var = getenv(MTS_PASSWD_HASH_VAR); ++ ++ do { ++ /* Variable is not set */ ++ if (!var) break; ++ ++ len = strlen(var); ++ ++ /* Variable is empty */ ++ if (len == 0) break; ++ ++ /* ++ * Length should be correct. Otherwise, do not unlock the device, just show the message and reset. ++ */ ++ if (len != 2*SHA256_SUM_LEN) { ++ puts("WARNING: password is corrupted\n"); ++ mts_do_reset(1000); ++ } ++ ++ /* LOCKED */ ++ rc = 1; ++ ++ } while (0); ++ ++ return rc; ++} ++ ++ ++/* ++ * ++ * Helper function for the password reading ++ * ++ */ ++static ++char *mts_password_delete_char(char *buffer, char *p, int *colp, int *np, int plen) ++{ ++ static char erase_seq[] = "\b \b"; ++ ++ if (*np == 0) { ++ return (p); ++ } ++ ++ --p; ++ puts(erase_seq); ++ (*colp)--; ++ ++ (*np)--; ++ return (p); ++} ++ ++/* ++ * ++ * Read password helper ++ * ++ */ ++static ++int mts_password_into_buffer(const char *const prompt, char *buf, size_t buflen) ++{ ++ char *p = buf; ++ char *p_buf = p; ++ int n = 0; /* buffer index */ ++ int plen = 0; /* prompt length */ ++ int col; /* output column cnt */ ++ char c; ++ ++ /* print prompt */ ++ if (prompt) { ++ plen = strlen(prompt); ++ puts (prompt); ++ } ++ ++ col = plen; ++ ++ for (;;) { ++ ++ WATCHDOG_RESET(); ++ ++ c = getc(); ++ ++ /* ++ * Special character handling ++ */ ++ switch (c) { ++ case '\r': /* Enter */ ++ case '\n': ++ *p = '\0'; ++ puts("\r\n"); ++ return (p - p_buf); ++ ++ case '\0': /* nul */ ++ case '\t': ++ continue; ++ ++ case 0x03: /* ^C - break */ ++ p_buf[0] = '\0'; /* discard input */ ++ puts("\r\n"); ++ return (-1); ++ ++ case 0x08: /* ^H - backspace */ ++ case 0x7F: /* DEL - backspace */ ++ p = mts_password_delete_char(p_buf, p, &col, &n, plen); ++ continue; ++ ++ default: ++ /* ++ * Must be a normal character then ++ */ ++ if (n < buflen - 2) { ++ ++col; /* echo input */ ++ *p++ = c; ++ ++n; ++ } ++ putc('*'); ++ } ++ } ++} ++ ++/* ++ * ++ * Read the password from input ++ * ++ */ ++static ++int read_password(char *buf, size_t buflen) ++{ ++ return mts_password_into_buffer(MTS_PASSWD_PROMPT, buf, buflen); ++} ++ ++/* ++ * ++ * Verify if the entered password is correct. ++ * ++ */ ++static ++int verify_password(char *pwd, size_t pwdlen) ++{ ++ char *hash_env = getenv(MTS_PASSWD_HASH_VAR);; ++ char *salt_env = getenv(MTS_PASSWD_SALT_VAR); ++ ++ if (pwd && pwdlen > 0 && hash_env && (strlen(hash_env) == 2*SHA256_SUM_LEN)) { ++ uint8_t hash[SHA256_SUM_LEN]; ++ uint8_t prefix[]={'0','3','e','3'}; ++ sha256_context ctx; ++ char tmp[3]; ++ int i; ++ ++ sha256_starts(&ctx); ++ sha256_update(&ctx, prefix, 4); ++ sha256_update(&ctx, (uint8_t *) pwd, pwdlen); ++ if (salt_env) { ++ size_t saltlen = strlen(salt_env); ++ sha256_update(&ctx, (uint8_t *) salt_env, saltlen); ++ } ++ sha256_finish(&ctx, hash); ++ memset(&ctx, 0, sizeof(sha256_context)); ++ ++ for (i = 0; i < SHA256_SUM_LEN; i++) { ++ snprintf(tmp, sizeof tmp, "%02x", hash[i]); ++ if (tolower(tmp[0]) != tolower(hash_env[2*i]) || ++ tolower(tmp[1]) != tolower(hash_env[2*i + 1])) { ++ break; ++ } ++ } ++ ++ if (i == SHA256_SUM_LEN) { ++ return 1; ++ } ++ } ++ ++ return 0; ++} ++ ++/* ++ * ++ * Check is the device is locked and ask the password. ++ * ++ */ ++void mts_run_passwd_loop(void) ++{ ++ char buf[MTS_PASSWD_MAX_LEN] = "\0"; ++ unsigned long delay = 1000; /* 1 second initially */ ++ int len; ++ int trynr = 0; ++ ++ /* Do not delete */ ++ printf("", "mts password protected"); ++ ++ if (mts_get_protection_status() == 0) { ++ return; ++ } ++ ++ while (1) { ++ if (trynr == MTS_PASSWD_ATTEMPTS) { ++ mts_do_reset(1000); ++ } ++ ++ len = read_password(buf, MTS_PASSWD_MAX_LEN); ++ if (len > 0) { ++ if (verify_password(buf, len)) { ++ /* zero out */ ++ memset(buf, 0, sizeof(buf)); ++ return; ++ } ++ puts("Permission denied\n"); ++ } ++ ++ trynr++; ++ ++ /* progressive delay */ ++ mdelay(delay); ++ delay *= 2; ++ if (delay > 4000) delay = 4000; ++ } ++ /* zero out */ ++ memset(buf, 0, sizeof(buf)); ++ return; ++} +diff --git a/include/common.h b/include/common.h +index a7fb05e..b334700 100644 +--- a/include/common.h ++++ b/include/common.h +@@ -41,6 +41,7 @@ typedef volatile unsigned char vu_char; + #include + #include + #include ++#include + #if defined(CONFIG_PCI) && (defined(CONFIG_4xx) && !defined(CONFIG_AP1000)) + #include + #endif +diff --git a/include/mts_passwd.h b/include/mts_passwd.h +new file mode 100644 +index 0000000..1668d8f +--- /dev/null ++++ b/include/mts_passwd.h +@@ -0,0 +1,13 @@ ++#ifndef _MTS_PASSWD_H ++#define _MTS_PASSWD_H ++ ++#define CONFIG_MTS_PASSWD ++ ++#if defined(CONFIG_MTS_PASSWD) ++#define CONFIG_SHA256 ++void mts_run_passwd_loop(void); ++#else ++#define mts_run_passwd_loop() {} ++#endif ++ ++#endif +\ No newline at end of file diff --git a/recipes-bsp/u-boot/u-boot_2012.10.bb b/recipes-bsp/u-boot/u-boot_2012.10.bb index 654564f..ab52e31 100644 --- a/recipes-bsp/u-boot/u-boot_2012.10.bb +++ b/recipes-bsp/u-boot/u-boot_2012.10.bb @@ -16,6 +16,8 @@ SRC_URI = "git://github.com/linux4sam/u-boot-at91.git;branch=u-boot-2012.10-at91 # add patch to speed up boot if ethernet autonegotiation fails SRC_URI += "file://u-boot-2010.06-macb-autoneg-timeout.patch" +# add password protection patch +SRC_URI += "file://u-boot-2012.10-pwd.patch" SRC_URI_append_mtcdt = " file://u-boot-2012.10-mtcdt.patch" -- cgit v1.2.3 From 87223519b59a8bf42d05f8f8b4ac76c0b811c990 Mon Sep 17 00:00:00 2001 From: Mykyta Dorokhin Date: Tue, 31 Jan 2017 13:41:42 +0200 Subject: Add password creation utility to mts-id-eeprom --- recipes-bsp/multitech/mts-id-eeprom.inc | 3 +- recipes-bsp/multitech/mts-id-eeprom/eeprom.patch | 262 +++++++++++++++++++++++ recipes-bsp/multitech/mts-io_1.1.4.bb | 4 - recipes-bsp/multitech/mts-io_1.5.9.bb | 4 + 4 files changed, 268 insertions(+), 5 deletions(-) create mode 100644 recipes-bsp/multitech/mts-id-eeprom/eeprom.patch delete mode 100644 recipes-bsp/multitech/mts-io_1.1.4.bb create mode 100644 recipes-bsp/multitech/mts-io_1.5.9.bb diff --git a/recipes-bsp/multitech/mts-id-eeprom.inc b/recipes-bsp/multitech/mts-id-eeprom.inc index 3bef9e9..d1e08b6 100644 --- a/recipes-bsp/multitech/mts-id-eeprom.inc +++ b/recipes-bsp/multitech/mts-id-eeprom.inc @@ -9,7 +9,8 @@ DEPENDS = "mts-io" SRCREV = "8801af07013ddfdf517d42bb50a21ebfad621460" -SRC_URI = "git://git.multitech.net/mts-id-eeprom.git;protocol=git" +SRC_URI = "git://git.multitech.net/mts-id-eeprom.git;protocol=git \ + file://eeprom.patch" S = "${WORKDIR}/git" inherit autotools diff --git a/recipes-bsp/multitech/mts-id-eeprom/eeprom.patch b/recipes-bsp/multitech/mts-id-eeprom/eeprom.patch new file mode 100644 index 0000000..4c19e22 --- /dev/null +++ b/recipes-bsp/multitech/mts-id-eeprom/eeprom.patch @@ -0,0 +1,262 @@ +diff -uNr old/src/eeprom_main.c new/src/eeprom_main.c +--- old/src/eeprom_main.c 2017-04-04 12:38:41.561484898 -0500 ++++ new/src/eeprom_main.c 2017-04-04 12:30:33.877499336 -0500 +@@ -1,7 +1,7 @@ + /* + * Create an image file for the MTCDP ID EEPROM + * +- * Copyright (C) 2016 by Multi-Tech Systems ++ * Copyright (C) 2013 by Multi-Tech Systems + * + * Author: James Maki + * +@@ -160,7 +160,6 @@ + fprintf(file, "capa-adc: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_ADC) ? "true" : "false"); + fprintf(file, "capa-wifi: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_WIFI) ? "true" : "false"); + fprintf(file, "capa-bluetooth: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_BLUETOOTH) ? "true" : "false"); +- fprintf(file, "capa-lora: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_LORA) ? "true" : "false"); + + fprintf(file, "capa: \""); + +@@ -188,20 +187,6 @@ + ptr += sprintf(ptr, "%02X", id_eeprom->uuid[i]); + } + fprintf(file, "uuid: \"%s\"\n", (char*)buf); +- +- fprintf(file, "lora-eui: \"%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\"\n", +- id_eeprom->lora_eui[0], +- id_eeprom->lora_eui[1], +- id_eeprom->lora_eui[2], +- id_eeprom->lora_eui[3], +- id_eeprom->lora_eui[4], +- id_eeprom->lora_eui[5], +- id_eeprom->lora_eui[6], +- id_eeprom->lora_eui[7]); +- +- fprintf(file, "lora-product-id: \"%.32s\"\n", id_eeprom->lora_product_id); +- fprintf(file, "lora-hw-version: \"%.32s\"\n", id_eeprom->lora_hw_version); +- + fprintf(file, "...\n"); + + fclose(file); +@@ -307,7 +292,6 @@ + log_info("capa-adc: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_ADC) ? "yes" : "no"); + log_info("capa-wifi: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_WIFI) ? "yes" : "no"); + log_info("capa-bluetooth: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_BLUETOOTH) ? "yes" : "no"); +- log_info("capa-lora: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_LORA) ? "yes" : "no"); + + log_info("mac-bluetooth: %02X:%02X:%02X:%02X:%02X:%02X", + id_eeprom->mac_bluetooth[0], +@@ -329,19 +313,6 @@ + ptr += sprintf(ptr, "%02X", id_eeprom->uuid[i]); + } + log_info("uuid: %s", (char*)buf); +- +- log_info("lora-eui: \"%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\"", +- id_eeprom->lora_eui[0], +- id_eeprom->lora_eui[1], +- id_eeprom->lora_eui[2], +- id_eeprom->lora_eui[3], +- id_eeprom->lora_eui[4], +- id_eeprom->lora_eui[5], +- id_eeprom->lora_eui[6], +- id_eeprom->lora_eui[7]); +- +- log_info("lora-product-id: %.32s", id_eeprom->lora_product_id); +- log_info("lora-hw-version: %.32s", id_eeprom->lora_hw_version); + } + + static void mts_ap_eeprom_inspect(struct mts_ap_eeprom_layout *ap_eeprom) +@@ -391,9 +362,7 @@ + fprintf(out, " --mac-addr |\n"); + fprintf(out, " --mac-bluetooth |\n"); + fprintf(out, " --mac-wifi |\n"); +- fprintf(out, " --lora-eui |\n"); +- fprintf(out, " --lora-hw-version |\n"); +- fprintf(out, " --lora-product-id |\n"); ++ fprintf(out, " --eui |\n"); + fprintf(out, " --imei |\n"); + fprintf(out, " --capa-gps |\n"); + fprintf(out, " --capa-din |\n"); +@@ -401,9 +370,7 @@ + fprintf(out, " --capa-adc |\n"); + fprintf(out, " --capa-wifi |\n"); + fprintf(out, " --capa-bluetooth |\n"); +- fprintf(out, " --capa-lora |\n"); + fprintf(out, " --capa-clear (clears all flags) |\n"); +- fprintf(out, " --hex-to-bin | \n"); + fprintf(out, " --out-format { bin | yaml (default) } |\n"); + fprintf(out, " --update |\n"); + fprintf(out, " --accessory-card\n"); +@@ -422,9 +389,7 @@ + CMD_OPT_MAC_ADDR, + CMD_OPT_MAC_BLUETOOTH, + CMD_OPT_MAC_WIFI, +- CMD_OPT_LORA_EUI, +- CMD_OPT_LORA_HW_VERSION, +- CMD_OPT_LORA_PRODUCT_ID, ++ CMD_OPT_EUI, + CMD_OPT_IMEI, + CMD_OPT_CAPA_GPS, + CMD_OPT_CAPA_DIN, +@@ -432,15 +397,12 @@ + CMD_OPT_CAPA_ADC, + CMD_OPT_CAPA_WIFI, + CMD_OPT_CAPA_BLUETOOTH, +- CMD_OPT_CAPA_LORA, + CMD_OPT_CAPA_CLEAR, + CMD_OPT_OUT_FORMAT, + CMD_OPT_UPDATE, + CMD_OPT_ACCESSORY_CARD, +- + CMD_OPT_VERSION, + CMD_OPT_HELP, +- CMD_OPT_HEX_TO_BIN, + }; + + static char *short_options = "f:"; +@@ -452,12 +414,10 @@ + {"device-id", 1, NULL, CMD_OPT_DEVICE_ID}, + {"uuid", 1, NULL, CMD_OPT_UUID}, + {"hw-version", 1, NULL, CMD_OPT_HW_VERSION}, +- {"lora-product-id", 1, NULL, CMD_OPT_LORA_PRODUCT_ID}, +- {"lora-hw-version", 1, NULL, CMD_OPT_LORA_HW_VERSION}, + {"mac-addr", 1, NULL, CMD_OPT_MAC_ADDR}, + {"mac-bluetooth", 1, NULL, CMD_OPT_MAC_BLUETOOTH}, + {"mac-wifi", 1, NULL, CMD_OPT_MAC_WIFI}, +- {"lora-eui", 1, NULL, CMD_OPT_LORA_EUI}, ++ {"eui", 1, NULL, CMD_OPT_EUI}, + {"imei", 1, NULL, CMD_OPT_IMEI}, + {"capa-gps", 0, NULL, CMD_OPT_CAPA_GPS}, + {"capa-din", 0, NULL, CMD_OPT_CAPA_DIN}, +@@ -465,9 +425,7 @@ + {"capa-adc", 0, NULL, CMD_OPT_CAPA_ADC}, + {"capa-wifi", 0, NULL, CMD_OPT_CAPA_WIFI}, + {"capa-bluetooth", 0, NULL, CMD_OPT_CAPA_BLUETOOTH}, +- {"capa-lora", 0, NULL, CMD_OPT_CAPA_LORA}, + {"capa-clear", 0, NULL, CMD_OPT_CAPA_CLEAR}, +- {"hex-to-bin", 0, NULL, CMD_OPT_HEX_TO_BIN}, + {"out-format", 1, NULL, CMD_OPT_OUT_FORMAT}, + {"update", 0, NULL, CMD_OPT_UPDATE}, + {"accessory-card", 0, NULL, CMD_OPT_ACCESSORY_CARD}, +@@ -494,9 +452,7 @@ + char *uuid = NULL; + char *hw_version = NULL; + char *mac_addr = NULL; +- char *lora_eui = NULL; +- char *lora_product_id = NULL; +- char *lora_hw_version = NULL; ++ char *eui = NULL; + + struct mts_id_eeprom_layout id_eeprom; + struct mts_ap_eeprom_layout ap_eeprom; +@@ -616,10 +572,6 @@ + product_id = optarg; + break; + +- case CMD_OPT_LORA_PRODUCT_ID: +- lora_product_id = optarg; +- break; +- + case CMD_OPT_DEVICE_ID: + device_id = optarg; + break; +@@ -641,10 +593,6 @@ + hw_version = optarg; + break; + +- case CMD_OPT_LORA_HW_VERSION: +- lora_hw_version = optarg; +- break; +- + case CMD_OPT_MAC_ADDR: + mac_addr = optarg; + break; +@@ -667,8 +615,8 @@ + } + break; + +- case CMD_OPT_LORA_EUI: +- lora_eui = optarg; ++ case CMD_OPT_EUI: ++ eui = optarg; + break; + + case CMD_OPT_IMEI: +@@ -699,10 +647,6 @@ + DEVICE_CAPA_SET(id_eeprom.capa, CAPA_BLUETOOTH); + break; + +- case CMD_OPT_CAPA_LORA: +- DEVICE_CAPA_SET(id_eeprom.capa, CAPA_LORA); +- break; +- + case CMD_OPT_CAPA_CLEAR: + memset(id_eeprom.capa, 0, sizeof(id_eeprom.capa)); + break; +@@ -716,22 +660,7 @@ + out_format = optarg; + + break; +- case CMD_OPT_HEX_TO_BIN: +- { +- char buf[1025]; +- char outbuf[1024]; +- size_t sz, len; +- while((sz=read(0,buf,sizeof buf)) > 0) { +- buf[sz] = 0; +- sz = asciiHexToBin(buf,outbuf); +- len = write(1,outbuf,sz); +- if(len != sz) { +- log_error("failure to write to stdout: %s",strerror(errno)); +- exit(1); +- } +- } +- exit(0); +- } ++ + default: + usage(stderr); + exit(1); +@@ -779,35 +708,16 @@ + exit(1); + } + } +- // on-board lora product id +- if (lora_product_id) { +- if (! accessory_card) { +- strncpy(id_eeprom.lora_product_id, lora_product_id, sizeof(id_eeprom.lora_product_id) - 1); +- } else { +- log_error("--lora-product-id option is not supported on accessory card eeprom"); +- usage(stderr); +- exit(1); +- } +- } +- // on-board lora hw version +- if (lora_hw_version) { +- if (! accessory_card) { +- strncpy(id_eeprom.lora_hw_version, lora_hw_version, sizeof(id_eeprom.lora_hw_version) - 1); +- } else { +- log_error("--lora-hw-version option is not supported on accessory card eeprom"); ++ if (eui) { ++ if (!accessory_card) { ++ log_error("EUI only supported on accessory card eeprom"); + usage(stderr); + exit(1); + } +- } +- if (lora_eui) { +- if (!accessory_card) { +- tmp = hwaddr_aton(lora_eui, id_eeprom.lora_eui, sizeof(id_eeprom.lora_eui)); +- } +- else { +- tmp = hwaddr_aton(lora_eui, ap_eeprom.eui, sizeof(ap_eeprom.eui)); +- } ++ ++ tmp = hwaddr_aton(eui, ap_eeprom.eui, sizeof(ap_eeprom.eui)); + if (!tmp) { +- log_error("invalid EUI %s", lora_eui); ++ log_error("invalid EUI %s", eui); + usage(stderr); + exit(1); + } diff --git a/recipes-bsp/multitech/mts-io_1.1.4.bb b/recipes-bsp/multitech/mts-io_1.1.4.bb deleted file mode 100644 index 85b3de1..0000000 --- a/recipes-bsp/multitech/mts-io_1.1.4.bb +++ /dev/null @@ -1,4 +0,0 @@ -require mts-io.inc - -PR = "${INC_PR}.0" - diff --git a/recipes-bsp/multitech/mts-io_1.5.9.bb b/recipes-bsp/multitech/mts-io_1.5.9.bb new file mode 100644 index 0000000..85b3de1 --- /dev/null +++ b/recipes-bsp/multitech/mts-io_1.5.9.bb @@ -0,0 +1,4 @@ +require mts-io.inc + +PR = "${INC_PR}.0" + -- cgit v1.2.3 From d4672b8ae8809d5314ef235a4a84a3bf6ce3b77f Mon Sep 17 00:00:00 2001 From: John Klug Date: Thu, 6 Apr 2017 11:16:06 -0500 Subject: Add patch for CRC Debug to u-boot --- .../u-boot/u-boot-2012.10/u-boot-env-crc-dbg.patch | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 recipes-bsp/u-boot/u-boot-2012.10/u-boot-env-crc-dbg.patch diff --git a/recipes-bsp/u-boot/u-boot-2012.10/u-boot-env-crc-dbg.patch b/recipes-bsp/u-boot/u-boot-2012.10/u-boot-env-crc-dbg.patch new file mode 100644 index 0000000..3671645 --- /dev/null +++ b/recipes-bsp/u-boot/u-boot-2012.10/u-boot-env-crc-dbg.patch @@ -0,0 +1,58 @@ + + Print out CRC values for environment + +diff --git a/common/env_nand.c b/common/env_nand.c +index 79e8033..9a9bac7 100644 +--- a/common/env_nand.c ++++ b/common/env_nand.c +@@ -83,15 +83,22 @@ int env_init(void) + #if defined(ENV_IS_EMBEDDED) || defined(CONFIG_NAND_ENV_DST) + int crc1_ok = 0, crc2_ok = 0; + env_t *tmp_env1; ++ uint32_t calc_crc; + + #ifdef CONFIG_ENV_OFFSET_REDUND + env_t *tmp_env2; + + tmp_env2 = (env_t *)((ulong)env_ptr + CONFIG_ENV_SIZE); +- crc2_ok = crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc; ++ calc_crc = crc32(0, tmp_env2->data, ENV_SIZE); ++ crc2_ok = calc_crc == tmp_env2->crc; ++ printf("env_relocate_spec: crc2_ok=%d saved crc=0x%x calculated crc=0x%x flags=%d\n", ++ crc2_ok,calc_crc,tmp_env2->crc,tmp_env2->flags); + #endif + tmp_env1 = env_ptr; +- crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc; ++ calc_crc = crc32(0, tmp_env1->data, ENV_SIZE); ++ crc1_ok = saved_crc == tmp_env1->crc; ++ printf("env_relocate_spec: crc1_ok=%d saved crc=0x%x calculated crc=0x%x flags=%d\n", ++ crc1_ok,calc_crc,tmp_env1->crc,tmp_env1->flags); + + if (!crc1_ok && !crc2_ok) { + gd->env_addr = 0; +@@ -333,6 +340,7 @@ void env_relocate_spec(void) + #if !defined(ENV_IS_EMBEDDED) + int crc1_ok = 0, crc2_ok = 0; + env_t *ep, *tmp_env1, *tmp_env2; ++ uint32_t calc_crc; + + tmp_env1 = (env_t *)malloc(CONFIG_ENV_SIZE); + tmp_env2 = (env_t *)malloc(CONFIG_ENV_SIZE); +@@ -347,9 +355,14 @@ void env_relocate_spec(void) + + if (readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2)) + puts("No Valid Redundant Environment Area found\n"); +- +- crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc; +- crc2_ok = crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc; ++ calc_crc = crc32(0, tmp_env1->data, ENV_SIZE); ++ crc1_ok = calc_crc == tmp_env1->crc; ++ printf("env_relocate_spec: crc1_ok=%d saved crc=0x%x calculated crc=0x%x flags=%d\n", ++ crc1_ok,calc_crc,tmp_env1->crc,tmp_env1->flags); ++ calc_crc = crc32(0, tmp_env2->data, ENV_SIZE); ++ crc2_ok = calc_crc == tmp_env2->crc; ++ printf("env_relocate_spec: crc2_ok=%d saved crc=0x%x calculated crc=0x%x flags=%d\n", ++ crc2_ok,calc_crc,tmp_env2->crc,tmp_env2->flags); + + if (!crc1_ok && !crc2_ok) { + set_default_env("!bad CRC"); -- cgit v1.2.3 From 8254d468bd749a5aa7df3dde68b3a1175b5e23e8 Mon Sep 17 00:00:00 2001 From: John Klug Date: Thu, 6 Apr 2017 11:55:29 -0500 Subject: Debug patch to cause dbg() function to print --- recipes-bsp/multitech/u-boot-linux-utils/dbg.patch | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 recipes-bsp/multitech/u-boot-linux-utils/dbg.patch diff --git a/recipes-bsp/multitech/u-boot-linux-utils/dbg.patch b/recipes-bsp/multitech/u-boot-linux-utils/dbg.patch new file mode 100644 index 0000000..af81220 --- /dev/null +++ b/recipes-bsp/multitech/u-boot-linux-utils/dbg.patch @@ -0,0 +1,15 @@ +# Set the debug flag for the build so we can monitor +# what is going on. +diff --git a/configure.in b/configure.in +index 8fdc9ef..7a2eb01 100644 +--- a/configure.in ++++ b/configure.in +@@ -15,7 +15,7 @@ required header missing])) + + AC_CHECK_LIB([z], [crc32], [], AC_MSG_ERROR([libz is required])) + +-AC_DEFINE([DEBUG], 0, [set to 1 to enable debug]) ++AC_DEFINE([DEBUG], 1, [set to 1 to enable debug]) + AC_DEFINE([MTD_ENV1], "/dev/mtd3", [set to the first u-boot env mtd]) + AC_DEFINE([MTD_ENV2], "/dev/mtd4", [set to the second (redundant) u-boot env mtd]) + AC_DEFINE([MTD_SIZE], 0x20000, [size of u-boot env mtd]) -- cgit v1.2.3 From 1c83ec7a7931d63a6ac7cc7a28c277ae802b0e8e Mon Sep 17 00:00:00 2001 From: John Klug Date: Thu, 6 Apr 2017 11:56:23 -0500 Subject: patch to prevent inadvertant erasure of environment and allow deliberate erasure --- .../multitech/u-boot-linux-utils/crc_erase.patch | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 recipes-bsp/multitech/u-boot-linux-utils/crc_erase.patch 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); -- cgit v1.2.3 From e6fe39351d3363273365ef9be3c4ed4fa274e602 Mon Sep 17 00:00:00 2001 From: John Klug Date: Thu, 6 Apr 2017 14:13:38 -0500 Subject: 2nd attempt:patch to prevent inadvertant erasure of environment and allow deliberate erasure --- recipes-bsp/multitech/u-boot-linux-utils/crc_erase.patch | 10 ++++++---- 1 file changed, 6 insertions(+), 4 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 index 67cd5ef..5d78703 100644 --- a/recipes-bsp/multitech/u-boot-linux-utils/crc_erase.patch +++ b/recipes-bsp/multitech/u-boot-linux-utils/crc_erase.patch @@ -3,7 +3,7 @@ # 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 +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) @@ -54,7 +54,7 @@ index e240475..f10eaa3 100644 crc1_ok = 0; } -@@ -315,20 +324,26 @@ int main(int argc, char *argv[]) { +@@ -315,20 +324,27 @@ int main(int argc, char *argv[]) { error("read_uboot_env failed"); return 1; } @@ -75,8 +75,10 @@ index e240475..f10eaa3 100644 crc2_ok = 0; } - if (!crc1_ok && !crc2_ok) { +- 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; @@ -85,7 +87,7 @@ index e240475..f10eaa3 100644 } else if (crc1_ok && !crc2_ok) { env = env1; } else if (!crc1_ok && crc2_ok) { -@@ -353,6 +368,9 @@ int main(int argc, char *argv[]) { +@@ -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); -- cgit v1.2.3 From cf2c9f7209b8a9927e3debfda0d0ca6a57af6d28 Mon Sep 17 00:00:00 2001 From: John Klug Date: Thu, 6 Apr 2017 15:23:22 -0500 Subject: Add CRC environment printout to u-boot --- recipes-bsp/u-boot/u-boot_2012.10.bb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recipes-bsp/u-boot/u-boot_2012.10.bb b/recipes-bsp/u-boot/u-boot_2012.10.bb index ab52e31..fc0c7d2 100644 --- a/recipes-bsp/u-boot/u-boot_2012.10.bb +++ b/recipes-bsp/u-boot/u-boot_2012.10.bb @@ -1,4 +1,4 @@ -PR = "r6" +PR = "r7" require u-boot.inc LICENSE = "GPLv2" @@ -12,6 +12,7 @@ SRCREV="8978bdafbad84c0c9878c9ff331930ca6edf9a76" SRC_URI = "git://github.com/linux4sam/u-boot-at91.git;branch=u-boot-2012.10-at91 \ file://u-boot-2012.10-sam9x5-eth-mii-fix.patch \ + file://u-boot-env-crc-dbg.patch \ " # add patch to speed up boot if ethernet autonegotiation fails -- cgit v1.2.3 From 35b6b59cc3aabc1cd062aed3f7298e12d914ce98 Mon Sep 17 00:00:00 2001 From: John Klug Date: Fri, 7 Apr 2017 18:58:12 -0500 Subject: Update configure --- recipes-bsp/multitech/u-boot-linux-utils/dbg.patch | 15 ------------ .../u-boot-linux-utils/uboot_configure.patch | 28 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 15 deletions(-) delete mode 100644 recipes-bsp/multitech/u-boot-linux-utils/dbg.patch create mode 100644 recipes-bsp/multitech/u-boot-linux-utils/uboot_configure.patch diff --git a/recipes-bsp/multitech/u-boot-linux-utils/dbg.patch b/recipes-bsp/multitech/u-boot-linux-utils/dbg.patch deleted file mode 100644 index af81220..0000000 --- a/recipes-bsp/multitech/u-boot-linux-utils/dbg.patch +++ /dev/null @@ -1,15 +0,0 @@ -# Set the debug flag for the build so we can monitor -# what is going on. -diff --git a/configure.in b/configure.in -index 8fdc9ef..7a2eb01 100644 ---- a/configure.in -+++ b/configure.in -@@ -15,7 +15,7 @@ required header missing])) - - AC_CHECK_LIB([z], [crc32], [], AC_MSG_ERROR([libz is required])) - --AC_DEFINE([DEBUG], 0, [set to 1 to enable debug]) -+AC_DEFINE([DEBUG], 1, [set to 1 to enable debug]) - AC_DEFINE([MTD_ENV1], "/dev/mtd3", [set to the first u-boot env mtd]) - AC_DEFINE([MTD_ENV2], "/dev/mtd4", [set to the second (redundant) u-boot env mtd]) - AC_DEFINE([MTD_SIZE], 0x20000, [size of u-boot env mtd]) diff --git a/recipes-bsp/multitech/u-boot-linux-utils/uboot_configure.patch b/recipes-bsp/multitech/u-boot-linux-utils/uboot_configure.patch new file mode 100644 index 0000000..e7a7fe0 --- /dev/null +++ b/recipes-bsp/multitech/u-boot-linux-utils/uboot_configure.patch @@ -0,0 +1,28 @@ +commit 0de7b48ba5bfca360d7c1840e9415f8a8177eede +Author: John Klug +Date: Fri Apr 7 16:33:13 2017 -0500 + + Defaults for u-boot-linux-utils + debug turned on + +diff --git a/configure.in b/configure.in +index 8fdc9ef..85998a9 100644 +--- a/configure.in ++++ b/configure.in +@@ -15,12 +15,15 @@ required header missing])) + + AC_CHECK_LIB([z], [crc32], [], AC_MSG_ERROR([libz is required])) + +-AC_DEFINE([DEBUG], 0, [set to 1 to enable debug]) ++AC_DEFINE([DEBUG], 1, [set to 1 to enable debug]) + AC_DEFINE([MTD_ENV1], "/dev/mtd3", [set to the first u-boot env mtd]) + AC_DEFINE([MTD_ENV2], "/dev/mtd4", [set to the second (redundant) u-boot env mtd]) + AC_DEFINE([MTD_SIZE], 0x20000, [size of u-boot env mtd]) +-AC_DEFINE([DEFAULT_ENV], ["bootargs=mem=64M console=ttyS0,115200 root=/dev/mtdblock8 ro rootfstype=jffs2\0" "bootcmd=nboot.jffs2 ${loadaddr} 0 ${kernel_addr}; bootm ${loadaddr}\0" "bootdelay=3\0" "baudrate=115200\0" "ethaddr=00:D0:A0:02:0D:E1\0" "ipaddr=192.168.2.1\0" "serverip=192.168.2.2\0" "netmask=255.255.255.0\0" "hostname=AT91SAM9G20\0" "loadaddr=0x21400000\0" "kernel_addr=0x000A0000\0" "\0"] ++ ++AC_DEFINE([DEFAULT_ENV], ["baudrate=115200\0" "bootargs=mem=256M console=ttyS0,115200 root=/dev/mtdblock8 ro rootfstype=jffs2\0" "bootcmd=nboot.jffs2 ${loadaddr} 0 ${kernel_addr}; bootm ${loadaddr}\0" "bootdelay=0\0" "ethact=macb0\0" "hostname=AT91SAM9G25\0" "ipaddr=192.168.2.1\0" "kernel_addr=0x200000\0" "loadaddr=0x22000000\0" "serverip=192.168.2.2\0" "netmask=255.255.255.0\0" "stderr=serial\0" "stdin=serial\0" "stdout=serial\0"] + , [default env if corrupt]) + ++AC_DEFINE([MAC_PATH],["/sys/devices/platform/mts-io/mac-eth"], [MAC_PATH for defining ethaddr= in boot environment]) ++ + AC_OUTPUT([Makefile src/Makefile]) + -- cgit v1.2.3 From 851eb02635f7dfbf20864cb8e9b01d59ad07ec45 Mon Sep 17 00:00:00 2001 From: John Klug Date: Mon, 10 Apr 2017 12:26:19 -0500 Subject: Fix MAC address in default environment --- .../multitech/u-boot-linux-utils/crc_erase.patch | 99 ------------ .../multitech/u-boot-linux-utils/uboot_mac.patch | 169 +++++++++++++++++++++ recipes-bsp/multitech/u-boot-linux-utils_0.0.1.bb | 7 +- 3 files changed, 174 insertions(+), 101 deletions(-) delete mode 100644 recipes-bsp/multitech/u-boot-linux-utils/crc_erase.patch create mode 100644 recipes-bsp/multitech/u-boot-linux-utils/uboot_mac.patch 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 +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 -- cgit v1.2.3 From 64e496749524a51fdb2e52dbf94b1e7774d962fa Mon Sep 17 00:00:00 2001 From: John Klug Date: Tue, 11 Apr 2017 09:56:56 -0500 Subject: Add header files to u-boot developer package. --- recipes-bsp/u-boot/u-boot.inc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/recipes-bsp/u-boot/u-boot.inc b/recipes-bsp/u-boot/u-boot.inc index 38a8a79..869b142 100644 --- a/recipes-bsp/u-boot/u-boot.inc +++ b/recipes-bsp/u-boot/u-boot.inc @@ -29,6 +29,8 @@ SPL_BINARY ?= "" SPL_IMAGE ?= "${SPL_BINARY}-${MACHINE}-${PV}-${PR}" SPL_SYMLINK ?= "${SPL_BINARY}-${MACHINE}" +FILES_${PN}-dev += "${includedir}/u-boot/* ${includedir}/u-boot/configs/* ${includedir}/u-boot/asm/*" + do_compile () { if [ "${@base_contains('DISTRO_FEATURES', 'ld-is-gold', 'ld-is-gold', '', d)}" = "ld-is-gold" ] ; then sed -i 's/$(CROSS_COMPILE)ld$/$(CROSS_COMPILE)ld.bfd/g' config.mk @@ -63,6 +65,8 @@ do_install () { install ${S}/${SPL_BINARY} ${D}/boot/${SPL_IMAGE} ln -sf ${SPL_IMAGE} ${D}/boot/${SPL_BINARY} fi + mkdir -p ${D}/usr/include/u-boot || true + (cd ${S}/include;find . | cpio -pdum ${D}/usr/include/u-boot) } FILES_${PN} = "/boot ${sysconfdir}" -- cgit v1.2.3 From bbcd7379378e41ed22505cada25c68a7b6cdf821 Mon Sep 17 00:00:00 2001 From: John Klug Date: Tue, 11 Apr 2017 10:00:21 -0500 Subject: Print out CRC in correct order. --- recipes-bsp/u-boot/u-boot-2012.10/u-boot-env-crc-dbg.patch | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/recipes-bsp/u-boot/u-boot-2012.10/u-boot-env-crc-dbg.patch b/recipes-bsp/u-boot/u-boot-2012.10/u-boot-env-crc-dbg.patch index 3671645..418a734 100644 --- a/recipes-bsp/u-boot/u-boot-2012.10/u-boot-env-crc-dbg.patch +++ b/recipes-bsp/u-boot/u-boot-2012.10/u-boot-env-crc-dbg.patch @@ -2,7 +2,7 @@ Print out CRC values for environment diff --git a/common/env_nand.c b/common/env_nand.c -index 79e8033..9a9bac7 100644 +index 79e8033..5536a39 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -83,15 +83,22 @@ int env_init(void) @@ -19,14 +19,14 @@ index 79e8033..9a9bac7 100644 + calc_crc = crc32(0, tmp_env2->data, ENV_SIZE); + crc2_ok = calc_crc == tmp_env2->crc; + printf("env_relocate_spec: crc2_ok=%d saved crc=0x%x calculated crc=0x%x flags=%d\n", -+ crc2_ok,calc_crc,tmp_env2->crc,tmp_env2->flags); ++ crc2_ok,tmp_env2->crc,calc_crc,tmp_env2->flags); #endif tmp_env1 = env_ptr; - crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc; + calc_crc = crc32(0, tmp_env1->data, ENV_SIZE); + crc1_ok = saved_crc == tmp_env1->crc; + printf("env_relocate_spec: crc1_ok=%d saved crc=0x%x calculated crc=0x%x flags=%d\n", -+ crc1_ok,calc_crc,tmp_env1->crc,tmp_env1->flags); ++ crc1_ok,tmp_env1->crc,calc_crc,tmp_env1->flags); if (!crc1_ok && !crc2_ok) { gd->env_addr = 0; @@ -48,11 +48,11 @@ index 79e8033..9a9bac7 100644 + calc_crc = crc32(0, tmp_env1->data, ENV_SIZE); + crc1_ok = calc_crc == tmp_env1->crc; + printf("env_relocate_spec: crc1_ok=%d saved crc=0x%x calculated crc=0x%x flags=%d\n", -+ crc1_ok,calc_crc,tmp_env1->crc,tmp_env1->flags); ++ crc1_ok,tmp_env1->crc,calc_crc,tmp_env1->flags); + calc_crc = crc32(0, tmp_env2->data, ENV_SIZE); + crc2_ok = calc_crc == tmp_env2->crc; + printf("env_relocate_spec: crc2_ok=%d saved crc=0x%x calculated crc=0x%x flags=%d\n", -+ crc2_ok,calc_crc,tmp_env2->crc,tmp_env2->flags); ++ crc2_ok,tmp_env2->crc,calc_crc,tmp_env2->flags); if (!crc1_ok && !crc2_ok) { set_default_env("!bad CRC"); -- cgit v1.2.3 From 4d60d1a92e1aff03b2687317cd166e0e30c41243 Mon Sep 17 00:00:00 2001 From: John Klug Date: Tue, 11 Apr 2017 15:08:28 -0500 Subject: Need to add the asm files to u-boot include list --- recipes-bsp/u-boot/u-boot.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/recipes-bsp/u-boot/u-boot.inc b/recipes-bsp/u-boot/u-boot.inc index 869b142..ab718a6 100644 --- a/recipes-bsp/u-boot/u-boot.inc +++ b/recipes-bsp/u-boot/u-boot.inc @@ -67,6 +67,7 @@ do_install () { fi mkdir -p ${D}/usr/include/u-boot || true (cd ${S}/include;find . | cpio -pdum ${D}/usr/include/u-boot) + (cd ${S} ; rm ${D}/usr/include/u-boot/asm ; cd arch/arm/include ; find asm | cpio -pdum ${D}/usr/include/u-boot) } FILES_${PN} = "/boot ${sysconfdir}" -- cgit v1.2.3 From 649ca4f91935ac2843c661cd1ff437ee83effe3e Mon Sep 17 00:00:00 2001 From: John Klug Date: Tue, 11 Apr 2017 18:01:18 -0500 Subject: Start of deriving the environment from the u-boot package. --- .../u-boot-linux-utils/uboot_configure.patch | 18 +++---- .../multitech/u-boot-linux-utils/uboot_mac.patch | 55 +++++++++++++++------- recipes-bsp/multitech/u-boot-linux-utils_0.0.1.bb | 7 +-- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/recipes-bsp/multitech/u-boot-linux-utils/uboot_configure.patch b/recipes-bsp/multitech/u-boot-linux-utils/uboot_configure.patch index e7a7fe0..d8f5223 100644 --- a/recipes-bsp/multitech/u-boot-linux-utils/uboot_configure.patch +++ b/recipes-bsp/multitech/u-boot-linux-utils/uboot_configure.patch @@ -1,11 +1,11 @@ -commit 0de7b48ba5bfca360d7c1840e9415f8a8177eede +commit 591d0dab81465e5e0df5b5ba6b70e2ec74f25bbc Author: John Klug -Date: Fri Apr 7 16:33:13 2017 -0500 +Date: Tue Apr 11 17:35:38 2017 -0500 - Defaults for u-boot-linux-utils + debug turned on + Allow a DEFAULT ENV file, and get the MTD_SIZE from CONFIG_ENV_SIZE in uboot diff --git a/configure.in b/configure.in -index 8fdc9ef..85998a9 100644 +index 8fdc9ef..8f6a1db 100644 --- a/configure.in +++ b/configure.in @@ -15,12 +15,15 @@ required header missing])) @@ -16,13 +16,15 @@ index 8fdc9ef..85998a9 100644 +AC_DEFINE([DEBUG], 1, [set to 1 to enable debug]) AC_DEFINE([MTD_ENV1], "/dev/mtd3", [set to the first u-boot env mtd]) AC_DEFINE([MTD_ENV2], "/dev/mtd4", [set to the second (redundant) u-boot env mtd]) - AC_DEFINE([MTD_SIZE], 0x20000, [size of u-boot env mtd]) +-AC_DEFINE([MTD_SIZE], 0x20000, [size of u-boot env mtd]) -AC_DEFINE([DEFAULT_ENV], ["bootargs=mem=64M console=ttyS0,115200 root=/dev/mtdblock8 ro rootfstype=jffs2\0" "bootcmd=nboot.jffs2 ${loadaddr} 0 ${kernel_addr}; bootm ${loadaddr}\0" "bootdelay=3\0" "baudrate=115200\0" "ethaddr=00:D0:A0:02:0D:E1\0" "ipaddr=192.168.2.1\0" "serverip=192.168.2.2\0" "netmask=255.255.255.0\0" "hostname=AT91SAM9G20\0" "loadaddr=0x21400000\0" "kernel_addr=0x000A0000\0" "\0"] +-, [default env if corrupt]) + -+AC_DEFINE([DEFAULT_ENV], ["baudrate=115200\0" "bootargs=mem=256M console=ttyS0,115200 root=/dev/mtdblock8 ro rootfstype=jffs2\0" "bootcmd=nboot.jffs2 ${loadaddr} 0 ${kernel_addr}; bootm ${loadaddr}\0" "bootdelay=0\0" "ethact=macb0\0" "hostname=AT91SAM9G25\0" "ipaddr=192.168.2.1\0" "kernel_addr=0x200000\0" "loadaddr=0x22000000\0" "serverip=192.168.2.2\0" "netmask=255.255.255.0\0" "stderr=serial\0" "stdin=serial\0" "stdout=serial\0"] - , [default env if corrupt]) - +AC_DEFINE([MAC_PATH],["/sys/devices/platform/mts-io/mac-eth"], [MAC_PATH for defining ethaddr= in boot environment]) + ++AC_DEFINE_UNQUOTED([DEFAULT_ENV], ++ [$(cat ../DEFAULT_ENV.cfg | tr -d '\n')], ++ [default environment values]) + AC_OUTPUT([Makefile src/Makefile]) diff --git a/recipes-bsp/multitech/u-boot-linux-utils/uboot_mac.patch b/recipes-bsp/multitech/u-boot-linux-utils/uboot_mac.patch index 5b92f35..77f28a2 100644 --- a/recipes-bsp/multitech/u-boot-linux-utils/uboot_mac.patch +++ b/recipes-bsp/multitech/u-boot-linux-utils/uboot_mac.patch @@ -1,27 +1,50 @@ -commit de3ea4470a6da4c01bfff9377649324747c1e3c9 +commit afa8fc0d0b3d8ccde464ab207724491c7b732c3d Author: John Klug -Date: Mon Apr 10 12:16:08 2017 -0500 +Date: Tue Apr 11 17:58:15 2017 -0500 - Add MAC address in default environment and add clearenv functionality. + Derive MTD size from CONFIG_ENV_SIZE diff --git a/src/u_boot.c b/src/u_boot.c -index e240475..7eea5e9 100644 +index e240475..8c4fced 100644 --- a/src/u_boot.c +++ b/src/u_boot.c -@@ -36,6 +36,12 @@ +@@ -33,8 +33,25 @@ + #include + #include +- ++#include #include "u_boot.h" - ++static char *env_strings(void) ++{ ++ char *p; ++ int count; ++ static const char *bd = "bootdelay="; ++ count = strlen(bd); ++ count += snprintf(NULL,0,"%d",CONFIG_BOOTDELAY); ++ p = malloc(count); ++ snprintf(p,count,"%d",CONFIG_BOOTDELAY); ++ return p; ++} ++ + +#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) +@@ -46,7 +63,7 @@ static int tokcmp(const char *cmd, const char *pattern) { + } + + #define ENV_HEADER_SIZE (sizeof(uint32_t) + sizeof(uint8_t)) +-#define ENV_DATA_SIZE (MTD_SIZE - ENV_HEADER_SIZE) ++#define ENV_DATA_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE) + + struct environment { + uint32_t crc; +@@ -64,6 +81,8 @@ static int write_uboot_env(const char *device, struct environment *env) error("mtd_erase_all %s failed", device); return -1; } @@ -30,7 +53,7 @@ index e240475..7eea5e9 100644 fd = open(device, O_WRONLY); if (fd < 0) { -@@ -166,7 +174,7 @@ static int cmd_setenv(struct environment *env, int argc, char **argv) +@@ -166,7 +185,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] == '=') { @@ -39,7 +62,7 @@ index e240475..7eea5e9 100644 cp = next_var(var); while (*cp) { -@@ -213,7 +221,7 @@ static int cmd_setenv(struct environment *env, int argc, char **argv) +@@ -213,7 +232,7 @@ static int cmd_setenv(struct environment *env, int argc, char **argv) } env->crc = crc32(0, (uint8_t *) env->data, sizeof(env->data)); @@ -48,7 +71,7 @@ index e240475..7eea5e9 100644 env->flags = 0; tmp = write_uboot_env(MTD_ENV1, env); -@@ -238,7 +246,7 @@ static void print_version(const char *name) { +@@ -238,7 +257,7 @@ static void print_version(const char *name) { } static void usage(FILE *out) { @@ -57,7 +80,7 @@ index e240475..7eea5e9 100644 fprintf(out, "\n"); } -@@ -252,6 +260,7 @@ int main(int argc, char *argv[]) { +@@ -252,6 +271,7 @@ int main(int argc, char *argv[]) { struct environment *env2; uint32_t crc1_ok; uint32_t crc2_ok; @@ -65,7 +88,7 @@ index e240475..7eea5e9 100644 if (argc <= 1) { usage(stderr); -@@ -301,12 +310,18 @@ int main(int argc, char *argv[]) { +@@ -301,12 +321,18 @@ int main(int argc, char *argv[]) { error("read_uboot_env failed"); return 1; } @@ -87,7 +110,7 @@ index e240475..7eea5e9 100644 crc1_ok = 0; } -@@ -315,20 +330,64 @@ int main(int argc, char *argv[]) { +@@ -315,20 +341,64 @@ int main(int argc, char *argv[]) { error("read_uboot_env failed"); return 1; } @@ -157,7 +180,7 @@ index e240475..7eea5e9 100644 } else if (crc1_ok && !crc2_ok) { env = env1; } else if (!crc1_ok && crc2_ok) { -@@ -353,6 +412,9 @@ int main(int argc, char *argv[]) { +@@ -353,6 +423,9 @@ int main(int argc, char *argv[]) { err = cmd_printenv(env, argc, argv); } else if (!tokcmp(cmd, "setenv")) { err = cmd_setenv(env, argc, argv); 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 0d5f2dc..3d69336 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 @@ -6,17 +6,18 @@ LICENSE = "GPLv2" LIC_FILES_CHKSUM = "file://COPYING;md5=94d55d512a9ba36caa9b7df079bae19f" PR = "r3" -DEPENDS = "mtd-utils" +DEPENDS = "mtd-utils u-boot" # tag 0.0.1 SRCREV = "9c154405c2d01648f41c6a72bcc96f9865c4f07c" SRC_URI = "git://git.multitech.net/u-boot-linux-utils.git;protocol=git \ file://uboot_mac.patch \ - file://uboot_configure.patch" + file://uboot_configure.patch \ + file://DEFAULT_ENV.cfg" S = "${WORKDIR}/git" - +CFLAGS += "-idirafter ${STAGING_DIR_TARGET}/usr/include/u-boot -save-temps -MD" inherit autotools PARALLEL_MAKE = "" -- cgit v1.2.3 From 0da88426f7a78c477e7f3132e9a8e04621112e5a Mon Sep 17 00:00:00 2001 From: John Klug Date: Wed, 12 Apr 2017 09:11:00 -0500 Subject: Add DEFAULT_ENV for easily adding custom to the environment. --- recipes-bsp/multitech/u-boot-linux-utils/DEFAULT_ENV.cfg | 1 + 1 file changed, 1 insertion(+) create mode 100644 recipes-bsp/multitech/u-boot-linux-utils/DEFAULT_ENV.cfg diff --git a/recipes-bsp/multitech/u-boot-linux-utils/DEFAULT_ENV.cfg b/recipes-bsp/multitech/u-boot-linux-utils/DEFAULT_ENV.cfg new file mode 100644 index 0000000..261fc86 --- /dev/null +++ b/recipes-bsp/multitech/u-boot-linux-utils/DEFAULT_ENV.cfg @@ -0,0 +1 @@ +"ethact=macb0\0" "stderr=serial\0" "stdin=serial\0" "stdout=serial\0" -- cgit v1.2.3 From 6961cf49ca534aa612ebcf32b9fafa2abe52e31c Mon Sep 17 00:00:00 2001 From: John Klug Date: Wed, 12 Apr 2017 13:00:14 -0500 Subject: Parameters for environment defaults now come mostly from u-boot header files --- .../multitech/u-boot-linux-utils/uboot_c.patch | 283 +++++++++++++++++++++ .../u-boot-linux-utils/uboot_configure.patch | 16 +- .../multitech/u-boot-linux-utils/uboot_mac.patch | 192 -------------- recipes-bsp/multitech/u-boot-linux-utils_0.0.1.bb | 4 +- 4 files changed, 291 insertions(+), 204 deletions(-) create mode 100644 recipes-bsp/multitech/u-boot-linux-utils/uboot_c.patch delete mode 100644 recipes-bsp/multitech/u-boot-linux-utils/uboot_mac.patch diff --git a/recipes-bsp/multitech/u-boot-linux-utils/uboot_c.patch b/recipes-bsp/multitech/u-boot-linux-utils/uboot_c.patch new file mode 100644 index 0000000..33374dd --- /dev/null +++ b/recipes-bsp/multitech/u-boot-linux-utils/uboot_c.patch @@ -0,0 +1,283 @@ +commit 4099235d80474025bb86b75caddbb6c25f573d9b +Author: John Klug +Date: Wed Apr 12 12:50:36 2017 -0500 + + Parameters for defaults come mostly from u-boot header files + +diff --git a/src/u_boot.c b/src/u_boot.c +index e240475..9480471 100644 +--- a/src/u_boot.c ++++ b/src/u_boot.c +@@ -33,8 +33,16 @@ + #include + + #include +- ++#include + #include "u_boot.h" ++#include "mtd_erase_all.h" ++ ++#define XMK_STR(x) #x ++#define MK_STR(x) XMK_STR(x) ++ ++#define DUMMY_MAC "00:00:00:00:00:00" ++ ++#define EMPTY_CRC 0xf9137807 + + static int tokcmp(const char *cmd, const char *pattern) { + int len = strlen(cmd); +@@ -46,8 +54,10 @@ static int tokcmp(const char *cmd, const char *pattern) { + } + + #define ENV_HEADER_SIZE (sizeof(uint32_t) + sizeof(uint8_t)) +-#define ENV_DATA_SIZE (MTD_SIZE - ENV_HEADER_SIZE) ++#define ENV_DATA_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE) + ++#define DO_WRITE_ENV 1 ++#define SKIP_WRITE_ENV 0 + struct environment { + uint32_t crc; + uint8_t flags; +@@ -64,6 +74,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) { +@@ -144,7 +156,7 @@ static int cmd_printenv(struct environment *env, int argc, char **argv) + return true; + } + +-static int cmd_setenv(struct environment *env, int argc, char **argv) ++static int cmd_setenv(struct environment *env, int argc, char **argv, int do_write) + { + int tmp; + char *var; +@@ -166,7 +178,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,18 +225,19 @@ 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); +- if (tmp < 0) { +- dbg("write_uboot_env %s failed with %d", MTD_ENV1, tmp); +- } +- tmp = write_uboot_env(MTD_ENV2, env); +- if (tmp < 0) { +- dbg("write_uboot_env %s failed with %d", MTD_ENV1, tmp); ++ if(do_write == DO_WRITE_ENV) { ++ tmp = write_uboot_env(MTD_ENV1, env); ++ if (tmp < 0) { ++ dbg("write_uboot_env %s failed with %d", MTD_ENV1, tmp); ++ } ++ tmp = write_uboot_env(MTD_ENV2, env); ++ if (tmp < 0) { ++ dbg("write_uboot_env %s failed with %d", MTD_ENV1, tmp); ++ } + } +- + return true; + } + +@@ -238,7 +251,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 +265,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 +315,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 +335,130 @@ 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; ++ char *genarg[2]; ++ char number[128]; ++ ++ 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+1); ++ 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); ++ } ++ } ++ p[len] = 0; ++ genarg[0] = "ethaddr"; ++ genarg[1] = p; ++ if (cmd_setenv(env,2,genarg,SKIP_WRITE_ENV) == false) ++ exit(1); ++ free(p); ++ genarg[1] = number; ++ ++#ifdef CONFIG_BAUDRATE ++ genarg[0] = "baudrate"; ++ sprintf(number,"%lld",(long long)(CONFIG_BAUDRATE)); ++ if (cmd_setenv(env,2,genarg,SKIP_WRITE_ENV) == false) ++ exit(1); ++#endif ++#ifdef CONFIG_BOOTDELAY ++ genarg[0] = "bootdelay"; ++ sprintf(number,"%lld",(long long)(CONFIG_BOOTDELAY)); ++ if (cmd_setenv(env,2,genarg,SKIP_WRITE_ENV) == false) ++ exit(1); ++#endif ++#ifdef CONFIG_LOADADDR ++ genarg[0] = "loadaddr"; ++ sprintf(number,"0x%llx",(long long)(CONFIG_LOADADDR)); ++ if (cmd_setenv(env,2,genarg,SKIP_WRITE_ENV) == false) ++ exit(1); ++#endif ++#ifdef CONFIG_HOSTNAME ++ genarg[0] = "hostname"; ++ genarg[1] = MK_STR(CONFIG_HOSTNAME); ++ if (cmd_setenv(env,2,genarg,SKIP_WRITE_ENV) == false) ++ exit(1); ++#endif ++#ifdef CONFIG_IPADDR ++ genarg[0] = "ipaddr"; ++ genarg[1] = MK_STR(CONFIG_IPADDR); ++ if (cmd_setenv(env,2,genarg,SKIP_WRITE_ENV) == false) ++ exit(1); ++#endif ++#ifdef CONFIG_SERVERIP ++ genarg[0] = "serverip"; ++ genarg[1] = MK_STR(CONFIG_SERVERIP); ++ if (cmd_setenv(env,2,genarg,SKIP_WRITE_ENV) == false) ++ exit(1); ++#endif ++#ifdef CONFIG_NETMASK ++ genarg[0] = "netmask"; ++ genarg[1] = MK_STR(CONFIG_NETMASK); ++ if (cmd_setenv(env,2,genarg,SKIP_WRITE_ENV) == false) ++ exit(1); ++#endif ++#ifdef CONFIG_EXTRA_ENV_SETTINGS ++ p = env->data; ++ while((p = next_var(p)) && *p); ++ len = (p - env->data); ++ if (len + sizeof CONFIG_EXTRA_ENV_SETTINGS < ENV_DATA_SIZE) ++ memcpy(env->data + len,CONFIG_EXTRA_ENV_SETTINGS,sizeof CONFIG_EXTRA_ENV_SETTINGS); ++ else ++ fprintf(stderr,"Default memory settings overflow. Current size %d, CONFIG_EXTRA_ENV_SETTINGS size %d, Maximum %d\n", ++ len,sizeof CONFIG_EXTRA_ENV_SETTINGS,ENV_DATA_SIZE); ++#endif ++#ifdef CONFIG_BOOTARGS ++ genarg[0] = "bootargs"; ++ genarg[1] = CONFIG_BOOTARGS; ++ if (cmd_setenv(env,2,genarg,SKIP_WRITE_ENV) == false) ++ exit(1); ++#endif ++#ifdef CONFIG_BOOTCOMMAND ++ genarg[0] = "bootcmd"; ++ genarg[1] = CONFIG_BOOTCOMMAND; ++ if (cmd_setenv(env,2,genarg,SKIP_WRITE_ENV) == false) ++ exit(1); ++#endif ++ } 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) { +@@ -352,7 +482,10 @@ int main(int argc, char *argv[]) { + if (!tokcmp(cmd, "printenv")) { + err = cmd_printenv(env, argc, argv); + } else if (!tokcmp(cmd, "setenv")) { +- err = cmd_setenv(env, argc, argv); ++ err = cmd_setenv(env, argc, argv, DO_WRITE_ENV); ++ } 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_configure.patch b/recipes-bsp/multitech/u-boot-linux-utils/uboot_configure.patch index d8f5223..eb650a0 100644 --- a/recipes-bsp/multitech/u-boot-linux-utils/uboot_configure.patch +++ b/recipes-bsp/multitech/u-boot-linux-utils/uboot_configure.patch @@ -1,19 +1,15 @@ -commit 591d0dab81465e5e0df5b5ba6b70e2ec74f25bbc +commit cc5abf5a1ed0f0cc5487e8f87b8cf69c6b8173ea Author: John Klug -Date: Tue Apr 11 17:35:38 2017 -0500 +Date: Wed Apr 12 12:31:28 2017 -0500 - Allow a DEFAULT ENV file, and get the MTD_SIZE from CONFIG_ENV_SIZE in uboot + Remove debug diff --git a/configure.in b/configure.in -index 8fdc9ef..8f6a1db 100644 +index 8fdc9ef..0377375 100644 --- a/configure.in +++ b/configure.in -@@ -15,12 +15,15 @@ required header missing])) - - AC_CHECK_LIB([z], [crc32], [], AC_MSG_ERROR([libz is required])) - --AC_DEFINE([DEBUG], 0, [set to 1 to enable debug]) -+AC_DEFINE([DEBUG], 1, [set to 1 to enable debug]) +@@ -18,9 +18,12 @@ AC_CHECK_LIB([z], [crc32], [], AC_MSG_ERROR([libz is required])) + AC_DEFINE([DEBUG], 0, [set to 1 to enable debug]) AC_DEFINE([MTD_ENV1], "/dev/mtd3", [set to the first u-boot env mtd]) AC_DEFINE([MTD_ENV2], "/dev/mtd4", [set to the second (redundant) u-boot env mtd]) -AC_DEFINE([MTD_SIZE], 0x20000, [size of u-boot env mtd]) diff --git a/recipes-bsp/multitech/u-boot-linux-utils/uboot_mac.patch b/recipes-bsp/multitech/u-boot-linux-utils/uboot_mac.patch deleted file mode 100644 index 77f28a2..0000000 --- a/recipes-bsp/multitech/u-boot-linux-utils/uboot_mac.patch +++ /dev/null @@ -1,192 +0,0 @@ -commit afa8fc0d0b3d8ccde464ab207724491c7b732c3d -Author: John Klug -Date: Tue Apr 11 17:58:15 2017 -0500 - - Derive MTD size from CONFIG_ENV_SIZE - -diff --git a/src/u_boot.c b/src/u_boot.c -index e240475..8c4fced 100644 ---- a/src/u_boot.c -+++ b/src/u_boot.c -@@ -33,8 +33,25 @@ - #include - - #include -- -+#include - #include "u_boot.h" -+static char *env_strings(void) -+{ -+ char *p; -+ int count; -+ static const char *bd = "bootdelay="; -+ count = strlen(bd); -+ count += snprintf(NULL,0,"%d",CONFIG_BOOTDELAY); -+ p = malloc(count); -+ snprintf(p,count,"%d",CONFIG_BOOTDELAY); -+ return p; -+} -+ -+ -+#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); -@@ -46,7 +63,7 @@ static int tokcmp(const char *cmd, const char *pattern) { - } - - #define ENV_HEADER_SIZE (sizeof(uint32_t) + sizeof(uint8_t)) --#define ENV_DATA_SIZE (MTD_SIZE - ENV_HEADER_SIZE) -+#define ENV_DATA_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE) - - struct environment { - uint32_t crc; -@@ -64,6 +81,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 +185,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 +232,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 +257,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 +271,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 +321,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 +341,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 +423,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 3d69336..6135d5d 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 @@ -12,12 +12,12 @@ DEPENDS = "mtd-utils u-boot" SRCREV = "9c154405c2d01648f41c6a72bcc96f9865c4f07c" SRC_URI = "git://git.multitech.net/u-boot-linux-utils.git;protocol=git \ - file://uboot_mac.patch \ + file://uboot_c.patch \ file://uboot_configure.patch \ file://DEFAULT_ENV.cfg" S = "${WORKDIR}/git" -CFLAGS += "-idirafter ${STAGING_DIR_TARGET}/usr/include/u-boot -save-temps -MD" +CFLAGS += "-idirafter ${STAGING_DIR_TARGET}/usr/include/u-boot" inherit autotools PARALLEL_MAKE = "" -- cgit v1.2.3