已经是N个月以前的东西了,但还是贴出来记录一下把。
当时的好奇心,在UBOOT中加入了YAFFS
问题很多,但是可以视觉上感受一下。在uboot中加入yaffs的感觉,更主要的是当时
想更清楚的了解一下yaffs的架构。。 是天生为nand为存在的。
PS:
1,根本不算是在 UBOOT中支持yaffs系统。只是能运行。
2,需要uboot中nand部分代码支持。
3,只要是应用了nand中的一些函数,来了解一下yaffs和
nand物理结构之间的关系。
1.你要下载yaffs1的代码。不是yaffs2哦.我是把它放在uboot/fa/yaffs下面。
当然要修改makefile
yaffs文件列表如下:
devextras.h yaffs_ecc.h yaffs_flashif.h yaffs_guts.h yaffscfg.h yaffsfs.h
yaffsinterface.h ydirectenv.h yportenv.h cmd_yaffs.c
mkyaffsimage.c yaffs_ecc.c yaffs_flashif.c
yaffs_guts.c
yaffscfg.c yaffsfs.c
2命令:
你要下cmd结构体从其名字大概你就猜出来了。
如下:
ystart 。。初始化一下把,挂载
yend 。。释放
yfs ls/cdir document_name ..列出当前文件夹下文件/进入子文件夹(不太确定了。)
有兴趣和耐心的你可以看看我当时丑陋的代码
3.在common中加入文件cmd_yaffs.c
#include
#include
#include
#include
#include
extern struct nand_chip nand_dev_desc[1];
extern int curr_device;
extern int nand_erase(struct nand_chip* nand, size_t ofs, size_t len, int clean);
extern int nand_rw (struct nand_chip* nand, int cmd,
size_t start, size_t len,
size_t * retlen, u_char * buf);
extern int nand_write_oob(struct nand_chip* nand, size_t ofs, size_t len,size_t * retlen, const u_char * buf);
extern int nand_read_oob(struct nand_chip* nand, size_t ofs, size_t len,size_t * retlen, u_char * buf);
#define SHOW_N_COL 60
/*for path*/
unsigned char curdir[64];
char * rootdir="/flash/";
int level=1;
/*for op*/
yaffs_DIR *pdir=NULL;
struct yaffs_dirent *pdirent=NULL;
void do_yaffs_init (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
yaffs_StartUp();
yaffs_mount(rootdir);
//psildir=yaffs_opendir(rootdir);
printf("now mount node: %s \n",rootdir);
memset(curdir,0,64);
memcpy(curdir,rootdir,10);
printf("now CurDir ==[%s]\n",curdir);
/*
while(pdir=yaffs_readdir(psildir))
{
printf("%s ",pdir->d_name);
i++;
if(i>k)
{
printf("\n");
k=k+4;
}
}
yaffs_mkdir("/flash/jmpsil",O_RDWR);
pdir=NULL;
while(pdir=yaffs_readdir(psildir))
{
printf("**%s...",pdir->d_name);
i++;
if(i>k)
{
printf("\n");
k=k+4;
}
}
*/
//yaffs_closedir(psildir);
//yaffs_unmount(pt);
}
U_BOOT_CMD(
ystart, 1, 0, do_yaffs_init,
"yaffs_init\n",
);
void do_yaffs_end(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
yaffs_unmount(rootdir);
}
U_BOOT_CMD(
yend, 1, 0, do_yaffs_end,
"yaffs_init\n",
);
void do_yaffs_com(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
switch (argc) {
case 0:
case 1:
printf("Usage:\n Cread write read files or dir If you hope\n");
return 1;
case 2:
if (strcmp(argv[1],"ls") == 0) {
int i=0;
int k=4;
pdir=yaffs_opendir(curdir);
printf("file:\n");
while(pdirent=yaffs_readdir(pdir))
{
printf("%s ",pdirent->d_name);
i++;
if(i>k)
{
printf("\n");
k=k+4;
}
}
printf("\n");//range uboot>
return 0;
} else if (strcmp(argv[1],"curdir") == 0) {
printf("CurDir:\n %s\n",curdir);
return 0;
} else if (strcmp(argv[1],"..") == 0) {
if(level>2)
{
int le,m;
char *pt;
le=strlen(curdir);
if(curdir[le-1]!='/')
printf("path is wrong\n");
for(m=le-2;m>6;m--)
{
if(curdir[m]=='/')
break;
}
printf("m=== %d\n",m);
pt=(char *)malloc(m+1);
memcpy(pt,curdir,m+1);
memset(curdir,0,64);
memcpy(curdir,pt,m+1);
curdir[m+1]='\0';
printf("path %s\n",curdir);
level--;
}
else if(level==1)
{
printf("Warnning: Being top catalog\n");
}else if(level==2)
{
memset(curdir,0,64);
memcpy(curdir,rootdir,10);
level=1;
}
return 0;
}
printf("please try other comand\n");
return 1;
case 3:
if (strcmp(argv[1],"cdir") == 0) {
int i,j,k;
char *pt;
printf("name size is : %d\n",strlen(argv[2]) );
printf("curdir size if :%d\n",strlen(curdir) );
i=strlen(argv[2]);
j=strlen(curdir);
k=i+j;
pt=(char *)malloc(k+1);
memcpy(pt,curdir,j);
memcpy(pt+j,argv[2],i);
pt[i+j]='\0';
printf("k=== %d\n",k);
printf("new dir path : %s ...len : %d\n",pt,strlen(pt));
yaffs_mkdir(pt,O_RDWR);
free(pt);
return 0;
} else if (strcmp(argv[1],"ind") == 0) {
int i,j;
i=strlen(argv[2]);
j=strlen(curdir);
memcpy(&curdir[j],argv[2],i );
level++;
curdir[i+j]='/';
curdir[i+j+1]='\0';
printf("now change Curdir To: %s\n",curdir);
return 0;
} else if (strcmp(argv[1],"ddir") == 0) {
int i,j;
char *pt;
i=strlen(curdir);
j=strlen(argv[2]);
pt=(char *)malloc(j+i+1);
memcpy(pt,curdir,i);
memcpy(pt+i,argv[2],j);
pt[i+j]='\0';
yaffs_rmdir(pt);
free(pt);
return 0;
}
default:
printf("this is default\n");
}
}
U_BOOT_CMD(
yfs, 4, 0, do_yaffs_com,
"yaffs_init\n",
);
/*lsmem add size */
void mem_show(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
unsigned long cn,i,k;
k=0;
unsigned long tmp=0;
ulong addr =simple_strtoul(argv[1], NULL, 16);
ulong size =simple_strtoul(argv[2], NULL, 16);
unsigned long *pt=NULL;
printf("addr: 0x %x\n",addr);
printf("size: 0x %x\n",size);
pt=(unsigned long *)addr;
printf("pt: : 0x %x\n",pt);
cn=size/4;
for(i=0;i{
//printf("%08x", *(pt+i) );
printf("%08x", *(pt+i) );
/*
if((k==0))
{
tmp=(((*(pt+i))&0xf<<28)|((*(pt+i))&0xf00<<16)|((*(pt+i))&0xf0000<<4)|((*(pt+i))&0xf000000>>8));
k=4;
}
else if((k==4))
{
tmp=tmp+(((*(pt+i))&0xf<<12)|((*(pt+i))&0xf00)|((*(pt+i))&0xf0000>>12)|((*(pt+i))&0xf000000>>24));
k=8;
}
if(k==8)
{
printf("%08x", *(pt+i));
k=0;
tmp=0;
}
*/
}
}
U_BOOT_CMD(
lsmem, 4, 0, mem_show,
"show mem\n",
);
void ls_oob(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
unsigned long addr;
unsigned long leng;
unsigned long block=32*512;
int cn;
unsigned char buf[16];
unsigned long total;
unsigned char bb[16]={1,2,3,4,5,6,7,8,9,0,1,1,2,3,2,3};
unsigned char res[16]={255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255};
switch (argc) {
case 4:
if(strcmp(argv[1],"init")==0){
//printf("init\n");
unsigned long ad;
ad = simple_strtoul(argv[2], NULL, 16);
leng = simple_strtoul(argv[3], NULL, 16);
int i,j;
cn=leng/block;
printf("ad: 0x%x lenth:0x %x \n",ad,leng);
for(i=0;i {
addr=i*block+ad;
nand_write_oob(nand_dev_desc + curr_device,addr, 16, (size_t *)&total,(u_char*)bb);
}
}else if(strcmp(argv[1],"resum")==0){
printf("resum\n");
unsigned long ad;
ad = simple_strtoul(argv[2], NULL, 16);
leng = simple_strtoul(argv[3], NULL, 16);
int i,j;
cn=leng/block;
printf("ad: 0x%x lenth:0x %x \n",ad,leng);
printf("res[1]==[%x]\n",res[1]);
for(i=0;i {
addr=i*block+ad;
nand_write_oob(nand_dev_desc + curr_device,addr, 16, (size_t *)&total,(u_char*)res);
}
}
break;
case 3:
addr = simple_strtoul(argv[1], NULL, 16);
leng = simple_strtoul(argv[2], NULL, 16);
cn=leng/block;
printf("addr:0x%x lenth:0x%x Nblock :%d \n",addr,leng,cn);
int i,j;
unsigned long ad;
total=0;
for(i=0;i {
ad=i*block+addr;
memset(buf,0,16);
printf("");
nand_read_oob(nand_dev_desc + curr_device,ad, 16, (size_t *)&total,(u_char*)buf);
for(j=0;j<16;j++)
{
if(buf[j]!=0xff)
printf("%d : %d .......%d\n",i,j,buf[j]);
}
if(total!=16)
printf("%d get oob is fail\n",i);
total=0;
}
break;
default:
printf("this is a default\n");
}
printf("over\n");
}
void oob_set(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
unsigned char bb[16]={1,2,3,4,5,6,7,8,9,0,1,1,2,3,2,3};
unsigned char br[16]={255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255};
int total;
unsigned long addr;
int i;
unsigned long ad=0x1100000;
unsigned long leng=100000;
unsigned long block=32*512;
int cn=leng/block;
for(i=0;i {
addr=i*block+ad;
nand_write_oob(nand_dev_desc + curr_device,addr, 16, (size_t *)&total,(u_char*)bb);
}
}
U_BOOT_CMD(
setoob, 4, 0, oob_set,
"ls oob\n",
);
void oob_res(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
unsigned char bb[16]={255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255};
int total;
unsigned long addr;
int i;
unsigned long ad=0x1100000;
unsigned long leng=100000;
unsigned long block=32*512;
int cn=leng/block;
printf("resume oob \n");
for(i=0;i {
addr=i*block+ad;
nand_write_oob(nand_dev_desc + curr_device,addr, 16, (size_t *)&total,(u_char*)bb);
if(total!=16)
printf("Nblock :%d set fail\n",i);
}
}
U_BOOT_CMD(
resoob, 4, 0, oob_res,
"ls oob\n",
);
U_BOOT_CMD(
oob, 4, 0, ls_oob,
"ls oob\n",
);