裸机移植yaffs2文件系统(4)

/* wait for room in the tx FIFO */
 
    //while ((!(uart->UTRSTAT & 0x2)));
 
    while (uart->UFSTAT & (1<<14));
 
    uart->UTXH = c;
 
}
 
返回bootstrap_main()函数,调用mem_mallloc_init()函数初始化动态分配的存储区,为我们调用malloc()函数做好准备工作,如下:
 
void mem_malloc_init(ulong start, ulong size)
 
{
 
    mem_malloc_start = start;
 
    mem_malloc_end = start + size;
 
    mem_malloc_brk = start;
 
   
 
    memset((void *)mem_malloc_start, 0, size);
 
    printf("malloc memory space: 0x%lx~0x%lx\n", start, start+size);
 

 
函数返回,调用函数
 
ptr = (char *)malloc(MALLOC_SIZE);
 
其中MALLOC_SIZE定义在makefile函数,MALLOC_SIZE=0x100000。我们深入到malloc函数中去,如下
 
声明位置:yaffs2/common/malloc.h
 
#define mALLOc      malloc
 
Void_t* mALLOc(size_t);
 
定义位置:yaffs2/common/dlmalloc.c
 
代码量很大,不拷贝了。
 
返回bootstrap_main()函数,调用如下函数目的是测试动态分配到存储区域是否成功:
 
    strncpy(ptr, "Hello World!\n", MALLOC_SIZE);
 
    printf("Malloc address: %p, string: %s\n", ptr, ptr);
 
    free(ptr);
 
接着就到了测试yaffs2文件系统的阶段了。
 
#define YAFFSFS_MNT_POINT              "/nand"
 
yaffs_test(YAFFSFS_MNT_POINT);
 
hang:
 
    while(1)
 
        ;
 
    return 0;
 
}
 
其中yaffs_test()函数主要是通过创建文件或目录,并删除一些文件的功能来达到测试yaffs2文件系统是否移植成功,代码如下:
 
位置:与bootstrap_main()函数同处于一个位置。
 
void yaffs_test(const char *mountpt)
 
{
 
    yaffs_start_up();
 

yaffs_format(mountpt,0,0,0);
 

yaffs_mount(mountpt);
 
    printf("'%s' mounted\n", mountpt);
 

mkdir(mountpt, "foo");
 
    mkfile(mountpt, "foo/f1");
 

mkfile(mountpt, "foo/f2");
 
    mkfile(mountpt, "foo/f3");
 
    mkfile(mountpt, "foo/f4");
 

mkdir(mountpt, "bar");
 
    mkfile(mountpt, "bar/f1");
 
    ls(mountpt, NULL);
 

rm(mountpt, "foo/f4");
 
    rm(mountpt, "bar");
 
    ls(mountpt, NULL);
 

printf("unmount and remount\n\n");
 
   
 
    /*  Unmount/remount yaffs_trace_mask */
 
    yaffs_unmount(mountpt);
 
    yaffs_mount(mountpt);
 
    ls(mountpt, NULL);
 
}
 
其中yaffs_start_up()函数用来配置将要用到的设备,如下:
 
位置:yaffs2/yaffs2/yaffscfg2k.c
 
/* Configure the devices that will be used */
 
int yaffs_start_up(void)
 
{
 
    static int start_up_called = 0;
 

if(start_up_called)
 
        return 0;
 
    start_up_called = 1;
 

yaffs_devconfig(YAFFSFS_MNT_POINT, YAFFSFS_START_BLOCK, YAFFSFS_END_BLOCK);
 

/* Call the OS initialisation (eg. set up lock semaphore */
 
    yaffsfs_OSInitialisation();
 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/4be9678c1495a1085cea27b68226880c.html