Chinaunix首页 | 论坛 | 博客
  • 博客访问: 477016
  • 博文数量: 100
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 955
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-21 09:30
文章分类

全部博文(100)

文章存档

2017年(1)

2016年(16)

2015年(83)

我的朋友

分类: 嵌入式

2015-06-27 10:23:55


点击(此处)折叠或打开

  1. tftp即tftpboot,执行tftp调用do_tftpb,

  2. int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  3. {
  4.     int ret;

  5.     bootstage_mark_name(BOOTSTAGE_KERNELREAD_START, "tftp_start");
  6.     /* 标记 record 结构体*/

  7.     ret = netboot_common(TFTPGET, cmdtp, argc, argv);
  8.     /* 开始tftp服务 */

  9.     bootstage_mark_name(BOOTSTAGE_KERNELREAD_STOP, "tftp_done");
  10.     return ret;
  11. }


  12. netboot_common ->
  13.  NetLoop(TFTPGET){

  14. ...
  15.     net_set_state(NETLOOP_CONTINUE);
  16.     switch (net_check_prereq(protocol)) {

  17.     ...
  18.         case TFTPGET:
  19. #ifdef CONFIG_CMD_TFTPPUT
  20.         case TFTPPUT:
  21. #endif
  22.             /* always use ARP to get server ethernet address */
  23.             TftpStart(protocol);//准备工作,net_set_udp_handler(TftpHandler);
  24.             break;
  25.         ...
  26.     }
  27. ...
  28. //下面进入死循环,正式开启传输(通过eth_rx()),当接受包长度<512,表示收到最后一个包,传输完成。
  29.     for (;;) {
  30.         WATCHDOG_RESET();
  31. #ifdef CONFIG_SHOW_ACTIVITY
  32.         show_activity(1);
  33. #endif
  34.         /*
  35.          *    Check the ethernet for a new packet. The ethernet
  36.          *    receive routine will process it.
  37.          */
  38.         eth_rx();//eth_current->recv(eth_current); 即dm9000_rx ->NetReceive(NetRxPackets[0], RxLen);
  39. /*
  40.         NetReceive ->
  41.         (*udp_packet_handler)((uchar *)ip + IP_UDP_HDR_SIZE,
  42.                         ntohs(ip->udp_dst),
  43.                         src_ip,
  44.                         ntohs(ip->udp_src),
  45.                         ntohs(ip->udp_len) - UDP_HDR_SIZE);
  46. udp_packet_handler在TftpStart()被注册:net_set_udp_handler(TftpHandler);
  47. */
  48.         /*
  49.          *    Abort if ctrl-c was pressed.
  50.          */
  51.         if (ctrlc()) {
  52.             /* cancel any ARP that may not have completed */
  53.             NetArpWaitPacketIP = 0;

  54.             net_cleanup_loop();
  55.             eth_halt();
  56.             /* Invalidate the last protocol */
  57.             eth_set_last_protocol(BOOTP);

  58.             puts("\nAbort\n");
  59.             /* include a debug print as well incase the debug
  60.              messages are directed to stderr */
  61.             debug_cond(DEBUG_INT_STATE, "--- NetLoop Abort!\n");
  62.             goto done;
  63.         }

  64.         ArpTimeoutCheck();

  65.         /*
  66.          *    Check for a timeout, and run the timeout handler
  67.          *    if we have one.
  68.          */
  69.         if (timeHandler && ((get_timer(0) - timeStart) > timeDelta)) {
  70.             thand_f *x;

  71. #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
  72. #if    defined(CONFIG_SYS_FAULT_ECHO_LINK_DOWN)    && \
  73.     defined(CONFIG_STATUS_LED)            && \
  74.     defined(STATUS_LED_RED)
  75.             /*
  76.              * Echo the inverted link state to the fault LED.
  77.              */
  78.             if (miiphy_link(eth_get_dev()->name,
  79.                  CONFIG_SYS_FAULT_MII_ADDR)) {
  80.                 status_led_set(STATUS_LED_RED, STATUS_LED_OFF);
  81.             } else {
  82.                 status_led_set(STATUS_LED_RED, STATUS_LED_ON);
  83.             }
  84. #endif /* CONFIG_SYS_FAULT_ECHO_LINK_DOWN, ... */
  85. #endif /* CONFIG_MII, ... */
  86.             debug_cond(DEBUG_INT_STATE, "--- NetLoop timeout\n");
  87.             x = timeHandler;
  88.             timeHandler = (thand_f *)0;
  89.             (*x)();
  90.         }


  91.         switch (net_state) {

  92.         case NETLOOP_RESTART:
  93.             NetRestarted = 1;
  94.             goto restart;

  95.         case NETLOOP_SUCCESS:
  96.             net_cleanup_loop();
  97.             if (NetBootFileXferSize > 0) {
  98.                 printf("Bytes transferred = %ld (%lx hex)\n",
  99.                     NetBootFileXferSize,
  100.                     NetBootFileXferSize);
  101.                 setenv_hex("filesize", NetBootFileXferSize);
  102.                 setenv_hex("fileaddr", load_addr);
  103.             }
  104.             if (protocol != NETCONS)
  105.                 eth_halt();
  106.             else
  107.                 eth_halt_state_only();

  108.             eth_set_last_protocol(protocol);

  109.             ret = NetBootFileXferSize;
  110.             debug_cond(DEBUG_INT_STATE, "--- NetLoop Success!\n");
  111.             goto done;

  112.         case NETLOOP_FAIL:
  113.             net_cleanup_loop();
  114.             /* Invalidate the last protocol */
  115.             eth_set_last_protocol(BOOTP);
  116.             debug_cond(DEBUG_INT_STATE, "--- NetLoop Fail!\n");
  117.             goto done;

  118.         case NETLOOP_CONTINUE:
  119.             continue;
  120.         }
  121.     }




  122. ...
  123. }
  124. ->



  125. (update.c没有用到)
  126. load_addr在cmd_net.c(227)中根据键入参数重置:
  127.     case 3:    load_addr = simple_strtoul(argv[1], NULL, 16);

  128. #define TFTP_MTU_BLOCKSIZE 1024 在
  129. static unsigned short TftpBlkSizeOption = TFTP_MTU_BLOCKSIZE;
  130. 在tftp.c(374)向服务端配置
  131.         /* try for more effic. blk size */
  132.         pkt += sprintf((char *)pkt, "blksize%c%d%c",
  133.                 0, TftpBlkSizeOption, 0);

阅读(2124) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~