📄 btldr_pi.c
字号:
} switch (comp) {#ifdef REPLACE_VECTOR_TABLE case c_VECTORS: if (TRUE == comp_info[comp].is_SDRAM_resident) { ret |= flash_write(comp_flash_info[comp].START_OFFSET, (unsigned short *) (comp_info[comp].fheader.load_addr), comp_info[comp].fheader.num_bytes, NULL); if (ret == 0) { comp_info[comp].is_FLASH_resident = TRUE; } } break;#endif case c_BOOTLDR: if (TRUE == comp_info[comp].is_SDRAM_resident) { ret |= flash_write(comp_flash_info[comp].START_OFFSET, (unsigned short *) (comp_info[comp].fheader.load_addr), comp_info[comp].fheader.num_bytes, get_val_from_addr); if (ret == 0) { comp_info[comp].is_FLASH_resident = TRUE; } } break; case c_PARAMS: if (TRUE == comp_info[comp].is_SDRAM_resident) { ret |= flash_write(comp_flash_info[comp].START_OFFSET, (unsigned short *) &(comp_flash_info[comp].MAGIC_NUM), sizeof(MAGIC_t),NULL); ret |= flash_write(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t), (unsigned short *) ¤t_params, sizeof(current_params),NULL);#if defined(DSC24_OSD) ret |= flash_write(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t) + sizeof(current_params), (unsigned short *) &(comp_info[comp].fheader), sizeof(FHEADER_t), NULL); ret |= flash_write(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t) + sizeof(current_params) + sizeof(FHEADER_t), (unsigned short *) (comp_info[comp].fheader.load_addr), comp_info[comp].fheader.num_bytes, get_val_from_addr);#endif if (ret == 0) { comp_info[comp].is_FLASH_resident = TRUE; } } break; case c_KERNEL: if (TRUE == comp_info[comp].is_SDRAM_resident) { ret |= flash_write(comp_flash_info[comp].START_OFFSET, (unsigned short *) &(comp_flash_info[comp].MAGIC_NUM), sizeof(MAGIC_t), NULL); ret |= flash_write(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t), (unsigned short *) &(comp_info[comp].fheader), sizeof(FHEADER_t), NULL); ret |= flash_write(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t) + sizeof(FHEADER_t), (unsigned short *) (comp_info[comp].fheader.load_addr), comp_info[comp].fheader.num_bytes, get_val_from_addr); if (ret == 0) { comp_info[comp].is_FLASH_resident = TRUE; } /* If the kernel is compressed, then "remove" the compressed kernel from RAM, so rrload boot logic will store the decompressed image there */#if ( BSPCONF_KERNEL_COMPRESSED == 1 ) || ( BSPCONF_FS_COMPRESSED == 1 ) if (image_is_compressed((char *)comp_info[comp].fheader.load_addr)) { comp_info[comp].is_SDRAM_resident = FALSE; }#endif } break; case c_FILESYS: // util_printf("flashing -- load_addr 0x%X, entry_addr 0x%X, num_bytes 0x%X, offset 0x%X\n", // comp_info[comp].fheader.load_addr, // comp_info[comp].fheader.entry_addr, // comp_info[comp].fheader.num_bytes, // comp_flash_info[comp].START_OFFSET); // *debug* temp. if (TRUE == comp_info[comp].is_SDRAM_resident) {#if !defined(OMAP1510) ret |= flash_write(comp_flash_info[comp].START_OFFSET, (unsigned short *) &(comp_flash_info[comp].MAGIC_NUM), sizeof(MAGIC_t), NULL); ret |= flash_write(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t), (unsigned short *) &(comp_info[comp].fheader), sizeof(FHEADER_t), NULL); ret |= flash_write(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t) + sizeof(FHEADER_t), (unsigned short *) (comp_info[comp].fheader.load_addr), comp_info[comp].fheader.num_bytes, get_val_from_addr);#else // JFFS2 cannot handle the header info. // REVISIT - DG: Now that we are leaving out the header, what bad things happen? ret |= flash_write(comp_flash_info[comp].START_OFFSET, (unsigned short *) (comp_info[comp].fheader.load_addr), comp_info[comp].fheader.num_bytes, get_val_from_addr);#endif if (ret == 0) { comp_info[comp].is_FLASH_resident = TRUE; } /* If the file system is compressed, then "remove" the compressed file system from RAM, so rrload boot logic will store the decompressed image there */#if ( BSPCONF_KERNEL_COMPRESSED == 1 ) || ( BSPCONF_FS_COMPRESSED == 1 ) if (image_is_compressed((char *)comp_info[comp].fheader.load_addr)) { comp_info[comp].is_SDRAM_resident = FALSE; }#endif } break; default: SYSTEM_FATAL("Logic Error"); break; } status = flash_flush(); if (status >= 0) { util_printf("Flash Write error at offset %d\n",status); return -1; } return ret;}/****************************** Routine: Description: Note: See btldr_pi.h for description. ******************************/int cmd_copy_comp(comp_t c, //component src_dest_t s, //src src_dest_t d, //dest port_format_t f, //format progress_meter_CBack_t CBack, int strobe_interval){ int ret = 0; // !!!!!!!!!!! // Note: // Of all the possible combinations of s and d parameters // only the following are currently supported by this particular // bootloader. Other bootloaders implementing the btldr_pi.h // interface may chose to support more combinations. // // 1. copy from port to sdram // 2. copy from flash to sdram // 3. copy from sdram to flash // // !!!!!!!!!!! prog_strobe = CBack; strobe_delta = strobe_interval; strobe_cnt = 0; switch (d) { default: // The d parameter is totally ignored since all // the currently supported modes can be deduced by // testing the s param only. break; } switch (s) { // Note: | Again, with the specified source (s) we'll assume the // | destination -- independent of the dest (d) parameter. case sd_SDRAM: ret |= push_to_flash(c); break; case sd_FLASH: pull_from_flash(c); break; case sd_TFTP: if (c_KERNEL == c) { connect_tftp(current_params.device_IP, current_params.server_IP, current_params.device_MAC, current_params.server_MAC, current_params.kernel_path); } else if (c_FILESYS == c) { connect_tftp(current_params.device_IP, current_params.server_IP, current_params.device_MAC, current_params.server_MAC, current_params.filesys_path); } #if defined(DSC24_OSD) else if (c_PARAMS == c) { connect_tftp(current_params.device_IP, current_params.server_IP, current_params.device_MAC, current_params.server_MAC, current_params.OSD_path); } #endif ret |= load(c,s,f); disconnect_tftp(); break; case sd_PARPORT: case sd_SERPORT: ret |= load(c,s,f); break; default: SYSTEM_FATAL("Logic Error"); break; } return ret;}/****************************** Routine: Description: Note: See btldr_pi.h for description. ******************************/params_t *cmd_get_params(void){ return ¤t_params;}/****************************** Routine: Description: Note: See btldr_pi.h for description. ******************************/void cmd_boot_kernel(int auto_xfer, // TRUE or FALSE, progress_meter_CBack_t CBack, int strobe_interval){ if (auto_xfer) { // If the kernel and/or file system is in RAM, // check to see if it is compressed#if ( BSPCONF_KERNEL_COMPRESSED == 1 ) || ( BSPCONF_FS_COMPRESSED == 1 ) if (comp_info[c_KERNEL].is_SDRAM_resident && image_is_compressed((char *)comp_info[c_KERNEL].fheader.load_addr)) { util_printf("\nRAM kernel image is compressed.\n"); util_printf("You must first save the kernel to flash.\n\n"); util_printf("Press enter to return to main menu. "); util_gets(cmd,CMDMAX); return; } if (comp_info[c_FILESYS].is_SDRAM_resident && image_is_compressed((char *)comp_info[c_FILESYS].fheader.load_addr)) { util_printf("\nRAM file system image is compressed.\n"); util_printf("You must first save the file system to flash.\n\n"); util_printf("Press enter to return to main menu. "); util_gets(cmd,CMDMAX); return; }#endif if (!comp_info[c_KERNEL].is_SDRAM_resident) { // If the kernel or file system is not in RAM and needs to be there, // copy them to RAM. Data recorded with the // image indicates our course of action. If the // image is intended to be used *directly* from flash // then the following calls have no effect. Ignore errors cmd_copy_comp(c_KERNEL,sd_FLASH,sd_SDRAM,f_NA,CBack,strobe_interval); }#if ( BSPCONF_KERNEL_COMPRESSED == 1 ) || ( BSPCONF_FS_COMPRESSED == 1 ) if (comp_info[c_FILESYS].is_SDRAM_resident) { if (image_is_compressed((char *)comp_info[c_FILESYS].fheader.load_addr)) { util_printf("\nRAM file system image is compressed.\n"); util_printf("You must first save the file system to flash.\n\n"); util_printf("Press enter to return to main menu. "); util_gets(cmd,CMDMAX); return; } }#endif if (!comp_info[c_FILESYS].is_SDRAM_resident) { cmd_copy_comp(c_FILESYS,sd_FLASH,sd_SDRAM,f_NA,CBack,strobe_interval); } } if (comp_info[c_KERNEL].is_SDRAM_resident || comp_info[c_KERNEL].is_FLASH_resident) { // Next, Put our device ethernet MAC in the special memory location // which the kernel will reference when initializing its // ethernet driver. // First write a magic string that gives validity to this area of SDRAM. // The kernel will test validity prior to using the command line we are // going to deposit. util_strcpy((unsigned char *)&__EtherMACMagicStr,"etherMAC-->"); *((unsigned char *)&__EtherMAC) = (unsigned char) 0; util_strcpy((unsigned char *)&__EtherMAC,current_params.device_MAC); // Next, Put our kernel command line overrides in the special // memory location which the kernel will reference on boot. // First write a magic string that gives validity to this area of SDRAM. // The kernel will test validity prior to using the command line we are // going to deposit. util_strcpy((unsigned char *)&__KernCommandLineMagicStr,"kcmdline-->"); *((unsigned char *)&__KernCommandLineOverride) = (unsigned char) 0; util_strcpy((unsigned char *)&__KernCommandLineOverride,current_params.kernel_cmdline); util_printf("\nCommand line overrides = %s\n",(unsigned char *)&__KernCommandLineOverride); util_printf("Jumping to 0x%X\n",comp_info[c_KERNEL].fheader.entry_addr); io_delay(100); // kill some time to allow printf chars to get out // the i/o port before we jump to the kernel.#if 0 *((unsigned int*)0xffff2800) = 0; // turn off power/status LED#endif lock_flash(); // We'll keep flash unlocked the whole // time the bootloader is running until // it is time to transfer control to the // kernel at which time we first lock // flash. Hopefully this will prevent // corrupted flash that might otherwise // result in a run-away program randomly // jumping into the flash logic of the // bootloader image still laying around // in ram from a prior run. // Make sure the cache doesn't have any bad data icache_disable(); icache_clear(); // Next, jump to it...#if defined(OMAP1510) // Note we set r0=0 and r1=171 on entry to kernel. (*((KERN_SIG)(comp_info[c_KERNEL].fheader.entry_addr)))(0,171);#elif defined(DM310) // Invalidate the DM310 instruction cache invalidate_cache(); // Note we set r0=0 and r1=172 on entry to kernel. (*((KERN_SIG)(comp_info[c_KERNEL].fheader.entry_addr)))(0,172);#else // Note r0 and r1 values don't matter on entry. (*((KERN_SIG)(comp_info[c_KERNEL].fheader.entry_addr)))(0,0);#endif }}/****************************** Routine: Description: Note: See btldr_pi.h for description. ******************************/void erase_comp(comp_t c){ flash_erase_range((comp_flash_info[c].START_OFFSET)+BSPCONF_FLASH_BASE, (comp_flash_info[c].END_OFFSET)+BSPCONF_FLASH_BASE); comp_info[c].is_FLASH_resident = FALSE;}/****************************** Routine: Description: Note: See btldr_pi.h for description. ******************************/void lock_flash(void){ FlashLockMode = 0x00000000;}/****************************** Routine: Description: Note: See btldr_pi.h for description. ******************************/void unlock_flash(void){ // Place a special pattern in a special // memory location. The idea here is that // stray program code running amock from // the kernel or a kernel driver that happens // to run itself into the flash logic of // bootloader (still left over in memory) // will not succeed in corrupting flash // since the low level routines will test // for this special pattern before modifying // any flash contents. In normal bootloader // operation the flash will remain unlocked // and then locked whenever it transfers // control to another program (e.g. the kernel) FlashLockMode = 0xBEEFFEED;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -