local: Simplify nanddump code

This commit is contained in:
Pali Rohár committed 2013-04-21 16:36:30 +02:00
1 parent fbd23222b1
commit 1c20e5ff5f
1 file changed
+28 -19
+28 -19
View File
@@ -256,7 +256,7 @@ static struct nanddump_args nanddump_rx4x[] = {
}; };
/* FIXME: Is this table correct? */ /* FIXME: Is this table correct? */
static struct nanddump_args nanddump[] = { static struct nanddump_args nanddump_old[] = {
[IMAGE_XLOADER] = { 1, 0, 0x00000200, 0x00003E00 }, [IMAGE_XLOADER] = { 1, 0, 0x00000200, 0x00003E00 },
[IMAGE_SECONDARY] = { 1, 0, 0x00004000, 0x0001C000 }, [IMAGE_SECONDARY] = { 1, 0, 0x00004000, 0x0001C000 },
[IMAGE_KERNEL] = { 1, 2, 0x00000800, 0x001FF800 }, [IMAGE_KERNEL] = { 1, 2, 0x00000800, 0x001FF800 },
@@ -264,6 +264,23 @@ static struct nanddump_args nanddump[] = {
[IMAGE_ROOTFS] = { 1, 4, 0x00000000, 0x0fb80000 }, [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 local_dump_image(enum image_type image, const char * file) {
int ret = -1; int ret = -1;
@@ -363,26 +380,18 @@ int local_dump_image(enum image_type image, const char * file) {
} else { } else {
if ( device == DEVICE_RX_51 ) { if ( device >= sizeof(nanddump)/sizeof(nanddump[0]) ) {
ERROR("Unsupported device");
if ( image >= sizeof(nanddump_rx51)/sizeof(nanddump_rx51[0]) || ! nanddump_rx51[image].valid ) { goto clean;
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 ( 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 ) { if ( ret != 0 ) {