📄 main.c
字号:
/* * $Id: main.c,v 1.11 2003/09/24 12:13:35 jfabo Exp $ * * Copyright (C) 2001, 2002 ETC s.r.o. * * 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. * * Written by Marcel Telka <marcel@telka.sk>, 2001, 2002. * */#include <.config.h>#include <_windows.h>#include <nkintr.h>#include <memory.h>#include <pehdr.h>#include <romldr.h>#include "board.h"#if CPU == SA1110#include <sa11x0/rc.h>#include <sa11x0/gpio.h>#endif#ifdef CONFIG_EP250_LCD#include <pxa2x0/lcd.h>#endif#if CPU == PXA250#include <pxa2x0/gpio.h>#endif#include "except.h"#include "debug.h"#include "flash.h"#include "download.h"#include "format.h"#include "splash.h"#define XBOOT_VERSION "0.3.0"const char NKSignon[] = { "\n\nxboot " XBOOT_VERSION " for " BOARD_NAME "\n" "Copyright (C) 2001, 2002, 2003 ETC s.r.o.\n" "xboot is free software, covered by the GNU General Public License, and you are\n" "welcome to change it and/or distribute copies of it under certain conditions.\n" "There is absolutely no warranty for xboot.\n\n"};/* this is very dirty trick (see KernelRelocate & main) */ROMHDR *volatile const pTOC = (ROMHDR *) 0xFFFFFFFF; /* Gets replaced by RomLoader with real address */struct exception_context the_exception_context[1];/* * Move all writeable data sections into RAM */voidKernelRelocate( ROMHDR *const pTOC ){ ULONG loop; COPYentry *cptr; if (pTOC == (ROMHDR *const) 0xFFFFFFFF) { EdbgOutputDebugString( "ERROR: Invalid pTOC in KernelRelocate(). Stop!\n" ); for (;;) ; } /* This is where the data sections become valid... don't read globals until after this */ for (loop = 0; loop < pTOC->ulCopyEntries; loop++) { cptr = (COPYentry *) (pTOC->ulCopyOffset + loop * sizeof (COPYentry)); if (cptr->ulCopyLen) memcpy( (void *) cptr->ulDest, (void *) cptr->ulSource, cptr->ulCopyLen ); if (cptr->ulCopyLen != cptr->ulDestLen) memset( (void *) (cptr->ulDest + cptr->ulCopyLen), 0, cptr->ulDestLen - cptr->ulCopyLen ); }}static voidHalt( void ){ EdbgOutputDebugString( "\nSystem halted.\n" ); for (;;) ; /* neverending story */}/* Launch is implemented in start.s */void Launch( DWORD );voidmain( void ){ ROMHDR RomHdr; /* ROM Table of Contents */ struct imginfo img; DWORD *lpdwToc; /* toc pointer */ int e; /* exception */ /* Copy data to RAM & zero out BSS */ KernelRelocate( pTOC ); OEMInitDebugSerial(); EdbgOutputDebugString( NKSignon ); EdbgOutputDebugString( "Stack=0x%X\n", &lpdwToc ); /* init RomHdr */ memset( &RomHdr, -1, sizeof (ROMHDR) );#ifdef CONFIG_SPLASH_SCREEN /* display splash screen */ splash_screen();#endif#if CPU == SA1110 EdbgOutputDebugString( "RCSR = 0x%X\n", RCSR ); EdbgOutputDebugString( "Power button status (GPIO %d) = %d\n", GPIO_PWR, (GPLR >> GPIO_PWR) & 1 );#endif Try { if (DownloadImage( &img )) { EdbgOutputDebugString( "Download image failed. Trying XIP.\n" ); img.launch_addr = img.start = img.target = MEM_VIRT_WINCE; } } Catch( e ) { EdbgOutputDebugString( "\n\nFLASH error: %d!!!\n\n\n", e ); Halt(); } /* Check for pTOC signature ("CECE") */ if (*(DWORD *) (img.target + 64) == ROM_SIGNATURE) EdbgOutputDebugString( "Found pTOC signature.\n" ); else { EdbgOutputDebugString( "ERROR: Did not find pTOC signature. Stop!\n" ); Halt(); } /* Copy RomHdr from image */ lpdwToc = (DWORD *) *(DWORD *) (img.target + 68); memcpy( &RomHdr, lpdwToc, sizeof (ROMHDR) ); EdbgOutputDebugString( "ROMHDR at Address 0x%X\n", lpdwToc ); EdbgOutputDebugString( "RomHdr.ulRAMStart=0x%X RomHdr.physfirst=0x%X.\n", RomHdr.ulRAMStart, RomHdr.physfirst ); EdbgOutputDebugString( "LaunchAddr=0x%X\n", img.launch_addr ); /* convert img.launch_addr to virtual address */ img.launch_addr = img.launch_addr - img.start + img.target; EdbgOutputDebugString( "\nJumping to image at 0x%X\n", img.launch_addr ); EdbgOutputDebugString( "First instructions=(0x%X, 0x%X, 0x%X)...\n", *(DWORD *) img.launch_addr, *(DWORD *) (img.launch_addr + 4), *(DWORD *) (img.launch_addr + 8) ); /* convert img.launch_addr to physical address */ switch (img.launch_addr & 0xFF000000) { case MEM_VIRT_FLASH: img.launch_addr -= MEM_VIRT_FLASH - MEM_PHYS_FLASH; break; case MEM_VIRT_SDRAM: img.launch_addr -= MEM_VIRT_SDRAM - MEM_PHYS_SDRAM; break; }#ifdef CONFIG_SPLASH_SCREEN /* turn off display */ display_off(); /* deinit display backlight and contrast */ deinit_display_accessories();#endif /* init display for wince image */#ifdef CONFIG_EP250_LCD GPDR1 |= GPIO1_GP58 | GPIO1_GP59 | GPIO1_GP60 | GPIO1_GP61 | GPIO1_GP62 | GPIO1_GP63; GPDR2 |= GPIO2_GP64 | GPIO2_GP65 | GPIO2_GP74 | GPIO2_GP75 | GPIO2_GP76; GAFR1_U = GAFR1_U_AF58(ALT_FN_2_OUT) | GAFR1_U_AF59(ALT_FN_2_OUT) | GAFR1_U_AF60(ALT_FN_2_OUT) | GAFR1_U_AF61(ALT_FN_2_OUT) | GAFR1_U_AF62(ALT_FN_2_OUT) | GAFR1_U_AF63(ALT_FN_2_OUT); GAFR2_L = GAFR2_L_AF64(ALT_FN_2_OUT) | GAFR2_L_AF65(ALT_FN_2_OUT) | GAFR2_L_AF74(ALT_FN_2_OUT) | GAFR2_L_AF75(ALT_FN_2_OUT) | GAFR2_L_AF76(ALT_FN_2_OUT); EdbgOutputDebugString( "Configuring LCD Controller for " );#ifdef CONFIG_EP250_SC09Q002_AZA EdbgOutputDebugString( "Hitachi SC09Q002-AZA\n" ); LCCR1 = LCCR1_BLW(0) | LCCR1_ELW(0) | LCCR1_HSW(0) | LCCR1_PPL(319); LCCR2 = LCCR2_BFW(0) | LCCR2_EFW(0) | LCCR2_VSW(5) | LCCR2_LPP(239); LCCR3 = LCCR3_BPP(3) | LCCR3_PCP | LCCR3_ACB(0xFF) | LCCR3_PCD(22);#endif /* CONFIG_EP250_SC09Q002_AZA */#ifdef CONFIG_EP250_SC16H002_ZZA EdbgOutputDebugString( "Hitachi SC16H002-ZZA\n" ); LCCR1 = LCCR1_BLW(0) | LCCR1_ELW(0) | LCCR1_HSW(0) | LCCR1_PPL(639); LCCR2 = LCCR2_BFW(0) | LCCR2_EFW(0) | LCCR2_VSW(2) | LCCR2_LPP(239); LCCR3 = LCCR3_BPP(3) | LCCR3_PCP | LCCR3_ACB(0xFF) | LCCR3_PCD(11); #endif /* CONFIG_EP250_SC16H002_ZZA */#ifdef CONFIG_EP250_SX19V001_Z1A EdbgOutputDebugString( "Hitachi SX19V001-Z1A\n" ); LCCR1 = LCCR1_BLW(2) | LCCR1_ELW(2) | LCCR1_HSW(2) | LCCR1_PPL(639); LCCR2 = LCCR2_BFW(0) | LCCR2_EFW(0) | LCCR2_VSW(10) | LCCR2_LPP(479); LCCR3 = LCCR3_BPP(3) | LCCR3_PCP | LCCR3_ACB(0xFF) | LCCR3_PCD(3);#endif /* CONFIG_EP250_SX19V001_Z1A */#endif /* CONFIG_EP250_LCD */#if CPU == PXA250 /* STUART */ GPDR1 = GPDR1 & ~GPIO1_GP46 | GPIO1_GP47; GAFR1_L |= GAFR1_L_AF46(ALT_FN_2_IN) | GAFR1_L_AF47(ALT_FN_1_OUT); /* FFUART */ GPDR1 = GPDR1 & ~GPIO1_GP34 | GPIO1_GP39; GAFR1_L |= GAFR1_L_AF34(ALT_FN_1_IN) | GAFR1_L_AF39(ALT_FN_2_OUT);#endif OEMFlushDebugSerial(); /* wait for transmitting all data */ OEMDeinitDebugSerial(); /* Launch is implemented in start.s */ Launch( img.launch_addr ); /* Some catastrophic error occurred */ OEMInitDebugSerial(); EdbgOutputDebugString( "! Fatal error in ETC Bootloader, halting...\n" ); Halt();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -