9
0
Fork 0
barebox/arch/arm/mach-at91/boot_test_cmd.c

99 lines
1.9 KiB
C
Raw Normal View History

/*
* Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
*
* Under GPLv2 only
*/
#include <common.h>
#include <command.h>
#include <libbb.h>
#include <getopt.h>
#include <fs.h>
#include <fcntl.h>
#include <malloc.h>
#include <errno.h>
static int do_at91_boot_test(int argc, char *argv[])
{
int opt;
u32 *buf32;
void *buf;
void (*jump)(void) = NULL;
int fd;
int ret = 1;
char *sram = "/dev/sram0";
u32 read_size, write_size;
u32 tmp = 0;
while ((opt = getopt(argc, argv, "j:s:")) > 0) {
switch (opt) {
case 'j':
jump = (void*)simple_strtoul(optarg, NULL, 0);
break;
case 's':
sram = optarg;
break;
default:
return COMMAND_ERROR_USAGE;
}
}
if (argc < optind + 1)
return COMMAND_ERROR_USAGE;
buf32 = buf = read_file(argv[optind], &read_size);
if (!buf)
return -EINVAL;
write_size = buf32[5];
printf("size of the size %d\n", read_size);
printf("size to load in sram %d\n", write_size);
if (write_size > read_size) {
printf("file smaller than requested sram loading size (%d < %d)\n", write_size, read_size);
goto err;
}
fd = open(sram, O_WRONLY);
if (fd < 0) {
printf("could not open %s: %s\n", sram, errno_str());
ret = fd;
goto err;
}
while (write_size) {
tmp = write(fd, buf, write_size);
if (tmp < 0) {
perror("write");
goto err_open;
}
buf += tmp;
write_size -= tmp;
}
shutdown_barebox();
jump();
err_open:
close(fd);
err:
free(buf);
return ret;
}
BAREBOX_CMD_HELP_START(at91_boot_test)
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_TEXT("Options:")
BAREBOX_CMD_HELP_OPT ("-j ADDR", "jump address")
BAREBOX_CMD_HELP_OPT ("-s SRAM", "SRAM device (default /dev/sram0)")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(at91_boot_test)
.cmd = do_at91_boot_test,
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 and execute from SRAM")
BAREBOX_CMD_OPTS("at91_boot_test [-js] FILE")
BAREBOX_CMD_GROUP(CMD_GRP_BOOT)
BAREBOX_CMD_HELP(cmd_at91_boot_test_help)
BAREBOX_CMD_END