2012-11-15 01:39:18 +01:00
|
|
|
/*
|
|
|
|
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
|
|
|
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2012-11-23 22:09:10 +01:00
|
|
|
#include <sys/statvfs.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
|
|
#include <libgen.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <fcntl.h>
|
2012-11-24 11:09:46 +01:00
|
|
|
#include <dirent.h>
|
2012-11-23 22:09:10 +01:00
|
|
|
|
2012-11-15 01:39:18 +01:00
|
|
|
#include "local.h"
|
2012-11-20 21:24:02 +01:00
|
|
|
#include "global.h"
|
2012-11-15 01:39:18 +01:00
|
|
|
#include "device.h"
|
|
|
|
|
#include "image.h"
|
2012-11-24 01:01:53 +01:00
|
|
|
#include "cal.h"
|
2012-11-24 11:09:46 +01:00
|
|
|
#include "disk.h"
|
2012-11-15 01:39:18 +01:00
|
|
|
|
2012-11-21 14:14:21 +01:00
|
|
|
static int failed;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
static enum device device = DEVICE_UNKNOWN;
|
|
|
|
|
static int16_t hwrev = -1;
|
|
|
|
|
static char kernel_ver[256];
|
|
|
|
|
static char initfs_ver[256];
|
|
|
|
|
static char nolo_ver[256];
|
|
|
|
|
static char sw_ver[256];
|
|
|
|
|
static char content_ver[256];
|
|
|
|
|
static char rd_mode[256];
|
2012-11-24 11:08:25 +01:00
|
|
|
static int usb_host_mode = -1;
|
|
|
|
|
static int root_device = -1;
|
2012-11-24 01:01:53 +01:00
|
|
|
|
|
|
|
|
#define min(a, b) (a < b ? a : b)
|
|
|
|
|
#define local_cal_copy(dest, from, len) strncpy(dest, from, min(len, sizeof(dest)-1))
|
|
|
|
|
#define local_cal_read(cal, str, ptr, len) ( cal_read_block(cal, str, &ptr, &len, 0) == 0 && ptr )
|
2013-09-07 22:16:47 +02:00
|
|
|
#define local_cal_readcopy(cal, str, dest) do { void * ptr; unsigned long int len; if ( local_cal_read(cal, str, ptr, len) ) local_cal_copy(dest, ptr, len); } while ( 0 )
|
2012-11-24 01:01:53 +01:00
|
|
|
|
|
|
|
|
static void local_cal_parse(void) {
|
|
|
|
|
|
|
|
|
|
struct cal * cal = NULL;
|
|
|
|
|
char buf[128];
|
|
|
|
|
|
2012-11-24 11:08:25 +01:00
|
|
|
printf("Reading CAL...\n");
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
if ( cal_init(&cal) < 0 || ! cal )
|
|
|
|
|
return;
|
|
|
|
|
|
2013-09-07 22:16:47 +02:00
|
|
|
local_cal_readcopy(cal, "kernel-ver", kernel_ver);
|
|
|
|
|
local_cal_readcopy(cal, "initfs-ver", kernel_ver);
|
|
|
|
|
local_cal_readcopy(cal, "nolo-ver", nolo_ver);
|
|
|
|
|
local_cal_readcopy(cal, "sw-release-ver", sw_ver);
|
|
|
|
|
local_cal_readcopy(cal, "content-ver", content_ver);
|
|
|
|
|
local_cal_readcopy(cal, "r&d_mode", rd_mode);
|
2012-11-24 01:01:53 +01:00
|
|
|
|
2012-11-24 15:42:34 +01:00
|
|
|
/* overwritten hw revision */
|
2012-11-24 01:01:53 +01:00
|
|
|
memset(buf, 0, sizeof(buf));
|
2013-09-07 22:16:47 +02:00
|
|
|
local_cal_readcopy(cal, "hw-ver", buf);
|
2012-11-24 01:01:53 +01:00
|
|
|
|
2012-11-24 15:42:34 +01:00
|
|
|
if ( buf[0] && sscanf(buf, "%hd", &hwrev) != 1 )
|
2012-11-24 01:01:53 +01:00
|
|
|
hwrev = -1;
|
|
|
|
|
|
2012-11-24 15:42:34 +01:00
|
|
|
if ( hwrev == -1 ) {
|
|
|
|
|
|
|
|
|
|
/* original hw revision */
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
2013-09-07 22:16:47 +02:00
|
|
|
local_cal_readcopy(cal, "phone-info", buf);
|
2012-11-24 15:42:34 +01:00
|
|
|
buf[4] = 0;
|
|
|
|
|
|
|
|
|
|
if ( buf[0] && sscanf(buf, "%hd", &hwrev) != 1 )
|
|
|
|
|
hwrev = -1;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
buf[0] = 0;
|
2013-09-07 22:16:47 +02:00
|
|
|
local_cal_readcopy(cal, "usb_host_mode", buf);
|
2012-11-24 01:01:53 +01:00
|
|
|
usb_host_mode = buf[0];
|
|
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
2013-09-07 22:16:47 +02:00
|
|
|
local_cal_readcopy(cal, "root_device", buf);
|
2012-11-24 01:01:53 +01:00
|
|
|
|
|
|
|
|
if ( strcmp(buf, "mmc") == 0 )
|
|
|
|
|
root_device = 1;
|
|
|
|
|
else if ( strcmp(buf, "usb") == 0 )
|
|
|
|
|
root_device = 2;
|
|
|
|
|
else
|
|
|
|
|
root_device = 0;
|
|
|
|
|
|
|
|
|
|
cal_finish(cal);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 01:39:18 +01:00
|
|
|
int local_init(void) {
|
|
|
|
|
|
|
|
|
|
char buf[1024];
|
|
|
|
|
char * ptr;
|
|
|
|
|
char * ptr2;
|
|
|
|
|
FILE * file;
|
|
|
|
|
|
2012-11-21 14:14:21 +01:00
|
|
|
if ( failed )
|
|
|
|
|
return -1;
|
|
|
|
|
|
2012-11-15 01:39:18 +01:00
|
|
|
file = fopen("/proc/cpuinfo", "r");
|
2012-11-21 14:14:21 +01:00
|
|
|
if ( ! file ) {
|
|
|
|
|
failed = 1;
|
2012-11-15 01:39:18 +01:00
|
|
|
return -1;
|
2012-11-21 14:14:21 +01:00
|
|
|
}
|
2012-11-15 01:39:18 +01:00
|
|
|
|
|
|
|
|
while ( fgets(buf, sizeof(buf), file) ) {
|
|
|
|
|
|
|
|
|
|
if ( strncmp(buf, "Hardware", strlen("Hardware")) == 0 ) {
|
|
|
|
|
|
|
|
|
|
ptr = buf + strlen("Hardware");
|
|
|
|
|
|
|
|
|
|
while ( ptr < buf + sizeof(buf) && *ptr > 0 && *ptr <= 32 )
|
|
|
|
|
++ptr;
|
|
|
|
|
|
|
|
|
|
if ( *ptr != ':' )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
++ptr;
|
|
|
|
|
|
|
|
|
|
while ( ptr < buf + sizeof(buf) && *ptr > 0 && *ptr <= 32 )
|
|
|
|
|
++ptr;
|
|
|
|
|
|
|
|
|
|
if ( ! *ptr )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ptr2 = buf + strlen(buf);
|
|
|
|
|
|
|
|
|
|
while ( *ptr2 <= 32 ) {
|
|
|
|
|
*ptr2 = 0;
|
|
|
|
|
--ptr2;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-23 22:08:45 +01:00
|
|
|
if ( strcmp(ptr, "Nokia 770") == 0 )
|
2012-11-15 01:39:18 +01:00
|
|
|
device = DEVICE_SU_18;
|
2012-11-23 22:08:45 +01:00
|
|
|
else if ( strcmp(ptr, "Nokia N800") == 0 )
|
2012-11-15 01:39:18 +01:00
|
|
|
device = DEVICE_RX_34;
|
2012-11-23 22:08:45 +01:00
|
|
|
else if ( strcmp(ptr, "Nokia N810") == 0 )
|
2012-11-15 01:39:18 +01:00
|
|
|
device = DEVICE_RX_44;
|
2012-11-23 22:08:45 +01:00
|
|
|
else if ( strcmp(ptr, "Nokia N810 WiMAX") == 0 )
|
2012-11-15 01:39:18 +01:00
|
|
|
device = DEVICE_RX_48;
|
2012-11-23 22:08:45 +01:00
|
|
|
else if ( strcmp(ptr, "Nokia RX-51 board") == 0 )
|
2012-11-15 01:39:18 +01:00
|
|
|
device = DEVICE_RX_51;
|
2012-11-23 22:08:45 +01:00
|
|
|
|
|
|
|
|
if ( device ) {
|
2012-11-15 01:39:18 +01:00
|
|
|
printf("Found local device: %s\n", device_to_long_string(device));
|
|
|
|
|
fclose(file);
|
2012-11-24 01:01:53 +01:00
|
|
|
local_cal_parse();
|
2012-11-15 01:39:18 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-21 14:14:21 +01:00
|
|
|
failed = 1;
|
2012-11-15 01:39:18 +01:00
|
|
|
printf("Not a local device\n");
|
|
|
|
|
fclose(file);
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum device local_get_device(void) {
|
|
|
|
|
|
|
|
|
|
return device;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_flash_image(struct image * image) {
|
|
|
|
|
|
2012-11-20 21:38:11 +01:00
|
|
|
ERROR("Not implemented yet");
|
2012-11-20 21:51:21 +01:00
|
|
|
(void)image;
|
2012-11-20 21:38:11 +01:00
|
|
|
return -1;
|
|
|
|
|
|
2012-11-15 01:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
2012-11-23 22:09:10 +01:00
|
|
|
static int local_nanddump(const char * file, int mtd, int offset, int length) {
|
2012-11-20 21:24:02 +01:00
|
|
|
|
2012-11-23 22:09:10 +01:00
|
|
|
struct statvfs buf;
|
2012-11-20 21:24:02 +01:00
|
|
|
char * command;
|
2012-11-23 22:09:10 +01:00
|
|
|
char * path;
|
2012-11-20 21:24:02 +01:00
|
|
|
size_t size;
|
|
|
|
|
int ret;
|
|
|
|
|
|
2012-11-23 22:09:10 +01:00
|
|
|
path = strdup(file);
|
|
|
|
|
if ( ! path )
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
ret = statvfs(dirname(path), &buf);
|
|
|
|
|
|
|
|
|
|
free(path);
|
|
|
|
|
|
|
|
|
|
if ( ret == 0 && buf.f_bsize * buf.f_bfree < (long unsigned int)length ) {
|
|
|
|
|
ERROR("Not enought free space (have: %lu, need: %d)", buf.f_bsize * buf.f_bfree, length);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size = snprintf(NULL, 0, "nanddump -i -o -b -s %d -l %d -f %s /dev/mtd%dro", offset, length, file, mtd);
|
2012-11-20 21:24:02 +01:00
|
|
|
|
2012-11-23 22:09:10 +01:00
|
|
|
command = malloc(size+1);
|
2012-11-20 21:24:02 +01:00
|
|
|
if ( ! command )
|
|
|
|
|
return 1;
|
|
|
|
|
|
2012-11-23 22:09:10 +01:00
|
|
|
snprintf(command, size+1, "nanddump -i -o -b -s %d -l %d -f %s /dev/mtd%dro", offset, length, file, mtd);
|
2012-11-20 21:24:02 +01:00
|
|
|
|
|
|
|
|
ret = system(command);
|
|
|
|
|
|
|
|
|
|
free(command);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct nanddump_args {
|
|
|
|
|
int valid;
|
|
|
|
|
int mtd;
|
|
|
|
|
int offset;
|
2012-11-23 22:09:10 +01:00
|
|
|
int length;
|
2012-11-20 21:24:02 +01:00
|
|
|
};
|
|
|
|
|
|
2013-02-01 13:19:35 +01:00
|
|
|
static struct nanddump_args nanddump_rx51[] = {
|
2012-11-23 22:09:10 +01:00
|
|
|
[IMAGE_XLOADER] = { 1, 0, 0x00000000, 0x00004000 },
|
|
|
|
|
[IMAGE_SECONDARY] = { 1, 0, 0x00004000, 0x0001C000 },
|
|
|
|
|
[IMAGE_KERNEL] = { 1, 3, 0x00000800, 0x001FF800 },
|
2013-02-01 13:19:35 +01:00
|
|
|
[IMAGE_INITFS] = { 1, 4, 0x00000000, 0x00200000 },
|
2012-11-23 22:09:10 +01:00
|
|
|
[IMAGE_ROOTFS] = { 1, 5, 0x00000000, 0x0fb40000 },
|
2012-11-20 21:24:02 +01:00
|
|
|
};
|
|
|
|
|
|
2013-04-21 16:34:43 +02:00
|
|
|
/* FIXME: Is this table correct? */
|
|
|
|
|
static struct nanddump_args nanddump_rx4x[] = {
|
|
|
|
|
[IMAGE_XLOADER] = { 1, 0, 0x00000200, 0x00003E00 },
|
|
|
|
|
[IMAGE_SECONDARY] = { 1, 0, 0x00004000, 0x0001C000 },
|
|
|
|
|
[IMAGE_KERNEL] = { 1, 2, 0x00000800, 0x0021F800 },
|
|
|
|
|
[IMAGE_INITFS] = { 1, 3, 0x00000000, 0x00400000 },
|
|
|
|
|
[IMAGE_ROOTFS] = { 1, 4, 0x00000000, 0x0f960000 },
|
|
|
|
|
};
|
|
|
|
|
|
2012-11-20 21:24:02 +01:00
|
|
|
/* FIXME: Is this table correct? */
|
2013-04-21 16:36:30 +02:00
|
|
|
static struct nanddump_args nanddump_old[] = {
|
2012-11-23 22:09:10 +01:00
|
|
|
[IMAGE_XLOADER] = { 1, 0, 0x00000200, 0x00003E00 },
|
|
|
|
|
[IMAGE_SECONDARY] = { 1, 0, 0x00004000, 0x0001C000 },
|
|
|
|
|
[IMAGE_KERNEL] = { 1, 2, 0x00000800, 0x001FF800 },
|
2013-02-01 13:19:35 +01:00
|
|
|
[IMAGE_INITFS] = { 1, 3, 0x00000000, 0x00200000 },
|
2012-11-23 22:09:10 +01:00
|
|
|
[IMAGE_ROOTFS] = { 1, 4, 0x00000000, 0x0fb80000 },
|
2012-11-20 21:24:02 +01:00
|
|
|
};
|
|
|
|
|
|
2013-04-21 16:36:30 +02:00
|
|
|
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
|
|
|
|
|
|
2012-11-20 20:42:17 +01:00
|
|
|
int local_dump_image(enum image_type image, const char * file) {
|
2012-11-15 01:39:18 +01:00
|
|
|
|
2012-11-23 22:09:10 +01:00
|
|
|
int ret = -1;
|
|
|
|
|
int fd = -1;
|
|
|
|
|
unsigned char * addr = NULL;
|
|
|
|
|
off_t nlen, len;
|
2012-11-24 11:09:46 +01:00
|
|
|
int align;
|
|
|
|
|
DIR * dir;
|
|
|
|
|
DIR * dir2;
|
|
|
|
|
struct dirent * dirent;
|
|
|
|
|
struct dirent * dirent2;
|
|
|
|
|
char * ptr;
|
|
|
|
|
int i;
|
|
|
|
|
char buf[1024];
|
|
|
|
|
char blk[1024];
|
2012-11-23 22:09:10 +01:00
|
|
|
|
2012-11-24 11:09:46 +01:00
|
|
|
printf("Dump %s image to file %s...\n", image_type_to_string(image), file);
|
2012-11-23 22:09:10 +01:00
|
|
|
|
2012-11-24 11:09:46 +01:00
|
|
|
if ( image == IMAGE_MMC ) {
|
2012-11-23 22:09:10 +01:00
|
|
|
|
2012-11-24 11:09:46 +01:00
|
|
|
/* Find block device in /dev/ for MyDocs (mmc device, partition 1) */
|
2012-11-20 21:24:02 +01:00
|
|
|
|
2012-11-24 11:09:46 +01:00
|
|
|
dir = opendir("/sys/class/mmc_host/");
|
|
|
|
|
if ( ! dir ) {
|
|
|
|
|
ERROR("Cannot find MyDocs mmc device");
|
2012-11-23 22:09:10 +01:00
|
|
|
goto clean;
|
2012-11-20 21:24:02 +01:00
|
|
|
}
|
|
|
|
|
|
2012-11-24 11:09:46 +01:00
|
|
|
blk[0] = 0;
|
2012-11-20 21:24:02 +01:00
|
|
|
|
2012-11-24 11:09:46 +01:00
|
|
|
while ( ( dirent = readdir(dir) ) ) {
|
|
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "/sys/class/mmc_host/%s/slot_name", dirent->d_name);
|
|
|
|
|
|
|
|
|
|
fd = open(buf, O_RDONLY);
|
|
|
|
|
if ( fd < 0 )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
buf[0] = 0;
|
2013-04-07 14:39:26 +02:00
|
|
|
if ( read(fd, buf, sizeof(buf)) < 0 )
|
|
|
|
|
buf[0] = 0;
|
2012-11-24 11:09:46 +01:00
|
|
|
close(fd);
|
|
|
|
|
|
|
|
|
|
if ( strncmp(buf, "internal", strlen("internal")) != 0 )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "/sys/class/mmc_host/%s/%s:0001", dirent->d_name, dirent->d_name);
|
|
|
|
|
|
|
|
|
|
dir2 = opendir(buf);
|
|
|
|
|
if ( ! dir2 )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
while ( ( dirent2 = readdir(dir2) ) ) {
|
|
|
|
|
|
|
|
|
|
if ( strncmp(dirent2->d_name, "block:mmcblk", strlen("block:mmcblk")) != 0 )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "/sys/class/mmc_host/%s/%s:0001/%s", dirent->d_name, dirent->d_name, dirent2->d_name);
|
|
|
|
|
|
|
|
|
|
blk[0] = 0;
|
|
|
|
|
if ( readlink(buf, blk, sizeof(blk)) < 0 )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ptr = strrchr(blk, '/');
|
|
|
|
|
if ( ! ptr ) {
|
|
|
|
|
blk[0] = 0;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strcpy(blk, "/dev/");
|
|
|
|
|
i = strlen("/dev/");
|
|
|
|
|
++ptr;
|
|
|
|
|
|
|
|
|
|
while ( *ptr )
|
|
|
|
|
blk[i++] = *(ptr++);
|
2012-11-20 21:24:02 +01:00
|
|
|
|
2012-11-24 11:09:46 +01:00
|
|
|
strcpy(blk+i, "p1");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closedir(dir2);
|
|
|
|
|
|
|
|
|
|
if ( blk[0] )
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
|
|
|
|
|
|
if ( ! blk[0] ) {
|
|
|
|
|
ERROR("Cannot find MyDocs mmc device");
|
2012-11-23 22:09:10 +01:00
|
|
|
goto clean;
|
2012-11-20 21:24:02 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-21 17:52:14 +02:00
|
|
|
ret = disk_dump_raw(blk, file);
|
2012-11-24 11:09:46 +01:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2013-04-21 16:36:30 +02:00
|
|
|
if ( device >= sizeof(nanddump)/sizeof(nanddump[0]) ) {
|
|
|
|
|
ERROR("Unsupported device");
|
|
|
|
|
goto clean;
|
|
|
|
|
}
|
2012-11-24 11:09:46 +01:00
|
|
|
|
2013-04-21 16:36:30 +02:00
|
|
|
if ( image >= nanddump[device].count ) {
|
|
|
|
|
ERROR("Unsuported image type: %s", image_type_to_string(image));
|
|
|
|
|
goto clean;
|
2012-11-24 11:09:46 +01:00
|
|
|
}
|
2012-11-20 21:24:02 +01:00
|
|
|
|
2013-04-21 16:36:30 +02:00
|
|
|
ret = local_nanddump(file, nanddump[device].args[image].mtd, nanddump[device].args[image].offset, nanddump[device].args[image].length);
|
|
|
|
|
|
2012-11-20 21:24:02 +01:00
|
|
|
}
|
|
|
|
|
|
2012-11-24 11:09:46 +01:00
|
|
|
if ( ret != 0 ) {
|
|
|
|
|
ret = -1;
|
2012-11-23 22:09:10 +01:00
|
|
|
goto clean;
|
2012-11-24 11:09:46 +01:00
|
|
|
}
|
2012-11-23 22:09:10 +01:00
|
|
|
|
|
|
|
|
fd = open(file, O_RDWR);
|
|
|
|
|
if ( fd < 0 )
|
|
|
|
|
goto clean;
|
|
|
|
|
|
|
|
|
|
len = lseek(fd, 0, SEEK_END);
|
|
|
|
|
if ( len == (off_t)-1 || len == 0 )
|
|
|
|
|
goto clean;
|
|
|
|
|
|
|
|
|
|
addr = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
|
|
|
|
|
|
|
|
if ( addr == MAP_FAILED )
|
|
|
|
|
addr = NULL;
|
|
|
|
|
|
|
|
|
|
if ( ! addr )
|
|
|
|
|
goto clean;
|
|
|
|
|
|
|
|
|
|
for ( nlen = len; nlen > 0; --nlen )
|
|
|
|
|
if ( addr[nlen-1] != 0xFF )
|
|
|
|
|
break;
|
|
|
|
|
|
2012-11-24 11:08:25 +01:00
|
|
|
if ( image == IMAGE_MMC )
|
|
|
|
|
align = 8;
|
|
|
|
|
else
|
|
|
|
|
align = 7;
|
|
|
|
|
|
|
|
|
|
if ( ( nlen & ( ( 1ULL << align ) - 1 ) ) != 0 )
|
|
|
|
|
nlen = ((nlen >> align) + 1) << align;
|
2012-11-23 22:09:10 +01:00
|
|
|
|
2012-11-24 11:08:25 +01:00
|
|
|
if ( nlen == 0 ) {
|
|
|
|
|
printf("File %s is empty, removing it...\n", file);
|
|
|
|
|
unlink(file);
|
|
|
|
|
} else if ( nlen != len ) {
|
2012-11-23 22:09:10 +01:00
|
|
|
printf("Truncating file %s to %d bytes...\n", file, (int)nlen);
|
2013-04-07 14:39:26 +02:00
|
|
|
if ( ftruncate(fd, nlen) < 0 )
|
|
|
|
|
ERROR_INFO("Cannot truncate file %s", file);
|
2012-11-23 22:09:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clean:
|
|
|
|
|
if ( addr )
|
|
|
|
|
munmap(addr, len);
|
|
|
|
|
|
|
|
|
|
if ( fd >= 0 )
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
return ret;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_check_badblocks(const char * device) {
|
|
|
|
|
|
2012-11-20 21:38:11 +01:00
|
|
|
ERROR("Not implemented yet");
|
2012-11-20 21:51:21 +01:00
|
|
|
(void)device;
|
2012-11-20 21:38:11 +01:00
|
|
|
return -1;
|
|
|
|
|
|
2012-11-15 01:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_reboot_device(void) {
|
|
|
|
|
|
|
|
|
|
if ( system("dsmetool -b") == 0 )
|
|
|
|
|
return 0;
|
|
|
|
|
return system("reboot");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_get_root_device(void) {
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
return root_device;
|
2012-11-20 21:38:11 +01:00
|
|
|
|
2012-11-15 01:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_set_root_device(int device) {
|
|
|
|
|
|
2012-11-20 21:38:11 +01:00
|
|
|
ERROR("Not implemented yet");
|
2012-11-20 21:51:21 +01:00
|
|
|
(void)device;
|
2012-11-20 21:38:11 +01:00
|
|
|
return -1;
|
|
|
|
|
|
2012-11-15 01:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_get_usb_host_mode(void) {
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
return usb_host_mode;
|
2012-11-20 21:38:11 +01:00
|
|
|
|
2012-11-15 01:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_set_usb_host_mode(int enable) {
|
|
|
|
|
|
2012-11-20 21:38:11 +01:00
|
|
|
ERROR("Not implemented yet");
|
2012-11-20 21:51:21 +01:00
|
|
|
(void)enable;
|
2012-11-20 21:38:11 +01:00
|
|
|
return -1;
|
|
|
|
|
|
2012-11-15 01:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_get_rd_mode(void) {
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
if ( strncmp(rd_mode, "master", strlen("master")) == 0 )
|
2012-11-15 01:39:18 +01:00
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_set_rd_mode(int enable) {
|
|
|
|
|
|
2012-11-20 21:38:11 +01:00
|
|
|
ERROR("Not implemented yet");
|
2012-11-20 21:51:21 +01:00
|
|
|
(void)enable;
|
2012-11-20 21:38:11 +01:00
|
|
|
return -1;
|
|
|
|
|
|
2012-11-15 01:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_get_rd_flags(char * flags, size_t size) {
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
const char * ptr;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
if ( strncmp(rd_mode, "master", strlen("master")) == 0 )
|
|
|
|
|
ptr = rd_mode + strlen("master");
|
2012-11-15 01:39:18 +01:00
|
|
|
else
|
2012-11-24 01:01:53 +01:00
|
|
|
ptr = rd_mode;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
|
|
|
|
if ( *ptr == ',' )
|
|
|
|
|
++ptr;
|
|
|
|
|
|
|
|
|
|
if ( ! *ptr ) {
|
|
|
|
|
flags[0] = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strncpy(flags, ptr, size);
|
|
|
|
|
flags[size-1] = 0;
|
2012-11-20 21:38:11 +01:00
|
|
|
return 0;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_set_rd_flags(const char * flags) {
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
ERROR("Not implemented yet");
|
|
|
|
|
(void)flags;
|
|
|
|
|
return -1;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int16_t local_get_hwrev(void) {
|
|
|
|
|
|
|
|
|
|
return hwrev;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_set_hwrev(int16_t hwrev) {
|
|
|
|
|
|
2012-11-20 21:38:11 +01:00
|
|
|
ERROR("Not implemented yet");
|
2012-11-20 21:51:21 +01:00
|
|
|
(void)hwrev;
|
2012-11-20 21:38:11 +01:00
|
|
|
return -1;
|
|
|
|
|
|
2012-11-15 01:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_get_kernel_ver(char * ver, size_t size) {
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
strncpy(ver, kernel_ver, size);
|
|
|
|
|
ver[size-1] = 0;
|
|
|
|
|
return 0;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_set_kernel_ver(const char * ver) {
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
ERROR("Not implemented yet");
|
|
|
|
|
(void)ver;
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_get_initfs_ver(char * ver, size_t size) {
|
|
|
|
|
|
|
|
|
|
strncpy(ver, initfs_ver, size);
|
|
|
|
|
ver[size-1] = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_set_initfs_ver(const char * ver) {
|
|
|
|
|
|
|
|
|
|
ERROR("Not implemented yet");
|
|
|
|
|
(void)ver;
|
|
|
|
|
return -1;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_get_nolo_ver(char * ver, size_t size) {
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
strncpy(ver, nolo_ver, size);
|
|
|
|
|
ver[size-1] = 0;
|
|
|
|
|
return 0;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_set_nolo_ver(const char * ver) {
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
ERROR("Not implemented yet");
|
|
|
|
|
(void)ver;
|
|
|
|
|
return -1;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_get_sw_ver(char * ver, size_t size) {
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
strncpy(ver, sw_ver, size);
|
|
|
|
|
ver[size-1] = 0;
|
|
|
|
|
return 0;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_set_sw_ver(const char * ver) {
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
ERROR("Not implemented yet");
|
|
|
|
|
(void)ver;
|
|
|
|
|
return -1;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_get_content_ver(char * ver, size_t size) {
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
strncpy(ver, content_ver, size);
|
|
|
|
|
ver[size-1] = 0;
|
|
|
|
|
return 0;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int local_set_content_ver(const char * ver) {
|
|
|
|
|
|
2012-11-24 01:01:53 +01:00
|
|
|
ERROR("Not implemented yet");
|
|
|
|
|
(void)ver;
|
|
|
|
|
return -1;
|
2012-11-15 01:39:18 +01:00
|
|
|
|
|
|
|
|
}
|