9、u-boot增加串口xmodem协议
u-boot中已经有了串口驱动,现在要添加load命令,即使用串口xmodem协议传输文件。
(1)在smdk2440.h中增加支持loadx命令的配置,修改代码如下:
- #define CONFIG_MTD_DEVICE
- #define CONFIG_MTD_PARTITIONS
- #define MTDIDS_DEFAULT "nand0=nandflash0"
- #define MTDPARTS_DEFAULT "mtdparts=nandflash0:1m@0(bios)," \
- "128k(params)," \
- "4m(kernel)," \
- "-(root)"
- #define ENABLE_CMD_LOADB_X 1
(2)修改common目录下的cmd_load.c文件,加入load_serial_xmodem的函数声明,修改的代码如下:
- #if defined(CONFIG_CMD_LOADB)
- #if defined(ENABLE_CMD_LOADB_X)
- static ulong load_serial_xmodem (ulong offset);
- #endif
- static ulong load_serial_ymodem (ulong offset);
- #endif
(3)在do_load_serial_bin 函数中修改代码如下:- if (load_baudrate != current_baudrate) {
- printf ("## Switch baudrate to %d bps and press ENTER ...\n",
- load_baudrate);
- udelay(50000);
- gd->baudrate = load_baudrate;
- serial_setbrg ();
- udelay(50000);
- for (;;) {
- if (getc() == '\r')
- break;
- }
- }
-
- #if defined(ENABLE_CMD_LOADB_X)
- 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) {
- #else
- if (strcmp(argv[0],"loady")==0) {
- #endif
- //if (strcmp(argv[0],"loady")==0) { /* zjw del 20121012 */
- printf ("## Ready for binary (ymodem) download "
- "to 0x%08lX at %d bps...\n",
- offset,
- load_baudrate);
- addr = load_serial_ymodem (offset);
- } else {
- printf ("## Ready for binary (kermit) download "
- "to 0x%08lX at %d bps...\n",
- offset,
- load_baudrate);
- addr = load_serial_bin (offset);
- if (addr == ~0) {
- load_addr = 0;
- printf ("## Binary (kermit) download aborted\n");
- rcode = 1;
- } else {
- printf ("## Start Addr = 0x%08lX\n", addr);
- load_addr = addr;
- }
- }
(4)在函数load_serial_ymodem之前增加load_serial_xmodem函数的实现,代码如下:
- #if defined(ENABLE_CMD_LOADB_X)
- 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 CFG_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;
- }
- #endif
(5)在最后面的U_BOOT_CMD处加入loadx命令,修改的代码如下:
- #if defined(CONFIG_CMD_LOADB)
- U_BOOT_CMD(
- loadb, 3, 0, do_load_serial_bin,
- "load binary file over serial line (kermit 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
- 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'"
- );
- #endif
重新编译u-boot,下载到NandFlash中运行,可以看到已经支持了loadx命令,可以使用loadx命令通过串口来下载东西了,效果如下:
阅读(907) | 评论(0) | 转发(0) |