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

📄 load.c

📁 MIPS下的boottloader yamon 的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        /* read out load address */
        shell_load_addr       = load_adr_context[0] ;
	shell_load_addr_valid = TRUE;

        switch( rc )
        {
          case ERROR_LOAD_NONE :
	    break;	       /* Done */
          case ERROR_LOAD_BREAK :
	    return SHELL_ERROR_CONTROL_C_DETECTED;
          default :
            if( !retry )
            {
	        return raw_error;
            }

            if( raw_error != ERROR_NET_ARP_TIME_OUT )
            {
	        return raw_error;
            }
	    else
	    {
	        if( first_error )
		{
                    printf( "\n" );
		    first_error = FALSE;
		}

	        shell_command_error( NULL, raw_error );
	    }

    	    break;
        }

	if( rc != ERROR_LOAD_NONE )
	{
	    /* Pause 1 sec */
	    sys_wait_ms( 1000 );
	}
    }
    while( rc != ERROR_LOAD_NONE );

    /* insert start address */
    strcpy( msg, MSG_LOAD );
    insert = strchr( msg, '$' );
    ch = insert[sizeof(UINT32)*2];	    
    sprintf( insert, "%08x", (UINT32)load_adr_context[0] );
    insert[sizeof(UINT32)*2] = ch;

    /* insert min address */
    insert = strchr( msg, '$' );
    ch = insert[sizeof(UINT32)*2];	    
    sprintf( insert, "%08x", (UINT32)load_adr_context[1] );
    insert[sizeof(UINT32)*2] = ch;

    /* insert max address */
    insert = strchr( msg, '$' );
    ch = insert[sizeof(UINT32)*2];	    
    sprintf( insert, "%08x", (UINT32)load_adr_context[2] );
    insert[sizeof(UINT32)*2] = ch;

    switch( format )
    { 
      case MOTOROLA_S3 :
	format_string = "SREC"; break;
      case MICROSOFT_BIN :
	format_string = "WINCEBIN"; break;
      default :
	format_string = "UNKNOWN"; break;
    }

    insert = strchr( insert, '$' );
    sprintf( insert, "%s", format_string );
    printf( msg );

    return OK;
}


/************************************************************************
 *                          parse
 ************************************************************************/
