📄 main.c
字号:
/*------------------------------------------------------------------------- * 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";unsigned char *flash_base = 0;void flash_test(void){ unsigned char data = 0; int i; flash_base = (unsigned char *)0x00000000; /* read ID */ *(flash_base+0x5555) = 0xaa; barrier(); *(flash_base+0x2aaa) = 0x55; barrier(); *(flash_base+0x5555) = 0x90; barrier(); msleep(10); SerialOutputString("Flash version and ID: "); for(i=0; i<3; i++){ data = *(flash_base+i); SerialOutputHex(data); SerialOutputString(" "); } SerialOutputString("\n"); *(flash_base+0x5555) = 0xaa; barrier(); *(flash_base+0x2aaa) = 0x55; barrier(); *(flash_base+0x5555) = 0xf0; barrier(); msleep(10); }void atmel_check_toggle(char *addr){ unsigned char last, data; data = (*addr)&0x40; do{ last = data; data = (*addr)&0x40; }while(last!=data); }void atmel_write(char *dst, char *src, int nword){ int page, bp; dst += (int)flash_base; nword<<=2; for(page=0; page<nword; page+=256){ *(flash_base+0x5555) = 0xaa; barrier(); *(flash_base+0x2aaa) = 0x55; barrier(); *(flash_base+0x5555) = 0xa0; barrier(); for(bp=page; bp<page+256; bp++){ *(dst+bp) = *(src+bp); }// atmel_check_toggle(dst+page);// while(!((*(dst+bp-1))&0x80)); msleep(2); }}#include "nand.c" static char cmdl[] = "root=/dev/ram0 console=ttyS0 init=/linuxrc";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; memcpy(blob_status.cmdline, cmdl, strlen(cmdl)); /* 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; } /* 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"); serial_init(blob_status.downloadSpeed); } else { SerialOutputString("Start sending using the XMODEM protocol (repeated ^X to quit).\n\n"); } *numRead = XModemReceive((char *) startAddress, bufLen); SerialOutputString("\n\n\n"); if (blob_status.terminalSpeed != blob_status.downloadSpeed) { SerialOutputString("\n(Please switch your terminal emulator back to "); PrintSerialSpeed(blob_status.terminalSpeed); SerialOutputString(" baud)\n"); } if(*numRead < 0) { /* something went wrong */ retval = *numRead; /* reload the correct memory */ do_reload(argv[1]); serial_init(blob_status.terminalSpeed); return retval; } SerialOutputString("Received "); SerialOutputDec(*numRead); SerialOutputString(" (0x"); SerialOutputHex(*numRead); SerialOutputString(") bytes");#ifdef BLOB_DEBUG SerialOutputString(" at 0x"); SerialOutputHex((u32) startAddress);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -