Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4462266
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: 嵌入式

2011-04-17 20:50:44

严重参照: u-boot-2011.03在TQ2440上的移植(10)--支持串口xmodem协议

1、在windows下的SecureCRT只支持Xmodem和Zmodem,为了方便在Windows下载U-Boot,现在修改代码增加对Xmodem的支持,即增加一个命令loadx。

vi common/cmd_load.c

在ymodem命令下添加xmodem命令

U_BOOT_CMD(
 loady, 3, 0, do_load_serial_bin,
 "load binary file over serial line (ymodem mode)",
 "[ off ] [ baud ]\n"
 "    - load binary file over serial line"
 " with offset 'off' and baudrate 'baud'"
);

#if defined(ENABLE_CMD_LOADB_X)
U_BOOT_CMD(
 loadx, 3, 0,    do_load_serial_bin,
 "load binary file over serial line (xmodem mode)",
 "[ off ] [ baud ]\n"
 "    - load binary file over serial line"
 " with offset 'off' and baudrate 'baud'"
);
#endif

上面的条件编译需要在 include/configs/smdk2440.h中添加

#define ENABLE_CMD_LOADB_X     1

 

2、在do_load_serial_bin函数中增加对loadx命令的处理分支。也是依照loady来实现的:

if (strcmp(argv[0],"loadx")==0) {
  printf ("## Ready for binary (xmodem) download "
   "to 0x%08lX at %d bps...\n",
   offset,
   load_baudrate);

  addr = load_serial_xmodem (offset);

 }else if (strcmp(argv[0],"loady")==0) {
  printf ("## Ready for binary (ymodem) download "
   "to 0x%08lX at %d bps...\n",
   offset,
   load_baudrate);

  addr = load_serial_ymodem (offset);

3、在第2步被调用的函数load_serial_xmodem (offset),它是依照load_serial_ymodem (offset)实现的。


添加:static ulong load_serial_xmodem (ulong offset);

#if defined(CONFIG_CMD_LOADB)
static ulong load_serial_ymodem (ulong offset);
static ulong load_serial_xmodem (ulong offset);
#endif


添加:

static ulong load_serial_xmodem (ulong offset)
{
 int size;
 char buf[32];
 int err;
 int res;
 connection_info_t info;
 char xmodemBuf[1024];
 ulong store_addr = ~0;
 ulong addr = 0;

 size = 0;
 info.mode = xyzModem_xmodem;
 res = xyzModem_stream_open (&info, &err);
 if (!res) {

  while ((res =
   xyzModem_stream_read (xmodemBuf, 1024, &err)) > 0) {
   store_addr = addr + offset;
   size += res;
   addr += res;
#ifndef CONFIG_SYS_NO_FLASH
   if (addr2info (store_addr)) {
    int rc;

    rc = flash_write ((char *) xmodemBuf,
        store_addr, res);
    if (rc != 0) {
     flash_perror (rc);
     return (~0);
    }
   } else
#endif
   {
    memcpy ((char *) (store_addr), xmodemBuf,
     res);
   }

  }
 } else {
  printf ("%s\n", xyzModem_error (err));
 }

 xyzModem_stream_close (&err);
 xyzModem_stream_terminate (false, &getcxmodem);


 flush_cache (offset, size);

 printf ("## Total Size      = 0x%08x = %d Bytes\n", size, size);
 sprintf (buf, "%X", size);
 setenv ("filesize", buf);

 return offset;
}


至此,u-boot已经支持串口xmodem协议。

用命令 loadx 即可

[SMDK2440]# loadx
## Ready for binary (xmodem) download to 0x32000000 at 115200 bps...
CCC

点击SecureCRT菜单里Transfer选择Send Xmodem,选择要下载的文件即可。

  1. DRAM: 64 MiB
  2. Flash: 2 MiB
  3. NAND: 256 MiB
  4. In: serial
  5. Out: serial
  6. Err: serial
  7. Net: dm9000
  8. [SMDK2440]# saveenv
  9. Saving Environment to NAND...
  10. Erasing Nand...
  11. Erasing at 0x4000000000002 -- 0% complete.
  12. Writing to Nand... done
  13. [SMDK2440]# loadx
  14. ## Ready for binary (xmodem) download to 0x33000000 at 115200 bps...
  15. CCCCCCCCCCCCCCCCCCCCCxyzModem - CRC mode, 0(SOH)/0(STX)/0(CAN) packets, 20

  16. retries
  17. ## Total Size = 0x00000000 = 0 Bytes
  18. [SMDK2440]#
  19. Starting xmodem transfer. Press Ctrl+C to cancel.
  20. Transferring mini_ws.c...

  21. <INTERRUPT>
  22. [SMDK2440]# <INTERRUPT>
  23. [SMDK2440]# loadx
  24. ## Ready for binary (xmodem) download to 0x33000000 at 115200 bps...
  25. CCCCCCCCC
  26. Starting xmodem transfer. Press Ctrl+C to cancel.
  27. Transferring post.html...
  28.   100% 302 bytes 151 bytes/s 00:00:02 0 Errors

  29. yzModem - CRC mode, 3(SOH)/0(STX)/0(CAN) packets, 9 retries
  30. ## Total Size = 0x0000012e = 302 Bytes
  31. [SMDK2440]#


PS:SecureCRT的设置和使用

<1>界面如下

<2>串口设置,点击菜单File --> connect 在出现的对话框中选择传输协议,如下图右边的框框里的勾勾都去掉

<3>下载上传路径设置点击菜单Options-->Session Options -->Xmodem/Zmodem





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