2002-09-18 12:49:44 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FLASH support
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2007-07-05 16:01:24 +00:00
|
|
|
#include <cfi_flash.h>
|
2005-08-07 23:03:24 +00:00
|
|
|
|
2002-09-18 12:49:44 +00:00
|
|
|
int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
2007-07-05 16:01:23 +00:00
|
|
|
struct memarea_info mem;
|
2002-09-18 12:49:44 +00:00
|
|
|
|
2007-07-05 16:01:23 +00:00
|
|
|
if (argc != 2) {
|
2002-09-18 12:49:44 +00:00
|
|
|
printf ("Usage:\n%s\n", cmdtp->usage);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-07-05 16:01:39 +00:00
|
|
|
|
2007-07-05 16:01:23 +00:00
|
|
|
if (spec_str_to_info(argv[1], &mem)) {
|
|
|
|
printf("-ENOPARSE\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2005-08-07 23:03:24 +00:00
|
|
|
|
2007-07-05 16:01:23 +00:00
|
|
|
if (!mem.device->driver) {
|
|
|
|
printf("This device has no driver\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!mem.device->driver->erase) {
|
|
|
|
printf("This device cannot be erased\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2005-08-07 23:03:24 +00:00
|
|
|
|
2007-07-05 16:01:40 +00:00
|
|
|
if(dev_erase(mem.device, mem.size, mem.start)) {
|
|
|
|
perror("erase");
|
|
|
|
return 1;
|
|
|
|
}
|
2007-07-05 16:01:39 +00:00
|
|
|
|
2007-07-05 16:01:23 +00:00
|
|
|
return 0;
|
2002-09-18 12:49:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
|
|
|
{
|
2007-07-05 16:01:23 +00:00
|
|
|
int p;
|
2002-09-18 12:49:44 +00:00
|
|
|
int rcode = 0;
|
2007-07-05 16:01:23 +00:00
|
|
|
struct memarea_info mem_info;
|
2006-04-01 11:41:03 +00:00
|
|
|
|
2002-09-18 12:49:44 +00:00
|
|
|
if (argc < 3) {
|
|
|
|
printf ("Usage:\n%s\n", cmdtp->usage);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-08-05 17:43:17 +00:00
|
|
|
if (strcmp(argv[1], "off") == 0) {
|
2002-09-18 12:49:44 +00:00
|
|
|
p = 0;
|
2003-08-05 17:43:17 +00:00
|
|
|
} else if (strcmp(argv[1], "on") == 0) {
|
2002-09-18 12:49:44 +00:00
|
|
|
p = 1;
|
2003-08-05 17:43:17 +00:00
|
|
|
} else {
|
2002-09-18 12:49:44 +00:00
|
|
|
printf ("Usage:\n%s\n", cmdtp->usage);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-07-05 16:01:39 +00:00
|
|
|
|
2007-07-05 16:01:23 +00:00
|
|
|
if (spec_str_to_info(argv[2], &mem_info)) {
|
|
|
|
printf ("-EPARSE\n");
|
2002-09-18 12:49:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-07-05 16:01:23 +00:00
|
|
|
// rcode = flash_sect_protect (p, addr_first, addr_last);
|
2002-09-18 12:49:44 +00:00
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
2003-06-27 21:31:46 +00:00
|
|
|
/**************************************************/
|
|
|
|
|
2003-07-01 21:06:45 +00:00
|
|
|
U_BOOT_CMD(
|
2007-07-05 16:01:23 +00:00
|
|
|
erase, 2, 0, do_flerase,
|
2003-06-27 21:31:46 +00:00
|
|
|
"erase - erase FLASH memory\n",
|
2007-07-05 16:01:23 +00:00
|
|
|
"write me\n"
|
2003-06-27 21:31:46 +00:00
|
|
|
);
|
|
|
|
|
2003-07-01 21:06:45 +00:00
|
|
|
U_BOOT_CMD(
|
|
|
|
protect, 4, 1, do_protect,
|
2003-06-27 21:31:46 +00:00
|
|
|
"protect - enable or disable FLASH write protection\n",
|
|
|
|
"on start end\n"
|
|
|
|
" - protect FLASH from addr 'start' to addr 'end'\n"
|
2005-07-21 09:45:50 +00:00
|
|
|
"protect on start +len\n"
|
|
|
|
" - protect FLASH from addr 'start' to end of sect "
|
|
|
|
"w/addr 'start'+'len'-1\n"
|
2003-06-27 21:31:46 +00:00
|
|
|
"protect on N:SF[-SL]\n"
|
|
|
|
" - protect sectors SF-SL in FLASH bank # N\n"
|
|
|
|
"protect on bank N\n - protect FLASH bank # N\n"
|
|
|
|
"protect on all\n - protect all FLASH banks\n"
|
|
|
|
"protect off start end\n"
|
|
|
|
" - make FLASH from addr 'start' to addr 'end' writable\n"
|
2005-07-21 09:45:50 +00:00
|
|
|
"protect off start +len\n"
|
|
|
|
" - make FLASH from addr 'start' to end of sect "
|
|
|
|
"w/addr 'start'+'len'-1 wrtable\n"
|
2003-06-27 21:31:46 +00:00
|
|
|
"protect off N:SF[-SL]\n"
|
|
|
|
" - make sectors SF-SL writable in FLASH bank # N\n"
|
|
|
|
"protect off bank N\n - make FLASH bank # N writable\n"
|
|
|
|
"protect off all\n - make all FLASH banks writable\n"
|
|
|
|
);
|