分类:
2012-05-09 13:16:54
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)
{
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,选择要下载的文件即可。
Transferring HISTORY.TXT...
100% 7 KB 3 KB/s 00:00:02 0 Errors
yzModem - CRC mode, 63(SOH)/0(STX)/0(CAN) packets, 7 retries
## Total Size = 0x00001f01 = 7937 Bytes
[SMDK2440]#
PS:SecureCRT的设置和使用
<1>界面如下
<2>串口设置,点击菜单File --> connect 在出现的对话框中选择传输协议,如下图右边的框框里的勾勾都去掉
<3>下载上传路径设置点击菜单Options-->Session Options -->Xmodem/Zmodem