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

📄 main.c

📁 bootloader相互交流
💻 C
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------- * Filename:      main.c * Version:       $Id: main.c,v 1.23 2002/01/07 14:48:25 seletz Exp $ * Copyright:     Copyright (C) 1999, Jan-Derk Bakker * Author:        Jan-Derk Bakker <J.D.Bakker@its.tudelft.nl> * Description:   Main file for the trivially simple bootloader for the  *                LART boards * Created at:    Mon Aug 23 20:00:00 1999 * Modified by:   Erik Mouw <J.A.K.Mouw@its.tudelft.nl> * Modified at:   Sat Mar 25 14:31:16 2000 *-----------------------------------------------------------------------*//* * main.c: main file for the blob bootloader * * Copyright (C) 1999 2000 2001 *   Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl) and *   Erik Mouw (J.A.K.Mouw@its.tudelft.nl) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * */#ident "$Id: main.c,v 1.23 2002/01/07 14:48:25 seletz Exp $"#ifdef HAVE_CONFIG_H# include <blob/config.h>#endif#include <blob/arch.h>#include <blob/command.h>#include <blob/errno.h>#include <blob/error.h>#include <blob/flash.h>#include <blob/init.h>#include <blob/led.h>#include <blob/main.h>#include <blob/md5.h>#include <blob/md5support.h>#include <blob/memory.h>#include <blob/param_block.h>#include <blob/sa1100.h>#include <blob/serial.h>#include <blob/time.h>#include <blob/util.h>#include <blob/uucodec.h>#include <blob/xmodem.h>static int do_reload(char *what);static void PrintSerialSpeed(serial_baud_t speed);blob_status_t blob_status;static char *version_str = PACKAGE " version " VERSION " for " BOARD_NAME "\n";volatile unsigned short *flash_base;#define CNT 2000*1000*10  // At least 20void flash_test(void){ unsigned short data[3] ; int i; flash_base = (volatile unsigned short *)0x00000000;/*asm (	" 	mov %0,PC 	 "	: "=r" (data[0]));*/ /* read ID */ flash_base[0x5555] = 0xaaaa; //barrier(); flash_base[0x2aaa] = 0x5555; //barrier(); flash_base[0x5555] = 0x9090; //barrier(); msleep(20); SerialOutputString("Flash version and ID: "); for(i=0; i<3; i++){     data[i] = flash_base[i];     SerialOutputHex(data[i]);     SerialOutputString(" "); } SerialOutputString("\n");      flash_base[0x5555] = 0xaaaa; flash_base[0x2aaa] = 0x5555; flash_base[0x5555] = 0xf0f0; msleep(20); }void atmel_check_toggle(unsigned short *addr){ volatile unsigned short last, data; data = (*addr); do{     last = data;     data = (*addr); }while(last!=data); }/*void mysleep(int n){  int i, j, k;  i=0;  while(i++<n){	j=0;	while(j++<n){	  k=0;	  while(k++<n){}	}  }}*/void atmel_write(u32 *dst, u32 *src, int nword){#define MYDEBUG 	int page, bp; int i, timeout=60000; static int percent=0; volatile unsigned short *block; volatile unsigned short *src16; unsigned short *dst_end; dst += (int)flash_base; nword<<=2; dst_end = (unsigned short *)((char*)dst+nword); //erasing... for(block=dst; block<dst_end; block+=0x1000){ block[0x5555] = 0xaaaa; block[0x2aaa] = 0x5555; block[0x5555] = 0x8080; block[0x5555] = 0xaaaa; block[0x2aaa] = 0x5555; block[0] = 0x3030; msleep(200); SerialOutputString("."); } SerialOutputString("\nErasing done\n");#define program#ifdef program  //programming SerialOutputString("\nBegin to program.\n"); src16 = (volatile unsigned short*)src; for(block=(volatile unsigned short*)dst;block<dst_end;block+=32768,src16+=32768) {	 //each block   SerialOutputString("\nWriting a block...\n");#if 0	 SerialOutputString("block=");	 SerialOutputHex(block);	 SerialOutputString("\nsrc16=");	 SerialOutputHex(src16);	 SerialOutputString("\n");#endif	  for(i=0; i<32768; i++){			 //one block       block[0x5555] = 0xaaaa;       block[0x2aaa] = 0x5555;       block[0x5555] = 0xa0a0;       block[i] = src16[i];            while(1){	  			SerialOutputString("\rWaiting");	  			SerialOutputString("\rWaiting");	  			if(block[i]==src16[i]) {	    			SerialOutputString("\rOK");	    			break;	  			}       }    }//endfor one block  }//endfor all the block  SerialOutputString("\nProgram Finished\n");#endif#undef MYDEBUG}#include "nand.c" int main(void){	int numRead = 0;	char commandline[MAX_COMMANDLINE_LENGTH];	int i;	int retval = 0;#ifdef PARAM_START	u32 conf;#endif	/* call subsystems */	init_subsystems();	/* initialise status */	blob_status.paramType = fromFlash;	blob_status.kernelType = fromFlash;	blob_status.ramdiskType = fromFlash;	blob_status.downloadSpeed = baud_115200;	blob_status.terminalSpeed = baud_115200;	blob_status.load_ramdisk = 1;	blob_status.cmdline[0] = '\0';	blob_status.boot_delay = 5;	/* call serial_init() because the default 9k6 speed might not           be what the user requested */	serial_init(blob_status.terminalSpeed);	/* parse the core tag, for critical things like terminal speed */#ifdef PARAM_START	parse_ptag((void *) PARAM_START, &conf);#endif	/* Print the required GPL string */	SerialOutputString("\nConsider yourself LARTed!\n\n");	SerialOutputString(version_str);	SerialOutputString("Copyright (C) 1999 2000 2001 "			   "Jan-Derk Bakker and Erik Mouw\n");		SerialOutputString(PACKAGE " comes with ABSOLUTELY NO WARRANTY; "			   "read the GNU GPL for details.\n");	SerialOutputString("This is free software, and you are welcome "			   "to redistribute it\n");	SerialOutputString("under certain conditions; "			   "read the GNU GPL for details.\n");	/* get the amount of memory */	get_memory_map();#ifdef BLOB_DEBUG	{		register u32 stackptr;		SerialOutputString("Current stack pointer: 0x");		asm("mov %0, sp": "=r" (stackptr));		SerialOutputHex(stackptr);		serial_write('\n');	}#endif	/* Parse all the tags in the paramater block */#ifdef PARAM_START	parse_ptags((void *) PARAM_START, &conf);#endif	/* Load kernel and ramdisk from flash to RAM */	do_reload("blob");	do_reload("kernel");	//if(blob_status.load_ramdisk)	//	do_reload("ramdisk");	/* wait 10 seconds before starting autoboot */	/*SerialOutputString("Autoboot in progress, press any key to stop ");*/	/*	for(i = 0; i < blob_status.boot_delay; i++) {		serial_write('.'); 		retval = SerialInputBlock(commandline, 1, 1); 		if(retval > 0)			break;	}*/	/* boot into kernel */	commandline[0] = '\0';	parse_command("boot");	/* no key was pressed, so proceed booting the kernel */	if(retval == 0) {		commandline[0] = '\0';		parse_command("boot");	}	SerialOutputString("\nAutoboot aborted\n");	SerialOutputString("Type \"help\" to get a list of commands\n");	flash_test();        nand_readid();//        nand_test();	/* the command loop. endless, of course */	for(;;) {		DisplayPrompt(NULL);		/* wait 10 minutes for a command */		numRead = GetCommand(commandline, MAX_COMMANDLINE_LENGTH, 600);		if(numRead > 0) {			if((retval = parse_command(commandline)) < 0 )				printerror(retval, NULL);		}	}	return 0;} /* main */static int set_download_parameters(char *name, u32 *startAddress, 				    int *bufLen, int **numRead,				   u32 **digest){	if(strncmp(name, "blob", 5) == 0) {		/* download blob */		*startAddress = BLOB_RAM_BASE;		*bufLen = BLOB_FLASH_LEN;		*numRead = &blob_status.blobSize;		*digest = blob_status.blob_md5_digest;		blob_status.blobType = fromDownload;#ifdef PARAM_START	} else if(strncmp(name, "param", 6) == 0) {		/* download param */		*startAddress = PARAM_RAM_BASE;		*bufLen = PARAM_FLASH_LEN;		*numRead = &blob_status.paramSize;		*digest = blob_status.param_md5_digest;		blob_status.paramType = fromDownload;#endif	} else if(strncmp(name, "kernel", 7) == 0) {		/* download kernel */		*startAddress = KERNEL_RAM_BASE;		*bufLen = KERNEL_FLASH_LEN;		*numRead = &blob_status.kernelSize;		*digest = blob_status.kernel_md5_digest;		blob_status.kernelType = fromDownload;	} else if(strncmp(name, "ramdisk", 8) == 0) {		/* download ramdisk */		*startAddress = RAMDISK_RAM_BASE;		*bufLen = RAMDISK_FLASH_LEN;		*numRead = &blob_status.ramdiskSize;		*digest = blob_status.ramdisk_md5_digest;		blob_status.ramdiskType = fromDownload;	} else {		printerror(-EINVAL, name);		return -EINVAL;	}	return 0;}static int xdownload(int argc, char *argv[]){	u32 startAddress;	int bufLen;	int *numRead;	int retval;	u32 *digest;	if(argc < 2)		return -ENOPARAMS;	retval = set_download_parameters(argv[1], &startAddress,					 &bufLen, &numRead, &digest);	if (blob_status.terminalSpeed != blob_status.downloadSpeed) {		SerialOutputString("Switching to ");		PrintSerialSpeed(blob_status.downloadSpeed);		SerialOutputString(" baud\n");		SerialOutputString("Switch your terminal emulator to the same speed and\n");		SerialOutputString("start sending using the XMODEM protocl (repeated ^X) to quit.\n");		SerialOutputString(PACKAGE " will switch back to ");		PrintSerialSpeed(blob_status.terminalSpeed);		SerialOutputString(" baud after XMODEM succeeds or times out.\n");

⌨️ 快捷键说明

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