From: Piotr Dymacz Date: Tue, 28 Apr 2015 12:28:40 +0000 (+0200) Subject: Remove fake, software FLASH protection command and related function... we really... X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ab21014ff06565e57ab20cc4b2e9de7e8d6d96b7;p=oweals%2Fu-boot_mod.git Remove fake, software FLASH protection command and related function... we really don't need it and all it does is just increase final image size --- diff --git a/u-boot/board/ar7240/common/ar7240_flash.c b/u-boot/board/ar7240/common/ar7240_flash.c index 610b401..71e46c1 100644 --- a/u-boot/board/ar7240/common/ar7240_flash.c +++ b/u-boot/board/ar7240/common/ar7240_flash.c @@ -73,7 +73,6 @@ static void flash_set_geom(int size, int sector_count, int sector_size){ for(i = 0; i < info->sector_count; i++){ info->start[i] = CFG_FLASH_BASE + (i * info->sector_size); - info->protect[i] = 0; } } diff --git a/u-boot/common/cmd_custom.c b/u-boot/common/cmd_custom.c index 626b082..5e8b701 100644 --- a/u-boot/common/cmd_custom.c +++ b/u-boot/common/cmd_custom.c @@ -228,10 +228,6 @@ int do_default_env(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]){ end_addr = flash_sect_addr + len - 1; - if(flash_sect_protect(0, flash_sect_addr, end_addr)){ - return(1); - } - /* erase whole env sector */ if(flash_sect_erase(flash_sect_addr, end_addr)){ rcode = 1; diff --git a/u-boot/common/cmd_flash.c b/u-boot/common/cmd_flash.c index cb24011..d5eff2e 100644 --- a/u-boot/common/cmd_flash.c +++ b/u-boot/common/cmd_flash.c @@ -383,171 +383,6 @@ int flash_sect_erase(ulong addr_first, ulong addr_last){ 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; isector_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", @@ -562,29 +397,4 @@ 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 */ diff --git a/u-boot/common/env_flash.c b/u-boot/common/env_flash.c index adabd2e..e49b600 100644 --- a/u-boot/common/env_flash.c +++ b/u-boot/common/env_flash.c @@ -138,23 +138,8 @@ int saveenv(void){ 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){ @@ -163,19 +148,12 @@ int saveenv(void){ } 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))) || @@ -184,11 +162,8 @@ int saveenv(void){ 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; @@ -212,10 +187,6 @@ 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 */ @@ -268,20 +239,10 @@ int saveenv(void){ 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){ @@ -291,9 +252,6 @@ int saveenv(void){ //debug("done\n"); } - /* try to re-protect */ - (void)flash_sect_protect(1, flash_sect_addr, end_addr); - return(rcode); } @@ -320,9 +278,7 @@ void env_relocate_spec(void){ 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){ @@ -330,9 +286,7 @@ void env_relocate_spec(void){ 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){ diff --git a/u-boot/common/flash.c b/u-boot/common/flash.c index 8faf2c7..aa51071 100644 --- a/u-boot/common/flash.c +++ b/u-boot/common/flash.c @@ -78,18 +78,6 @@ int flash_write(char *src, ulong addr, ulong cnt){ return(ERR_INVAL); } - for(info = info_first; info <= info_last; ++info){ - ulong b_end = info->start[0] + info->size; /* bank end addr */ - short s_end = info->sector_count - 1; - for(i = 0; i < info->sector_count; ++i){ - ulong e_addr = (i == s_end) ? b_end : info->start[i + 1]; - - if((end >= info->start[i]) && (addr < e_addr) && (info->protect[i] != 0)){ - return(ERR_PROTECTED); - } - } - } - /* finally write data to flash */ for(info = info_first; info <= info_last && cnt > 0; ++info){ ulong len; @@ -121,9 +109,6 @@ void flash_perror(int err){ case ERR_NOT_ERASED: puts("## Error: FLASH not erased\n"); break; - case ERR_PROTECTED: - puts("## Error: can't write to protected sectors\n"); - break; case ERR_INVAL: puts("## Error: outside available FLASH\n"); break; diff --git a/u-boot/include/flash.h b/u-boot/include/flash.h index f63a360..7fab7f7 100644 --- a/u-boot/include/flash.h +++ b/u-boot/include/flash.h @@ -35,7 +35,6 @@ typedef struct { ushort sector_count; /* number of erase units */ ulong flash_id; /* combined device & manufacturer code */ ulong start[CFG_MAX_FLASH_SECT]; /* physical sector start addresses */ - uchar protect[CFG_MAX_FLASH_SECT]; /* sector protection status */ } flash_info_t; @@ -43,7 +42,6 @@ typedef struct { extern unsigned long flash_init (void); extern int flash_erase(flash_info_t *, int, int); extern int flash_sect_erase(ulong addr_first, ulong addr_last); -extern int flash_sect_protect(int flag, ulong addr_first, ulong addr_last); /* common/flash.c */ extern int flash_write(char *, ulong, ulong);