#define structprint(a,b) printf(#b); printf("=%x\n",a->b);
#define structprint2(a,b) printf(#b); printf("=%x\n",a.b);
extern int nand_curr_device ;
extern nand_info_t nand_info[CONFIG_SYS_MAX_NAND_DEVICE];
打印nand信息
static void printnand()
{
// int crc1_ok = 0, crc2_ok = 0;
// env_t *ep, *tmp_env1, *tmp_env2;
// tmp_env1 = (env_t *)malloc(CONFIG_ENV_SIZE);
// tmp_env2 = (env_t *)malloc(CONFIG_ENV_SIZE);
// if ((tmp_env1 == NULL) || (tmp_env2 == NULL)) {
// puts("Can't allocate buffers for environment\n");
// free(tmp_env1);
// free(tmp_env2);
// set_default_env("!malloc() failed");
// return;
// }
//if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1))
printf("nand_curr_device=%d",nand_curr_device);
structprint2(nand_info[nand_curr_device],type);
structprint2(nand_info[nand_curr_device],flags);
structprint2(nand_info[nand_curr_device],size);
structprint2(nand_info[nand_curr_device],erasesize);
structprint2(nand_info[nand_curr_device],writesize);
structprint2(nand_info[nand_curr_device],oobsize);
structprint2(nand_info[nand_curr_device],oobavail);
structprint2(nand_info[nand_curr_device],name);
structprint2(nand_info[nand_curr_device],index);
structprint2(nand_info[nand_curr_device],numeraseregions);
}
typedef struct _ENTRY {
int used;
ENTRY entry;
} _ENTRY;
打印环境变量
static void pintenv()
{
char *res, *p;
size_t totlen;
int i, n;
ENTRY *ep ;
struct hsearch_data * htab =&env_htab;
for (i = 1, n = 0, totlen = 0; i <= htab->size; ++i) {
if (htab->table[i].used > 0) {
ep = &htab->table[i].entry;
printf("%s=%s\n",ep->key,ep->data);
}
}
}
打印板子信息
static void printbd()
{
int i;
bd_t *bd = gd->bd;
structprint(bd,bi_baudrate)
structprint(bd,bi_ip_addr)
structprint(bd,bi_arch_number)
structprint(bd,bi_boot_params)
for(i=0;i<CONFIG_NR_DRAM_BANKS;i++){
structprint(bd,bi_dram[i].start)
structprint(bd,bi_dram[i].size)
}
}
打印gd
static void printgd()
{
// bd_t *bd;
//unsigned long flags;
printnand();
pintenv();
printbd();
structprint(gd,flags);
//printf("gd->flags=%x\n",gd->flags);
#if 1
///* /* structprint(gd,flags);
//unsigned long baudrate;
structprint(gd,baudrate);
//unsigned long have_console; serial_init() was called
structprint(gd,have_console);
//unsigned long env_addr; Address of Environment struct
structprint(gd,env_addr);
//unsigned long env_valid; Checksum of Environment valid?
structprint(gd,env_valid);
//unsigned long fb_base; base address of frame buffer
structprint(gd,fb_base);
#ifdef CONFIG_FSL_ESDHC
//unsigned long sdhc_clk;
structprint(gd,sdhc_clk);
#endif
#ifdef CONFIG_AT91FAMILY
// "static data" needed by at91's clock.c
//unsigned long cpu_clk_rate_hz;
structprint(gd,cpu_clk_rate_hz);
//unsigned long main_clk_rate_hz;
structprint(gd,main_clk_rate_hz);
//unsigned long mck_rate_hz;
structprint(gd,mck_rate_hz);
//unsigned long plla_rate_hz;
structprint(gd,plla_rate_hz);
//unsigned long pllb_rate_hz;
structprint(gd,pllb_rate_hz);
//unsigned long at91_pllb_usb_init;
structprint(gd,at91_pllb_usb_init);
#endif
#ifdef CONFIG_ARM
// "static data" needed by most of timer.c on ARM platforms
//unsigned long timer_rate_hz;
structprint(gd,timer_rate_hz);
//unsigned long tbl;
structprint(gd,tbl);
//unsigned long tbu;
structprint(gd,tbu);
//unsigned long long timer_reset_value;
structprint(gd,timer_reset_value);
//unsigned long lastinc;
structprint(gd,lastinc);
#endif
#ifdef CONFIG_IXP425
//unsigned long timestamp;
structprint(gd,timestamp);
#endif
//unsigned long relocaddr; Start address of U-Boot in RAM
structprint(gd,relocaddr);
//phys_size_t ram_size; RAM size
structprint(gd,ram_size);
//unsigned long mon_len; monitor len
structprint(gd,mon_len);
//unsigned long irq_sp; irq stack pointer
structprint(gd,irq_sp);
//unsigned long start_addr_sp; start_addr_stackpointer
structprint(gd,start_addr_sp);
//unsigned long reloc_off;
structprint(gd,reloc_off);
#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
//unsigned long tlb_addr;
structprint(gd,tlb_addr);
#endif
//void **jt; jump table
structprint(gd,jt);
//char env_buf[32]; buffer for getenv() before reloc.
structprint(gd,env_buf);
#endif
}
int do_info (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
int i;
printgd();
return 0;
}
U_BOOT_CMD (info, 2, 1, do_info,
"loadable FPGA image support",
"[operation type] [device number] [image address] [image size]\n"
);
导出nand块的内容
static int nand_dump(nand_info_t *nand, ulong off)
{
int i;
u_char *datbuf, *oobbuf, *p;
static loff_t last;
printf("writesize:%x oobsize:%x",nand->writesize,nand->oobsize);
last = off;
datbuf = malloc(nand->writesize + nand->oobsize);
oobbuf = malloc(nand->oobsize);
if (!datbuf || !oobbuf) {
puts("No memory for page buffer\n");
return 1;
}
off = off * nand->writesize ;
loff_t addr = (loff_t) off;
struct mtd_oob_ops ops;
memset(&ops, 0, sizeof(ops));
ops.datbuf = datbuf;
ops.oobbuf = oobbuf; /* must exist, but oob data will be appended to ops.datbuf */
ops.len = nand->writesize;
ops.ooblen = nand->oobsize;
ops.mode = MTD_OOB_RAW;
i = nand->read_oob(nand, addr, &ops);
if (i < 0) {
printf("Error (%d) reading page %08lx\n", i, off);
free(datbuf);
free(oobbuf);
return 1;
}
printf("Page %08lx dump:\n", off);
i = nand->writesize >> 4;
p = datbuf;
while (i--) {
printf("\t%02x %02x %02x %02x %02x %02x %02x %02x"
" %02x %02x %02x %02x %02x %02x %02x %02x\n",
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
p[8], p[9], p[10], p[11], p[12], p[13], p[14],
p[15]);
p += 16;
}
puts("OOB:\n");
i = nand->oobsize >> 3;
while (i--) {
printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n",
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
p += 8;
}
free(datbuf);
free(oobbuf);
return 0;
}
char _ctoi(char c)
{
if(c>='0'&&c<='9')return c-'0';
if(c>='a'&&c<='f')return c-'a';
return 0;
}
int _atox(char* s)
{
unsigned int a=0;
unsigned int b=0;
int i=0;
while(s[i]){
a<<=4;
a|=_ctoi(s[i]);
i++;
if(i>=8)break;
}
return a;
}
nand dump
int do_ndump (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
int i;
if(argc<2){
printf("ERR: parameter < 2\n");
return 0;
}
i = _atox(argv[1]);
printf("i=%x",i);
nand_dump(&nand_info[nand_curr_device], i);
return 0;
}
U_BOOT_CMD (ndump, 2, 1, do_ndump,
"loadable FPGA image support",
"[operation type] [device number] [image address] [image size]\n"
);
内存导出
static void our_mdump(int memaddress)
{
size_t amount_loaded = 0;
size_t len;
int i;
int rval;
printf("our_ndump:%x",memaddress);
len = 512;
u_char* char_ptr=(u_char* )memaddress;
for(i=0;i<len;i++){
printf("%2.2x " ,char_ptr[i]);
if((i&0xf)==15)printf("\n");
}
}
int do_mdump (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
int i;
if(argc<2){
printf("ERR: parameter < 2\n");
return 0;
}
i = _atox(argv[1]);
our_mdump(i);
return 0;
}
U_BOOT_CMD (mdump, 2, 1, do_mdump,
"loadable FPGA image support",
"[operation type] [device number] [image address] [image size]\n"
);
static unsigned int read_cpsr (void)
{
unsigned long old,temp;
__asm__ __volatile__("mrs %0, cpsr\n"
: "=r" (old)
:
);
return old ;
}
static void write_p15_c1 (unsigned long value)
{
#ifdef MMU_DEBUG
printf ("write %08lx to p15/c1\n", value);
#endif
__asm__ __volatile__(
"mcr p15, 0, %0, c1, c0, 0 @ write it back\n"
:
: "r" (value)
: "memory");
}
static unsigned long read_p15_c1 (void)
{
unsigned long value;
__asm__ __volatile__(
"mrc p15, 0, %0, c1, c0, 0 @ read control reg\n"
: "=r" (value)
:
: "memory");
#ifdef MMU_DEBUG
printf ("p15/c1 is = %08lx\n", value);
#endif
return value;
}
static unsigned long read_p15_c2 (void)
{
unsigned long value;
__asm__ __volatile__(
"mrc p15, 0, %0, c2, c0, 0 @ read control reg\n"
: "=r" (value)
:
: "memory");
#ifdef MMU_DEBUG
printf ("p15/c1 is = %08lx\n", value);
#endif
return value;
}
打印分页内存
int do_pagetable (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
int i;
int tmp;
unsigned int data;
data = read_cpsr();
printf("cpsr=%x\n",data);
data = read_p15_c1();
printf("cp15 c1=%x\n",data);
data = read_p15_c2();
printf("cp15 c2=%x\n",data);
printf("uboot address:%x offset:%x\n",CONFIG_SYS_NAND_U_BOOT_START,CONFIG_SYS_NAND_U_BOOT_OFFS);
printf("nand page size:%x block size:%x oobsize:%x pagecount:%x \n",CONFIG_SYS_NAND_PAGE_SIZE,CONFIG_SYS_NAND_BLOCK_SIZE,CONFIG_SYS_NAND_OOBSIZE,CONFIG_SYS_NAND_PAGE_COUNT);
printf("sdram address:%x size:%x\n",PHYS_DRAM_1,PHYS_DRAM_1_SIZE);
printf("nand adress:%x\n",CONFIG_SYS_NAND_ADDR);
printf("sys memtest :%x-%x\n",CONFIG_SYS_MEMTEST_START,CONFIG_SYS_MEMTEST_END);
printf("sys load address:%x\n",CONFIG_SYS_LOAD_ADDR);
printf("sysram address:%x size:%x\n",SRAM0_START,SRAM0_SIZE);
return 0;
}
U_BOOT_CMD (page, 2, 1, do_pagetable,
"loadable FPGA image support",
"[operation type] [device number] [image address] [image size]\n"
);
nand擦除
int do_nanderaseall()
{
int i, ret = 0;
ulong addr;
loff_t off, size;
char *cmd, *s;
nand_info_t *nand;
#ifdef CONFIG_SYS_NAND_QUIET
int quiet = CONFIG_SYS_NAND_QUIET;
#else
int quiet = 0;
#endif
int dev = nand_curr_device;
/* at least two arguments please */
quiet = 0;
nand_erase_options_t opts;
/* "clean" at index 2 means request to write cleanmarker */
int clean = 0;
int o = clean ? 3 : 2;
int scrub = 0;
int part = 0;
int chip = 1;
int spread = 0;
int args = 0;
/*
* Don't allow missing arguments to cause full chip/partition
* erases -- easy to do accidentally, e.g. with a misspelled
* variable name.
*/
// *off = 0;
//*size = nand_info[*idx].size;
nand = &nand_info[dev];
memset(&opts, 0, sizeof(opts));
opts.offset = 0;
opts.length = nand->size;
opts.jffs2 = clean;
opts.quiet = quiet;
opts.spread = spread;
ret = nand_erase_opts(nand, &opts);
printf("%s\n", ret ? "ERROR" : "OK");
return ret == 0 ? 0 : 1;
}
int do_ndel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
do_nanderaseall();
return 0;
}
U_BOOT_CMD (ndel, 2, 1, do_ndel,
"loadable FPGA image support",
"[operation type] [device number] [image address] [image size]\n"
);
#endif