|
发表于 2006-6-15 22:48:30
|
显示全部楼层
void
command_load(int argc, const char **argv)
{
char *buf = (char *)RAM_BASE;
//loff_t to;
unsigned long to; /* is declared to long-long type ? */
size_t size;
int modem = 0;
int where_to = 0;
int ret;
size_t retlen;
mtd_partition_t *dst_part;
int flag;
char file_name[255] = { 0, };
/* Parse arguments */
switch (argc) {
case 2:
if (strncmp("help", argv[1], 4) == 0) {
goto print_usage;
} else {
goto invalid_cmd;
}
break;
case 4:
dst_part = get_mtd_partition(argv[2]);
if (dst_part == NULL) {
printk("Could not found \"%s\" partition\n", argv[2]);
return;
}
to = dst_part->offset;
size = dst_part->size;
flag = dst_part->flag;
modem = modem_is(argv[3]);
break;
case 5:
to = strtoul(argv[2], NULL, 0, &ret);
if (ret) goto error_parse_arg;
size = (size_t)strtoul(argv[3], NULL, 0, &ret);
if (ret) goto error_parse_arg;
modem = modem_is(argv[4]);
flag = 0;
break;
default:
goto invalid_cmd;
}
if (strncmp("flash", argv[1], 5) == 0) {
where_to = LOAD_TO_FLASH;
} else if (strncmp("ram", argv[1], 3) == 0) {
where_to = LOAD_TO_RAM;
} else {
printk("invalid argument. 'flash' or 'ram' is available\n");
return;
}
/* if load to ram */
if (where_to == LOAD_TO_RAM) {
buf = (char *)to;
}
/* download a file */
retlen = download_file(buf, size, modem, file_name);
/* hacked by nandy. delay for serial output */
{ int i = 0x10000; while (i > 0) i--; }
if (retlen == 0) {
printk("Failed downloading file\n");
return;
}
printk("Downloaded file at 0x%08lx, size = %d bytes\n", buf, retlen);
switch (where_to) {
case LOAD_TO_FLASH:
if (retlen > size) {
printk("An image size is too large to write flash.
wanted = 0x%08lx, loaded = 0x%08lx\n", size, retlen);
return;
}
if (flag & MF_ISRAM) {
printk("Ooops, actually this partition is ram. It's tweak...!\n");
return -1;
}
ret = write_to_flash((loff_t)to, retlen, buf, flag);
break;
case LOAD_TO_RAM:
break;
}
这部分的代码,个人感觉load命令在load ram和flash时都是下载到ram中,如果是flash的话,在switch中用了write_to_flash函数写入到flash中 |
|