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

📄 parser.c

📁 Intrisyc 公司的PXA255-bootloader,源码易懂
💻 C
📖 第 1 页 / 共 4 页
字号:
   {      itc_printf("CRC-32 of %d bytes at 0x%x is 0x%x\r\n", len, start,                  update_crc(INITIAL_CRC32, (u8 *)start, len));   }   return 1;}////////////////////////////////////////////////////////////////////////////////// bootme_parse// PURPOSE: Broadcasts a MS Platform Builder "bootme" message to announce our//          presence to any instances of such on the subnet.// PARAMS:  (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intbootme_parse(char const *arg){   cebootme();   return 1;}////////////////////////////////////////////////////////////////////////////////// help_parse// PURPOSE: Parses a help command and prints the appropriate help message.// PARAMS:  (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////inthelp_parse(char const *arg){   print_help(arg);   return 1;}////////////////////////////////////////////////////////////////////////////////// updatece_parse// PURPOSE: Parses an updatece command, downloads and flashes a CE .bin file.// PARAMS:  (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intupdatece_parse(char const *arg){   int size = 0;   if(status.ciaddr == 0)   {      message_print(PARSE_DHCP_MESSAGE);      if(!init_dhcp(&status.ciaddr,	            &status.siaddr,		    &status.giaddr,		    &status.smask))      {	 error_print(DHCP_TIMEOUT_ERROR);	 return 0;      }   }      do      cebootme();   while((size = tftplisten((u8 *)BL_TEMP_RAM)) < 0);    itc_printf("Flashing bin file: ");      return block_write_flash((u32 *)KERNEL_FLASH_START,		            (u32 *)BL_TEMP_RAM,			    size,			    FLASH_DEFAULT);}////////////////////////////////////////////////////////////////////////////////// runce_parse// PURPOSE: Parses an updatece command, downloads, decodes, and boots a CE .bin//          file.// PARAMS:  (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intrunce_parse(char const *arg){   void (*kernel)(void);   if(status.ciaddr == 0)   {      message_print(PARSE_DHCP_MESSAGE);      if(!init_dhcp(&status.ciaddr,	            &status.siaddr,		    &status.giaddr,		    &status.smask))      {	 error_print(DHCP_TIMEOUT_ERROR);	 return 0;      }   }   do      cebootme();   while(tftplisten((u8 *)BL_TEMP_RAM) < 0);    message_print(RAM_CLEAR_MESSAGE);   memset32((u32 *)CE_CLEAR_BASE, 0, CE_CLEAR_SIZE / sizeof(u32));   message_print(LOADING_CE_MESSAGE);   kernel = (void (*)(void))cedecode((u8 *)CE_RAM_BASE,		                     (u8 *)BL_TEMP_RAM);   if((u32 *)kernel != NULL)   {      kernel();   }   return 0;}////////////////////////////////////////////////////////////////////////////////// set_ip_parse// PURPOSE: Parses a set ip command; sets the IP address of the board to either//          the value specified, or gets one via bootp or dhcp.// PARAMS:  (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intset_ip_parse(char const *arg){   int retval = 0;   if(*arg != 0)   {      u32 iaddr;            if(cmpstr(arg, "dhcp"))      {	 retval =  init_dhcp(&status.ciaddr,			     &status.siaddr,			     &status.giaddr,			     &status.smask);      }      else if(cmpstr(arg, "bootp"))      {	 retval =  init_bootp(&status.ciaddr,			      &status.siaddr,			      &status.giaddr,			      &status.smask);      }      else if(cmpstr(arg, "zeroconf"))      {	 retval =  init_zeroconf(&status.ciaddr,			         &status.siaddr,			         &status.giaddr,			         &status.smask,			         &status.ttl);      }      else      {	 if(!(iaddr = atoip(arg)))	 {	    error_print(PARSE_INVALID_ARG_ERROR);	    return 0;	 }	 else	 {	    const u32 flags = FLAG_USE_STATICIP;	    status.ciaddr = iaddr;            (void) eeprom_write_item("FLAGS", sizeof("FLAGS")-1,                                     &flags, sizeof(flags));            (void) eeprom_write_item("SIP", sizeof("SIP")-1,                                     &status.ciaddr, sizeof(status.ciaddr));	    retval = 1;	 }      }   }   itc_printf("IP address: %s\r\n", iptoa(status.ciaddr));   return retval;			   }////////////////////////////////////////////////////////////////////////////////// set_mac_parse// PURPOSE: Parses a set mac command, and updates the MAC address of the board// PARAMS:  (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intset_mac_parse(char const *arg){   u16 macaddr[3];   char temp[5];   int retval = 0;   char answer;   unsigned int num;      if(*arg != 0)   {      if(itc_strlen(arg) < 12 ||         !(atou16(arg, &macaddr[0]) &&           atou16(arg += 4, &macaddr[1]) &&           atou16(arg += 4, &macaddr[2])))      {	 error_print(PARSE_INVALID_ARG_ERROR);	 return 0;      }      else      {         arg = next_token(arg);	 if (*arg != '\0')	 {            if (!atoi (arg, &num))	    {	       num = 0;	    }	 } else	 {	    num = 0;	 }	          itc_printf("\CAUTION: Changing the MAC address can cause serious network problems.\r\n\Are you sure you want to continue? [y/n] ");         while (!input_byte_serial(&answer))            idle();         itc_printf("%c\r\n", answer);         if (answer != 'y')         {            itc_printf("MAC address not changed\r\n");            return 0;         }      	 macaddr[0] = htons(macaddr[0]);	 macaddr[1] = htons(macaddr[1]);	 macaddr[2] = htons(macaddr[2]);	 retval = write_mac_ethernet((u16 *)macaddr, (unsigned short)num);	 init_ethernet((u16 *)status.macaddr);      }   }   itc_printf("MAC address: ");   u16toa(htons(status.macaddr[0]), temp);   itc_printf(temp);   u16toa(htons(status.macaddr[1]), temp);   itc_printf(temp);   u16toa(htons(status.macaddr[2]), temp);   itc_printf(temp);   itc_printf("\r\n");      return retval;}////////////////////////////////////////////////////////////////////////////////// eraseflash_parse// PURPOSE: Parses an eraseflash command and erases flash appropriately.// PARAMS:  (IN) char *arg - argument string// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////interaseflash_parse(char const *arg){   u32 start = 0, length = 0;   if(!get_number_parse(arg, &start))   {      error_print(PARSE_INVALID_ARG_ERROR);      return 0;   }   arg = next_token(arg);   if(start < 1 || start > (NUM_FLASH_BLOCKS - 1))   {      error_print(PARSE_RANGE_ERROR);      return 0;   }   if(!get_number_parse(arg, &length))   {      char answer = 'n';      length = NUM_FLASH_BLOCKS - start;      itc_printf("Do you wish to erase flash blocks %i-%i? [y/n] ",                 start, NUM_FLASH_BLOCKS-1);      while(!input_byte_serial(&answer))         idle();      itc_printf("%c\r\n", answer);      if(answer != 'y')         return 0;   }   else   {      if((length + start) > NUM_FLASH_BLOCKS)      {	 error_print(PARSE_RANGE_ERROR);	 return 0;      }   }   while(length-- > 0)   {      u32 *flash_addr = (u32 *)(start * flash_block_size_platform());      itc_printf("\rErasing block %i", start++);      if(!block_erase_flash(flash_addr))      {	 return 0;      }   }   itc_printf("\r\n");   return 1;}////////////////////////////////////////////////////////////////////////////////// reboot_parse// PURPOSE: Reboot the machine// PARAMS:  (IN) char *arg - argument string.// RETURNS: Never returns.////////////////////////////////////////////////////////////////////////////////intreboot_parse(char const *arg){   void (*restart_vector)(void) = 0;   if(!get_number_parse(arg, (u32 *)&restart_vector))   {       restart_vector = NULL;   }   itc_printf("Restarting...\r\n");   // Wait for serial buffer to be flushed   delay(1);   restart_vector();   itc_printf("Strange--we didn't restart\r\n");   return 1;    // Should never get here}////////////////////////////////////////////////////////////////////////////////// ping_parse// PURPOSE: Sends ICMP echo request to remote node.// PARAMS:  (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intping_parse(char const *arg){   u32 iaddr;   if(!(iaddr = atoip(arg)))   {      error_print(PARSE_INVALID_IP_ERROR);      return 0;   }   if(status.ciaddr == 0)   {      message_print(PARSE_DHCP_MESSAGE);      if(!init_dhcp(&status.ciaddr,	            &status.siaddr,		    &status.giaddr,		    &status.smask))      {	 error_print(DHCP_TIMEOUT_ERROR);	 return 0;      }   }   itc_printf("Pinging %s\r\n", iptoa(iaddr));   icmpping(iaddr);   // Wait a moment for the response to come in so it doesn't mess up our   // output.   delay(1);   return 1;}////////////////////////////////////////////////////////////////////////////////// createfis_parse// PURPOSE: Calculates CRC on a memory range.// PARAMS:  (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intcreatefis_parse(char const *arg){   static struct fis_image_desc fistable[NUM_FLASH_BLOCKS];   struct fis_image_desc *fisentry = fistable;   int blocks,totalblocks,numentries;   // Clear out fis image to default   memset8((u8 *)fistable, 0xff, sizeof(fistable));   if (!get_number_parse(arg, (u32 *)&blocks) || (blocks < 1))   {      error_print(PARSE_INVALID_ARG_ERROR);      return 0;   }   // Set up magic RedBoot entry as first block as a duplicate to user's   // first entry.  Linux only parses the table if it sees this entry.   itc_strcpy(fisentry->name, "RedBoot");   fisentry->flash_base = (char *) PLATFORM_FLASH_BASE;   fisentry->mem_base = 0;   fisentry->size = blocks * MAIN_BLOCK_SIZE;   fisentry->entry_point = 0;   fisentry->data_length = blocks * MAIN_BLOCK_SIZE;   fisentry->desc_cksum = 0;   fisentry->file_cksum = 0;   ++fisentry;   numentries = 1;   totalblocks = 0;     // First entry in loop is duplicate of RedBoot entry   while (*arg != '\0')   {      if (numentries == 1)      {          // First entry is always for I-Boot          itc_strcpy(fisentry->name, "I-Boot");      } else      {          // Zero out name because itoa doesn't nul-terminate          memset8((u8 *)fisentry->name, 0, sizeof(fisentry->name));          itc_strcpy(fisentry->name, "Partition ");          itoa(numentries, &fisentry->name[10]);      }      fisentry->flash_base =         (char *) (PLATFORM_FLASH_BASE + totalblocks * MAIN_BLOCK_SIZE);      fisentry->mem_base = 0;      fisentry->size = blocks * MAIN_BLOCK_SIZE;      fisentry->entry_point = 0;      fisentry->data_length = blocks * MAIN_BLOCK_SIZE;      fisentry->desc_cksum = 0;      fisentry->file_cksum = 0;      ++fisentry;      ++numentries;      totalblocks += blocks;      arg = next_token(arg);      if (*arg && (!get_number_parse(arg, (u32 *)&blocks) || (blocks < 1)))      {         error_print(PARSE_INVALID_ARG_ERROR);         return 0;      }   }   if (totalblocks > (NUM_FLASH_BLOCKS - 1))   {       itc_printf("Error: Too many blocks specified\r\n");       return 0;   }   if (totalblocks < (NUM_FLASH_BLOCKS - 1))   {       itc_printf("NOTE: %d blocks are unallocated\r\n",                  NUM_FLASH_BLOCKS - 1 - totalblocks);   }   itc_printf("Flashing: ");   if (block_write_flash(        (u32 *)(PLATFORM_FLASH_BASE + PLATFORM_FLASH_SIZE - MAIN_BLOCK_SIZE),        (u32 *)fistable,        numentries*sizeof(struct fis_image_desc), FLASH_DEFAULT))   {      return 1;   }   return 0;}#ifdef TAGGED_EEPROM////////////////////////////////////////////////////////////////////////////////// eeclear_parse// PURPOSE: Clear the contents of the EEPROM, except for the MAC address// PARAMS:  (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////inteeclear_parse(char const *arg){    itc_printf("Clearing the contents of the EEPROM\r\n");    nv_upgrade(1);    return 0;}////////////////////////////////////////////////////////////////////////////////// eedump_parse// PURPOSE: Dump the contents of the EEPROM// PARAMS:  (IN) char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////inteedump_parse(char const *arg){    eeprom_dump();    return 0;}#endif // TAGGED_EEPROM

⌨️ 快捷键说明

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