summaryrefslogtreecommitdiffstats
path: root/src/local.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2012-11-20 21:24:02 +0100
committerPali Rohár <pali.rohar@gmail.com>2012-11-20 21:24:02 +0100
commit01ec9928f94971e4edd99f755247a87c889c0669 (patch)
tree5d45594a871587045e10abd97400f633eb7cc166 /src/local.c
parentbd141d27396d82335d960c179c49ecd33c020cb4 (diff)
download0xFFFF-01ec9928f94971e4edd99f755247a87c889c0669.tar.bz2
local: Implement local_dump_image
Diffstat (limited to 'src/local.c')
-rw-r--r--src/local.c70
1 files changed, 67 insertions, 3 deletions
diff --git a/src/local.c b/src/local.c
index 8498eab..c6ffc0a 100644
--- a/src/local.c
+++ b/src/local.c
@@ -25,6 +25,7 @@
#endif
#include "local.h"
+#include "global.h"
#include "device.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) {
- /* kernel on n900:
- system("nanddump -s 0x000800 -f /var/tmp/zImage /dev/mtd3");
- */
+ if ( device == DEVICE_RX_51 ) {
+
+ 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;
}