设为首页 加入收藏

TOP

裸机移植yaffs2文件系统(四)
2014-11-24 03:17:17 来源: 作者: 【 】 浏览:16
Tags:裸机 移植 yaffs2 文件 系统
>ULCON = 0x3;

/*

* tx=level,rx=edge,disable timeout int.,enable rx error int.,

* normal,interrupt or polling

*/

uart->UCON = (1<<8) | (1<<2) | (1<<0);


// uart->UMCON = 0x1; /* RTS up */


s3c2440_set_baudrate(baudrate, index);


return (0);

}

设置波特率函数s3c2440_set_baudrate()

void s3c2440_set_baudrate(unsigned int baudrate, int index)

{

struct s3c2440_uart *uart = s3c2440_get_base_uart(index);

unsigned int reg = 0;

int i;

reg = s3c2440_get_pclk() / (16 * baudrate) - 1;


uart->UBRDIV = reg;

for (i = 0; i < 100; i++);

}

返回到bootstrap_main()函数中去,看下printf()函数如何将打印信息通过串口显示出来。

#define CFG_PBSIZE 1024 /* Print Buffer Size */

void printf(const char *fmt, ...)

{

va_list args;

uint i;

char printbuffer[CFG_PBSIZE];


va_start(args, fmt);


/* For this to work, printbuffer must be larger than

* anything we ever want to print.

*/

i = vsprintf(printbuffer, fmt, args);

va_end(args);


console_serial_puts(printbuffer);

}

调用函数console_serial_puts()函数,如下:

#define console_serial_puts(s) s3c2440_serial_puts(s, CONSOLE_SERIAL)

void s3c2440_serial_puts(const char *s, int index)

{

while (*s)

{

if (*s == '\n') /* If \n, also do \r */

s3c2440_serial_putc('\r', index);

s3c2440_serial_putc (*s++, index);

}

}

调用函数s3c2440_serial_putc()函数,如下:

/*

* Output a single byte to the serial port.

*/

void s3c2440_serial_putc (char c, int index)

{

struct s3c2440_uart *uart = s3c2440_get_base_uart(index);


/* 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 */

首页 上一页 1 2 3 4 5 6 下一页 尾页 4/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇PHP的SO扩展编程入门 下一篇C++你所不知道的sprintf_s与sprin..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·常用meta整理 | 菜鸟 (2025-12-25 01:21:52)
·SQL HAVING 子句:深 (2025-12-25 01:21:47)
·SQL CREATE INDEX 语 (2025-12-25 01:21:45)
·Shell 传递参数 (2025-12-25 00:50:45)
·Linux echo 命令 - (2025-12-25 00:50:43)