[PATCH 04/10] common/memtest.c: Distil common error reporting code
Andrey Smirnov
andrew.smirnov at gmail.com
Wed May 13 19:54:21 PDT 2015
Move all of the common code for error message output into a new
function mem_test_report_failure() and convert the rest of the code to
use it.
Signed-off-by: Andrey Smirnov <andrew.smirnov at gmail.com>
---
common/memtest.c | 53 ++++++++++++++++++++++++++++-------------------------
1 file changed, 28 insertions(+), 25 deletions(-)
diff --git a/common/memtest.c b/common/memtest.c
index 57e2ad9..d8d1154 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -28,6 +28,17 @@
#include <errno.h>
#include <memtest.h>
+static void mem_test_report_failure(const char *failure_description,
+ resource_size_t expected_value,
+ resource_size_t actual_value,
+ volatile resource_size_t *address)
+{
+ printf("FAILURE (%s): "
+ "expected 0x%08x, actual 0x%08x at address 0x%08x.\n",
+ failure_description, expected_value, actual_value,
+ (resource_size_t)address);
+}
+
int mem_test_bus_integrity(resource_size_t _start,
resource_size_t _end)
{
@@ -87,9 +98,8 @@ int mem_test_bus_integrity(resource_size_t _start,
*dummy = ~val;
readback = *start;
if (readback != val) {
- printf("FAILURE (data line): "
- "expected 0x%08x, actual 0x%08x at address 0x%08x.\n",
- val, readback, (resource_size_t)start);
+ mem_test_report_failure("data line",
+ val, readback, start);
return -EIO;
}
@@ -97,10 +107,8 @@ int mem_test_bus_integrity(resource_size_t _start,
*dummy = val;
readback = *start;
if (readback != ~val) {
- printf("FAILURE (data line): "
- "Is 0x%08x, should be 0x%08x at address 0x%08x.\n",
- readback,
- ~val, (resource_size_t)start);
+ mem_test_report_failure("data line",
+ ~val, readback, start);
return -EIO;
}
}
@@ -174,11 +182,8 @@ int mem_test_bus_integrity(resource_size_t _start,
for (offset = 1; offset <= num_words; offset <<= 1) {
temp = start[offset];
if (temp != pattern) {
- printf("FAILURE: Address bit "
- "stuck high @ 0x%08x:"
- " expected 0x%08x, actual 0x%08x.\n",
- (resource_size_t)&start[offset],
- pattern, temp);
+ mem_test_report_failure("address bit stuck high",
+ pattern, temp, &start[offset]);
return -EIO;
}
}
@@ -203,11 +208,9 @@ int mem_test_bus_integrity(resource_size_t _start,
if ((temp != pattern) &&
(offset != offset2)) {
- printf("FAILURE: Address bit stuck"
- " low or shorted @"
- " 0x%08x: expected 0x%08x, actual 0x%08x.\n",
- (resource_size_t)&start[offset],
- pattern, temp);
+ mem_test_report_failure(
+ "address bit stuck low or shorted",
+ pattern, temp, &start[offset]);
return -EIO;
}
}
@@ -278,10 +281,10 @@ int mem_test_dram(resource_size_t _start,
temp = start[offset];
if (temp != (offset + 1)) {
- printf("\nFAILURE (read/write) @ 0x%08x:"
- " expected 0x%08x, actual 0x%08x.\n",
- (resource_size_t)&start[offset],
- (offset + 1), temp);
+ printf("\n");
+ mem_test_report_failure("read/write",
+ (offset + 1),
+ temp, &start[offset]);
return -EIO;
}
@@ -306,10 +309,10 @@ int mem_test_dram(resource_size_t _start,
temp = start[offset];
if (temp != anti_pattern) {
- printf("\nFAILURE (read/write): @ 0x%08x:"
- " expected 0x%08x, actual 0x%08x.\n",
- (resource_size_t)&start[offset],
- anti_pattern, temp);
+ printf("\n");
+ mem_test_report_failure("read/write",
+ anti_pattern,
+ temp, &start[offset]);
return -EIO;
}
--
2.1.4
More information about the barebox
mailing list