📄 1btldr_pi.c
字号:
/****************************** Routine: Description: ******************************/static void push_to_flash(comp_t comp){ int status; if (TRUE == flash_area_has_content(comp)) { util_printf("Warning: Can't overwrite existing one; Aborting\n"); util_printf("Press <Enter>....\n"); util_gets(cmd,CMDMAX); return; } switch (comp) { case c_BOOTLDR: if (TRUE == comp_info[comp].is_SRAM_resident) { 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); comp_info[comp].is_FLASH_resident = TRUE; } break; case c_PARAMS: if (TRUE == comp_info[comp].is_SRAM_resident) { flash_write(comp_flash_info[comp].START_OFFSET, (unsigned short *) &(comp_flash_info[comp].MAGIC_NUM), sizeof(MAGIC_t),NULL); flash_write(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t), (unsigned short *) ¤t_params, sizeof(current_params),NULL); flash_write(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t) + sizeof(current_params), (unsigned short *) &(comp_info[comp].fheader), sizeof(FHEADER_t), NULL); 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); comp_info[comp].is_FLASH_resident = TRUE; } break; case c_KERNEL: if (TRUE == comp_info[comp].is_SDRAM_resident) { flash_write(comp_flash_info[comp].START_OFFSET, (unsigned short *) &(comp_flash_info[comp].MAGIC_NUM), sizeof(MAGIC_t), NULL); flash_write(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t), (unsigned short *) &(comp_info[comp].fheader), sizeof(FHEADER_t), NULL); 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); comp_info[comp].is_FLASH_resident = TRUE; } 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) { flash_write(comp_flash_info[comp].START_OFFSET, (unsigned short *) &(comp_flash_info[comp].MAGIC_NUM), sizeof(MAGIC_t), NULL); flash_write(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t), (unsigned short *) &(comp_info[comp].fheader), sizeof(FHEADER_t), NULL); 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); comp_info[comp].is_FLASH_resident = TRUE; } break; default: SYSTEM_FATAL("Logic Error"); break; } status = flash_flush(); if (status >= 0) { util_printf("Flash Write error at offset %d\n",status); SYSTEM_FATAL("Fatal"); }}/****************************** 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){ // !!!!!!!!!!! // 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 // 4. copy from sram to flash // // !!!!!!!!!!! prog_strobe = CBack; strobe_delta = strobe_interval; strobe_cnt = 0; switch (d) { default: // The d parameter is totally ignored since all // the currenlty 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: case sd_SRAM: push_to_flash(c); break; case sd_FLASH: pull_from_flash(c); break; case sd_TFTP:/* if (c_BOOTLDR == c) { connect_tftp(current_params.device_IP, current_params.server_IP, current_params.device_MAC, current_params.server_MAC);// current_params.bootldr_path); }*/ 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); } load(c,s,f); disconnect_tftp(); break; case sd_PARPORT: case sd_SERPORT: util_printf("Seclect the protocol and the file!\n"); load(c,s,f); break;/* case sd_USB: util_printf("Put the file to the USB!\n"); load(c,s,f); break;*/ default: SYSTEM_FATAL("Logic Error"); break; }}/****************************** 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){ struct tag *params = (struct tag *)0x01230100; if (auto_xfer) { // Next, Check to see if the components needed for a // kernel boot are already in RAM. If not there // already then move the image to RAM *if* it needs // to go there before use. 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. if ((comp_info[c_KERNEL].is_FLASH_resident)&(!comp_info[c_KERNEL].is_SDRAM_resident)) { cmd_copy_comp(c_KERNEL,sd_FLASH,sd_SDRAM,f_NA,CBack,strobe_interval); } if ((comp_info[c_FILESYS].is_FLASH_resident)&(!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 ) { 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. 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. params->hdr.tag = ATAG_CORE; params->hdr.size = tag_size(tag_core); params->u.core.flags = 0; params->u.core.pagesize = PAGE_SIZE; params->u.core.rootdev = RAMDISK_MAJOR << 8 | 0; params = tag_next(params); params->hdr.tag = ATAG_MEM; params->hdr.size = tag_size(tag_mem32); params->u.mem.start = 0x01230000; params->u.mem.size = 64 * 1024 * 1024; params = tag_next(params); if (util_strlen(current_params.kernel_cmdline)) { params->hdr.tag = ATAG_CMDLINE; params->hdr.size = (sizeof(struct tag_header) + util_strlen(current_params.kernel_cmdline) + 3) >> 2; util_strcpy(params->u.cmdline.cmdline, current_params.kernel_cmdline); util_printf("\nCommand line overrides = %s\n", params->u.cmdline.cmdline); params = tag_next(params); } params->hdr.tag = ATAG_NONE; params->hdr.size = 0; // Next, jump to it... // Note r0 and r1 values don't matter on entry. (*((KERN_SIG)(comp_info[c_KERNEL].fheader.entry_addr)))(0,0); }}/****************************** 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 + -