?? 1btldr_pi.c
字號:
/* * 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> * * 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 "util.h"#include "srec.h"#include "rawbin.h"#include "osd.h"#include "linux.h"#include "usb.h"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.extern 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 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#define MAGIC_DEF 0xbeefface// This flash map works for DM270 (Intel F640 Chips).static const comp_flash_info_t comp_flash_info_640[c_END] = { // MAGIC // Start // End { MAGIC_DEF, 0x00000000, 0x0005ffff }, // i = c_BOOTLDR ~384 KB (first sector of each chip). { MAGIC_DEF, 0x00060000, 0x0007ffff }, // i = c_PARAMS ~128 KB (next one sector of each chip). { MAGIC_DEF, 0x00080000, 0x0027ffff }, // i = c_KERNEL ~2 MB // start on (64*2)kbyte boundary. { MAGIC_DEF, 0x00280000, 0x007fffff } // i = c_FILESYS ~5.5 MB // start on (64*2)kbyte boundary.};static comp_flash_info_t *comp_flash_info; // always points to either // comp_flash_info_160 or // comp_flash_info_128 or ..etc..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];/* Some boards (such as the OMAP Innovator) have an Ethernet address * stored in an EEPROM. The Ethernet initialization function for these * boards should retrieve the Ethernet address and store it in * default_MAC. The address in default_MAC will be used if and only if * the device MAC address stored in the parameter flash is a null string. */char default_MAC[18] = "00:e0:be:ef:fa:ce";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();// fat_format(); 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. } // Setup the array that defines the start and stop // addresses for the various components that can be // stored in flash. The addresses in this array need // to be carefully choosen to start on an erase // boundary of the specific flash chips detected. 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.bootldr_path[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'; // 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].fheader.load_addr = start; comp_info[c_BOOTLDR].fheader.num_bytes = bytes; comp_info[c_BOOTLDR].fheader.entry_addr =(unsigned int) &main; // Next, indicate that we at least have some default set of params. comp_info[c_PARAMS].is_SRAM_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. cmd_copy_comp(c_PARAMS,sd_FLASH,sd_SRAM,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; // 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; } // Next, Do we have a filesystem stored? comp = c_FILESYS; 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; } }}/****************************** Routine: Description: Call Back routine used when doing I/O port component loads ******************************/static void put_val_at_addr(unsigned short *vaddr, unsigned short val){
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -