vivi源代码分析3
来源:互联网 发布:arc gis软件下载 编辑:程序博客网 时间:2024/06/12 01:03
ret = mtd_dev_init();
/*
* VIVI Interfaces
*/
#ifdef CONFIG_MTD
int write_to_flash(loff_t ofs, size_t len, const u_char *buf, int flag);
int mtd_dev_init(void);
#else
#define write_to_flash(a, b, c, d) (int)(1)
#define mtd_dev_init() (int)(1)
#endif
int mtd_init(void)
{
int ret;
#ifdef CONFIG_MTD_CFI
ret = cfi_init();
#endif
#ifdef CONFIG_MTD_SMC
ret = smc_init();
#endif
#ifdef CONFIG_S3C2410_AMD_BOOT
ret = amd_init();
#endif
mymtd = mmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip));
this = (struct nand_chip *)(&mymtd[1]);
memset((char *)mymtd, 0, sizeof(struct mtd_info));
memset((char *)this, 0, sizeof(struct nand_chip));
mymtd->priv = this;
/* set NAND Flash controller */
nfconf = NFCONF;
/* NAND Flash controller enable */
nfconf |= NFCONF_FCTRL_EN;
/* Set flash memory timing */
nfconf &= ~NFCONF_TWRPH1; /* 0x0 */
nfconf |= NFCONF_TWRPH0_3; /* 0x3 */
nfconf &= ~NFCONF_TACLS; /* 0x0 */
NFCONF = nfconf;
/* Set address of NAND IO lines */
this->hwcontrol = smc_hwcontrol;
this->write_cmd = write_cmd;
this->write_addr = write_addr;
this->read_data = read_data;
this->write_data = write_data;
this->wait_for_ready = wait_for_ready;
/* Chip Enable -> RESET -> Wait for Ready -> Chip Disable */
this->hwcontrol(NAND_CTL_SETNCE);
this->write_cmd(NAND_CMD_RESET);
this->wait_for_ready();
this->hwcontrol(NAND_CTL_CLRNCE);
smc_insert(this);
inline int
smc_insert(struct nand_chip *this) {
/* Scan to find existance of the device */
if (smc_scan(mymtd)) {
return -ENXIO;
}
/* Allocate memory for internal data buffer */
this->data_buf = mmalloc(sizeof(u_char) *
(mymtd->oobblock + mymtd->oobsize));
if (!this->data_buf) {
printk("Unable to allocate NAND data buffer for S3C2410./n");
this->data_buf = NULL;
return -ENOMEM;
}
return 0;
}
struct nand_flash_dev {
char * name;
int manufacture_id;
int model_id;
int chipshift;
char page256;
char pageadrlen;
unsigned long erasesize;
};
static struct nand_flash_dev nand_flash_ids[] = {
{"Toshiba TC5816BDC", NAND_MFR_TOSHIBA, 0x64, 21, 1, 2, 0x1000}, // 2Mb 5V
... ....
{"Samsung K9D1G08V0M", NAND_MFR_SAMSUNG, 0x79, 27, 0, 3, 0x4000}, // 128Mb
{NULL,}
};
init_priv_data();
int
init_priv_data(void)
{
int ret_def;
#ifdef CONFIG_PARSE_PRIV_DATA
int ret_saved;
#endif
ret_def = get_default_priv_data();
#ifdef CONFIG_PARSE_PRIV_DATA
ret_saved = load_saved_priv_data();
if (ret_def && ret_saved) {
printk("Could not found vivi parameters./n");
return -1;
} else if (ret_saved && !ret_def) {
printk("Could not found stored vivi parameters.");
printk(" Use default vivi parameters./n");
} else {
printk("Found saved vivi parameters./n");
}
#else
if (ret_def) {
printk("Could not found vivi parameters/n");
return -1;
} else {
printk("Found default vivi parameters/n");
}
#endif
return 0;
int get_default_param_tlb(void)
{
char *src = (char *)&default_vivi_parameters;
char *dst = (char *)(VIVI_PRIV_RAM_BASE + PARAMETER_TLB_OFFSET);
int num = default_nb_params;
if (src == NULL) return -1;
/*printk("number of vivi parameters = %d/n", num); */
*(nb_params) = num;
//参数表的长度不可以超过预设内存的大小
if ((sizeof(vivi_parameter_t)*num) > PARAMETER_TLB_SIZE) {
printk("Error: too large partition table/n");
return -1;
}
//首先复制magic number
memcpy(dst, vivi_param_magic, 8);
//预留下8个字节作为扩展
dst += 16;
//复制真正的parameter
memcpy(dst, src, (sizeof(vivi_parameter_t)*num));
return 0;
}
typedef struct parameter {
char name[MAX_PARAM_NAME];
param_value_t value;
void (*update_func)(param_value_t value);
} vivi_parameter_t;
vivi_parameter_t default_vivi_parameters[] = {
{ "mach_type", MACH_TYPE, NULL },
{ "media_type", MT_S3C2410, NULL },
{ "boot_mem_base", 0x30000000, NULL },
{ "baudrate", UART_BAUD_RATE, NULL },
{ "xmodem_one_nak", 0, NULL },
{ "xmodem_initial_timeout", 300000, NULL },
{ "xmodem_timeout", 1000000, NULL },
{ "ymodem_initial_timeout", 1500000, NULL },
{ "boot_delay", 0x1000000, NULL }
};
int default_nb_params = ARRAY_SIZE(default_vivi_parameters);
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
typedef struct user_command {
const char *name;
void (*cmdfunc)(int argc, const char **);
struct user_command *next_cmd;
const char *helpstr;
} user_command_t;
user_command_t help_cmd = {
"help",
command_help,
NULL,
"help [{cmds}] /t/t/t-- Help about help?"
};
void command_help(int argc, const char **argv)
{
user_command_t *curr;
/* help <command>. invoke <command> with 'help' as an argument */
if (argc == 2) {
if (strncmp(argv[1], "help", strlen(argv[1])) == 0) {
printk("Are you kidding?/n");
return;
}
argv[0] = argv[1];
argv[1] = "help";
execcmd(argc, argv);
return;
}
printk("Usage:/n");
curr = head_cmd;
while(curr != NULL) {
printk(" %s/n", curr->helpstr);
curr = curr->next_cmd;
}
}
void add_command(user_command_t *cmd)
{
if (head_cmd == NULL) {
head_cmd = tail_cmd = cmd;
} else {
tail_cmd->next_cmd = cmd;
tail_cmd = cmd;
}
/*printk("Registered '%s' command/n", cmd->name);*/
}
转自http://blog.chinaunix.net/u/21948/showart.php?id=379460
- vivi源代码分析3
- vivi源代码分析3
- Bootloader(Vivi)源代码分析
- vivi源代码分析1
- vivi源代码分析2
- Bootloader(Vivi)源代码分析
- vivi源代码分析1
- vivi源代码分析2
- Bootloader(Vivi)源代码分析
- s3c2410的Bootloader(Vivi)源代码分析
- s3c2410的Bootloader(Vivi)源代码分析
- vivi源代码最为详细分析(一)
- vivi源代码最为详细分析(二)
- vivi源代码最为详细分析(三)
- vivi分析
- vivi分析
- vivi开发笔记: MMU分析|ARM,vivi
- VIVI讲解与分析
- vivi源代码分析1
- Linux下通过freetds连接MSSQL数据库
- vivi源代码分析2
- Microsoft ®Office2003 实战秘笈
- What's new in Spring 2.0 and 2.5?
- vivi源代码分析3
- 改变tomcat的默认页
- 在Windows下进行Linux/FreeBSD/Unix的GCC远程开发和调试
- 在VB中使用水晶报表的一种简易编程方法
- 解决vs2005自带水晶报表次数的限制的次数
- 上海电信区别对待老客户
- 90后炫富女最新图片
- PHP异常处理
- 广百股份(002187)、新嘉联(002188)公布中签号码