RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / ui / ui_test_flash.c
blob2473e1e96255142492ee1c718c623e31437c13e4
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * Flash Test commands File: ui_test_flash.c
5 *
6 * Some commands to test the flash device interface.
7 *
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
9 *
10 *********************************************************************
12 * Copyright 2000,2001,2002,2003
13 * Broadcom Corporation. All rights reserved.
15 * This software is furnished under license and may be used and
16 * copied only in accordance with the following terms and
17 * conditions. Subject to these conditions, you may download,
18 * copy, install, use, modify and distribute modified or unmodified
19 * copies of this software in source and/or binary form. No title
20 * or ownership is transferred hereby.
22 * 1) Any source code used, modified or distributed must reproduce
23 * and retain this copyright notice and list of conditions
24 * as they appear in the source file.
26 * 2) No right is granted to use any trade name, trademark, or
27 * logo of Broadcom Corporation. The "Broadcom Corporation"
28 * name may not be used to endorse or promote products derived
29 * from this software without the prior written permission of
30 * Broadcom Corporation.
32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44 * THE POSSIBILITY OF SUCH DAMAGE.
45 ********************************************************************* */
48 #include "lib_types.h"
49 #include "lib_string.h"
50 #include "lib_queue.h"
51 #include "lib_malloc.h"
52 #include "lib_printf.h"
54 #include "cfe_iocb.h"
55 #include "cfe_device.h"
56 #include "cfe_console.h"
57 #include "cfe_devfuncs.h"
58 #include "cfe_timer.h"
59 #include "cfe_ioctl.h"
61 #include "cfe_error.h"
63 #include "ui_command.h"
65 int ui_init_flashtestcmds(void);
67 static int ui_cmd_flashtest(ui_cmdline_t *cmd,int argc,char *argv[]);
68 //static int ui_cmd_readnvram(ui_cmdline_t *cmd,int argc,char *argv[]);
69 //static int ui_cmd_erasenvram(ui_cmdline_t *cmd,int argc,char *argv[]);
71 int ui_init_flashtestcmds(void)
73 cmd_addcmd("show flash",
74 ui_cmd_flashtest,
75 NULL,
76 "Display information about a flash device.",
77 "show flash [-sectors]",
78 "-sectors;Display sector information");
82 return 0;
86 static char *flashtypes[] = {
87 "Unknown","SRAM","ROM","Flash"
91 static int ui_cmd_flashtest(ui_cmdline_t *cmd,int argc,char *argv[])
93 flash_info_t info;
94 int fd;
95 int retlen;
96 int res = 0;
97 int idx;
98 flash_sector_t sector;
99 nvram_info_t nvraminfo;
100 char *devname;
101 int showsectors;
103 devname = cmd_getarg(cmd,0);
104 if (!devname) return ui_showusage(cmd);
106 showsectors = cmd_sw_isset(cmd,"-sectors");
108 fd = cfe_open(devname);
109 if (fd < 0) {
110 ui_showerror(fd,"Could not open flash device %s",devname);
111 return fd;
114 res = cfe_ioctl(fd,IOCTL_FLASH_GETINFO,(uint8_t *) &info,sizeof(flash_info_t),&retlen,0);
115 if (res == 0) {
116 printf("FLASH: Base %016llX size %08X type %02X(%s) flags %08X\n",
117 info.flash_base,info.flash_size,info.flash_type,flashtypes[info.flash_type],
118 info.flash_flags);
120 else {
121 printf("FLASH: Could not determine flash information\n");
124 res = cfe_ioctl(fd,IOCTL_NVRAM_GETINFO,(uint8_t *) &nvraminfo,sizeof(nvram_info_t),&retlen,0);
125 if (res == 0) {
126 printf("NVRAM: Offset %08X Size %08X EraseFlg %d\n",
127 nvraminfo.nvram_offset,nvraminfo.nvram_size,nvraminfo.nvram_eraseflg);
129 else {
130 printf("NVRAM: Not supported by this flash\n");
133 if (showsectors && (info.flash_type == FLASH_TYPE_FLASH)) {
134 printf("Flash sector information:\n");
136 idx = 0;
137 for (;;) {
138 sector.flash_sector_idx = idx;
139 res = cfe_ioctl(fd,IOCTL_FLASH_GETSECTORS,(uint8_t *) &sector,sizeof(flash_sector_t),&retlen,0);
140 if (res != 0) {
141 printf("ioctl error\n");
142 break;
144 if (sector.flash_sector_status == FLASH_SECTOR_INVALID) break;
145 printf(" Sector %d offset %08X size %d\n",
146 sector.flash_sector_idx,
147 sector.flash_sector_offset,
148 sector.flash_sector_size);
149 idx++;
153 cfe_close(fd);
154 return 0;