?? btldr_pi.c127
字號:
/* * File: btldr_pi.c * * An implementation of a bootloader command processor which exposes the * btldr_pi.h interface. Please see btldr_pi.h for more info. * * SEE ALSO: * btldr_pi.h * * Copyright (C) 2002 RidgeRun, Inc. * Author: RidgeRun, Inc <skranz@ridgerun.com> * - Support for DSC25 added, 9-6-02, Gregory Nutt * - Support for DM270 added, 2-19-03, Gregory Nutt * * 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 SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * 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., * 675 Mass Ave, Cambridge, MA 02139, USA. * * Please report all bugs/problems to the author or <support@dsplinux.net> * * key: RRGPLCR (do not remove) * */#include "types.h"#include "btldr_pi.h"#include "flash.h"#include "net.h"#include "ether.h"#include "tftp.h"#include "io.h"#include "memconfig.h"#include "util.h"#include "srec.h"#include "rawbin.h"#include "osd.h"#include "decompress.h"#include "cache.h"#include "linux.h"// Memory that can be used by the gunzip uncompressor// Last 1 Mbytes of SD RAM#define SDRAM_END ( BSPCONF_SDRAM_BASE + BSPCONF_SDRAM_SIZE)#define GUNZIP_MALLOC_SIZE (1024 * 1024) // 1 Mbyte#define GUNZIP_MALLOC_START (SDRAM_END - GUNZIP_MALLOC_SIZE)extern int __KernCommandLineMagicStr; // defined by linker script.extern int __KernCommandLineOverride; // defined by linker script.extern int __EtherMACMagicStr; // defined by linker script.extern int __EtherMAC; // defined by linker script.extern int btldr_start; // These values are determined by theextern int btldr_end; // the linker script when the btldr is // built. This allows the bootloader to // know at run time what address range // it occupies. This is important for the // bootloader's ability to store itself in // flash.extern unsigned int FlashFileSysStart; // These values are determined by theextern unsigned int FlashFileSysEnd ; // linker script and allow the user to // override the start and end boundaries // that define where the filesystem will // be stored in FLASH. This lets users, // that know exactly how big there kernel // is, to get rid of the some padding that // might normally exists between the kernel // and filesystem component bins as defined // by the comp_flash_info* arrays defined // later in this file. This is talked about // in the memory map portion of the BSP // documentation.unsigned long FlashLockMode; // This is a global variable that will // be tested by the flash*.c module before // erases or writes flash. If the special // code 0xBEEFFEED is not present here then // the all flash mod operations will fail // and report a flash locked state.char *free_memory_start; // used by gunzip uncompressorint free_memory_size; // in bytes#ifdef REPLACE_VECTOR_TABLE/* For the OMAP710 we need these to support replacing the vector table. */extern int __vector_start;extern int __vector_end;#endifextern int main(int argc, char *argv[]); // Signature of the bootloader // entry point. This entry_addr // will be required whenever // the bootloader flashes itself.typedef void(*KERN_SIG)(int r0, int r1); // Signature of the kernel entry point // which the bootloader will be calling // whenever a "boot" command is executed.typedef unsigned int MAGIC_t;typedef struct { MAGIC_t MAGIC_NUM; unsigned int START_OFFSET; unsigned int END_OFFSET;} comp_flash_info_t;//typedef unsigned short u16;//typedef unsigned int u32;#if DSC21typedef struct { u16 control; u16 mode; u16 count; u16 src_lo; u16 src_hi; u16 dest_lo; u16 dest_hi; u16 status;} dma_reg_t;#define MAX_DMA_SIZE 0x7FC#elif DSC24typedef struct { u16 src_hi; u16 src_lo; u16 dest_hi; u16 dest_lo; u16 count; u16 mode; u16 control;} dma_reg_t;#define MAX_DMA_SIZE 0xFFF0#elif DSC25typedef struct { u16 control; u16 mode; u16 count; u16 src_lo; u16 src_hi; u16 dest_lo; u16 dest_hi; u16 status;} dma_reg_t;#elif DM270typedef struct { u16 control; u16 mode; u16 count; u16 src_lo; u16 src_hi; u16 dest_lo; u16 dest_hi; u16 status;} dma_reg_t;#define MAX_DMA_SIZE 0x7FC#elif DM310typedef struct { u16 control; u16 mode; u16 count; u16 src_lo; u16 src_hi; u16 dest_lo; u16 dest_hi; u16 status;} dma_reg_t;#endif#define MAGIC_DEF 0xbeeffacestatic comp_flash_info_t comp_flash_info[c_END] = { { /* c_BOOTLDR */ MAGIC_DEF, BSPCONF_BTLDR_FLASH_OFFSET, BSPCONF_BTLDR_FLASH_OFFSET+BSPCONF_BTLDR_FLASH_SIZE-1 }, { /* c_PARAMS */ MAGIC_DEF, BSPCONF_PARAMS_FLASH_OFFSET, BSPCONF_PARAMS_FLASH_OFFSET+BSPCONF_PARAMS_FLASH_SIZE-1 }, { /* c_KERNEL */ MAGIC_DEF, BSPCONF_KERNEL_FLASH_OFFSET, BSPCONF_KERNEL_FLASH_OFFSET+BSPCONF_KERNEL_FLASH_SIZE-1 }, { /* c_FILESYS */ MAGIC_DEF, BSPCONF_FS_FLASH_OFFSET, BSPCONF_FS_FLASH_OFFSET+BSPCONF_FS_FLASH_SIZE-1 },#ifdef REPLACE_VECTOR_TABLE { /* c_VECTORS */ MAGIC_DEF, BSPCONF_FLASH_OFFSET, /* Offset to start of region */ BSPCONF_FLASH_OFFSET + 0x00000030, /* Offset to start of region */#endif};typedef struct { unsigned int load_addr; unsigned int entry_addr; unsigned int num_bytes;} FHEADER_t;typedef struct { int is_SDRAM_resident; int is_SRAM_resident; int is_FLASH_resident; FHEADER_t fheader;} comp_info_t;static comp_info_t comp_info[c_END];static params_t current_params;static progress_meter_CBack_t prog_strobe;static int strobe_cnt;static int strobe_delta;#define CMDMAX 10static unsigned char cmd[CMDMAX];extern void StageTwoBoardInit(void);/****************************** Routine: Description: ******************************/void btldr_init(void){ unsigned int i, start, end, bytes, f_type; unsigned char *fill_p; io_init(); f_type = flash_init(); // f_type set as either 160 or 128 // as underlying implementation detects // the type of flash chips of the EVM.// tftp_init(); net_init();// ether_init(); cache_init(); for (i=0; i<c_END; i++) { comp_info[i].is_SDRAM_resident = FALSE; // default; override below if necessary. comp_info[i].is_SRAM_resident = FALSE; // default; override below if necessary. comp_info[i].is_FLASH_resident = FALSE; // default; override below if necessary. } if(f_type==640){ // comp_flash_info = (comp_flash_info_t *) comp_flash_info_640; } else{SYSTEM_FATAL("Wrong Flash!");} { // Has the user supplied filesystem location overrides // in the linker script? If so pick those up now. unsigned int FileSysStart; unsigned int FileSysEnd; FileSysStart = (unsigned int)(&FlashFileSysStart); FileSysEnd = (unsigned int)(&FlashFileSysEnd); if (FileSysStart || FileSysEnd) { // Yes, at least one of them is defined to be // non zero which means the user wants to override // the normal hardcoded flash location used // when storing a filesytem (See rrload linker script // for more details). if (FileSysStart) { if (FileSysStart <= comp_flash_info[c_KERNEL].START_OFFSET) { util_printf("\n"); util_printf("Error - Linker script FileSysStart too small and\n"); util_printf(" leaves no room for storing a kernel image!\n"); while (1) {} } else { comp_flash_info[c_KERNEL].END_OFFSET = FileSysStart-1; comp_flash_info[c_FILESYS].START_OFFSET = FileSysStart; } } if (FileSysEnd) { comp_flash_info[c_FILESYS].END_OFFSET = FileSysEnd; } } } // Fill the params area with 0xff so that if we // dump this area using the emulator we'll more // easily see our param strings in a sea of 0xff // chars instead of random data. Not logically // necessary, just convienient -- and not fool // proof either as when you start editing params // using the UI to make strings shorter than they // where originally then some remnants from the // old string values will show beyond the null char // of the new string. fill_p=(unsigned char *)¤t_params; bytes = sizeof(params_t); for (i=0; i<bytes; i++) { *fill_p = 0xFF; fill_p++; } // Assign some default string values within the params area. current_params.MAX_STR_LEN = PARAM_STR_LEN; // space avail for each string below. current_params.server_IP[0] = '\0'; current_params.server_MAC[0] = '\0'; current_params.device_IP[0] = '\0'; current_params.device_MAC[0] = '\0'; current_params.kernel_path[0] = '\0'; current_params.filesys_path[0] = '\0'; current_params.kernel_cmdline[0] = '\0'; current_params.user_data_1[0] = '\0'; current_params.user_data_2[0] = '\0'; current_params.user_data_3[0] = '\0'; current_params.user_data_4[0] = '\0'; current_params.user_data_5[0] = '\0';#if defined(DSC24_OSD) current_params.OSD_path[0] = '\0'; current_params.OSD_enable[0] = '\0';#endif // Next, fill in information for the bootloader proper. start = (unsigned int)(&btldr_start); end = (unsigned int)(&btldr_end); bytes = (end - start) + 1; comp_info[c_BOOTLDR].is_SRAM_resident = TRUE;// comp_info[c_BOOTLDR].is_SDRAM_resident = TRUE; comp_info[c_BOOTLDR].fheader.load_addr = start; comp_info[c_BOOTLDR].fheader.num_bytes = bytes; comp_info[c_BOOTLDR].fheader.entry_addr =(unsigned int) &main;#ifdef REPLACE_VECTOR_TABLE // Next, fill in information for the vector table start = (unsigned int)(&__vector_start); end = (unsigned int)(&__vector_end); bytes = (end - start) + 1; comp_info[c_VECTORS].is_SDRAM_resident = TRUE; comp_info[c_VECTORS].fheader.load_addr = start; comp_info[c_VECTORS].fheader.num_bytes = bytes;#endif // Next, indicate that we at least have some default set of params. comp_info[c_PARAMS].is_SRAM_resident = TRUE;// comp_info[c_PARAMS].is_SDRAM_resident = TRUE; // Next, copy any params that might be stored in // flash into our, so far defaulted, SDRAM based params // structure otherwise leave it as is. Ignore any errors cmd_copy_comp(c_PARAMS,sd_FLASH,sd_SRAM,f_NA,NULL,0); //cmd_copy_comp(c_PARAMS,sd_FLASH,sd_SDRAM,f_NA,NULL,0); // Next, Establish correct is_FLASH_resident setting for // the various components. { MAGIC_t magicn; comp_t comp; // Next, Do we have the bootloader stored? comp_info[c_BOOTLDR].is_FLASH_resident = FALSE;// comp_info[c_BOOTLDR].is_FLASH_resident = TRUE; // no magic num associated // with flash bootldr image. // So just assign a default. // Next, Do we have bootloader user params stored? comp = c_PARAMS; flash_read(comp_flash_info[comp].START_OFFSET, (unsigned short *) &magicn, sizeof(MAGIC_t), NULL); if (comp_flash_info[comp].MAGIC_NUM == magicn) { comp_info[comp].is_FLASH_resident = TRUE; } // Next, Do we have a kernel stored? comp = c_KERNEL; flash_read(comp_flash_info[comp].START_OFFSET, (unsigned short *) &magicn, sizeof(MAGIC_t), NULL); if (comp_flash_info[comp].MAGIC_NUM == magicn) { comp_info[comp].is_FLASH_resident = TRUE;#if BSPCONF_BTLDR_MEMMAP_DEBUG flash_read(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t), (unsigned short *) &(comp_info[comp].fheader), sizeof(FHEADER_t), NULL);#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -