mirror of https://github.com/OpenIPC/firmware.git
Merge pull request #142 from widgetii/master
Fix U-Boot env autodiscovery patch for non-standard environmentspull/146/head
commit
c8a251eef6
|
@ -1,5 +1,5 @@
|
||||||
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
|
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
|
||||||
index 2a61a5d6f0..a008254a6a 100644
|
index 2a61a5d6f0..19f92e5cdd 100644
|
||||||
--- a/tools/env/fw_env.c
|
--- a/tools/env/fw_env.c
|
||||||
+++ b/tools/env/fw_env.c
|
+++ b/tools/env/fw_env.c
|
||||||
@@ -37,7 +37,11 @@
|
@@ -37,7 +37,11 @@
|
||||||
|
@ -24,30 +24,44 @@ index 2a61a5d6f0..a008254a6a 100644
|
||||||
rc = -1;
|
rc = -1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1725,6 +1730,91 @@ static int check_device_config(int dev)
|
@@ -1725,6 +1730,105 @@ static int check_device_config(int dev)
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
+#define CRC_SZ 4
|
+#define CRC_SZ 4
|
||||||
+// Assume env only size of 64Kb
|
+
|
||||||
+#define ENV_LEN 0x10000
|
+// By default use 0x10000 but then can be changed after detection
|
||||||
|
+static size_t env_len = 0x10000;
|
||||||
+
|
+
|
||||||
+// Detect U-Boot environment area offset
|
+// Detect U-Boot environment area offset
|
||||||
+static int uboot_detect_env(void *buf, size_t len) {
|
+static int uboot_detect_env(void *buf, size_t size, size_t erasesize) {
|
||||||
+ // Jump over memory by step
|
+ size_t possible_lens[] = {0x10000, 0x40000, 0x20000};
|
||||||
+ int scan_step = ENV_LEN;
|
|
||||||
+ int res = -1;
|
|
||||||
+
|
+
|
||||||
+ for (int baddr = 0; baddr < len; baddr += scan_step) {
|
+ // Jump over memory by step
|
||||||
|
+ int scan_step = erasesize;
|
||||||
|
+
|
||||||
|
+ for (int baddr = 0; baddr < size; baddr += scan_step) {
|
||||||
+ uint32_t expected_crc = *(int *)(buf + baddr);
|
+ uint32_t expected_crc = *(int *)(buf + baddr);
|
||||||
+ uint32_t crc = crc32(0, buf + baddr + CRC_SZ, ENV_LEN - CRC_SZ);
|
+
|
||||||
+ if (crc == expected_crc) {
|
+ for (int i = 0; i < sizeof(possible_lens) / sizeof(possible_lens[0]);
|
||||||
+ res = baddr;
|
+ i++) {
|
||||||
+ break;
|
+ if (possible_lens[i] + baddr > size)
|
||||||
|
+ continue;
|
||||||
|
+
|
||||||
|
+ uint32_t crc = crc32(0, buf + baddr + CRC_SZ, possible_lens[i] - CRC_SZ);
|
||||||
|
+
|
||||||
|
+#if 0
|
||||||
|
+ printf("Detecting at %#x with len %#x CRC is %#x ~ %#x\n", baddr,
|
||||||
|
+ possible_lens[i], crc, expected_crc);
|
||||||
|
+#endif
|
||||||
|
+ if (crc == expected_crc) {
|
||||||
|
+ env_len = possible_lens[i];
|
||||||
|
+ return baddr;
|
||||||
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ return res;
|
+ return -1;
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static char *open_mtdblock(int i, int *fd, uint32_t size, int flags) {
|
+static char *open_mtdblock(int i, int *fd, uint32_t size, int flags) {
|
||||||
|
@ -70,7 +84,7 @@ index 2a61a5d6f0..a008254a6a 100644
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static char dev[80];
|
+static char dev[80];
|
||||||
+static int detect_env() {
|
+static int detect_env(void) {
|
||||||
+ FILE *fp;
|
+ FILE *fp;
|
||||||
+ char name[80];
|
+ char name[80];
|
||||||
+ int i, es, ee;
|
+ int i, es, ee;
|
||||||
|
@ -93,14 +107,14 @@ index 2a61a5d6f0..a008254a6a 100644
|
||||||
+ i, &blockfd, mtd.size, MAP_POPULATE /* causes read-ahead on the file */);
|
+ i, &blockfd, mtd.size, MAP_POPULATE /* causes read-ahead on the file */);
|
||||||
+ if (!addr)
|
+ if (!addr)
|
||||||
+ return res;
|
+ return res;
|
||||||
+ int off = uboot_detect_env(addr, mtd.size);
|
+ int off = uboot_detect_env(addr, mtd.size, mtd.erasesize);
|
||||||
+ close(blockfd);
|
+ close(blockfd);
|
||||||
+ if (off != -1) {
|
+ if (off != -1) {
|
||||||
+ DEVNAME(0) = dev;
|
+ DEVNAME(0) = dev;
|
||||||
+ DEVOFFSET(0) = off;
|
+ DEVOFFSET(0) = off;
|
||||||
+ ENVSIZE(0) = ENV_LEN;
|
+ ENVSIZE(0) = env_len;
|
||||||
+ DEVESIZE(0) = mtd.erasesize;
|
+ DEVESIZE(0) = mtd.erasesize;
|
||||||
+ ENVSECTORS(0) = 1;
|
+ ENVSECTORS(0) = mtd.size / mtd.erasesize;
|
||||||
+ res = 1;
|
+ res = 1;
|
||||||
+ break;
|
+ break;
|
||||||
+ }
|
+ }
|
||||||
|
@ -116,7 +130,7 @@ index 2a61a5d6f0..a008254a6a 100644
|
||||||
static int parse_config(struct env_opts *opts)
|
static int parse_config(struct env_opts *opts)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@@ -1735,9 +1825,11 @@ static int parse_config(struct env_opts *opts)
|
@@ -1735,9 +1839,11 @@ static int parse_config(struct env_opts *opts)
|
||||||
#if defined(CONFIG_FILE)
|
#if defined(CONFIG_FILE)
|
||||||
/* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */
|
/* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */
|
||||||
if (get_config(opts->config_file)) {
|
if (get_config(opts->config_file)) {
|
||||||
|
|
Loading…
Reference in New Issue