static UINT32
parse(
    char   *s,
    UINT32 *protocol,
    UINT32 *src,
    char   **filename )
{
    UINT32 state;
    char   *proto_start;
    char   *src_start;
    char   *name_start;

    proto_start = NULL;
    src_start   = NULL;
    name_start  = NULL;

    state = ST_START;

    while( (state != ST_DONE) && (state != ST_ERROR) )
    {
        switch( state )
	{
	  case ST_START :
	    switch( *s )
	    {
	      case ':' :
		shell_error_hint = msg_hint_filename;
		state = ST_ERROR;
		break;
	      case '/' :
		state = ST_GET_SRC_OR_NAME;
		break;
	      case ' ' :
		state = ST_ERROR;
		break;
	      case '\0' :
		state = ST_DONE;
		break;
	      default :
	        proto_start = s;
		state       = ST_GET_PROTOCOL;
		break;
	    }
	    break;
	  
	  case ST_GET_PROTOCOL :
	    switch( *s )
	    {
	      case ':' :
	        *s    = '\0';
		state = ST_GOT_PROTOCOL;
		break;
	      case '/' :
	      case ' ' :
	      case '\0' :
		shell_error_hint = msg_hint_filename;
		state = ST_ERROR;
		break;
	      default :
		state = ST_GET_PROTOCOL;
		break;
	    }
	    break;

	  case ST_GOT_PROTOCOL :
	    switch( *s )
	    {
	      case ':' :
	        state = ST_ERROR;
	        break;
	      case '/' :
	        state = ST_GET_SRC_OR_NAME;
	        break;
	      case ' ' :
	        state = ST_ERROR;
	        break;
	      case '\0' :
	        state = ST_DONE;
		break;
	      default :
	        state = ST_ERROR;
	        break;
	    }
	    break;
	  case ST_GET_SRC_OR_NAME :
	    switch( *s )
	    {
	      case '/' :
	        src_start = s + 1;
	        state     = ST_GET_SRC;
	        break;
	      case ' ' :
	        state = ST_ERROR;
	        break;
	      case '\0' :
	        state = ST_ERROR;
		break;
	      case ':' :
	      default  :
	        name_start = s;
	        state      = ST_GET_NAME;
	        break;
	    }
	    break;

	  case ST_GET_SRC :
	    switch( *s )
	    {
	      case ':' :
	        state = ST_ERROR;
	        break;
	      case '/' :
	        *s         = '\0';
		name_start = s + 1;
		state      = ST_GET_NAME;
	        break;
	      case ' ' :
	        state = ST_ERROR;
	        break;
	      case '\0' :
		state = ST_DONE;
		break;
	      default :
	        state = ST_GET_SRC;
	        break;
	    }
	    break;

	  case ST_GET_NAME :
	    switch( *s )
	    {
	      case '/' :
		if( s[-1] == '/' )
		    state = ST_ERROR;
		else
	            state = ST_GET_NAME;
	        break;
	      case ' ' :
	        state = ST_ERROR;
	        break;
	      case '\0' :
		state = ST_DONE;
		break;
	      case ':' :
	      default :
	        state = ST_GET_NAME;
	        break;
	    }
	    break;

	  default :
	    break;
	}

        s++;
    }

    if( state == ST_DONE )
    {
        /* Get protocol */
        if( !proto_start )
	{
            if( !env_get( "bootprot",
		          &proto_start, NULL, 0 ) )
	    {
	        /* Only fails on platforms not supporting Ethernet */
	        proto_start = "asc";
	    }
	}

	if( !env_decode_bootprot(
	        proto_start,
		protocol,
		sizeof(UINT32) ) )
        {
	    shell_error_hint = msg_hint_filename;
	    return SHELL_ERROR_BOOTPROT;
        }

	/* Get source */
	if( !src_start )
	{
	    if( !env_get( (*protocol == PROTOCOL_ASC) ?
		         "bootserport" : "bootserver",
		    &src_start, NULL, 0 ) )
	    {
	        src_start = "";
	    }
        }

        if( *protocol == PROTOCOL_ASC )
        {
	    if( !env_decode_bootserport(
	            src_start,
		    src,
		    sizeof(UINT32) ) )
            {
	        return SHELL_ERROR_PORT;
            }
	}
	else
	{
	    /* Must be IP address */
	    if( !env_ip_s2num( src_start, src, sizeof(UINT32) ) )
	        return SHELL_ERROR_IP;
	}

	/* Filename */
        if( *protocol == PROTOCOL_TFTP )
	{
	    if( name_start )
		*filename = name_start;
	    else
	    {
	        if( !env_get( "bootfile", filename, NULL, 0 ) )
		    *filename = "";
	    }

	    if( strspn( *filename, " " ) == strlen( *filename ) )
	    {
		/* All whitespace filename */
		return SHELL_ERROR_FILENAME;
	    }
	}
	else
	{
  	    if( name_start )
	        return SHELL_ERROR_SYNTAX;
        }

        return OK;
    }
    else
        return SHELL_ERROR_SYNTAX;
}


/* Command definition for help */
static t_cmd cmd_def =
{
    "load",
     load,

    "load [-r]\n"
    "     ([tftp:][//<ipaddr>][/<filename>]) |\n"
    "     ([asc:] [//(tty0|tty1)])",

    "Load image from serial port or Ethernet to RAM or flash (depending\n"
    "on address). The only image type currently supported is SREC.\n"
    "\n"
    "On platforms supporting both Ethernet and serial port, the default\n"
    "protocol is taken from the environment variable 'bootprot'. On\n"
    "platforms without Ethernet, the only (and default) protocol is 'asc'.\n"
    "\n"
    "If loading from serial port, the default port is taken from the\n"
    "environment variable 'bootserport'.\n"
    "\n"
    "If loading from Ethernet, the IP address of the TFTP server and\n"
    "the filename may be specified. If an IP address is not specified,\n"
    "it is taken from the environment variable 'bootserver'. If a\n"
    "filename is not specified, it is taken from the environment\n"
    "variable 'bootfile'. Note that the TFTP protocol limits the maximum\n"
    "file size (SREC file size, not actual binary data size) to 32 MBytes\n"
    "(even 16 MBytes on some TFTP servers). If this limit is exceeded,\n"
    "the load will fail.\n"
    "\n"
    "For the currently supported formats, the execution entrypoint of the\n"
    "image is embedded in the image. This address is saved such that the\n"
    "'go' command can use it as the default entrypoint.\n"
    "\n"
    "During the load operation, the current load address will be shown on\n"
    "the 8-position hex display (if present).\n"
    "\n"
    "Note that the load command prevents the user from overwriting the\n"
    "environment flash area.",

    options,
    OPTION_COUNT,

    FALSE
};

