45 Commits
Author SHA1 Message Date
Pali Rohár bf24ca2345 Release version 0.9 2021-01-05 19:16:39 +01:00
Pali Rohár 5c845a947e usb-device: Specify alternate id for cold flashing 2021-01-05 15:51:10 +01:00
Pali Rohár 673ccaf71d usb-device: Add N900 U-Boot mode (TTY via USB) to device list 2021-01-05 15:32:20 +01:00
Pali Rohár 9bc4b8c26f usb-device: Check that usb device provides required interface/alternate settings 2021-01-05 15:04:31 +01:00
Pali Rohár e6422cf5a2 usb-device: Remove dead usb_set_configuration() code
It is on worng place, must be called prior usb_claim_interface() and currently no device use it.
2021-01-05 14:38:02 +01:00
Pali Rohár a6effa8f62 usb-device: Remove 0x0421/0x3f00 from list
It was some internal Nokia development board with just temporary device id. Not a real RX-34 device.
2021-01-05 13:45:01 +01:00
Pali Rohár e16a79f75e usb-device: Fix interface id for Nokia N9 Sync mode and disable it as it use unsupported ADL protocol 2021-01-05 13:28:29 +01:00
Pali Rohár 93bd73d451 usb-device: Fix iterating over supported list of devices 2021-01-05 12:35:40 +01:00
Pali Rohár 0e5ceffa42 disk: Fix detecting Nokia N9 device 2021-01-05 12:32:34 +01:00
Pali Rohár ca080dd33f usb-device: Add device ids for Nokia N950 and Nokia N9 2020-12-26 01:40:57 +01:00
Pali Rohár 4ae1f13624 usb-device: Fix range or printable characters 2020-11-29 21:56:29 +01:00
Pali Rohár 69a7c2705e usb-device: Fix error message for usb_set_altinterface 2020-11-29 21:55:17 +01:00
Devendranath Thadi 8d053c9074 Travis-ci: added support for ppc64le
Signed-off-by: Devendranath Thadi <devendranath.thadi3@gmail.com>
2020-11-17 09:02:09 +00:00
Pali Rohár f37c2cd7e8 all: Fix delays for all operations 2020-04-25 20:04:51 +02:00
Pali Rohár e94279eecb local: Do not show error message about missing dump files which were skipped 2020-01-15 23:38:29 +01:00
Pali Rohár 52793b733d disk: Check if reading from block device failed 2019-09-30 17:42:16 +02:00
Sevan Janiyan 4bd0a47b22 Rewrap 2019-09-30 00:39:24 +01:00
Sevan Janiyan adeca0dd45 Grammar 2019-09-30 00:38:57 +01:00
Pali Rohár b87411c02f Release version 0.8 2018-07-08 12:22:33 +02:00
Aaro Koskinen 7f38b4bd10 usb-device: restore N800 support
N800 has stopped working at some point, not sure why:

  $ 0xFFFF -I
  [...]
  Waiting for USB device...
  Found USB device: SU-18/RX-44/RX-48/RX-51/RM-680 (0x421:0x105) in NOLO mode
  USB device product string: Nokia N800 (Update mode)
  USB device serial number string: (not detected)
  Detected USB device: RX-34
  Error: Device mishmash

Add the device to 0421:0105 list, and it works again:

  Waiting for USB device...
  Found USB device: SU-18/RX-34/RX-44/RX-48/RX-51/RM-680 (0x421:0x105) in NOLO mode
  USB device product string: Nokia N800 (Update mode)
  USB device serial number string: (not detected)
  Detected USB device: RX-34

  Initializing NOLO...
  Device: RX-34
  [...]
2018-04-19 22:46:11 +03:00
Pali Rohár 9e5646d30e travis: Do not run Coverity Scan jobs on non-master branches and in pull requests 2018-02-26 13:10:35 +01:00
Pali Rohár 33442482c6 disk: Fix detection of busnum
Unpatched version of libusb on linux platform does not set location, but
Debian's version of libusb has a patch which set it. For compatibility with
other systems without unpatched libusb version, read busnum from dirname
which seems to be always set.

