⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1btldr_pi.c

📁 针对德州仪器DM270开发板的bootloader,其实现了内核的下载以及文件系统的下载
💻 C
📖 第 1 页 / 共 3 页
字号:
  // Since this callback is used during I/O port loads  // which might be processing an incoming XIP compontent  // we'll have to check the address as appropriate.    if (io_AddressIsInFlashSpace((unsigned int)vaddr)) {    // The load is going directly to flash. XIP components.    flash_write(((unsigned int)(vaddr)-BSPCONF_FLASH_BASE),&val,2,NULL);  }  else {    *vaddr = val;  }  if (prog_strobe) {    // Let client update whatever UI progress    // meter they might be displaying.    if (strobe_cnt++ == strobe_delta) {      strobe_cnt = 0;      (*prog_strobe)();    }      }}/****************************** Routine: Description: ******************************/static void get_val_from_addr(unsigned short *vaddr, unsigned short *val){  *val = *vaddr;  // printf("0x%x: 0x%x\n",vaddr,*val); // *debug* temp.  if (prog_strobe) {    // Let client update whatever UI progress    // meter they might be displaying.    if (strobe_cnt++ == strobe_delta) {      strobe_cnt = 0;      (*prog_strobe)();    }      }}/****************************** Routine: Description: ******************************/static void load(comp_t c,                 src_dest_t s, port_format_t f){  int status = LOAD_OK;   int use_header = TRUE;  GetByteCallBack_t GetByteFunc;  switch(s) {    case sd_PARPORT:      GetByteFunc = io_getchar_par;      break;    case sd_SERPORT:      GetByteFunc = io_getchar_ser;      break;/*    case sd_USB:      GetByteFunc = usb_getchar;      break;*/    case sd_TFTP:      GetByteFunc = getchar_tftp;      break;    case sd_FLASH:    case sd_SDRAM:    case sd_SRAM:    default:      SYSTEM_FATAL("Wrong I/O port!");      break;  }  switch(f) {    case f_SREC:      {        srec_RegisterGetByte(GetByteFunc);        srec_RegisterPut(&put_val_at_addr);        status = srec_parse(&(comp_info[c].fheader.load_addr),                            &(comp_info[c].fheader.entry_addr),                            &(comp_info[c].fheader.num_bytes));      }      break;    case f_RR_BINARY:      {        rawbin_RegisterGetByte(GetByteFunc);        rawbin_RegisterPut(&put_val_at_addr);        status = rawbin_parse(&(comp_info[c].fheader.load_addr),                              &(comp_info[c].fheader.entry_addr),                              &(comp_info[c].fheader.num_bytes),				      &use_header);      }      break;/*    case f_BINARY:      {        rawbin_RegisterGetByte(GetByteFunc);        rawbin_RegisterPut(&put_val_at_addr);        status = bin_parse(&(comp_info[c].fheader.load_addr),                              &(comp_info[c].fheader.num_bytes));      }      break;*/    case f_NA:    default:      SYSTEM_FATAL("Wrong format!");      break;  }    if (LOAD_OK != status) {    util_printf("ERROR: parse status = %d: Aborting.\n",status);  }  else {    util_printf("LOAD OK!\n");    // Next,    // Where did that load just go? ram or flash? Remember that    // components intended to run in-place in flash will be loaded    // directly into the flash memory map space (XIP). If so, we assume the    // loaded image was constructed to load to the very specific flash    // locations we've documented for kernel and filesystem XIP component    // images. Also, we assume that prior to the load the user had    // first erased that area of flash. For more information look at    // XIP discussions in project doc.    if (io_AddressIsInFlashSpace(comp_info[c].fheader.load_addr)) {      util_printf("The kernel is in the FLASH!\n");      // XIP component image just loaded to flash. Now need to add       // the magic num and info header that goes with it.      flash_flush();      // JFFS2 cannot handle the header info.      // REVISIT - RA - This is not a great idea.  Steve Kranz recommends      // moving the filesystem to 0x00250000, and leave the header info      // at 0x00240000.      flash_write(comp_flash_info[c].START_OFFSET,                  (unsigned short *) &(comp_flash_info[c].MAGIC_NUM),                  sizeof(MAGIC_t),                  NULL);      flash_write(comp_flash_info[c].START_OFFSET + sizeof(MAGIC_t),                  (unsigned short *) &(comp_info[c].fheader),                  sizeof(FHEADER_t),                  NULL);      flash_flush();      comp_info[c].is_FLASH_resident = TRUE;    }    else {      // Ram based component just loaded.      util_printf("The kernel is in the SDRAM!\n");      comp_info[c].is_SDRAM_resident = TRUE;     }  }    return;}/****************************** Routine: Description: ******************************/static void dma_flash_read(unsigned int offset,  // Of flash.                           unsigned int dest, // Destination buffer                           unsigned int num_bytes){        u32 frm_addr,to_addr,count;        volatile dma_reg_t *dma_regs = (dma_reg_t *) 0x30a38;        //util_printf("\nin dma copy\n");        dma_regs = (dma_reg_t *) 0x30a38;        frm_addr = offset;        to_addr = dest;        to_addr -= 0x900000;  // Pull offset from SDRAM base.        count = num_bytes;        dma_regs->mode =0x1D; // Set mode for SDRAM and FLASH.        while (count > 0)        {                //util_printf("From is %X\n",frm_addr);                dma_regs->src_hi = (frm_addr>>16)&0x3ff;                dma_regs->src_lo = (frm_addr & 0xffff);                //util_printf("To is %X\n",to_addr);                dma_regs->dest_hi = (to_addr>>16)&0x3ff;                dma_regs->dest_lo = (to_addr & 0xffff);                //util_printf("Count is %X\n", count);                if (count < MAX_DMA_SIZE)                {                        dma_regs->count = count;                        dma_regs->control = 1;  //Trigger DMA.                        count = 0;                } else                {                        dma_regs->count = MAX_DMA_SIZE;                        dma_regs->control = 1;  //Trigger DMA.                        count -= MAX_DMA_SIZE;                        frm_addr += MAX_DMA_SIZE;                        to_addr += MAX_DMA_SIZE;                }                while(dma_regs->control); //delay till dma done.        }}/****************************** Routine: Description: ******************************/static void pull_from_flash(comp_t comp){  MAGIC_t magicn;  switch (comp) {    case 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) {        flash_read(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t),                   (unsigned short *) &current_params,                   sizeof(current_params),                   NULL);        comp_info[comp].is_SDRAM_resident = TRUE;      }      break;    case c_KERNEL:    case 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) {        flash_read(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t),                   (unsigned short *) &(comp_info[comp].fheader),                   sizeof(FHEADER_t),                   NULL);        if (io_AddressIsInFlashSpace(comp_info[comp].fheader.load_addr)) {          // This component is intended to be used in-place. It          // has a load_addr that is in flash space which means          // that when the user originally "loaded" this component          // the srec or rrbin or ?? image indicated that it was to          // load into flash space. In this case there is no need          // to move it to SDRAM before using it.           return;        }        // Next, move the image to SDRAM as per the        // value of load_addr recored with the image.        dma_flash_read(comp_flash_info[comp].START_OFFSET + sizeof(MAGIC_t) + sizeof(FHEADER_t),                       comp_info[comp].fheader.load_addr,                       comp_info[comp].fheader.num_bytes);                comp_info[comp].is_SDRAM_resident = TRUE;        // util_printf("retrieved -- load_addr 0x%X, entry_addr 0x%X, num_bytes 0x%X\n",        //             comp_info[comp].fheader.load_addr,        //             comp_info[comp].fheader.entry_addr,        //             comp_info[comp].fheader.num_bytes); // *debug* temp.      }      break;    case c_BOOTLDR:      // Pull this to SDRAM, why? Ignore this request since      // for the bootldr the very act of doing so would pull      // bytes down on top of the very program running now,      // presumably at that same SDRAM location. So, for this      // particular implementation of the btldr_pi.h      // programmer's interface, we will not support this type      // of flash -> SDRAM copy request.      break;    default:      SYSTEM_FATAL("Logic Error");      break;  }}/****************************** Routine: Description: ******************************/static int flash_area_has_content(comp_t comp){  unsigned short test_word;    return FALSE; // *debug* temp  // A Quick-and-Dirty test to see if the area of flash  // that normally holds component "comp" is already occupied  // with content.  switch (comp) {    case c_BOOTLDR:    case c_PARAMS:    case c_KERNEL:    case c_FILESYS:      // good it's one we recognize.      break;    default:      // what?, just return.     return TRUE;     break;  }  flash_read(comp_flash_info[comp].START_OFFSET,             (unsigned short *)&test_word,             sizeof(unsigned short),             NULL);  if (0xFFFF == test_word) {    // no content, this area of flash appears to be empty (erased).    return FALSE;  }  else {    // content found.     return TRUE;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -