blob: 7d68e9554465f13eca392ca034cc6f024eba90cb [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*******************************************************************************
2 * Copyright (C) 2016, ZIXC Corporation.
3 *
4 * File Name:cmd_erase.c
5 * File Mark:
6 * Description:
7 * Others:
8 * Version: 1.0
9 * Author: zangxiaofeng
10 * Date: 2013-3-15
11 * History 1:
12 * Date:
13 * Version:
14 * Author:
15 * Modification:
16 * History 2:
17 ********************************************************************************/
18
19
20/****************************************************************************
21* Include files
22****************************************************************************/
23#include <common.h>
24#include <command.h>
25#include <net.h>
26#include <jffs2/load_kernel.h>
27#include "downloader_config.h"
28#include "downloader_nand.h"
29#include "downloader_serial.h"
30#include "errno.h"
31#include "mmc.h"
32
33/****************************************************************************
34* Function Definitions
35****************************************************************************/
36
37extern partition_table_t * g_partition_table;
38extern char *tsp_console_buffer;
39
40
41/*******************************************************************************
42 * Function:do_erase
43 * Description:
44 * Parameters:
45 * Input:
46 *
47 * Output:
48 *
49 * Returns:
50 *
51 *
52 * Others:
53 ********************************************************************************/
54int do_erase(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
55{
56 partition_entry_t *part = NULL;
57 char *par=NULL;
58 char *ack=tsp_console_buffer;
59 int ret = 0;
60 int type = 0;
61
62 if(argc<2)
63 {
64 return cmd_usage(cmdtp);
65 }
66 type = read_boot_flashtype();
67 par = argv[1]; /*erase cmd*/
68 if((strcmp(par,"all") == 0) || (strcmp(par,"raw") == 0))
69 {
70 if((type == IF_TYPE_NAND)||(type == IF_TYPE_SPI_NAND))
71 {
72 ret = downloader_nand_eraseall();
73 }
74 else if(type == IF_TYPE_NOR)
75 {
76 ret = downloader_nor_eraseall();
77 }
78
79 if(ret == 0)
80 {
81 sprintf(ack,"OKAY");
82 downloader_serial_write(ack, strlen(ack)+1);
83 return 0;
84 }
85 else
86 {
87 sprintf(ack,"FAIL NAND ERASE");
88 downloader_serial_write(ack, strlen(ack)+1);
89 return ENOSYS; /* Function not implemented */
90 }
91 }
92
93 if(strcmp(par,"auto") == 0)
94 {
95 if((type == IF_TYPE_NAND)||(type == IF_TYPE_SPI_NAND))
96 {
97 ret = downloader_nand_erase_auto();
98 }
99 else if(type == IF_TYPE_NOR)
100 {
101 ret = downloader_nor_erase_auto();
102 }
103
104 if(ret == 0)
105 {
106 sprintf(ack,"OKAY");
107 downloader_serial_write(ack, strlen(ack)+1);
108 return 0;
109 }
110 else
111 {
112 sprintf(ack,"FAIL NAND ERASE");
113 downloader_serial_write(ack, strlen(ack)+1);
114 return ENOSYS; /* Function not implemented */
115 }
116 }
117
118 part = downloader_get_part(par);
119 if(part == NULL)
120 {
121 sprintf(ack,"FAIL INVALID PARTITION");
122 downloader_serial_write(ack, strlen(ack)+1);
123 return EINVAL; /* Invalid argument */
124 }
125
126 if((type == IF_TYPE_NAND)||(type == IF_TYPE_SPI_NAND))
127 {
128 ret = downloader_nand_erase(part,part->part_size);
129 }
130 else if(type == IF_TYPE_NOR)
131 {
132 ret = downloader_nor_erase(part, part->part_size);
133 }
134
135
136 if(ret == 0)
137 {
138 sprintf(ack,"OKAY");
139 downloader_serial_write(ack, strlen(ack)+1);
140 return 0;
141 }
142 else
143 {
144 sprintf(ack,"FAIL NAND ERASE");
145 downloader_serial_write(ack, strlen(ack)+1);
146 return ENOSYS; /* Function not implemented */
147 }
148}
149
150U_BOOT_CMD(
151 erase, CONFIG_SYS_MAXARGS, 0, do_erase,
152 "Erase nand: erase [partition]",
153 ""
154);
155
156