nolo: Fix cmt info and implement nolo_set_hwrev
This commit is contained in:
1 parent
c0e490cc30
commit
7868ad0c71
1 file changed
+13
-182
+13
-182
@@ -110,10 +110,10 @@ static int nolo_identify_string(struct usb_device_info * dev, const char * str,
|
|||||||
static int nolo_set_string(struct usb_device_info * dev, char * str, char * arg) {
|
static int nolo_set_string(struct usb_device_info * dev, char * str, char * arg) {
|
||||||
|
|
||||||
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_STRING, 0, 0, str, strlen(str), 2000) < 0 )
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_STRING, 0, 0, str, strlen(str), 2000) < 0 )
|
||||||
ERROR_RETURN("NOLO_REQUEST_STRING failed", -1);
|
ERROR_RETURN("NOLO_STRING failed", -1);
|
||||||
|
|
||||||
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_SET_STRING, 0, 0, arg, strlen(arg), 2000) < 0 )
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_SET_STRING, 0, 0, arg, strlen(arg), 2000) < 0 )
|
||||||
ERROR_RETURN("NOLO_REQUEST_STRING_ARG failed", -1);
|
ERROR_RETURN("NOLO_SET_STRING failed", -1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -122,10 +122,10 @@ static int nolo_set_string(struct usb_device_info * dev, char * str, char * arg)
|
|||||||
static int nolo_get_string(struct usb_device_info * dev, char * str, char * out, size_t size) {
|
static int nolo_get_string(struct usb_device_info * dev, char * str, char * out, size_t size) {
|
||||||
|
|
||||||
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_STRING, 0, 0, str, strlen(str), 2000) < 0 )
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_STRING, 0, 0, str, strlen(str), 2000) < 0 )
|
||||||
ERROR_RETURN("NOLO_REQUEST_STRING failed", -1);
|
ERROR_RETURN("NOLO_STRING failed", -1);
|
||||||
|
|
||||||
if ( usb_control_msg(dev->udev, NOLO_QUERY, NOLO_GET_STRING, 0, 0, out, size, 2000) < 0 )
|
if ( usb_control_msg(dev->udev, NOLO_QUERY, NOLO_GET_STRING, 0, 0, out, size, 2000) < 0 )
|
||||||
ERROR_RETURN("NOLO_RESPONCE_STRING failed", -1);
|
ERROR_RETURN("NOLO_GET_STRING failed", -1);
|
||||||
|
|
||||||
out[size-1] = 0;
|
out[size-1] = 0;
|
||||||
return strlen(out);
|
return strlen(out);
|
||||||
@@ -392,7 +392,13 @@ int nolo_flash_image(struct usb_device_info * dev, struct image * image) {
|
|||||||
int state = 0;
|
int state = 0;
|
||||||
last_total = 0;
|
last_total = 0;
|
||||||
|
|
||||||
printf("Erasing CMT...\n");
|
if ( nolo_get_string(dev, "cmt:status", buf, sizeof(buf)) < 0 )
|
||||||
|
ERROR_RETURN("cmt:status failed", -1);
|
||||||
|
|
||||||
|
if ( strncmp(buf, "idle", strlen("idle")) == 0 )
|
||||||
|
state = 4;
|
||||||
|
else
|
||||||
|
printf("Erasing CMT...\n");
|
||||||
|
|
||||||
while ( state != 4 ) {
|
while ( state != 4 ) {
|
||||||
|
|
||||||
@@ -682,8 +688,8 @@ int nolo_get_hwrev(struct usb_device_info * dev, char * hwrev, size_t size) {
|
|||||||
|
|
||||||
int nolo_set_hwrev(struct usb_device_info * dev, const char * hwrev) {
|
int nolo_set_hwrev(struct usb_device_info * dev, const char * hwrev) {
|
||||||
|
|
||||||
printf("nolo_set_hwrev is not implemented yet\n");
|
printf("Setting HW revision to: %s\n", hwrev);
|
||||||
return -1;
|
return nolo_set_string(dev, "hw_rev", (char *)hwrev);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -780,178 +786,3 @@ int nolo_set_content_ver(struct usb_device_info * dev, const char * ver) {
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**** OLD CODE ****/
|
|
||||||
|
|
||||||
|
|
||||||
//#define CMD_WRITE 64
|
|
||||||
//#define CMD_QUERY 192
|
|
||||||
|
|
||||||
//struct usb_dev_handle *dev;
|
|
||||||
|
|
||||||
//static void query_error_message()
|
|
||||||
//{
|
|
||||||
/* query error message */
|
|
||||||
/* int len = 0;
|
|
||||||
char nolomsg[2048];
|
|
||||||
memset(nolomsg, '\0', 2048);
|
|
||||||
usb_control_msg(dev, 192, 5, 0, 0, nolomsg, 2048, 2000);
|
|
||||||
nolomsg[2047] = '\0';
|
|
||||||
printf("\nNOLO says:\n");
|
|
||||||
if (nolomsg[0] == '\0') {
|
|
||||||
printf(" (.. silence ..)\n");
|
|
||||||
} else {
|
|
||||||
// dump_bytes((unsigned char *)nolomsg, 128);
|
|
||||||
do {
|
|
||||||
printf(" - %s\n", nolomsg+len);
|
|
||||||
len+=strlen(nolomsg+len)+1;
|
|
||||||
} while(nolomsg[len]!='\0');
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//void flash_image(struct image * image)
|
|
||||||
//{
|
|
||||||
// FILE *fd;
|
|
||||||
// int vlen = 0;
|
|
||||||
// int request;
|
|
||||||
/*/ n800 flash queries have a variable size */
|
|
||||||
// unsigned char fquery[256]; /* flash query */
|
|
||||||
/* unsigned long long size, off;
|
|
||||||
unsigned char bsize[4], tmp;
|
|
||||||
unsigned char nolofiller[128];
|
|
||||||
const char * piece = image_type_to_string(image->type);
|
|
||||||
const char * version = image->version;
|
|
||||||
ushort hash = image->hash;
|
|
||||||
|
|
||||||
// if (piece == NULL) {
|
|
||||||
//exit(1);
|
|
||||||
// piece = fpid_file(filename);
|
|
||||||
if (piece == NULL) {
|
|
||||||
printf("Unknown piece type\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// printf("Piece type: %s\n", piece);
|
|
||||||
// }*/
|
|
||||||
|
|
||||||
/* if (piece != NULL) {
|
|
||||||
if (!strcmp(piece, "fiasco")) {
|
|
||||||
fiasco_flash(filename);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/* if (version)
|
|
||||||
vlen = strlen(version)+1;
|
|
||||||
|
|
||||||
// fd = fopen(filename, "rb");
|
|
||||||
// if (fd == NULL) {
|
|
||||||
// printf("Cannot open file\n");
|
|
||||||
// exit(1);
|
|
||||||
// }*/
|
|
||||||
/* cook flash query */
|
|
||||||
/* memset(fquery, '\x00', 27); // reset buffer
|
|
||||||
memcpy(fquery, "\x2e\x19\x01\x01", 4); // header
|
|
||||||
//memcpy(fquery+5, "\xbf\x6b", 2); // some magic (modified crc16???)
|
|
||||||
memcpy(fquery+5, &hash, 2);
|
|
||||||
tmp = fquery[5]; fquery[5] = fquery[6]; fquery[6] = tmp;
|
|
||||||
memcpy(fquery+7, piece, strlen(piece)); // XXX ??!??
|
|
||||||
|
|
||||||
printf("| hash: 0x%hhx%hhx ", fquery[5], fquery[6]);
|
|
||||||
// size = get_file_size(filename);
|
|
||||||
size = image->size;
|
|
||||||
bsize[0] = (size & 0xff000000) >> 24;
|
|
||||||
bsize[1] = (size & 0x00ff0000) >> 16;
|
|
||||||
bsize[2] = (size & 0x0000ff00) >> 8;
|
|
||||||
bsize[3] = (size & 0x000000ff);
|
|
||||||
printf("size: %lld (%02x %02x %02x %02x)\n",
|
|
||||||
size, bsize[0], bsize[1], bsize[2], bsize[3]);
|
|
||||||
memcpy(fquery+0x13, &bsize, 4);
|
|
||||||
if (vlen) memcpy(fquery+27, version, vlen);
|
|
||||||
|
|
||||||
if (!strcmp(piece, "rootfs"))
|
|
||||||
request = 85;
|
|
||||||
else request = 68;
|
|
||||||
|
|
||||||
//dump_bytes(fquery, 27+vlen);
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, request, 0, 0, (char *)fquery, 27+vlen, 2000) <0) {
|
|
||||||
query_error_message();
|
|
||||||
perror("flash_image.header");
|
|
||||||
exit(1);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*/ cook and bulk nollo filler */
|
|
||||||
/* memset(&nolofiller, '\xff', 128);
|
|
||||||
memcpy(nolofiller+0x00, "NOLO filler", 11);
|
|
||||||
memcpy(nolofiller+0x40, "NOLO filler", 11);
|
|
||||||
usb_bulk_write(dev, 2, (char *)nolofiller, 128, 5000);
|
|
||||||
usb_bulk_write(dev, 2, (char *)nolofiller, 0, 5000);*/
|
|
||||||
|
|
||||||
/*/ bulk write image here */
|
|
||||||
/* printf("[=] Bulkwriting the %s piece...\n", piece);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
#define BSIZE 0x20000
|
|
||||||
|
|
||||||
for(off = 0; off<size; off += BSIZE) {
|
|
||||||
char buf[BSIZE];
|
|
||||||
int bread, bsize = size-off;
|
|
||||||
if (bsize>BSIZE) bsize = BSIZE;
|
|
||||||
// bread = fread(buf, bsize, 1, fd);
|
|
||||||
bread = image_read(image, buf, bsize);
|
|
||||||
if (bread != 1)
|
|
||||||
printf("WARNING: Oops wrong read %d vs %d \n", bread, bsize);
|
|
||||||
bread = usb_bulk_write(dev, 2, buf, bsize, 5000);
|
|
||||||
if (bread == 64) {
|
|
||||||
query_error_message();
|
|
||||||
// fclose(fd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
printf_progressbar(off, size);
|
|
||||||
if (bread<0) {
|
|
||||||
printf("\n");
|
|
||||||
perror(" -ee- ");
|
|
||||||
// fclose(fd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
// fclose(fd);*/
|
|
||||||
/*/ EOF */
|
|
||||||
/* usb_bulk_write(dev, 2, (char *)nolofiller, 0, 1000);
|
|
||||||
printf_progressbar(1, 1);
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
// index = 4????
|
|
||||||
if (!strcmp(piece, "rootfs")) {
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, 82, 0, 0, (char *)fquery, 0, 30000)<0) {
|
|
||||||
fprintf(stderr, "Oops. Invalid checksum?\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int t = 0;
|
|
||||||
if (!strcmp(piece, "secondary"))
|
|
||||||
t = 1;
|
|
||||||
else
|
|
||||||
if (!strcmp(piece, "kernel"))
|
|
||||||
t = 3;
|
|
||||||
else
|
|
||||||
if (!strcmp(piece, "initfs"))
|
|
||||||
t = 4;
|
|
||||||
if (!strcmp(piece, "xloader"))
|
|
||||||
printf("xloader flashed not commiting until secondary arrives...\n");
|
|
||||||
else
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, 80, 0, t, (char *)fquery, 0, 10000)<0) {
|
|
||||||
fprintf(stderr, "Oops. Invalid checksum?\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// unknown query !! :""
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, 67, 0, 0, (char *)fquery, 0, 2000)<0) {
|
|
||||||
fprintf(stderr, "Oops, the flash was denied or so :/\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
printf("Flash done succesfully.\n");
|
|
||||||
}*/
|
|
||||||
|
|
||||||
Reference in new issue
Block a user