⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 arm7,44b0芯片的blob程序,适用于学嵌入式linux的新手.
💻 C
📖 第 1 页 / 共 2 页
字号:
#endif	serial_write('\n');	serial_init(blob_status.terminalSpeed);	return 0;}static char xdownloadhelp[] = "xdownload {blob|param|kernel|ramdisk}\n""Download <argument> image to RAM using xmodem\n";__commandlist(xdownload, "xdownload", xdownloadhelp);static int Flash(int argc, char *argv[]){	u32 *src;	u32 *dst;	u32 numBytes = 0;	u32 maxSize = 0;	u32 nwords;	block_source_t type = fromFlash;        int ptype;		if(argc < 2)		return -ENOPARAMS;	if(strncmp(argv[1], "blob", 5) == 0) {		src = (u32 *)BLOB_RAM_BASE;		dst = (u32 *)BLOB_FLASH_BASE;		maxSize = BLOB_FLASH_LEN;		numBytes = blob_status.blobSize;		type = blob_status.blobType;                ptype = 0;#ifdef PARAM_START	} else if(strncmp(argv[1], "param", 6) == 0) {		src = (u32 *)PARAM_RAM_BASE;		dst = (u32 *)PARAM_FLASH_BASE;		maxSize = PARAM_FLASH_LEN;		numBytes = blob_status.paramSize;		type = blob_status.paramType;                ptype = 0;#endif	} else if(strncmp(argv[1], "kernel", 7) == 0) {		src = (u32 *)KERNEL_RAM_BASE;		dst = (u32 *)KERNEL_FLASH_BASE;		numBytes = blob_status.kernelSize;		maxSize = KERNEL_FLASH_LEN;		type = blob_status.kernelType;                ptype = 1;	} else if(strncmp(argv[1], "ramdisk", 8) == 0) {		src = (u32 *)RAMDISK_RAM_BASE;		dst = (u32 *)RAMDISK_FLASH_BASE;		numBytes = blob_status.ramdiskSize;		maxSize = RAMDISK_FLASH_LEN;		type = blob_status.ramdiskType;                ptype = 1;	} else {		printerror(EINVAL, argv[1]);		return 0;	}	if(type == fromFlash) {		printerrprefix();		SerialOutputString(argv[1]);		SerialOutputString(" not downloaded\n");		return -EINVAL;	}	if(numBytes > maxSize) {		printerrprefix();		SerialOutputString("image too large for flash: 0x");		SerialOutputHex(numBytes);		SerialOutputString(" > 0x");		SerialOutputHex(maxSize);		serial_write('\n');		return -ETOOLONG;	}	nwords = (numBytes + sizeof(u32) - 1) / sizeof(u32);	SerialOutputString("Saving ");	SerialOutputString(argv[1]);	SerialOutputString(" to flash\n");        if(ptype==0){            atmel_write(dst, src, nwords);        }else{            nand_write(dst, src, nwords);//            flash_write_region(dst, src, nwords);        }	return 0;}static char flashhelp[] = "flash {blob|param|kernel|ramdisk}\n""Write <argument> image to flash\n";__commandlist(Flash, "flash", flashhelp);static int SetDownloadSpeed(int argc, char *argv[]){	if(argc < 2)		return -ENOPARAMS;	if(strncmp(argv[1], "1200", 5) == 0) {		blob_status.downloadSpeed = baud_1200;	} else if(strncmp(argv[1], "1k2", 4) == 0) {		blob_status.downloadSpeed = baud_1200;	} else if(strncmp(argv[1], "9600", 5) == 0) {		blob_status.downloadSpeed = baud_9600;	} else if(strncmp(argv[1], "9k6", 4) == 0) {		blob_status.downloadSpeed = baud_9600;	} else if(strncmp(argv[1], "19200", 6) == 0) {		blob_status.downloadSpeed = baud_19200;	} else if(strncmp(argv[1], "19k2", 5) == 0) {		blob_status.downloadSpeed = baud_19200;	} else if(strncmp(argv[1], "38400", 7) == 0) {		blob_status.downloadSpeed = baud_38400;	} else if(strncmp(argv[1], "38k4", 5) == 0) {		blob_status.downloadSpeed = baud_38400;	} else if(strncmp(argv[1], "57600", 6) == 0) {		blob_status.downloadSpeed = baud_57600;	} else if(strncmp(argv[1], "57k6", 5) == 0) {		blob_status.downloadSpeed = baud_57600;	} else if(strncmp(argv[1], "115200", 7) == 0) {		blob_status.downloadSpeed = baud_115200;	} else if(strncmp(argv[1], "115k2", 6) == 0) {		blob_status.downloadSpeed = baud_115200;	} else if(strncmp(argv[1], "230400", 7) == 0) {		blob_status.downloadSpeed = baud_230400;	} else if(strncmp(argv[1], "230k4", 6) == 0) {		blob_status.downloadSpeed = baud_230400;	} else {		return -EINVAL;	}	SerialOutputString("Download speed set to ");	PrintSerialSpeed(blob_status.downloadSpeed);	SerialOutputString(" baud\n");	return 0;}static char speedhelp[] = "speed [baudrate]\n""Set download speed. Valid baudrates are:\n""1200, 9600, 19200, 38400, 57600, 115200, 230400,\n"" 1k2,  9k6,  19k2,  38k4,  57k6,  115k2,  230k4\n";__commandlist(SetDownloadSpeed, "speed", speedhelp);static int PrintStatus(int argc, char *argv[]){	SerialOutputString(version_str);	SerialOutputString("Download speed      : ");	PrintSerialSpeed(blob_status.downloadSpeed);	SerialOutputString(" baud\n");	SerialOutputString("Terminal speed      : ");	PrintSerialSpeed(blob_status.terminalSpeed);	SerialOutputString(" baud\n");	SerialOutputString("blob    (0x");	SerialOutputHex(BLOB_FLASH_BASE);	SerialOutputString("): ");	if(blob_status.blobType == fromFlash) {		SerialOutputString("from flash\n");	} else {		SerialOutputString("downloaded at 0x");		SerialOutputHex(BLOB_RAM_BASE);		SerialOutputString(", ");		SerialOutputDec(blob_status.blobSize);		SerialOutputString(" bytes\n");	}#ifdef PARAM_START	SerialOutputString("param  (0x");	SerialOutputHex(PARAM_FLASH_BASE);	SerialOutputString("): ");	if(blob_status.paramType == fromFlash) {		SerialOutputString("from flash\n");	} else {		SerialOutputString("downloaded at 0x");		SerialOutputHex(PARAM_RAM_BASE);		SerialOutputString(", ");		SerialOutputDec(blob_status.paramSize);		SerialOutputString(" bytes\n");	}#else	SerialOutputString("param               : Not available\n");#endif	SerialOutputString("kernel  (0x");	SerialOutputHex(KERNEL_FLASH_BASE);	SerialOutputString("): ");	if(blob_status.kernelType == fromFlash) {		SerialOutputString("from flash\n");	} else {		SerialOutputString("downloaded at 0x");		SerialOutputHex(KERNEL_RAM_BASE);		SerialOutputString(", ");		SerialOutputDec(blob_status.kernelSize);		SerialOutputString(" bytes\n");	}	SerialOutputString("ramdisk (0x");	SerialOutputHex(RAMDISK_FLASH_BASE);	SerialOutputString("): ");	if(blob_status.ramdiskType == fromFlash) {		SerialOutputString("from flash\n");	} else {		SerialOutputString("downloaded at 0x");		SerialOutputHex(RAMDISK_RAM_BASE);		SerialOutputString(", ");		SerialOutputDec(blob_status.ramdiskSize);		SerialOutputString(" bytes\n");	}		return 0;}static char statushelp[] = "status\n""Display current status\n";__commandlist(PrintStatus, "status", statushelp);static int do_reload(char *what){	u32 *dst = 0;	u32 *src = 0;	int numWords;        int ptype;	if(strncmp(what, "blob", 5) == 0) {		dst = (u32 *)BLOB_RAM_BASE;		src = (u32 *)BLOB_FLASH_BASE;		numWords = BLOB_FLASH_LEN / 4;		blob_status.blobSize = 0;		blob_status.blobType = fromFlash;		ptype = 0;		SerialOutputString("Loading blob from flash ");#ifdef PARAM_START	} else if(strncmp(what, "param", 6) == 0) {		dst = (u32 *)PARAM_RAM_BASE;		src = (u32 *)PARAM_FLASH_BASE;		numWords = PARAM_FLASH_LEN / 4;		blob_status.paramSize = 0;		blob_status.paramType = fromFlash;		ptype = 0;		SerialOutputString("Loading paramater block from flash ");#endif	} else if(strncmp(what, "kernel", 7) == 0) {		dst = (u32 *)KERNEL_RAM_BASE;		src = (u32 *)KERNEL_FLASH_BASE;		numWords = KERNEL_FLASH_LEN / 4;		blob_status.kernelSize = 0;		blob_status.kernelType = fromFlash;		ptype = 1;		SerialOutputString("Loading kernel from flash ");	} else if(strncmp(what, "ramdisk", 8) == 0) {		dst = (u32 *)RAMDISK_RAM_BASE;		src = (u32 *)RAMDISK_FLASH_BASE;		numWords = RAMDISK_FLASH_LEN / 4;		blob_status.ramdiskSize = 0;		blob_status.ramdiskType = fromFlash;		ptype = 1;		SerialOutputString("Loading ramdisk from flash ");	} else {		ptype = 1;		printerror(EINVAL, what);		return 0;	}	if(ptype == 0){		MyMemCpy(dst, src, numWords);        }else{		nand_read(dst, src, numWords);        }	SerialOutputString(" done\n");	return 0;}static int Reload(int argc, char *argv[]){	if(argc < 2)		return -ENOPARAMS;	return do_reload(argv[1]);}static char reloadhelp[] = "reload {blob|param|kernel|ramdisk}\n""Reload <argument> from flash to RAM\n";__commandlist(Reload, "reload", reloadhelp);static void PrintSerialSpeed(serial_baud_t speed){	switch(speed) {	case baud_1200:		SerialOutputDec(1200);		break;	case baud_9600:		SerialOutputDec(9600);		break;	case baud_19200:		SerialOutputDec(19200);		break;	case baud_38400:		SerialOutputDec(38400);		break;	case baud_57600:		SerialOutputDec(57600);		break;	case baud_115200:		SerialOutputDec(115200);		break;	case baud_230400:		SerialOutputDec(230400);		break;	default:		SerialOutputString("(unknown)");		break;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -