u-boot在s3c2416上的移植(10)--支持串口xmodem协议
2013-10-22 15:29
375 查看
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>界面如下
![](file:///D:/Program%20Files/Tencent/QQ/Users/11051410/Image/S8%7DA)SRKRKE%60FV)TQM1VZK1.jpg)
<2>串口设置,点击菜单File --> connect 在出现的对话框中选择传输协议,如下图右边的框框里的勾勾都去掉
![](file:///D:/Program%20Files/Tencent/QQ/Users/11051410/Image/6N_IG@SDS%7DYP%7DVYB02D%7D077.jpg)
<3>下载上传路径设置点击菜单Options-->Session Options -->Xmodem/Zmodem
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>界面如下
![](file:///D:/Program%20Files/Tencent/QQ/Users/11051410/Image/S8%7DA)SRKRKE%60FV)TQM1VZK1.jpg)
<2>串口设置,点击菜单File --> connect 在出现的对话框中选择传输协议,如下图右边的框框里的勾勾都去掉
![](file:///D:/Program%20Files/Tencent/QQ/Users/11051410/Image/6N_IG@SDS%7DYP%7DVYB02D%7D077.jpg)
<3>下载上传路径设置点击菜单Options-->Session Options -->Xmodem/Zmodem
相关文章推荐
- Py_BuildValue()
- 详解reflect Java的反射机制
- 某个日期是在一年中的第几周——被遗忘的GregorianCalendar类
- OA办公系统一直都在帮助企业改变管理模式
- OCA读书笔记(15) - 执行数据库备份
- http以post方式上传一个文件,构造其请求头和消息报文(转载)
- Android有趣的全透明效果--Activity及Dialog的全透明3(转载)
- Android有趣的全透明效果--Activity及Dialog的全透明2(转载)
- Android有趣的全透明效果--Activity及Dialog的全透明(转载)
- android 自定义Dialog背景透明及显示位置设置(转载)
- E: Sub-process /usr/bin/dpkg returned an error code (1)错误解决
- android 设置activity为对话框,且背景为透明
- android 播放提示音
- 折半查找数据,折半查找插入位置
- android Button按下效果
- 解决下载Android源码时遇到的 download error
- Android UI布局 —— 仿QQ登录界面(转载)
- ngx_time_var
- android 界面布局 很好的一篇总结 【转】
- 转载-Android开发网上的一些重要知识点3