2013-06-03 23:13:52 +00:00
|
|
|
/*
|
|
|
|
* memtest - Perform a memory test
|
|
|
|
*
|
|
|
|
* (C) Copyright 2013
|
|
|
|
* Alexander Aring <aar@pengutronix.de>, Pengutronix
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <command.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <memtest.h>
|
2015-10-23 09:06:56 +00:00
|
|
|
#include <mmu.h>
|
2013-06-03 23:13:52 +00:00
|
|
|
|
2015-10-23 12:51:52 +00:00
|
|
|
static int do_test_one_area(struct mem_test_resource *r, int bus_only,
|
|
|
|
unsigned cache_flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
printf("Testing memory space: "
|
|
|
|
"0x%08x -> 0x%08x:\n",
|
|
|
|
r->r->start, r->r->end);
|
|
|
|
|
|
|
|
remap_range((void *)r->r->start, r->r->end -
|
|
|
|
r->r->start + 1, cache_flag);
|
|
|
|
|
|
|
|
ret = mem_test_bus_integrity(r->r->start, r->r->end);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (bus_only)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = mem_test_moving_inversions(r->r->start, r->r->end);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
printf("done.\n\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_memtest_thorough(struct list_head *memtest_regions,
|
2015-10-23 09:06:56 +00:00
|
|
|
int bus_only, unsigned cache_flag)
|
2013-06-03 23:13:52 +00:00
|
|
|
{
|
|
|
|
struct mem_test_resource *r;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
list_for_each_entry(r, memtest_regions, list) {
|
2015-10-23 12:51:52 +00:00
|
|
|
ret = do_test_one_area(r, bus_only, cache_flag);
|
|
|
|
if (ret)
|
2015-10-23 09:29:59 +00:00
|
|
|
return ret;
|
2013-06-03 23:13:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-23 12:51:52 +00:00
|
|
|
static int do_memtest_biggest(struct list_head *memtest_regions,
|
|
|
|
int bus_only, unsigned cache_flag)
|
|
|
|
{
|
|
|
|
struct mem_test_resource *r;
|
|
|
|
|
|
|
|
r = mem_test_biggest_region(memtest_regions);
|
|
|
|
if (!r)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return do_test_one_area(r, bus_only, cache_flag);
|
|
|
|
}
|
|
|
|
|
2013-06-03 23:13:52 +00:00
|
|
|
static int do_memtest(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int bus_only = 0, ret, opt;
|
2015-10-23 09:06:56 +00:00
|
|
|
uint32_t i, max_i = 1;
|
2013-06-03 23:13:52 +00:00
|
|
|
struct list_head memtest_used_regions;
|
2015-10-23 12:51:52 +00:00
|
|
|
int (*memtest)(struct list_head *, int, unsigned);
|
2015-10-23 12:57:13 +00:00
|
|
|
int cached = 0, uncached = 0;
|
2015-10-23 12:51:52 +00:00
|
|
|
|
|
|
|
memtest = do_memtest_biggest;
|
2013-06-03 23:13:52 +00:00
|
|
|
|
2015-10-23 12:57:13 +00:00
|
|
|
while ((opt = getopt(argc, argv, "i:btcu")) > 0) {
|
2013-06-03 23:13:52 +00:00
|
|
|
switch (opt) {
|
|
|
|
case 'i':
|
|
|
|
max_i = simple_strtoul(optarg, NULL, 0);
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
bus_only = 1;
|
|
|
|
break;
|
2015-10-23 12:51:52 +00:00
|
|
|
case 't':
|
|
|
|
memtest = do_memtest_thorough;
|
|
|
|
break;
|
2015-10-23 12:57:13 +00:00
|
|
|
case 'c':
|
|
|
|
cached = 1;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
uncached = 1;
|
|
|
|
break;
|
2013-06-03 23:13:52 +00:00
|
|
|
default:
|
|
|
|
return COMMAND_ERROR_USAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-23 12:57:13 +00:00
|
|
|
if (!arch_can_remap() && (cached || uncached)) {
|
|
|
|
printf("Cannot map cached or uncached\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-06-03 23:13:52 +00:00
|
|
|
if (optind > argc)
|
|
|
|
return COMMAND_ERROR_USAGE;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&memtest_used_regions);
|
|
|
|
|
2015-10-23 07:39:15 +00:00
|
|
|
ret = mem_test_request_regions(&memtest_used_regions);
|
2013-06-03 23:13:52 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (i = 1; (i <= max_i) || !max_i; i++) {
|
2015-10-11 18:43:34 +00:00
|
|
|
printf("Start iteration %u", i);
|
2013-06-03 23:13:52 +00:00
|
|
|
if (max_i)
|
2015-10-11 18:43:34 +00:00
|
|
|
printf(" of %u.\n", max_i);
|
|
|
|
else
|
|
|
|
putchar('\n');
|
2015-10-23 09:06:56 +00:00
|
|
|
|
2015-10-23 12:57:13 +00:00
|
|
|
if (cached) {
|
2013-06-03 23:13:52 +00:00
|
|
|
printf("Do memtest with caching enabled.\n");
|
2015-10-23 12:51:52 +00:00
|
|
|
ret = memtest(&memtest_used_regions,
|
2015-10-23 09:06:56 +00:00
|
|
|
bus_only, MAP_CACHED);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2015-10-23 12:57:13 +00:00
|
|
|
}
|
2015-10-23 09:06:56 +00:00
|
|
|
|
2015-10-23 12:57:13 +00:00
|
|
|
if (uncached) {
|
2015-10-23 09:06:56 +00:00
|
|
|
printf("Do memtest with caching disabled.\n");
|
2015-10-23 12:51:52 +00:00
|
|
|
ret = memtest(&memtest_used_regions,
|
2015-10-23 09:06:56 +00:00
|
|
|
bus_only, MAP_UNCACHED);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2015-10-23 12:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cached && !uncached) {
|
2015-10-23 12:51:52 +00:00
|
|
|
ret = memtest(&memtest_used_regions,
|
2015-10-23 09:06:56 +00:00
|
|
|
bus_only, MAP_DEFAULT);
|
2013-06-03 23:13:52 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2015-10-23 07:39:15 +00:00
|
|
|
mem_test_release_regions(&memtest_used_regions);
|
2013-06-03 23:13:52 +00:00
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
/*
|
|
|
|
* Set cursor to newline, because mem_test failed at
|
|
|
|
* drawing of progressbar.
|
|
|
|
*/
|
|
|
|
if (ret == -EINTR)
|
|
|
|
printf("\n");
|
|
|
|
|
2014-04-10 12:04:04 +00:00
|
|
|
printf("Memtest failed. Error: %d\n", ret);
|
2013-06-03 23:13:52 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2014-04-10 12:04:04 +00:00
|
|
|
|
|
|
|
printf("Memtest successful.\n");
|
|
|
|
return 0;
|
2013-06-03 23:13:52 +00:00
|
|
|
}
|
|
|
|
|
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(memtest)
|
|
|
|
BAREBOX_CMD_HELP_TEXT("Options:")
|
|
|
|
BAREBOX_CMD_HELP_OPT("-i ITERATIONS", "perform number of iterations (default 1, 0 is endless)")
|
|
|
|
BAREBOX_CMD_HELP_OPT("-b", "perform only a test on bus lines")
|
2015-10-23 12:57:13 +00:00
|
|
|
BAREBOX_CMD_HELP_OPT("-c", "cached. Test using cached memory")
|
|
|
|
BAREBOX_CMD_HELP_OPT("-u", "uncached. Test using uncached memory")
|
2015-10-23 12:51:52 +00:00
|
|
|
BAREBOX_CMD_HELP_OPT("-t", "thorough. test all free areas. If unset, only test biggest free area")
|
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_END
|
2013-06-03 23:13:52 +00:00
|
|
|
|
|
|
|
BAREBOX_CMD_START(memtest)
|
|
|
|
.cmd = do_memtest,
|
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("extensive memory test")
|
2015-12-19 18:33:58 +00:00
|
|
|
BAREBOX_CMD_OPTS("[-ibcut]")
|
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_MEM)
|
2013-06-03 23:13:52 +00:00
|
|
|
BAREBOX_CMD_HELP(cmd_memtest_help)
|
|
|
|
BAREBOX_CMD_END
|