Fixes: https://github.com/pali/0xFFFF/issues/5
2018-02-08 23:20:14 +01:00
Pali Rohár e987dcd948 disk: Remove remaining ENOMEDIUM 2018-02-08 20:35:12 +01:00
Pali Rohár 2fd11378c8 disk: Fix swapping maj1:min1 and maj2:min2 2018-02-08 20:28:31 +01:00
Pali Rohár 808ce724ee main: Print message after dumping finish 2018-02-08 19:49:54 +01:00
Pali Rohár ca1db96690 disk: Fix compile warning: comparison between signed and unsigned integer expressions 2018-02-08 19:49:13 +01:00
Pali Rohár a6c20b5ee4 disk: Open whole block device with O_NONBLOCK
This would simplify handling of ENOMEDIUM error.
2018-02-08 19:48:34 +01:00
Pali Rohár e685787e67 disk: Ensure that maj1:min1 is first device and maj2:min2 is second device 2018-02-08 19:24:11 +01:00
Edward Betts 10b495120e correct spelling mistake 2017-08-30 12:05:42 +01:00
Pali Rohár 559fe2a3bd disk: After opening blkdev, check that it is really block device 2017-07-09 17:26:13 +02:00
Pali Rohár ccec7a182f disk: Close device file handle when freeing structures 2017-07-09 14:57:41 +02:00
Pali Rohár 31569c169a disk: Fix detection of correct device in disk_open_dev() 2017-07-09 14:56:30 +02:00
Pali Rohár 27a55c3367 disk: Choose correct partition in disk_open_dev() 2017-07-06 20:55:41 +02:00
Pali Rohár cda5dc6116 main: Use image_alloc_from_fd() to fix race condition between calling stat and opening file 2017-06-17 23:48:01 +02:00
Pali Rohár 5cbd5e92b8 image: Add new function image_alloc_from_fd() 2017-06-17 23:47:10 +02:00
Pali Rohár 1ec3777cb8 image: Call image_free() when image_append() is failing 2017-06-17 23:46:50 +02:00
Pali Rohár 897919a70f main: Fix race condition between calling stat and rename 2017-06-17 23:10:36 +02:00
Pali Rohár 76b18b9d39 travis: Fix coverity job 2017-03-03 18:44:29 +01:00
Pali Rohár ffcc10f689 travis: Simplify configuration, move coverity_scan to matrix 2017-02-26 17:00:07 +01:00
Pali Rohár 16cdf3e776 travis: Run on container-based infrastructure 2017-02-26 16:19:42 +01:00
Pali Rohár dc81ebb855 travis: Use apt addon instead sudo 2017-02-26 16:09:52 +01:00
Pali Rohár 66ecce9a3d disk: Remove check which is always false
Type unsigned long long int according to C99 can store at least 2^64-1.
2017-01-09 22:56:33 +01:00
Pali Rohár 87867a5904 cal: Fix race condition between calling stat and opening file 2017-01-08 14:33:08 +01:00
Pali Rohár f0b8ee117b Makefile: Fix setting compiler 2017-01-08 03:42:34 +01:00
Pali Rohár 4c8206b44f travis: Enable clang and use separate job for Coverity 2017-01-08 03:33:39 +01:00
17 changed files with 233 additions and 122 deletions

No files matched your search