/* Command definition for help */
static t_cmd cmd_data_def =
{
    "loaddata",
     loaddata,

    "loaddata [-r]\n"
    "     ([tftp:][//<ipaddr>][/<filename>]) |\n"
    "     ([asc:] [//(tty0|tty1)])",

    "Load data from serial port or Ethernet to RAM at 0xA0100000 \n"
    "Used for copying nk.bin to RAM for subsequent flash store.\n"
    "\n"
    "On platforms supporting both Ethernet and serial port, the default\n"
    "protocol is taken from the environment variable 'bootprot'. On\n"
    "platforms without Ethernet, the only (and default) protocol is 'asc'.\n"
    "\n"
    "If loading from serial port, the default port is taken from the\n"
    "environment variable 'bootserport'.\n"
    "\n"
    "If loading from Ethernet, the IP address of the TFTP server and\n"
    "the filename may be specified. If an IP address is not specified,\n"
    "it is taken from the environment variable 'bootserver'. If a\n"
    "filename is not specified, it is taken from the environment\n"
    "variable 'bootfile'. Note that the TFTP protocol limits the maximum\n"
    "file size (SREC file size, not actual binary data size) to 32 MBytes\n"
    "(even 16 MBytes on some TFTP servers). If this limit is exceeded,\n"
    "the load will fail.\n"
    "\n"
    "For the currently supported formats, the execution entrypoint of the\n"
    "image is embedded in the image. This address is saved such that the\n"
    "'go' command can use it as the default entrypoint.\n"
    "\n"
    "During the load operation, the current load address will be shown on\n"
    "the 8-position hex display (if present).\n"
    "\n"
    "Note that the load command prevents the user from overwriting the\n"
    "environment flash area.",

    options,
    OPTION_COUNT,

    FALSE
};


/* Command definitions for SDB 'l' command (secret command) */
static t_cmd cmd_def_sdb_lower =
{
    "l",
    load_sdb,
    "l                        (Microsoft SDB command)",
    "Load image from serial port (console tty0) to RAM or Flash (depending\n"
    "on destination addresses).\n"
    "\n"
    "The only image type currently supported is SREC.",

    NULL,
    0,
    TRUE
};


/************************************************************************
 *  Implementation : Public functions
 ************************************************************************/

/************************************************************************
 *
 *                          shell_load_init
 *  Description :
 *  -------------
 *
 *  Initialise command
 *
 *  Return values :
 *  ---------------
 *
 *  void
 *
 ************************************************************************/
t_cmd *
shell_loaddata_init( void )
{
    return &cmd_data_def;
}

/************************************************************************
 *
 *                          shell_load_init
 *  Description :
 *  -------------
 *
 *  Initialise command
 *
 *  Return values :
 *  ---------------
 *
 *  void
 *
 ************************************************************************/
t_cmd *
shell_load_init( void )
{
    return &cmd_def;
}

/************************************************************************
 *
 *                          shell_load_sdb_init
 *  Description :
 *  -------------
 *
 *  Initialise command
 *
 *  Return values :
 *  ---------------
 *
 *  void
 *
 ************************************************************************/
t_cmd *
shell_load_sdb_init( void )
{
    return &cmd_def_sdb_lower;
}

⌨️ 快捷键说明

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