local: Implement local_dump_image

This commit is contained in:
Pali Rohár committed 2012-11-20 21:24:02 +01:00
1 parent bd141d2739
commit 01ec9928f9
1 file changed
+67 -3
+67 -3
View File
@@ -25,6 +25,7 @@
#endif #endif
#include "local.h" #include "local.h"
#include "global.h"
#include "device.h" #include "device.h"
#include "image.h" #include "image.h"
@@ -115,11 +116,74 @@ int local_flash_image(struct image * image) {
} }
static int local_nanddump(const char * file, int mtd, int offset) {
char * command;
size_t size;
int ret;
size = snprintf(NULL, 0, "nanddump -s %d -f %s /dev/mtd%dro", offset, file, mtd);
command = malloc(size);
if ( ! command )
return 1;
snprintf(command, size, "nanddump -s %d -f %s /dev/mtd%dro", offset, file, mtd);
ret = system(command);
free(command);
return ret;
}
struct nanddump_args {
int valid;
int mtd;
int offset;
};
static struct nanddump_args nanddump_n900[] = {
[IMAGE_XLOADER] = { 1, 0, 0x00000000 },
[IMAGE_SECONDARY] = { 1, 0, 0x00004200 },
[IMAGE_KERNEL] = { 1, 3, 0x00000800 },
[IMAGE_INITFS] = { 1, 4, 0x00000800 },
[IMAGE_ROOTFS] = { 1, 5, 0x00000000 },
};
/* FIXME: Is this table correct? */
static struct nanddump_args nanddump[] = {
[IMAGE_XLOADER] = { 1, 0, 0x00000200 },
[IMAGE_SECONDARY] = { 1, 0, 0x00004000 },
[IMAGE_KERNEL] = { 1, 2, 0x00000800 },
[IMAGE_INITFS] = { 1, 3, 0x00000800 },
[IMAGE_ROOTFS] = { 1, 4, 0x00000000 },
};
int local_dump_image(enum image_type image, const char * file) { int local_dump_image(enum image_type image, const char * file) {
/* kernel on n900: if ( device == DEVICE_RX_51 ) {
system("nanddump -s 0x000800 -f /var/tmp/zImage /dev/mtd3");
*/ if ( image < sizeof(nanddump_n900)/sizeof(nanddump_n900[0]) || ! nanddump_n900[image].valid ) {
ERROR("Unsuported image type: %s", image_type_to_string(image));
return -1;
}
return local_nanddump(file, nanddump_n900[image].mtd, nanddump_n900[image].offset);
} else {
if ( image < sizeof(nanddump)/sizeof(nanddump[0]) || ! nanddump[image].valid ) {
ERROR("Unsuported image type: %s", image_type_to_string(image));
return -1;
}
return local_nanddump(file, nanddump[image].mtd, nanddump[image].offset);
}
return -1;
} }