summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2013-04-21 16:36:30 +0200
committerPali Rohár <pali.rohar@gmail.com>2013-04-21 16:36:30 +0200
commit1c20e5ff5f95a85f02578b66e9c45d9962865cda (patch)
tree172635a40e685a2e1f0f65eb599079e2bf101a4a
parentfbd23222b178ae0d22782c0eb0261a636aa6eee4 (diff)
download0xFFFF-1c20e5ff5f95a85f02578b66e9c45d9962865cda.tar.bz2
local: Simplify nanddump code
-rw-r--r--src/local.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/local.c b/src/local.c
index 5af07ca..d9fc468 100644
--- a/src/local.c
+++ b/src/local.c
@@ -256,7 +256,7 @@ static struct nanddump_args nanddump_rx4x[] = {
};
/* FIXME: Is this table correct? */
-static struct nanddump_args nanddump[] = {
+static struct nanddump_args nanddump_old[] = {
[IMAGE_XLOADER] = { 1, 0, 0x00000200, 0x00003E00 },
[IMAGE_SECONDARY] = { 1, 0, 0x00004000, 0x0001C000 },
[IMAGE_KERNEL] = { 1, 2, 0x00000800, 0x001FF800 },
@@ -264,6 +264,23 @@ static struct nanddump_args nanddump[] = {
[IMAGE_ROOTFS] = { 1, 4, 0x00000000, 0x0fb80000 },
};
+struct nanddump_device {
+ size_t count;
+ struct nanddump_args * args;
+};
+
+#define NANDDUMP(device, array) [device] = { .count = sizeof(array)/sizeof(array[0]), .args = array }
+
+static struct nanddump_device nanddump[] = {
+ NANDDUMP(DEVICE_SU_18, nanddump_old),
+ NANDDUMP(DEVICE_RX_34, nanddump_old),
+ NANDDUMP(DEVICE_RX_44, nanddump_rx4x),
+ NANDDUMP(DEVICE_RX_48, nanddump_rx4x),
+ NANDDUMP(DEVICE_RX_51, nanddump_rx51),
+};
+
+#undef NANDDUMP
+
int local_dump_image(enum image_type image, const char * file) {
int ret = -1;
@@ -363,26 +380,18 @@ int local_dump_image(enum image_type image, const char * file) {
} else {
- if ( device == DEVICE_RX_51 ) {
-
- if ( image >= sizeof(nanddump_rx51)/sizeof(nanddump_rx51[0]) || ! nanddump_rx51[image].valid ) {
- ERROR("Unsuported image type: %s", image_type_to_string(image));
- goto clean;
- }
-
- ret = local_nanddump(file, nanddump_rx51[image].mtd, nanddump_rx51[image].offset, nanddump_rx51[image].length);
-
- } else {
-
- if ( image >= sizeof(nanddump)/sizeof(nanddump[0]) || ! nanddump[image].valid ) {
- ERROR("Unsuported image type: %s", image_type_to_string(image));
- goto clean;
- }
-
- ret = local_nanddump(file, nanddump[image].mtd, nanddump[image].offset, nanddump[image].length);
+ if ( device >= sizeof(nanddump)/sizeof(nanddump[0]) ) {
+ ERROR("Unsupported device");
+ goto clean;
+ }
+ if ( image >= nanddump[device].count ) {
+ ERROR("Unsuported image type: %s", image_type_to_string(image));
+ goto clean;
}
+ ret = local_nanddump(file, nanddump[device].args[image].mtd, nanddump[device].args[image].offset, nanddump[device].args[image].length);
+
}
if ( ret != 0 ) {