2010-06-28 12:18:35 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <fs.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <ioctl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <linux/mtd/mtd.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mtd/mtd-abi.h>
|
|
|
|
#include <mtd/ubi-user.h>
|
2012-12-17 15:48:26 +00:00
|
|
|
#include <mtd/ubi-media.h>
|
2010-06-28 12:18:35 +00:00
|
|
|
|
2011-12-21 13:18:57 +00:00
|
|
|
static int do_ubimkvol(int argc, char *argv[])
|
2010-06-28 12:18:35 +00:00
|
|
|
{
|
|
|
|
struct ubi_mkvol_req req;
|
|
|
|
int fd, ret;
|
2014-03-10 11:39:51 +00:00
|
|
|
uint64_t size;
|
2010-06-28 12:18:35 +00:00
|
|
|
|
|
|
|
if (argc != 4)
|
|
|
|
return COMMAND_ERROR_USAGE;
|
|
|
|
|
2014-03-10 11:39:51 +00:00
|
|
|
size = strtoull_suffix(argv[3], NULL, 0);
|
2010-06-28 12:18:35 +00:00
|
|
|
req.name_len = min_t(int, strlen(argv[2]), UBI_VOL_NAME_MAX);
|
|
|
|
strncpy(req.name, argv[2], req.name_len);
|
|
|
|
req.name[req.name_len] = 0;
|
|
|
|
|
|
|
|
req.vol_type = UBI_DYNAMIC_VOLUME;
|
|
|
|
req.bytes = size;
|
|
|
|
req.vol_id = UBI_VOL_NUM_AUTO;
|
|
|
|
req.alignment = 1;
|
|
|
|
|
|
|
|
fd = open(argv[1], O_WRONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
perror("open");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ioctl(fd, UBI_IOCMKVOL, &req);
|
|
|
|
if (ret)
|
|
|
|
printf("failed to create: %s\n", strerror(-ret));
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return ret ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
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(ubimkvol)
|
|
|
|
BAREBOX_CMD_HELP_TEXT("Create an UBI volume on UBIDEV with NAME and SIZE.")
|
|
|
|
BAREBOX_CMD_HELP_TEXT("If SIZE is 0 all available space is used for the volume.")
|
|
|
|
BAREBOX_CMD_HELP_END
|
2010-06-28 12:18:35 +00:00
|
|
|
|
|
|
|
BAREBOX_CMD_START(ubimkvol)
|
|
|
|
.cmd = do_ubimkvol,
|
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("create an UBI volume")
|
|
|
|
BAREBOX_CMD_OPTS("UBIDEV NAME SIZE")
|
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_PART)
|
2010-06-28 12:18:35 +00:00
|
|
|
BAREBOX_CMD_HELP(cmd_ubimkvol_help)
|
|
|
|
BAREBOX_CMD_END
|
|
|
|
|
|
|
|
|
2011-12-21 13:18:57 +00:00
|
|
|
static int do_ubiattach(int argc, char *argv[])
|
2010-06-28 12:18:35 +00:00
|
|
|
{
|
2013-09-17 05:12:08 +00:00
|
|
|
int opt;
|
2010-06-28 12:18:35 +00:00
|
|
|
struct mtd_info_user user;
|
|
|
|
int fd, ret;
|
2013-09-17 05:12:08 +00:00
|
|
|
int vid_hdr_offset = 0;
|
|
|
|
|
|
|
|
while((opt = getopt(argc, argv, "O:")) > 0) {
|
|
|
|
switch(opt) {
|
|
|
|
case 'O':
|
|
|
|
vid_hdr_offset = simple_strtoul(optarg, NULL, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return COMMAND_ERROR_USAGE;
|
|
|
|
}
|
|
|
|
}
|
2010-06-28 12:18:35 +00:00
|
|
|
|
2013-09-17 05:12:08 +00:00
|
|
|
if (optind == argc)
|
2010-06-28 12:18:35 +00:00
|
|
|
return COMMAND_ERROR_USAGE;
|
|
|
|
|
2013-09-17 05:12:08 +00:00
|
|
|
fd = open(argv[optind], O_RDWR);
|
2010-06-28 12:18:35 +00:00
|
|
|
if (fd < 0) {
|
|
|
|
perror("open");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ioctl(fd, MEMGETINFO, &user);
|
2013-07-23 09:29:34 +00:00
|
|
|
if (ret) {
|
|
|
|
printf("MEMGETINFO failed: %s\n", strerror(-ret));
|
|
|
|
goto err;
|
|
|
|
}
|
2010-06-28 12:18:35 +00:00
|
|
|
|
2013-09-17 05:12:08 +00:00
|
|
|
ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, vid_hdr_offset, 20);
|
2013-07-23 09:29:34 +00:00
|
|
|
if (ret < 0)
|
2010-06-28 12:18:35 +00:00
|
|
|
printf("failed to attach: %s\n", strerror(-ret));
|
2013-07-23 09:29:34 +00:00
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
err:
|
2010-06-28 12:18:35 +00:00
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return ret ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
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(ubiattach)
|
|
|
|
BAREBOX_CMD_HELP_TEXT("Options:")
|
|
|
|
BAREBOX_CMD_HELP_OPT ("-O OFFS", "VID header offset")
|
|
|
|
BAREBOX_CMD_HELP_END
|
2010-06-28 12:18:35 +00:00
|
|
|
|
|
|
|
BAREBOX_CMD_START(ubiattach)
|
|
|
|
.cmd = do_ubiattach,
|
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("attach mtd device to UBI")
|
|
|
|
BAREBOX_CMD_OPTS("[-O] MTDDEV")
|
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_PART)
|
2010-06-28 12:18:35 +00:00
|
|
|
BAREBOX_CMD_HELP(cmd_ubiattach_help)
|
|
|
|
BAREBOX_CMD_END
|
|
|
|
|
2013-03-01 10:52:26 +00:00
|
|
|
static int do_ubidetach(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int ubi_num, ret;
|
|
|
|
|
|
|
|
if (argc != 2)
|
|
|
|
return COMMAND_ERROR_USAGE;
|
|
|
|
|
|
|
|
ubi_num = simple_strtoul(argv[1], NULL, 0);
|
|
|
|
ret = ubi_detach_mtd_dev(ubi_num, 1);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
printf("failed to detach: %s\n", strerror(-ret));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
BAREBOX_CMD_START(ubidetach)
|
|
|
|
.cmd = do_ubidetach,
|
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("detach an UBI device")
|
|
|
|
BAREBOX_CMD_OPTS("UBINUM")
|
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_PART)
|
2013-03-01 10:52:26 +00:00
|
|
|
BAREBOX_CMD_END
|
|
|
|
|
2011-12-21 13:18:57 +00:00
|
|
|
static int do_ubirmvol(int argc, char *argv[])
|
2010-06-28 12:18:35 +00:00
|
|
|
{
|
|
|
|
struct ubi_mkvol_req req;
|
|
|
|
int fd, ret;
|
|
|
|
|
|
|
|
if (argc != 3)
|
|
|
|
return COMMAND_ERROR_USAGE;
|
|
|
|
|
|
|
|
strncpy(req.name, argv[2], UBI_VOL_NAME_MAX);
|
|
|
|
req.name[UBI_VOL_NAME_MAX] = 0;
|
|
|
|
|
|
|
|
fd = open(argv[1], O_WRONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
perror("open");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ioctl(fd, UBI_IOCRMVOL, &req);
|
|
|
|
if (ret)
|
|
|
|
printf("failed to delete: %s\n", strerror(-ret));
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return ret ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
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(ubirmvol)
|
|
|
|
BAREBOX_CMD_HELP_TEXT("Delete UBI volume NAME from UBIDEV")
|
|
|
|
BAREBOX_CMD_HELP_END
|
2010-06-28 12:18:35 +00:00
|
|
|
|
|
|
|
BAREBOX_CMD_START(ubirmvol)
|
|
|
|
.cmd = do_ubirmvol,
|
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("delete an UBI volume")
|
|
|
|
BAREBOX_CMD_OPTS("UBIDEV NAME")
|
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_PART)
|
2010-06-28 12:18:35 +00:00
|
|
|
BAREBOX_CMD_HELP(cmd_ubirmvol_help)
|
|
|
|
BAREBOX_CMD_END
|
|
|
|
|