2012-11-08 21:16:40 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief loady and loadx support.
|
|
|
|
*
|
|
|
|
* Provides loadx (over X-Modem) and loady(over Y-Modem) support to download
|
|
|
|
* images.
|
|
|
|
*
|
|
|
|
* FileName: commands/loadxy.c
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* (C) Copyright 2012 Robert Jarzmik <robert.jarzmik@free.fr>
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Serial up- and download support
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <console.h>
|
|
|
|
#include <xymodem.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <fs.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
|
|
|
|
#define DEF_FILE "image.bin"
|
|
|
|
|
|
|
|
static int console_change_speed(struct console_device *cdev, int baudrate)
|
|
|
|
{
|
|
|
|
int current_baudrate;
|
|
|
|
|
|
|
|
current_baudrate =
|
|
|
|
(int)simple_strtoul(dev_get_param(&cdev->class_dev,
|
|
|
|
"baudrate"), NULL, 10);
|
|
|
|
if (baudrate && baudrate != current_baudrate) {
|
|
|
|
printf("## Switch baudrate from %d to %d bps and press ENTER ...\n",
|
|
|
|
current_baudrate, baudrate);
|
|
|
|
mdelay(50);
|
|
|
|
cdev->setbrg(cdev, baudrate);
|
|
|
|
mdelay(50);
|
|
|
|
}
|
|
|
|
return current_baudrate;
|
|
|
|
}
|
|
|
|
|
2012-11-08 21:16:41 +00:00
|
|
|
static struct console_device *get_named_console(const char *cname)
|
|
|
|
{
|
|
|
|
struct console_device *cdev;
|
|
|
|
const char *target;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assumption to have BOTH CONSOLE_STDIN AND STDOUT in the
|
|
|
|
* same output console
|
|
|
|
*/
|
|
|
|
for_each_console(cdev) {
|
|
|
|
target = dev_id(&cdev->class_dev);
|
|
|
|
if (strlen(target) != strlen(cname))
|
|
|
|
continue;
|
|
|
|
printf("RJK: looking for %s in console name %s\n",
|
|
|
|
cname, target);
|
|
|
|
if ((cdev->f_active & (CONSOLE_STDIN | CONSOLE_STDOUT))
|
|
|
|
&& !strcmp(cname, target))
|
|
|
|
return cdev;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-08 21:16:40 +00:00
|
|
|
/**
|
|
|
|
* @brief provide the loady(Y-Modem or Y-Modem/G) support
|
|
|
|
*
|
|
|
|
* @param argc number of arguments
|
|
|
|
* @param argv arguments of loady command
|
|
|
|
*
|
|
|
|
* @return success or failure
|
|
|
|
*/
|
|
|
|
static int do_loady(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int is_ymodemg = 0, rc = 0, opt, rcode = 0;
|
|
|
|
int load_baudrate = 0, current_baudrate;
|
2012-11-08 21:16:41 +00:00
|
|
|
char *cname = NULL;
|
2012-11-08 21:16:40 +00:00
|
|
|
struct console_device *cdev = NULL;
|
|
|
|
|
2012-11-08 21:16:41 +00:00
|
|
|
while ((opt = getopt(argc, argv, "b:t:g")) > 0) {
|
2012-11-08 21:16:40 +00:00
|
|
|
switch (opt) {
|
|
|
|
case 'b':
|
|
|
|
load_baudrate = (int)simple_strtoul(optarg, NULL, 10);
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
is_ymodemg = 1;
|
|
|
|
break;
|
2012-11-08 21:16:41 +00:00
|
|
|
case 't':
|
|
|
|
cname = optarg;
|
|
|
|
break;
|
2012-11-08 21:16:40 +00:00
|
|
|
default:
|
|
|
|
perror(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-08 21:16:41 +00:00
|
|
|
if (cname)
|
|
|
|
cdev = get_named_console(cname);
|
|
|
|
else
|
2013-10-03 07:21:53 +00:00
|
|
|
cdev = console_get_first_active();
|
2012-11-08 21:16:41 +00:00
|
|
|
if (!cdev) {
|
|
|
|
printf("%s:No console device %s with STDIN and STDOUT\n",
|
|
|
|
argv[0], cname ? cname : "default");
|
2012-11-08 21:16:40 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_baudrate = console_change_speed(cdev, load_baudrate);
|
|
|
|
printf("## Ready for binary (ymodem) download at %d bps...\n",
|
|
|
|
load_baudrate ? load_baudrate : current_baudrate);
|
|
|
|
|
|
|
|
if (is_ymodemg)
|
|
|
|
rc = do_load_serial_ymodemg(cdev);
|
|
|
|
else
|
|
|
|
rc = do_load_serial_ymodem(cdev);
|
|
|
|
|
|
|
|
if (rc < 0) {
|
|
|
|
printf("## Binary (ymodem) download aborted (%d)\n", rc);
|
|
|
|
rcode = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
console_change_speed(cdev, current_baudrate);
|
|
|
|
|
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
commands: harmonize in-barebox documentation
This patch does probably too much, but it's hard (and very
cumbersome/time consuming) to break it out. What is does is this:
* each command has one short description, e.g. "list MUX configuration"
* made sure the short descriptions start lowercase
* each command has one usage. That string contains just the
options, e.g. "[-npn]". It's not part of the long help text.
* that is, it doesn't say "[OPTIONS]" anymore, every usable option
is listed by character in this (short) option string (the long
description is in the long help text, as before)
* help texts have been reworked, to make them
- sometimes smaller
- sometimes describe the options better
- more often present themselves in a nicer format
* all long help texts are now created with BUSYBOX_CMD_HELP_
macros, no more 'static const __maybe_unused char cmd_foobar_help[]'
* made sure the long help texts starts uppercase
* because cmdtp->name and cmdtp->opts together provide the new usage,
all "Usage: foobar" texts have been removed from the long help texts
* BUSYBOX_CMD_HELP_TEXT() provides the trailing newline by itself, this
is nicer in the source code
* BUSYBOX_CMD_HELP_OPT() provides the trailing newline by itself
* made sure no line gets longer than 77 characters
* delibertely renamed cmdtp->usage, so that we can get compile-time
errors (e.g. in out-of-tree modules that use register_command()
* the 'help' command can now always emit the usage, even without
compiled long help texts
* 'help -v' gives a list of commands with their short description, this
is similar like the old "help" command before my patchset
* 'help -a' gives out help of all commands
Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-13 08:28:42 +00:00
|
|
|
BAREBOX_CMD_HELP_START(loady)
|
|
|
|
BAREBOX_CMD_HELP_TEXT("Options:")
|
|
|
|
BAREBOX_CMD_HELP_OPT("-g", "use Y-Modem/G (use on lossless tty such as USB)")
|
|
|
|
BAREBOX_CMD_HELP_OPT("-b BAUD", "baudrate for download (default: console baudrate")
|
|
|
|
BAREBOX_CMD_HELP_OPT("-t NAME", "console name to use (default: current)")
|
|
|
|
BAREBOX_CMD_HELP_END
|
|
|
|
|
|
|
|
BAREBOX_CMD_START(loady)
|
|
|
|
.cmd = do_loady,
|
|
|
|
BAREBOX_CMD_DESC("load binary file over serial line (Y-Modem)")
|
|
|
|
BAREBOX_CMD_OPTS("[-gtb]")
|
|
|
|
BAREBOX_CMD_GROUP(CMD_GRP_BOOT)
|
|
|
|
BAREBOX_CMD_HELP(cmd_loady_help)
|
|
|
|
BAREBOX_CMD_END
|
|
|
|
|
|
|
|
|
2012-11-08 21:16:40 +00:00
|
|
|
/**
|
|
|
|
* @brief provide the loadx(X-Modem) support
|
|
|
|
*
|
|
|
|
* @param argc number of arguments
|
|
|
|
* @param argv arguments of loadx command
|
|
|
|
*
|
|
|
|
* @return success or failure
|
|
|
|
*/
|
|
|
|
static int do_loadx(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
ulong offset = 0;
|
|
|
|
int load_baudrate = 0, current_baudrate, ofd, opt, rcode = 0;
|
|
|
|
int open_mode = O_WRONLY;
|
2012-11-08 21:16:41 +00:00
|
|
|
char *output_file = NULL, *cname = NULL;
|
2012-11-08 21:16:40 +00:00
|
|
|
struct console_device *cdev = NULL;
|
|
|
|
|
2014-05-08 20:36:14 +00:00
|
|
|
while ((opt = getopt(argc, argv, "f:b:t:o:c")) > 0) {
|
2012-11-08 21:16:40 +00:00
|
|
|
switch (opt) {
|
|
|
|
case 'f':
|
|
|
|
output_file = optarg;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
load_baudrate = (int)simple_strtoul(optarg, NULL, 10);
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
offset = (int)simple_strtoul(optarg, NULL, 10);
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
open_mode |= O_CREAT;
|
|
|
|
break;
|
2012-11-08 21:16:41 +00:00
|
|
|
case 't':
|
|
|
|
cname = optarg;
|
|
|
|
break;
|
2012-11-08 21:16:40 +00:00
|
|
|
default:
|
|
|
|
perror(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-08 21:16:41 +00:00
|
|
|
if (cname)
|
|
|
|
cdev = get_named_console(cname);
|
|
|
|
else
|
2013-10-03 07:21:53 +00:00
|
|
|
cdev = console_get_first_active();
|
2012-11-08 21:16:41 +00:00
|
|
|
if (!cdev) {
|
commands: harmonize in-barebox documentation
This patch does probably too much, but it's hard (and very
cumbersome/time consuming) to break it out. What is does is this:
* each command has one short description, e.g. "list MUX configuration"
* made sure the short descriptions start lowercase
* each command has one usage. That string contains just the
options, e.g. "[-npn]". It's not part of the long help text.
* that is, it doesn't say "[OPTIONS]" anymore, every usable option
is listed by character in this (short) option string (the long
description is in the long help text, as before)
* help texts have been reworked, to make them
- sometimes smaller
- sometimes describe the options better
- more often present themselves in a nicer format
* all long help texts are now created with BUSYBOX_CMD_HELP_
macros, no more 'static const __maybe_unused char cmd_foobar_help[]'
* made sure the long help texts starts uppercase
* because cmdtp->name and cmdtp->opts together provide the new usage,
all "Usage: foobar" texts have been removed from the long help texts
* BUSYBOX_CMD_HELP_TEXT() provides the trailing newline by itself, this
is nicer in the source code
* BUSYBOX_CMD_HELP_OPT() provides the trailing newline by itself
* made sure no line gets longer than 77 characters
* delibertely renamed cmdtp->usage, so that we can get compile-time
errors (e.g. in out-of-tree modules that use register_command()
* the 'help' command can now always emit the usage, even without
compiled long help texts
* 'help -v' gives a list of commands with their short description, this
is similar like the old "help" command before my patchset
* 'help -a' gives out help of all commands
Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-13 08:28:42 +00:00
|
|
|
printf("%s:No console device %s with STDIN and STDOUT",
|
2012-11-08 21:16:41 +00:00
|
|
|
argv[0], cname ? cname : "default");
|
2012-11-08 21:16:40 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load Defaults */
|
2012-11-08 21:16:41 +00:00
|
|
|
if (!output_file)
|
2012-11-08 21:16:40 +00:00
|
|
|
output_file = DEF_FILE;
|
|
|
|
|
|
|
|
/* File should exist */
|
|
|
|
ofd = open(output_file, open_mode);
|
|
|
|
if (ofd < 0) {
|
|
|
|
perror(argv[0]);
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
/* Seek to the right offset */
|
|
|
|
if (offset) {
|
|
|
|
int seek = lseek(ofd, offset, SEEK_SET);
|
|
|
|
if (seek != offset) {
|
|
|
|
close(ofd);
|
|
|
|
ofd = 0;
|
|
|
|
perror(argv[0]);
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
current_baudrate = console_change_speed(cdev, load_baudrate);
|
2014-05-08 20:36:14 +00:00
|
|
|
printf("## Ready for binary (xmodem) download "
|
2012-11-08 21:16:40 +00:00
|
|
|
"to 0x%08lX offset on %s device at %d bps...\n", offset,
|
2014-05-08 20:36:14 +00:00
|
|
|
output_file, load_baudrate ? load_baudrate : current_baudrate);
|
|
|
|
rcode = do_load_serial_xmodem(cdev, ofd);
|
2012-11-08 21:16:40 +00:00
|
|
|
if (rcode < 0) {
|
2014-05-08 20:36:14 +00:00
|
|
|
printf("## Binary (xmodem) download aborted (%d)\n", rcode);
|
2012-11-08 21:16:40 +00:00
|
|
|
rcode = 1;
|
|
|
|
}
|
|
|
|
console_change_speed(cdev, current_baudrate);
|
|
|
|
|
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
commands: harmonize in-barebox documentation
This patch does probably too much, but it's hard (and very
cumbersome/time consuming) to break it out. What is does is this:
* each command has one short description, e.g. "list MUX configuration"
* made sure the short descriptions start lowercase
* each command has one usage. That string contains just the
options, e.g. "[-npn]". It's not part of the long help text.
* that is, it doesn't say "[OPTIONS]" anymore, every usable option
is listed by character in this (short) option string (the long
description is in the long help text, as before)
* help texts have been reworked, to make them
- sometimes smaller
- sometimes describe the options better
- more often present themselves in a nicer format
* all long help texts are now created with BUSYBOX_CMD_HELP_
macros, no more 'static const __maybe_unused char cmd_foobar_help[]'
* made sure the long help texts starts uppercase
* because cmdtp->name and cmdtp->opts together provide the new usage,
all "Usage: foobar" texts have been removed from the long help texts
* BUSYBOX_CMD_HELP_TEXT() provides the trailing newline by itself, this
is nicer in the source code
* BUSYBOX_CMD_HELP_OPT() provides the trailing newline by itself
* made sure no line gets longer than 77 characters
* delibertely renamed cmdtp->usage, so that we can get compile-time
errors (e.g. in out-of-tree modules that use register_command()
* the 'help' command can now always emit the usage, even without
compiled long help texts
* 'help -v' gives a list of commands with their short description, this
is similar like the old "help" command before my patchset
* 'help -a' gives out help of all commands
Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-13 08:28:42 +00:00
|
|
|
BAREBOX_CMD_HELP_START(loadx)
|
|
|
|
BAREBOX_CMD_HELP_TEXT("Options:")
|
2014-07-08 05:52:34 +00:00
|
|
|
BAREBOX_CMD_HELP_OPT("-f FILE", "download to FILE (default image.bin")
|
commands: harmonize in-barebox documentation
This patch does probably too much, but it's hard (and very
cumbersome/time consuming) to break it out. What is does is this:
* each command has one short description, e.g. "list MUX configuration"
* made sure the short descriptions start lowercase
* each command has one usage. That string contains just the
options, e.g. "[-npn]". It's not part of the long help text.
* that is, it doesn't say "[OPTIONS]" anymore, every usable option
is listed by character in this (short) option string (the long
description is in the long help text, as before)
* help texts have been reworked, to make them
- sometimes smaller
- sometimes describe the options better
- more often present themselves in a nicer format
* all long help texts are now created with BUSYBOX_CMD_HELP_
macros, no more 'static const __maybe_unused char cmd_foobar_help[]'
* made sure the long help texts starts uppercase
* because cmdtp->name and cmdtp->opts together provide the new usage,
all "Usage: foobar" texts have been removed from the long help texts
* BUSYBOX_CMD_HELP_TEXT() provides the trailing newline by itself, this
is nicer in the source code
* BUSYBOX_CMD_HELP_OPT() provides the trailing newline by itself
* made sure no line gets longer than 77 characters
* delibertely renamed cmdtp->usage, so that we can get compile-time
errors (e.g. in out-of-tree modules that use register_command()
* the 'help' command can now always emit the usage, even without
compiled long help texts
* 'help -v' gives a list of commands with their short description, this
is similar like the old "help" command before my patchset
* 'help -a' gives out help of all commands
Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-13 08:28:42 +00:00
|
|
|
BAREBOX_CMD_HELP_OPT("-o OFFS", "destination file OFFSet (default 0)")
|
|
|
|
BAREBOX_CMD_HELP_OPT("-b BAUD", "baudrate for download (default: console baudrate")
|
|
|
|
BAREBOX_CMD_HELP_OPT("-t NAME", "console name to use (default: current)")
|
|
|
|
BAREBOX_CMD_HELP_OPT("-c", "create file if not present")
|
|
|
|
BAREBOX_CMD_HELP_END
|
2012-11-08 21:16:40 +00:00
|
|
|
|
|
|
|
BAREBOX_CMD_START(loadx)
|
|
|
|
.cmd = do_loadx,
|
commands: harmonize in-barebox documentation
This patch does probably too much, but it's hard (and very
cumbersome/time consuming) to break it out. What is does is this:
* each command has one short description, e.g. "list MUX configuration"
* made sure the short descriptions start lowercase
* each command has one usage. That string contains just the
options, e.g. "[-npn]". It's not part of the long help text.
* that is, it doesn't say "[OPTIONS]" anymore, every usable option
is listed by character in this (short) option string (the long
description is in the long help text, as before)
* help texts have been reworked, to make them
- sometimes smaller
- sometimes describe the options better
- more often present themselves in a nicer format
* all long help texts are now created with BUSYBOX_CMD_HELP_
macros, no more 'static const __maybe_unused char cmd_foobar_help[]'
* made sure the long help texts starts uppercase
* because cmdtp->name and cmdtp->opts together provide the new usage,
all "Usage: foobar" texts have been removed from the long help texts
* BUSYBOX_CMD_HELP_TEXT() provides the trailing newline by itself, this
is nicer in the source code
* BUSYBOX_CMD_HELP_OPT() provides the trailing newline by itself
* made sure no line gets longer than 77 characters
* delibertely renamed cmdtp->usage, so that we can get compile-time
errors (e.g. in out-of-tree modules that use register_command()
* the 'help' command can now always emit the usage, even without
compiled long help texts
* 'help -v' gives a list of commands with their short description, this
is similar like the old "help" command before my patchset
* 'help -a' gives out help of all commands
Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-13 08:28:42 +00:00
|
|
|
BAREBOX_CMD_DESC("load binary file over serial line (X-Modem)")
|
|
|
|
BAREBOX_CMD_OPTS("[-fptbc]")
|
commands: group 'help' output
The old output of "help" was just producing a long list, that usually
scrolled of the screen (even on a X11 terminal). This list is more
compact, and also sorted by groups.
The old output format (plus grouping) is now available with 'help -v'.
Example:
Information commands:
?, devinfo, help, iomem, meminfo, version
Boot commands:
boot, bootm, go, loadb, loads, loadx, loady, saves, uimage
...
Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-13 14:14:05 +00:00
|
|
|
BAREBOX_CMD_GROUP(CMD_GRP_BOOT)
|
commands: harmonize in-barebox documentation
This patch does probably too much, but it's hard (and very
cumbersome/time consuming) to break it out. What is does is this:
* each command has one short description, e.g. "list MUX configuration"
* made sure the short descriptions start lowercase
* each command has one usage. That string contains just the
options, e.g. "[-npn]". It's not part of the long help text.
* that is, it doesn't say "[OPTIONS]" anymore, every usable option
is listed by character in this (short) option string (the long
description is in the long help text, as before)
* help texts have been reworked, to make them
- sometimes smaller
- sometimes describe the options better
- more often present themselves in a nicer format
* all long help texts are now created with BUSYBOX_CMD_HELP_
macros, no more 'static const __maybe_unused char cmd_foobar_help[]'
* made sure the long help texts starts uppercase
* because cmdtp->name and cmdtp->opts together provide the new usage,
all "Usage: foobar" texts have been removed from the long help texts
* BUSYBOX_CMD_HELP_TEXT() provides the trailing newline by itself, this
is nicer in the source code
* BUSYBOX_CMD_HELP_OPT() provides the trailing newline by itself
* made sure no line gets longer than 77 characters
* delibertely renamed cmdtp->usage, so that we can get compile-time
errors (e.g. in out-of-tree modules that use register_command()
* the 'help' command can now always emit the usage, even without
compiled long help texts
* 'help -v' gives a list of commands with their short description, this
is similar like the old "help" command before my patchset
* 'help -a' gives out help of all commands
Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-13 08:28:42 +00:00
|
|
|
BAREBOX_CMD_HELP(cmd_loadx_help)
|
2012-11-08 21:16:40 +00:00
|
|
|
BAREBOX_CMD_END
|