void env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) char buf[CONFIG_ENV_SIZE]; struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); u32 offset; if (init_mmc_for_env(mmc)) { use_default(); return; } if(mmc_get_env_addr(mmc, &offset)) { use_default(); return ; } if (read_env(mmc, CONFIG_ENV_SIZE, offset, buf)) { use_default(); return; } env_import(buf, 1); #endif }
static void flash_env_relocate_spec(int workmode) { #if !defined(ENV_IS_EMBEDDED) char buf[CONFIG_ENV_SIZE]; u32 start; if((workmode & WORK_MODE_PRODUCT) && (!(workmode & WORK_MODE_UPDATE))) { flash_use_efex_env(); } else { start = sunxi_partition_get_offset_byname(CONFIG_SUNXI_ENV_PARTITION); if(!start){ printf("fail to find part named %s\n", CONFIG_SUNXI_ENV_PARTITION); use_default(); return; } if(!sunxi_flash_read(start, CONFIG_ENV_SIZE/512, buf)) { use_default(); return; } env_import(buf, 1); } #endif }
/* * The legacy NAND code saved the environment in the first NAND device i.e., * nand_dev_desc + 0. This is also the behaviour using the new NAND code. */ void env_relocate_spec_nand(void) { #if !defined(ENV_IS_EMBEDDED) size_t total; int ret, i; u_char *data; data = (u_char*)malloc(CFG_ENV_SIZE); total = CFG_ENV_SIZE; for (i = 0; i < CFG_MAX_NAND_DEVICE; i++) { if (nand_scan(&nand_info[i], 1) == 0) { ret = nand_read(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)data); env_ptr = data; if (ret || total != CFG_ENV_SIZE) return use_default(); if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); } else { printf("no devices available\n"); return use_default(); } } /* */ #endif /* ! ENV_IS_EMBEDDED */ }
void env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) struct block_dev_desc_t *sata = NULL; int i = 0; if (sata_curr_device == -1) { if (sata_initialize()) return 1; sata_curr_device = CONFIG_SATA_ENV_DEV; } if (sata_curr_device >= CONFIG_SYS_SATA_MAX_DEVICE) { printf("Unknown SATA(%d) device for environment!\n", sata_curr_device); return 1; } sata = sata_get_dev(sata_curr_device); if (read_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, env_ptr)) return use_default(); if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); gd->env_valid = 1; #endif }
void env_relocate_spec (void) { #if !defined(ENV_IS_EMBEDDED) int crc1_ok = 0, crc2_ok = 0; env_t *tmp_env1, *tmp_env2; tmp_env1 = (env_t *) malloc(CONFIG_ENV_SIZE); tmp_env2 = (env_t *) malloc(CONFIG_ENV_SIZE); if ((tmp_env1 == NULL) || (tmp_env2 == NULL)) { puts("Can't allocate buffers for environment\n"); free (tmp_env1); free (tmp_env2); return use_default(); } if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1)) puts("No Valid Environment Area Found\n"); if (readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2)) puts("No Valid Reundant 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); if(!crc1_ok && !crc2_ok) { free(tmp_env1); free(tmp_env2); return use_default(); } else if(crc1_ok && !crc2_ok) gd->env_valid = 1; else if(!crc1_ok && crc2_ok) gd->env_valid = 2; else { /* both ok - check serial */ if(tmp_env1->flags == 255 && tmp_env2->flags == 0) gd->env_valid = 2; else if(tmp_env2->flags == 255 && tmp_env1->flags == 0) gd->env_valid = 1; else if(tmp_env1->flags > tmp_env2->flags) gd->env_valid = 1; else if(tmp_env2->flags > tmp_env1->flags) gd->env_valid = 2; else /* flags are equal - almost impossible */ gd->env_valid = 1; } free(env_ptr); if(gd->env_valid == 1) { env_ptr = tmp_env1; free(tmp_env2); } else { env_ptr = tmp_env2; free(tmp_env1); } #endif /* ! ENV_IS_EMBEDDED */ }
/* * The legacy NAND code saved the environment in the first NAND device i.e., * nand_dev_desc + 0. This is also the behaviour using the new NAND code. */ void env_relocate_spec (void) { #if !defined(ENV_IS_EMBEDDED) int ret; ret = readenv(CONFIG_ENV_OFFSET, (u_char *) env_ptr); if (ret) return use_default(); if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); #endif /* ! ENV_IS_EMBEDDED */ }
/* * The legacy NAND code saved the environment in the first NAND device i.e., * nand_dev_desc + 0. This is also the behaviour using the new NAND code. */ void env_relocate_spec (void) { #if !defined(ENV_IS_EMBEDDED) ulong total; int ret; total = CFG_ENV_SIZE; ret = nand_read(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr); if (ret || total != CFG_ENV_SIZE) return use_default(); if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); #endif /* ! ENV_IS_EMBEDDED */ }
void env_relocate_spec (void) { #if !defined(ENV_IS_EMBEDDED) int ret, total; ret = nand_rw(nand_dev_desc + 0, NANDRW_READ | NANDRW_JFFS2, CFG_ENV_OFFSET, CFG_ENV_SIZE, &total, (u_char*)env_ptr); if (ret || total != CFG_ENV_SIZE) return use_default(); if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); #endif /* ! ENV_IS_EMBEDDED */ }
void env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) block_dev_desc_t *sata = NULL; char buf[CONFIG_ENV_SIZE]; int ret; if (sata_curr_device == -1) { if (sata_initialize()) return; sata_curr_device = CONFIG_SATA_ENV_DEV; } if (sata_curr_device >= CONFIG_SYS_SATA_MAX_DEVICE) { printf("Unknown SATA(%d) device for environment!\n", sata_curr_device); return; } sata = sata_get_dev(sata_curr_device); if (read_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, buf)) return use_default(); ret = env_import(buf, 1); if (ret) gd->env_valid = 1; #endif }
void env_relocate_spec(void) { #if defined(CONFIG_SMDKC100) | defined(CONFIG_SMDKC110) | defined(CONFIG_S5P6442) if (INF_REG3_REG == 1) env_relocate_spec_onenand(); else if (INF_REG3_REG == 2) env_relocate_spec_nand(); else if (INF_REG3_REG == 3) env_relocate_spec_movinand(); else if (INF_REG3_REG == 4) env_relocate_spec_nor(); else use_default(); #elif !defined(CONFIG_SMDK6440) if (INF_REG3_REG >= 2 && INF_REG3_REG <= 6) env_relocate_spec_nand(); else if (INF_REG3_REG == 0 || INF_REG3_REG == 7) env_relocate_spec_movinand(); else if (INF_REG3_REG == 1) env_relocate_spec_onenand(); else printf("Unknown boot device\n"); #else if (INF_REG3_REG >= 3 && INF_REG3_REG <= 6) env_relocate_spec_nand(); else if (INF_REG3_REG == 0 || INF_REG3_REG == 1 || INF_REG3_REG == 7) env_relocate_spec_movinand(); #endif }
void env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); if (init_mmc_for_env(mmc)) return; if (read_env(mmc, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, env_ptr)) return use_default(); if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); gd->env_valid = 1; #endif }
/* * The legacy NAND code saved the environment in the first NAND device i.e., * nand_dev_desc + 0. This is also the behaviour using the new NAND code. */ void env_relocate_spec (void) { #if !defined(ENV_IS_EMBEDDED) ulong total; int ret; #if defined(CFG_ENV_OFFSET_OOB) struct mtd_info *mtd = &nand_info[0]; struct nand_chip *this = mtd->priv; int buf_len; uint8_t *buf; buf_len = (1 << this->bbt_erase_shift); buf_len += (buf_len >> this->page_shift) * mtd->oobsize; buf = malloc(buf_len); if (!buf) return; nand_read_raw(mtd, buf, 0, mtd->oobblock, mtd->oobsize); if (buf[mtd->oobblock + 8 + 0] == 'E' && buf[mtd->oobblock + 8 + 1] == 'N' && buf[mtd->oobblock + 8 + 2] == 'V' && buf[mtd->oobblock + 8 + 3] == '0') { CFG_ENV_OFFSET = *((unsigned long *) &buf[mtd->oobblock + 8 + 4]); /* fall through to the normal environment reading code below */ free(buf); puts("Found Environment offset in OOB..\n"); } else { free(buf); return use_default(); } #endif total = CFG_ENV_SIZE; ret = nand_read(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr); if (ret || total != CFG_ENV_SIZE) return use_default(); if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); #endif /* ! ENV_IS_EMBEDDED */ }
void env_relocate_spec (void) { #if !defined(ENV_IS_EMBEDDED) ulong total; int crc1_ok = 0, crc2_ok = 0; env_t *tmp_env1, *tmp_env2; total = CFG_ENV_SIZE; tmp_env1 = (env_t *) malloc(CFG_ENV_SIZE); tmp_env2 = (env_t *) malloc(CFG_ENV_SIZE); nand_read(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*) tmp_env1); nand_read(&nand_info[0], CFG_ENV_OFFSET_REDUND, &total, (u_char*) tmp_env2); crc1_ok = (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc); crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc); if(!crc1_ok && !crc2_ok) return use_default(); else if(crc1_ok && !crc2_ok) gd->env_valid = 1; else if(!crc1_ok && crc2_ok) gd->env_valid = 2; else { /* both ok - check serial */ if(tmp_env1->flags == 255 && tmp_env2->flags == 0) gd->env_valid = 2; else if(tmp_env2->flags == 255 && tmp_env1->flags == 0) gd->env_valid = 1; else if(tmp_env1->flags > tmp_env2->flags) gd->env_valid = 1; else if(tmp_env2->flags > tmp_env1->flags) gd->env_valid = 2; else /* flags are equal - almost impossible */ gd->env_valid = 1; } free(env_ptr); if(gd->env_valid == 1) { env_ptr = tmp_env1; free(tmp_env2); } else { env_ptr = tmp_env2; free(tmp_env1); } #endif /* ! ENV_IS_EMBEDDED */ }
void env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) char buf[CONFIG_ENV_SIZE]; unsigned long offset; struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); if (init_mmc_for_env(mmc)) { use_default(); return; } offset = find_mmc_env_offset(mmc); if (read_env(mmc, CONFIG_ENV_SIZE, offset, buf)) { use_default(); return; } env_import(buf, 1); #endif }
void env_relocate_spec(void) { #if defined(CONFIG_SMDKC210)|| defined(CONFIG_SMDKV310) if (INF_REG3_REG == 1) env_relocate_spec_onenand(); else if (INF_REG3_REG == 2) env_relocate_spec_nand(); else if (INF_REG3_REG == 3) env_relocate_spec_movinand(); else use_default(); #endif }
/* * The legacy NAND code saved the environment in the first NAND device i.e., * nand_dev_desc + 0. This is also the behaviour using the new NAND code. */ void env_relocate_spec (void) { #if !defined(ENV_IS_EMBEDDED) int ret, crc; ret = readenv(CONFIG_ENV_OFFSET, (u_char *) env_ptr); if (ret) { puts ("read enviroment failed\n"); use_default(); if (ret == 2) saveenv(); return; } crc = crc32(0, env_ptr->data, ENV_SIZE); if (crc != env_ptr->crc) { printf("calculate crc %x read crc %x\n", crc, env_ptr->crc); //puts ("bad CRC for enviroment\n"); return use_default(); } #endif /* ! ENV_IS_EMBEDDED */ }
void env_relocate_spec_movinand(void) { #if !defined(ENV_IS_EMBEDDED) uint *magic = (uint*)(PHYS_SDRAM_1); if ((0x24564236 != magic[0]) || (0x20764316 != magic[1])) { movi_read_env(virt_to_phys((ulong)env_ptr)); } if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); #endif /* ! ENV_IS_EMBEDDED */ }
void env_relocate_spec_onenand(void) { struct mtd_info *onenand; /* the following commands operate on the current device */ if (onenand_curr_device < 0 || onenand_curr_device >= CFG_MAX_ONENAND_DEVICE || !onenand_info[onenand_curr_device].name) { puts("\nno devices available\n"); return 1; } onenand = &onenand_info[onenand_curr_device]; #if !defined(ENV_IS_EMBEDDED) size_t total; int ret, i; u_char *data; data = (u_char*)malloc(CFG_ENV_SIZE); total = CFG_ENV_SIZE; for (i = 0; i < CFG_MAX_NAND_DEVICE; i++) { if (onenand_scan(&onenand_info[i], 1) == 0) { ret = onenand_read(onenand, CFG_ENV_OFFSET, &total, (u_char*)data); env_ptr = data; if (ret || total != CFG_ENV_SIZE) return use_default(); if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); } else { printf("no devices available\n"); return use_default(); } } /* */ #endif /* ! ENV_IS_EMBEDDED */ }
void env_relocate_spec_movinand(void) { #if !defined(ENV_IS_EMBEDDED) #if defined(CONFIG_CMD_MOVINAND) uint *magic = (uint*)(PHYS_SDRAM_1); if ((0x24564236 != magic[0]) || (0x20764316 != magic[1])) { #if !defined(CONFIG_S5P_MSHC) mmc_init(find_mmc_device(0)); movi_read_env(virt_to_phys((ulong)env_ptr)); #endif } if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); #endif /* CONFIG_CMD_MOVINAND */ #endif /* ! ENV_IS_EMBEDDED */ }
void env_relocate_spec_nor(void) { #if !defined(ENV_IS_EMBEDDED) size_t total; int ret, i; u_char *env_dst, *env_src; env_src = (u_char *)(CFG_FLASH_BASE + CFG_ENV_OFFSET); env_dst = (u_char *)malloc(CFG_ENV_SIZE); total = CFG_ENV_SIZE; memcpy(env_dst, env_src, total); env_ptr = env_dst; if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); #endif }
void env_relocate_spec_nor(void) { use_default(); }
void env_relocate_spec_onenand(void) { #if defined(CONFIG_CMD_ONENAND) use_default(); #endif }
/* * The legacy NAND code saved the environment in the first NAND device i.e., * nand_dev_desc + 0. This is also the behaviour using the new NAND code. */ void env_relocate_spec (void) { #if !defined(ENV_IS_EMBEDDED) //YWDRIVER_MODI 2010/3/5 d48zm modify #if 0 int ret; int blockstart = -1; ulong erasesize_blockalign = nand_info[0].erasesize; u_char* data_ptr = (u_char*)env_ptr; ssize_t offset = CFG_ENV_OFFSET; ssize_t envlen = CFG_ENV_SIZE; ulong readlen = erasesize_blockalign; ulong checklen = erasesize_blockalign; ssize_t boundbegin = CFG_ENV_OFFSET + YW_CFG_NAND_ENV_BOUND - erasesize_blockalign; while ((envlen > 0) && (offset <= boundbegin)){ if (envlen < erasesize_blockalign){ checklen = envlen; readlen = envlen; } /* * new eraseblock, check for bad block(s). Stay in the * loop to be sure if the offset changes because of * a bad block, that the next block that will be * written to is also checked. Thus avoiding errors if * the block(s) after the skipped block(s) is also bad * (number of blocks depending on the blockalign */ while (blockstart != (offset & (~erasesize_blockalign+1))) { blockstart = offset & (~erasesize_blockalign+1); ret = nand_block_isbad(&nand_info[0], offset); if (ret < 0) { printf("Bad block check failed\n"); return 1; } if (ret == 1) { offset = blockstart + erasesize_blockalign; printf("\rBad block at 0x%lx " "in erase block from " "0x%x will be skipped\n", (long) offset, blockstart); } } ret = nand_read(&nand_info[0], offset, &readlen, data_ptr); if (ret || readlen != checklen) return use_default(); envlen -= readlen; data_ptr += readlen; offset += readlen; } if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); #else ulong total; int ret; total = CFG_ENV_SIZE; ret = nand_read(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr); if (ret || total != CFG_ENV_SIZE) return use_default(); if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); #endif //YWDRIVER_MODI 2010/3/5 d48zm modify end #endif /* ! ENV_IS_EMBEDDED */ }
void env_relocate_spec_onenand(void) { use_default(); }