+22 -12
View File
@@ -1,22 +1,28 @@
sudo: false
language: c
arch:
- AMD64
- ppc64le
compiler:
- gcc
- clang
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq -y libusb-dev
script: if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then make ; fi
addons: &addons
apt:
packages:
- libusb-dev
matrix:
exclude:
- compiler: clang
- env: COVERITY_SCAN_BRANCH=1
env:
global:
include:
- compiler: gcc
if: (branch = master) AND (type != pull_request)
env:
- secure: "JdUp+xFykPZoYA4aRfmYk2CtilLapniQllWPKo2dDdJd1vzdawfTvVxIAKjy7ac9RKwZzg3Chq3RsMEXPv8BtaLbssw266C7RDLMgjacl1eFLcmGRj/Gkk9peDSZ6vVdGEcA2j+6KDSfpCa/XjFjvOufZOgKw6m+3+d0A4G45SI="
addons:
addons:
<<: *addons
coverity_scan:
project:
name: "pali/0xFFFF"
@@ -24,3 +30,7 @@ addons:
notification_email: pali.rohar@gmail.com
build_command: make
branch_pattern: master
script:
- if [ -n "$COVERITY_SCAN_TOKEN" ]; then exit 0; fi
- make
+13 -13
View File
@@ -10,24 +10,24 @@
_/ ___|_.|__|
'`
0xFFFF is Open Free Fiasco Firmware Flasher for Maemo devices. It support
generating and unpacking FIASCO images on local computer. Useful for editing
Maemo firmware package for future flash. It support via USB flashing any image
type to Maemo device and also \"cold\" flashing which means flashing dead device
with erased bootloader. There is support for booting kernel via USB without
flashing to NAND and also changing configuration of Maemo device (enable/disable
R&D mode, changing HW revision strings, ...).
0xFFFF is the Open Free Fiasco Firmware Flasher for Maemo devices. It supports
generating and unpacking FIASCO images. It is useful for editing Maemo firmware
packages before flashing. It supports flashing via USB any image type to a
Maemo device and also \"cold\" flashing which means flashing dead device with
erased bootloader. There is support for booting kernel via USB without flashing
to NAND and also changing configuration of Maemo device (enable/disable R&D
mode, changing HW revision strings, ...).
0xFFFF is alternative tool to proprietary Nokia flasher-3.5 and fiasco-gen.
0xFFFF generate compatible FIASCO images and also accept FIASCO images generated
by Nokia fiasco-gen.
0xFFFF is an alternative tool to proprietary Nokia flasher-3.5 and fiasco-gen.
0xFFFF generates compatible FIASCO images and also accepts FIASCO images
generated by Nokia fiasco-gen.
Use it with CARE. This is an experimental tool and it can brick your device.
It's not suposed to be stable, so nokia will probably release incompatible
It's not supposed to be stable, so Nokia will probably release incompatible
bootloaders to break this tool. USE IT AT YOUR OWN RISK.
PLEASE. Read carefully all the documentation inside doc/* for more information
before building or using the flasher to avoid questions, problems or so.
PLEASE. Read all the documentation inside doc/* carefully before building or
using the flasher to avoid questions, problems or so.
https://github.com/pali/0xFFFF
+1 -1
View File
@@ -1,4 +1,4 @@
VERSION = 0.7
VERSION = 0.9
PREFIX = /usr/local
# NetBSD stuff
+3 -3
View File
@@ -5,9 +5,9 @@ INSTALL ?= install
BUILD_DATE ?= $(shell LC_ALL=C date '+%b %e %Y')
CC = gcc
CROSS_CC = $(CROSS_COMPILE)$(CC)
HOST_CC = $(HOST_COMPILE)$(CC)
CC ?= cc
CROSS_CC ?= $(CROSS_COMPILE)$(CC)
HOST_CC ?= $(HOST_COMPILE)$(CC)
CPPFLAGS += -DVERSION=\"$(VERSION)\" -DBUILD_DATE="\"$(BUILD_DATE)\"" -D_POSIX_C_SOURCE=200809L -D_FILE_OFFSET_BITS=64
CFLAGS += -W -Wall -O2 -pedantic -std=c99
+3 -3
View File
@@ -76,14 +76,14 @@ int cal_init_file(const char * file, struct cal ** cal_out) {
off_t lsize = 0;
#endif
if ( stat(file, &st) != 0 )
return -1;
fd = open(file, O_RDONLY);
if ( fd < 0 )
return -1;
if ( fstat(fd, &st) != 0 )
goto err;
if ( S_ISREG(st.st_mode) )
size = st.st_size;
else if ( S_ISBLK(st.st_mode) ) {
+7 -7
View File
@@ -191,14 +191,14 @@ static int send_2nd(usb_dev_handle * udev, struct image * image) {
if ( ret != sizeof(omap_peripheral_msg) )
ERROR_RETURN("Sending OMAP peripheral boot message failed", -1);
SLEEP(5000);
MSLEEP(5);
printf("Sending 2nd X-Loader image size...\n");
ret = usb_bulk_write(udev, USB_WRITE_EP, (char *)&image->size, 4, WRITE_TIMEOUT);
if ( ret != 4 )
ERROR_RETURN("Sending 2nd X-Loader image size failed", -1);
SLEEP(5000);
MSLEEP(5);
printf("Sending 2nd X-Loader image...\n");
printf_progressbar(0, image->size);
@@ -217,7 +217,7 @@ static int send_2nd(usb_dev_handle * udev, struct image * image) {
printf_progressbar(sent, image->size);
}
SLEEP(50000);
MSLEEP(50);
return 0;
}
@@ -237,7 +237,7 @@ static int send_secondary(usb_dev_handle * udev, struct image * image) {
ERROR_RETURN("Sending X-Loader init message failed", -1);
printf("Waiting for X-Loader response...\n");
SLEEP(5000);
MSLEEP(5);
ret = usb_bulk_read(udev, USB_READ_EP, (char *)&buffer, 4, READ_TIMEOUT); /* 4 bytes - dummy value */
if ( ret != 4 )
ERROR_RETURN("No response", -1);
@@ -260,7 +260,7 @@ static int send_secondary(usb_dev_handle * udev, struct image * image) {
}
printf("Waiting for X-Loader response...\n");
SLEEP(5000);
MSLEEP(5);
ret = usb_bulk_read(udev, USB_READ_EP, (char *)&buffer, 4, READ_TIMEOUT); /* 4 bytes - dummy value */
if ( ret != 4 )
ERROR_RETURN("No response", -1);
@@ -296,7 +296,7 @@ static int ping_timeout(usb_dev_handle * udev) {
break;
}
SLEEP(5000);
MSLEEP(5);
--try_read;
}
@@ -413,7 +413,7 @@ int leave_cold_flash(struct usb_device_info * dev) {
if ( ret != sizeof(omap_memory_msg) )
ERROR_RETURN("Sending OMAP memory boot message failed", -1);
SLEEP(1000000);
MSLEEP(250);
return 0;
}
+79 -27
View File
@@ -51,6 +51,7 @@ int disk_open_dev(int maj, int min, int partition, int readonly) {
DIR * dir;
struct dirent * dirent;
int found;
int old_errno;
size_t len;
char blkdev[1024];
@@ -117,6 +118,18 @@ int disk_open_dev(int maj, int min, int partition, int readonly) {
blkdev[len] = 0;
fd = open(blkdev, (readonly ? O_RDONLY : O_RDWR) | O_EXCL | O_NONBLOCK);
if ( fd < 0 ) {
ERROR_INFO("Cannot open block device %s", blkdev);
return -1;
} else {
if ( fstat(fd, &st) != 0 || ! S_ISBLK(st.st_mode) || makedev(maj, min) != st.st_rdev ) {
ERROR("Block device %s does not have id %d:%d\n", blkdev, maj, min);
close(fd);
return -1;
}
}
} else if ( partition > 0 ) {
/* Select partition */
@@ -127,35 +140,48 @@ int disk_open_dev(int maj, int min, int partition, int readonly) {
return -1;
}
memcpy(blkdev+len, "p1", 3);
if ( stat(blkdev, &st) != 0 || ! S_ISBLK(st.st_mode) ) {
memcpy(blkdev+len, "1", 2);
if ( stat(blkdev, &st) != 0 || ! S_ISBLK(st.st_mode) ) {
blkdev[len] = 0;
fd = open(blkdev, O_RDONLY);
if ( fd < 0 ) {
if ( errno != ENOMEDIUM ) {
ERROR_INFO("Cannot open block device %s", blkdev);
if ( snprintf(blkdev+len, sizeof(blkdev)-len, "p%d", partition) >= (int)(sizeof(blkdev)-len) ) {
ERROR("Block device name is too long");
return -1;
}
fd = open(blkdev, (readonly ? O_RDONLY : O_RDWR) | O_EXCL);
if ( fd < 0 && errno == ENOENT ) {
if ( snprintf(blkdev+len, sizeof(blkdev)-len, "%d", partition) >= (int)(sizeof(blkdev)-len) ) {
ERROR("Block device name is too long");
return -1;
}
fd = open(blkdev, (readonly ? O_RDONLY : O_RDWR) | O_EXCL);
}
if ( fd < 0 && errno == ENOENT ) {
blkdev[len] = 0;
fd = open(blkdev, O_RDONLY | O_NONBLOCK);
if ( fd < 0 ) {
ERROR_INFO("Cannot open block device %s", blkdev);
} else {
close(fd);
ERROR("Block device does not have partitions");
ERROR("Block device %s does not have partitions", blkdev);
}
return -1;
}
}
}
if ( fd < 0 )
old_errno = errno;
printf("Found block device %s for partition %d\n", blkdev, partition);
if ( fd < 0 ) {
errno = old_errno;
ERROR_INFO("Cannot open block device %s", blkdev);
} else if ( fstat(fd, &st) != 0 || ! S_ISBLK(st.st_mode) ) {
ERROR("Block device %s is not block device\n", blkdev);
close(fd);
return -1;
}
fd = open(blkdev, (readonly ? O_RDONLY : O_RDWR) | O_EXCL);
} else {
ERROR("Invalid partition %d for block device %s", partition, blkdev);
fd = -1;
if ( fd < 0 ) {
if ( errno != ENOMEDIUM )
ERROR_INFO("Cannot open block device %s", blkdev);
return -1;
}
return fd;
@@ -195,7 +221,7 @@ int disk_dump_dev(int fd, const char * file) {
#else
blksize = lseek(fd, 0, SEEK_END);
if ( blksize == (off_t)-1 ) {
if ( (off_t)blksize == (off_t)-1 ) {
ERROR_INFO("Cannot get size of block device");
return -1;
}
@@ -207,11 +233,6 @@ int disk_dump_dev(int fd, const char * file) {
#endif
if ( blksize > ULLONG_MAX ) {
ERROR("Block device is too big");
return -1;
}
if ( blksize == 0 ) {
ERROR("Block device has zero size");
return -1;
@@ -249,6 +270,11 @@ int disk_dump_dev(int fd, const char * file) {
size = read(fd, global_buf, need);
if ( size == 0 )
break;
if ( size < 0 ) {
PRINTF_ERROR("Reading from block device failed");
close(fd2);
return -1;
}
if ( write(fd2, global_buf, size) != size ) {
PRINTF_ERROR("Dumping image failed");
close(fd2);
@@ -281,6 +307,7 @@ int disk_init(struct usb_device_info * dev) {
int maj2;
int min1;
int min2;
int tmp;
maj1 = -1;
maj2 = -1;
@@ -341,9 +368,17 @@ int disk_init(struct usb_device_info * dev) {
fclose(f);
if ( devnum != device->devnum || device->bus->location != busnum )
if ( device->devnum != devnum )
continue;
if ( device->bus->location ) {
if ( device->bus->location != busnum )
continue;
} else if ( device->bus->dirname[0] ) {
if ( atoi(device->bus->dirname) != (int)busnum )
continue;
}
if ( sscanf(dirent->d_name, "%d:%d", &maj2, &min2) != 2 ) {
maj2 = -1;
min2 = -1;
@@ -367,10 +402,20 @@ int disk_init(struct usb_device_info * dev) {
return -1;
}
/* Ensure that maj1:min1 is first device and maj2:min2 is second device */
if ( min2 != -1 && min2 < min1 ) {
tmp = min1;
min1 = min2;
min2 = tmp;
tmp = maj1;
maj1 = maj2;
maj2 = tmp;
}
/* TODO: change 1 to 0 when disk_flash_dev will be implemented */
/* RX-51 and RM-680 export MyDocs in first usb device and just first partion, so host system see whole device without MBR table */
if ( dev->device == DEVICE_RX_51 || dev->device == DEVICE_RM_680 )
/* RX-51, RM-680 and RM-696 export MyDocs in first usb device and just first partion, so host system see whole device without MBR table */
if ( dev->device == DEVICE_RX_51 || dev->device == DEVICE_RM_680 || dev->device == DEVICE_RM_696 )
fd = disk_open_dev(maj1, min1, -1, 1);
/* Other devices can export SD card as first partition and export whole mmc device, so host system will see MBR table */
else if ( maj2 != -1 && min2 != -1 )
@@ -378,7 +423,7 @@ int disk_init(struct usb_device_info * dev) {
else
fd = disk_open_dev(maj1, min1, 1, 1);
if ( fd < 0 && errno != ENOMEDIUM )
if ( fd < 0 )
return -1;
dev->data = fd;
@@ -394,6 +439,13 @@ int disk_init(struct usb_device_info * dev) {
}
void disk_exit(struct usb_device_info * dev) {
if ( dev->data >= 0 )
close(dev->data);
}
enum device disk_get_device(struct usb_device_info * dev) {
return dev->device;
+1
View File
@@ -24,6 +24,7 @@
#include "usb-device.h"
int disk_init(struct usb_device_info * dev);
void disk_exit(struct usb_device_info * dev);
enum device disk_get_device(struct usb_device_info * dev);
+1 -1
View File
@@ -22,7 +22,7 @@ extern int verbose;
#define ALLOC_ERROR() do { ERROR("Cannot allocate memory"); } while (0)
#define ALLOC_ERROR_RETURN(...) do { ALLOC_ERROR(); return __VA_ARGS__; } while (0)
#define SLEEP(usec) do { struct timespec _t = { 0, (usec) }; nanosleep(&_t, NULL); } while (0)
#define MSLEEP(msec) do { nanosleep(&(struct timespec){ (msec / 1000), (1000L * 1000L * (msec % 1000)) }, NULL); } while (0)
static inline void * MEMMEM(void *haystack, size_t haystacklen, const void *needle, size_t needlelen) {
for ( size_t i = 0; i < haystacklen; ++i ) {
+27 -14
View File
@@ -162,8 +162,10 @@ static int image_append(struct image * image, const char * type, const char * de
image->hash = image_hash_from_data(image);
image->devices = calloc(1, sizeof(struct device_list));
if ( ! image->devices )
return -1;
if ( ! image->devices ) {
image_free(image);
ALLOC_ERROR_RETURN(-1);
}
image->devices->device = DEVICE_ANY;
@@ -244,22 +246,33 @@ static struct image * image_alloc(void) {
struct image * image_alloc_from_file(const char * file, const char * type, const char * device, const char * hwrevs, const char * version, const char * layout) {
off_t offset;
struct image * image = image_alloc();
if ( ! image )
return NULL;
int fd;
image->is_shared_fd = 0;
image->fd = open(file, O_RDONLY);
if ( image->fd < 0 ) {
fd = open(file, O_RDONLY);
if ( fd < 0 ) {
ERROR_INFO("Cannot open image file %s", file);
free(image);
return NULL;
}
return image_alloc_from_fd(fd, file, type, device, hwrevs, version, layout);
}
struct image * image_alloc_from_fd(int fd, const char * orig_filename, const char * type, const char * device, const char * hwrevs, const char * version, const char * layout) {
off_t offset;
struct image * image = image_alloc();
if ( ! image ) {
close(fd);
return NULL;
}
image->is_shared_fd = 0;
image->fd = fd;
offset = lseek(image->fd, 0, SEEK_END);
if ( offset == (off_t)-1 ) {
ERROR_INFO("Cannot seek to end of file %s", file);
ERROR_INFO("Cannot seek to end of file %s", orig_filename);
close(image->fd);
free(image);
return NULL;
@@ -268,10 +281,10 @@ struct image * image_alloc_from_file(const char * file, const char * type, const
image->size = offset;
image->offset = 0;
image->cur = 0;
image->orig_filename = strdup(file);
image->orig_filename = strdup(orig_filename);
if ( lseek(image->fd, 0, SEEK_SET) == (off_t)-1 ) {
ERROR_INFO("Cannot seek to begin of file %s", file);
ERROR_INFO("Cannot seek to begin of file %s", orig_filename);
close(image->fd);
free(image->orig_filename);
free(image);
@@ -282,7 +295,7 @@ struct image * image_alloc_from_file(const char * file, const char * type, const
return NULL;
if ( ( ! type || ! type[0] ) && ( ! device || ! device[0] ) && ( ! hwrevs || ! hwrevs[0] ) && ( ! version || ! version[0] ) )
image_missing_values_from_name(image, file);
image_missing_values_from_name(image, orig_filename);
image_align(image);
+1
View File
@@ -64,6 +64,7 @@ struct image_list {
};
struct image * image_alloc_from_file(const char * file, const char * type, const char * device, const char * hwrevs, const char * version, const char * layout);
struct image * image_alloc_from_fd(int fd, const char * orig_filename, const char * type, const char * device, const char * hwrevs, const char * version, const char * layout);
struct image * image_alloc_from_shared_fd(int fd, size_t size, size_t offset, uint16_t hash, const char * type, const char * device, const char * hwrevs, const char * version, const char * layout);
void image_free(struct image * image);
void image_seek(struct image * image, size_t whence);
+26 -8
View File
@@ -155,10 +155,13 @@ static void parse_image_arg(char * arg, struct image_list ** image_first) {
char * version;
char * layout;
char * layout_file;
int fd;
/* First check if arg is file, then try to parse arg format */
if ( stat(arg, &st) == 0 ) {
image = image_alloc_from_file(arg, NULL, NULL, NULL, NULL, NULL);
fd = open(arg, O_RDONLY);
if ( fd >= 0 ) {
if ( fstat(fd, &st) == 0 && !S_ISDIR(st.st_mode) ) {
image = image_alloc_from_fd(fd, arg, NULL, NULL, NULL, NULL, NULL);
if ( ! image ) {
ERROR("Cannot load image file %s", arg);
exit(1);
@@ -166,6 +169,11 @@ static void parse_image_arg(char * arg, struct image_list ** image_first) {
image_list_add(image_first, image);
return;
}
close(fd);
} else if ( errno != ENOENT ) {
ERROR("Cannot load image file %s", arg);
exit(1);
}
layout_file = strchr(arg, '%');
if ( layout_file )
@@ -413,6 +421,8 @@ int main(int argc, char **argv) {
enum device detected_device = DEVICE_UNKNOWN;
int16_t detected_hwrev = -1;
struct stat st;
int i;
char buf[512];
char * ptr = NULL;
@@ -1239,6 +1249,8 @@ int main(int argc, char **argv) {
if ( chdir(buf) < 0 )
ERROR_INFO("Cannot chdir back to %s", buf);
printf("Done\n");
}
/* dump fiasco */
@@ -1249,7 +1261,7 @@ int main(int argc, char **argv) {
for ( i = 0; i < IMAGE_COUNT; ++i ) {
if ( ! image_tmp_name(i) )
if ( ! image_tmp_name(i) || ( stat(image_tmp_name(i), &st) < 0 && errno == ENOENT ) )
continue;
buf[0] = 0;
@@ -1319,14 +1331,12 @@ int main(int argc, char **argv) {
for ( i = 0; i < IMAGE_COUNT; ++i ) {
struct stat st;
int rename_ret;
int rename_errno;
if ( ! image_tmp_name(i) )
continue;
if ( stat(image_tmp_name(i), &st) != 0 )
continue;
switch ( i ) {
case IMAGE_2ND:
case IMAGE_XLOADER:
@@ -1357,10 +1367,18 @@ int main(int argc, char **argv) {
buf[0] = 0;
snprintf(buf, sizeof(buf), "%s-%s:%hd_%s", image_type_to_string(i), device_to_string(dev->detected_device), dev->detected_hwrev, ptr);
rename_ret = rename(image_tmp_name(i), buf);
rename_errno = errno;
if ( rename_ret < 0 && rename_errno == ENOENT )
continue;
printf("Renaming %s image file to %s...\n", image_type_to_string(i), buf);
if ( rename(image_tmp_name(i), buf) < 0 ) {
if ( rename_ret < 0 ) {
errno = rename_errno;
ERROR_INFO("Renaming failed");
buf[0] = 0;
+5
View File
@@ -361,6 +361,11 @@ int mkii_reboot_device(struct usb_device_info * dev, int update) {
if ( ret != 1 || msg->data[0] != 0 )
ERROR_RETURN("Cannot send reboot command", -1);
if (dev->data & MKII_UPDATE_MODE)
MSLEEP(100);
else
MSLEEP(3000);
return 0;
}
+1 -1
View File
@@ -541,7 +541,7 @@ int nolo_flash_image(struct usb_device_info * dev, struct image * image) {
}
SLEEP(0xc350); // 0.5s
MSLEEP(50);
}
+4 -1
View File
@@ -91,8 +91,11 @@ clean:
void dev_free(struct device_info * dev) {
if ( dev->usb )
if ( dev->usb ) {
if ( dev->usb->flash_device->protocol == FLASH_DISK )
disk_exit(dev->usb);
usb_close_device(dev->usb);
}
free(dev);
}
+39 -30
View File
@@ -46,16 +46,21 @@
#endif
static struct usb_flash_device usb_devices[] = {
{ 0x0421, 0x0096, -1, -1, -1, FLASH_DISK, { DEVICE_RX_44, 0 } },
{ 0x0421, 0x0105, 2, 1, -1, FLASH_NOLO, { DEVICE_SU_18, DEVICE_RX_44, DEVICE_RX_48, DEVICE_RX_51, DEVICE_RM_680, DEVICE_RM_696, 0 } },
{ 0x0421, 0x0106, 0, -1, -1, FLASH_COLD, { DEVICE_RX_51, DEVICE_RM_680, DEVICE_RM_696, 0 } },
{ 0x0421, 0x0189, -1, -1, -1, FLASH_DISK, { DEVICE_RX_48, 0 } },
{ 0x0421, 0x01c7, -1, -1, -1, FLASH_DISK, { DEVICE_RX_51, 0 } },
{ 0x0421, 0x01c8, 1, 1, -1, FLASH_MKII, { DEVICE_RX_51, DEVICE_RM_680, 0 } },
{ 0x0421, 0x03d1, -1, -1, -1, FLASH_DISK, { DEVICE_RM_680, 0 } },
{ 0x0421, 0x0431, -1, -1, -1, FLASH_DISK, { DEVICE_SU_18, DEVICE_RX_34, 0 } },
{ 0x0421, 0x04c3, -1, -1, -1, FLASH_DISK, { DEVICE_RX_34, 0 } },
{ 0x0421, 0x3f00, 2, 1, -1, FLASH_NOLO, { DEVICE_RX_34, 0 } },
/* vend prod i a protocol devices */
{ 0x0421, 0x0096, -1, -1, FLASH_DISK, { DEVICE_RX_44, 0 } },
{ 0x0421, 0x0105, 2, 1, FLASH_NOLO, { DEVICE_SU_18, DEVICE_RX_34, DEVICE_RX_44, DEVICE_RX_48, DEVICE_RX_51, DEVICE_RM_680, DEVICE_RM_696, 0 } },
{ 0x0421, 0x0106, 0, 0, FLASH_COLD, { DEVICE_RX_51, DEVICE_RM_680, DEVICE_RM_696, 0 } },
{ 0x0421, 0x0189, -1, -1, FLASH_DISK, { DEVICE_RX_48, 0 } },
{ 0x0421, 0x01c7, -1, -1, FLASH_DISK, { DEVICE_RX_51, 0 } },
{ 0x0421, 0x01c8, 1, 1, FLASH_MKII, { DEVICE_RX_51, DEVICE_RM_680, 0 } },
{ 0x0421, 0x01c8, 1, 0, FLASH_UNKN, { DEVICE_RX_51, 0 } }, /* U-Boot mode (TTY via USB) */
{ 0x0421, 0x03d1, -1, -1, FLASH_DISK, { DEVICE_RM_680, 0 } },
{ 0x0421, 0x03d2, 1, 1, FLASH_MKII, { DEVICE_RM_680, 0 } },
{ 0x0421, 0x0431, -1, -1, FLASH_DISK, { DEVICE_SU_18, DEVICE_RX_34, 0 } },
{ 0x0421, 0x04c3, -1, -1, FLASH_DISK, { DEVICE_RX_34, 0 } },
{ 0x0421, 0x0518, -1, -1, FLASH_DISK, { DEVICE_RM_696, 0 } },
{ 0x0421, 0x0519, -1, -1, FLASH_UNKN, { DEVICE_RM_696, 0 } }, /* RNDIS/Ethernet mode */
{ 0x0421, 0x051a, 2, 1, FLASH_UNKN, { DEVICE_RM_696, 0 } }, /* Sync mode (ADL protocol) */
};
static const char * usb_flash_protocols[] = {
@@ -134,7 +139,7 @@ static void usb_descriptor_info_print(usb_dev_handle * udev, struct usb_device *
buf[0] = 0;
for ( i = 0; i < ret; i+=2 ) {
sscanf(buf+i, "%2x", &x);
if ( x > 32 && x < 128 )
if ( x > 31 && x < 127 )
buf2[i/2] = x;
else {
buf2[0] = 0;
@@ -150,14 +155,29 @@ static void usb_descriptor_info_print(usb_dev_handle * udev, struct usb_device *
static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) {
int i;
size_t i;
char product[1024];
struct usb_device_info * ret = NULL;
for ( i = 0; usb_devices[i].vendor; ++i ) {
for ( i = 0; i < sizeof(usb_devices)/sizeof(usb_devices[0]); ++i ) {
if ( dev->descriptor.idVendor == usb_devices[i].vendor && dev->descriptor.idProduct == usb_devices[i].product ) {
if ( usb_devices[i].protocol == FLASH_UNKN )
continue;
if ( dev->descriptor.bNumConfigurations < 1 )
continue;
if ( usb_devices[i].interface != -1 ) {
if ( usb_devices[i].interface >= dev->config[0].bNumInterfaces )
continue;
if ( usb_devices[i].alternate != -1 ) {
if ( usb_devices[i].alternate >= dev->config[0].interface[usb_devices[i].interface].num_altsetting )
continue;
}
}
printf("\b\b ");
PRINTF_END();
PRINTF_ADD("Found ");
@@ -195,18 +215,7 @@ static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) {
if ( usb_devices[i].alternate >= 0 ) {
PRINTF_LINE("Setting alternate USB interface...");
if ( usb_set_altinterface(udev, usb_devices[i].alternate) < 0 ) {
PRINTF_ERROR("usb_claim_interface failed");
fprintf(stderr, "\n");
usb_reattach_kernel_driver(udev, usb_devices[i].interface);
usb_close(udev);
return NULL;
}
}
if ( usb_devices[i].configuration >= 0 ) {
PRINTF_LINE("Setting USB configuration...");
if ( usb_set_configuration(udev, usb_devices[i].configuration) < 0 ) {
PRINTF_ERROR("usb_set_configuration failed");
PRINTF_ERROR("usb_set_altinterface failed");
fprintf(stderr, "\n");
usb_reattach_kernel_driver(udev, usb_devices[i].interface);
usb_close(udev);
@@ -230,13 +239,13 @@ static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) {
ret->device = DEVICE_RX_44;
else if ( strcmp(product, "Nokia N810 Internet Tablet WiMAX Edition") == 0 || strcmp(product, "Nokia-RX48 (Update mode)") == 0 )
ret->device = DEVICE_RX_48;
else if ( strcmp(product, "N900 (Storage Mode)") == 0 || strcmp(product, "Nokia N900 (Update mode)") == 0 || strcmp(product, "N900 (PC-Suite Mode)") == 0 )
else if ( strcmp(product, "N900 (Storage Mode)") == 0 || strcmp(product, "Nokia N900 (Update mode)") == 0 || strcmp(product, "N900 (PC-Suite Mode)") == 0 || strcmp(product, "N900 (U-Boot)") == 0 )
ret->device = DEVICE_RX_51;
else if ( strcmp(product, "Nokia N950") == 0 || strcmp(product, "Sync Mode") == 0 || strcmp(product, "N950 (Update mode)") == 0 )
else if ( strcmp(product, "Nokia N950") == 0 || strcmp(product, "N950 (Update mode)") == 0 )
ret->device = DEVICE_RM_680;
else if ( strcmp(product, "N9 (Update mode)") == 0 || strcmp(product, "Nxy (Update mode)") == 0 )
else if ( strcmp(product, "Nokia N9") == 0 || strcmp(product, "N9 (Update mode)") == 0 || strcmp(product, "Nokia N9 RNDIS/Ethernet") == 0 )
ret->device = DEVICE_RM_696;
else if ( strcmp(product, "Nokia USB ROM") == 0 )
else if ( strcmp(product, "Nokia USB ROM") == 0 || strcmp(product, "Sync Mode") == 0 || strcmp(product, "Nxy (Update mode)") == 0 )
ret->device = DEVICE_ANY;
else
ret->device = DEVICE_UNKNOWN;
@@ -361,7 +370,7 @@ struct usb_device_info * usb_open_and_wait_for_device(void) {
if ( ret )
break;
SLEEP(0xc350); // 0.5s
MSLEEP(50);
}
-1
View File
@@ -49,7 +49,6 @@ struct usb_flash_device {
uint16_t product;
int interface;
int alternate;
int configuration;
enum usb_flash_protocol protocol;
enum device devices[DEVICE_COUNT];
};