return(rcode);
}
-#ifdef CFG_ENV_IS_IN_FLASH
-int do_protect(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){
- flash_info_t *info;
- ulong bank, addr_first, addr_last;
- int i, p, n, sect_first, sect_last;
- int rcode = 0;
-
- if(argc < 3){
-#ifdef CFG_LONGHELP
- if(cmdtp->help != NULL){
- printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help);
- } else {
- printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
- }
-#else
- printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
-#endif
- return(1);
- }
-
- if(strcmp(argv[1], "off") == 0){
- p = 0;
- } else if(strcmp(argv[1], "on") == 0){
- p = 1;
- } else {
-#ifdef CFG_LONGHELP
- if(cmdtp->help != NULL){
- printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help);
- } else {
- printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
- }
-#else
- printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
-#endif
- return(1);
- }
-
- if(strcmp(argv[2], "all") == 0){
- for(bank=1; bank <= CFG_MAX_FLASH_BANKS; ++bank){
- info = &flash_info[bank-1];
-
- if(info->flash_id == FLASH_UNKNOWN){
- continue;
- }
-
- printf("%sProtecting FLASH bank #%ld\n", p ? "" : "Un-", bank);
-
- for(i = 0; i < info->sector_count; ++i){
- info->protect[i] = p;
- }
- }
-
- return(rcode);
- }
-
- if((n = abbrev_spec(argv[2], &info, §_first, §_last)) != 0){
- if(n < 0){
- puts("## Error: bad sector spec\n");
- return(1);
- }
-
- printf("%sProtecting FLASH sectors: %d-%d in bank #%d\n", p ? "" : "Un-", sect_first, sect_last, (info-flash_info)+1);
-
- for(i = sect_first; i <= sect_last; i++){
- info->protect[i] = p;
- }
-
- return(rcode);
- }
-
- if(argc != 4){
-#ifdef CFG_LONGHELP
- if(cmdtp->help != NULL){
- printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help);
- } else {
- printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
- }
-#else
- printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
-#endif
- return(1);
- }
-
- if(strcmp(argv[2], "bank") == 0){
- bank = simple_strtoul(argv[3], NULL, 16);
-
- if((bank < 1) || (bank > CFG_MAX_FLASH_BANKS)){
- printf("## Error: only FLASH banks #1...#%d supported\n", CFG_MAX_FLASH_BANKS);
- return(1);
- }
-
- printf("%sProtecting FLASH bank #%ld\n", p ? "" : "Un-", bank);
- info = &flash_info[bank-1];
-
- if(info->flash_id == FLASH_UNKNOWN){
- puts("## Error: missing or unknown FLASH type\n");
- return(1);
- }
-
- for(i=0; i<info->sector_count; ++i){
- info->protect[i] = p;
- }
-
- return(rcode);
- }
-
- if(addr_spec(argv[2], argv[3], &addr_first, &addr_last) < 0){
- printf("## Error: bad address format\n");
- return(1);
- }
-
- if(addr_first >= addr_last){
-#ifdef CFG_LONGHELP
- if(cmdtp->help != NULL){
- printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help);
- } else {
- printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
- }
-#else
- printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
-#endif
- return(1);
- }
-
- rcode = flash_sect_protect(p, addr_first, addr_last);
- return(rcode);
-}
-
-int flash_sect_protect(int p, ulong addr_first, ulong addr_last){
- flash_info_t *info;
- ulong bank;
- int s_first[CFG_MAX_FLASH_BANKS], s_last[CFG_MAX_FLASH_BANKS];
- int protected, i;
- int planned;
- int rcode;
-
- rcode = flash_fill_sect_ranges( addr_first, addr_last, s_first, s_last, &planned );
-
- protected = 0;
-
- if(planned && (rcode == 0)){
- for(bank=0,info=&flash_info[0]; bank < CFG_MAX_FLASH_BANKS; ++bank, ++info){
- if(info->flash_id == FLASH_UNKNOWN){
- continue;
- }
-
- if(s_first[bank] >= 0 && s_first[bank] <= s_last[bank]){
- //debug("%sProtecting sectors %d..%d in bank %ld\n", p ? "" : "Un-", s_first[bank], s_last[bank], bank+1);
- protected += s_last[bank] - s_first[bank] + 1;
-
- for(i=s_first[bank]; i<=s_last[bank]; ++i){
- info->protect[i] = p;
- }
- }
- }
- //debug("%sProtected %d sectors\n", p ? "" : "Un-", protected);
- } else if(rcode == 0){
- puts("## Error: start and/or end address not on sector boundary\n");
- rcode = 1;
- }
-
- return(rcode);
-}
-#endif /* ifdef CFG_ENV_IS_IN_FLASH */
-
/**************************************************/
U_BOOT_CMD(erase, 3, 1, do_flerase, "erase FLASH memory\n",
"erase all\n"
"\t- erase all FLASH banks\n");
-#ifdef CFG_ENV_IS_IN_FLASH
-U_BOOT_CMD(protect, 4, 1, do_protect, "enable or disable FLASH write protection\n",
- "start end\n"
- "\t- protect FLASH from addr 'start' to addr 'end'\n"
- "protect start +len\n"
- "\t- protect FLASH from addr 'start' to end of sect w/addr 'start'+'len'-1\n"
- "protect on N:SF[-SL]\n"
- "\t- protect sectors SF-SL in FLASH bank #N\n"
- "protect on bank N\n"
- "\t- protect FLASH bank #N\n"
- "protect on all\n"
- "\t- protect all FLASH banks\n"
- "protect off start end\n"
- "\t- make FLASH from addr 'start' to addr 'end' writable\n"
- "protect off start +len\n"
- "\t- make FLASH from addr 'start' to end of sect w/addr 'start'+'len'-1 writable\n"
- "protect off N:SF[-SL]\n"
- "\t- make sectors SF-SL writable in FLASH bank #N\n"
- "protect off bank N\n"
- "\t- make FLASH bank #N writable\n"
- "protect off all\n"
- "\t- make all FLASH banks writable\n"
-);
-#endif /* ifdef CFG_ENV_IS_IN_FLASH */
-
#endif /* CFG_CMD_FLASH */
char flag = OBSOLETE_FLAG, new_flag = ACTIVE_FLAG;
#if CFG_ENV_SECT_SIZE > CFG_ENV_SIZE
ulong up_data = 0;
-#endif
-
- //debug("Protect off %08lX ... %08lX\n", (ulong)flash_addr, end_addr);
-
- if(flash_sect_protect(0, (ulong)flash_addr, end_addr)){
- goto Done;
- }
-
- //debug("Protect off %08lX ... %08lX\n", (ulong)flash_addr_new, end_addr_new);
- if(flash_sect_protect(0, (ulong)flash_addr_new, end_addr_new)){
- goto Done;
- }
-
-#if CFG_ENV_SECT_SIZE > CFG_ENV_SIZE
up_data = (end_addr_new + 1 - ((long)flash_addr_new + CFG_ENV_SIZE));
- //debug ("Data to save 0x%x\n", up_data);
if(up_data){
if((saved_data = malloc(up_data)) == NULL){
}
memcpy(saved_data, (void *)((long)flash_addr_new + CFG_ENV_SIZE), up_data);
- //debug("Data (start 0x%x, len 0x%x) saved at 0x%x\n", (long)flash_addr_new + CFG_ENV_SIZE, up_data, saved_data);
}
#endif
- //debug("Erasing Flash...");
- //debug(" %08lX ... %08lX ...", (ulong)flash_addr_new, end_addr_new);
-
if(flash_sect_erase((ulong)flash_addr_new, end_addr_new)){
goto Done;
}
- //debug("Writing to Flash... ");
- //debug(" %08lX ... %08lX ...", (ulong)&(flash_addr_new->data), sizeof(env_ptr->data)+(ulong)&(flash_addr_new->data));
-
if((rc = flash_write((char *)env_ptr->data, (ulong)&(flash_addr_new->data), sizeof(env_ptr->data))) ||
(rc = flash_write((char *)&(env_ptr->crc), (ulong)&(flash_addr_new->crc), sizeof(env_ptr->crc))) ||
(rc = flash_write(&flag, (ulong)&(flash_addr->flags), sizeof(flash_addr->flags))) ||
goto Done;
}
- //debug("done\n");
-
#if CFG_ENV_SECT_SIZE > CFG_ENV_SIZE
if(up_data){ /* restore the rest of sector */
- //debug("Restoring the rest of data to 0x%x len 0x%x\n", (long)flash_addr_new + CFG_ENV_SIZE, up_data);
if(flash_write(saved_data, (long)flash_addr_new + CFG_ENV_SIZE, up_data)){
flash_perror(rc);
goto Done;
free(saved_data);
}
- /* try to re-protect */
- (void)flash_sect_protect(1, (ulong)flash_addr, end_addr);
- (void)flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new);
-
return(rc);
}
#endif /* CMD_SAVEENV */
end_addr = flash_sect_addr + len - 1;
- //debug("Protect off %08lX ... %08lX\n", (ulong)flash_sect_addr, end_addr);
-
- if(flash_sect_protect(0, flash_sect_addr, end_addr)){
- return(1);
- }
-
- //debug("Erasing Flash...");
-
if(flash_sect_erase(flash_sect_addr, end_addr)){
return(1);
}
- //debug("Writing to Flash... ");
-
rc = flash_write((char *)env_buffer, flash_sect_addr, len);
if(rc != 0){
//debug("done\n");
}
- /* try to re-protect */
- (void)flash_sect_protect(1, flash_sect_addr, end_addr);
-
return(rcode);
}
gd->env_valid = 2;
- flash_sect_protect(0, (ulong)flash_addr_new, end_addr_new);
flash_write(&flag, (ulong)&(flash_addr_new->flags), sizeof(flash_addr_new->flags));
- flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new);
}
if(flash_addr->flags != ACTIVE_FLAG && (flash_addr->flags & ACTIVE_FLAG) == ACTIVE_FLAG){
gd->env_valid = 2;
- flash_sect_protect(0, (ulong)flash_addr, end_addr);
flash_write(&flag, (ulong)&(flash_addr->flags), sizeof(flash_addr->flags));
- flash_sect_protect(1, (ulong)flash_addr, end_addr);
}
if(gd->env_valid == 2){