flash: Rewrite flash_image code to use struct * image
This commit is contained in:
1 parent
0d76941600
commit
29084d4acf
4 files changed
+29
-21
No files matched your search
+23
-17
@@ -23,6 +23,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "image.h"
|
||||||
|
|
||||||
/*void check_nolo_order_failed()
|
/*void check_nolo_order_failed()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\nERROR: Provide xloader before the secondary. NOLO disagrees anything else.\n");
|
fprintf(stderr, "\nERROR: Provide xloader before the secondary. NOLO disagrees anything else.\n");
|
||||||
@@ -73,9 +75,9 @@ void query_error_message()
|
|||||||
check_nolo_order_failed();
|
check_nolo_order_failed();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
void flash_image(const char *filename, const char *piece, const char *device, const char *hwrevs, const char *version)
|
void flash_image(struct image * image)
|
||||||
{
|
{
|
||||||
FILE *fd;
|
// FILE *fd;
|
||||||
int vlen = 0;
|
int vlen = 0;
|
||||||
int request;
|
int request;
|
||||||
/*/ n800 flash queries have a variable size */
|
/*/ n800 flash queries have a variable size */
|
||||||
@@ -83,17 +85,19 @@ void flash_image(const char *filename, const char *piece, const char *device, co
|
|||||||
unsigned long long size, off;
|
unsigned long long size, off;
|
||||||
unsigned char bsize[4], tmp;
|
unsigned char bsize[4], tmp;
|
||||||
unsigned char nolofiller[128];
|
unsigned char nolofiller[128];
|
||||||
ushort hash = 0; //do_hash_file(filename, piece);
|
const char * piece = image_type_to_string(image->type);
|
||||||
|
const char * version = image->version;
|
||||||
|
ushort hash = image->hash;
|
||||||
|
|
||||||
if (piece == NULL) {
|
// if (piece == NULL) {
|
||||||
//exit(1);
|
//exit(1);
|
||||||
piece = fpid_file(filename);
|
// piece = fpid_file(filename);
|
||||||
if (piece == NULL) {
|
if (piece == NULL) {
|
||||||
printf("Unknown piece type\n");
|
printf("Unknown piece type\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf("Piece type: %s\n", piece);
|
// printf("Piece type: %s\n", piece);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/* if (piece != NULL) {
|
/* if (piece != NULL) {
|
||||||
if (!strcmp(piece, "fiasco")) {
|
if (!strcmp(piece, "fiasco")) {
|
||||||
@@ -105,11 +109,11 @@ void flash_image(const char *filename, const char *piece, const char *device, co
|
|||||||
if (version)
|
if (version)
|
||||||
vlen = strlen(version)+1;
|
vlen = strlen(version)+1;
|
||||||
|
|
||||||
fd = fopen(filename, "rb");
|
// fd = fopen(filename, "rb");
|
||||||
if (fd == NULL) {
|
// if (fd == NULL) {
|
||||||
printf("Cannot open file\n");
|
// printf("Cannot open file\n");
|
||||||
exit(1);
|
// exit(1);
|
||||||
}
|
// }
|
||||||
/* cook flash query */
|
/* cook flash query */
|
||||||
memset(fquery, '\x00', 27); // reset buffer
|
memset(fquery, '\x00', 27); // reset buffer
|
||||||
memcpy(fquery, "\x2e\x19\x01\x01", 4); // header
|
memcpy(fquery, "\x2e\x19\x01\x01", 4); // header
|
||||||
@@ -119,7 +123,8 @@ void flash_image(const char *filename, const char *piece, const char *device, co
|
|||||||
memcpy(fquery+7, piece, strlen(piece)); // XXX ??!??
|
memcpy(fquery+7, piece, strlen(piece)); // XXX ??!??
|
||||||
|
|
||||||
printf("| hash: 0x%hhx%hhx ", fquery[5], fquery[6]);
|
printf("| hash: 0x%hhx%hhx ", fquery[5], fquery[6]);
|
||||||
size = get_file_size(filename);
|
// size = get_file_size(filename);
|
||||||
|
size = image->size;
|
||||||
bsize[0] = (size & 0xff000000) >> 24;
|
bsize[0] = (size & 0xff000000) >> 24;
|
||||||
bsize[1] = (size & 0x00ff0000) >> 16;
|
bsize[1] = (size & 0x00ff0000) >> 16;
|
||||||
bsize[2] = (size & 0x0000ff00) >> 8;
|
bsize[2] = (size & 0x0000ff00) >> 8;
|
||||||
@@ -157,25 +162,26 @@ void flash_image(const char *filename, const char *piece, const char *device, co
|
|||||||
char buf[BSIZE];
|
char buf[BSIZE];
|
||||||
int bread, bsize = size-off;
|
int bread, bsize = size-off;
|
||||||
if (bsize>BSIZE) bsize = BSIZE;
|
if (bsize>BSIZE) bsize = BSIZE;
|
||||||
bread = fread(buf, bsize, 1, fd);
|
// bread = fread(buf, bsize, 1, fd);
|
||||||
|
bread = image_read(image, buf, bsize);
|
||||||
if (bread != 1)
|
if (bread != 1)
|
||||||
printf("WARNING: Oops wrong read %d vs %d \n", bread, bsize);
|
printf("WARNING: Oops wrong read %d vs %d \n", bread, bsize);
|
||||||
bread = usb_bulk_write(dev, 2, buf, bsize, 5000);
|
bread = usb_bulk_write(dev, 2, buf, bsize, 5000);
|
||||||
if (bread == 64) {
|
if (bread == 64) {
|
||||||
query_error_message();
|
query_error_message();
|
||||||
fclose(fd);
|
// fclose(fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
progressbar(off, size);
|
progressbar(off, size);
|
||||||
if (bread<0) {
|
if (bread<0) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
perror(" -ee- ");
|
perror(" -ee- ");
|
||||||
fclose(fd);
|
// fclose(fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
fclose(fd);
|
// fclose(fd);
|
||||||
/*/ EOF */
|
/*/ EOF */
|
||||||
usb_bulk_write(dev, 2, (char *)nolofiller, 0, 1000);
|
usb_bulk_write(dev, 2, (char *)nolofiller, 0, 1000);
|
||||||
progressbar(1, 1);
|
progressbar(1, 1);
|
||||||
|
|||||||
+1
-1
@@ -584,7 +584,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
for(c=0;c<pcs_n;c++) {
|
for(c=0;c<pcs_n;c++) {
|
||||||
printf("Flashing %s (%s)\n", pcs[c].type, pcs[c].name);
|
printf("Flashing %s (%s)\n", pcs[c].type, pcs[c].name);
|
||||||
flash_image(pcs[c].name, pcs[c].type, pcs[c].device, pcs[c].hwrevs, pcs[c].version);
|
// flash_image(pcs[c].name, pcs[c].type, pcs[c].device, pcs[c].hwrevs, pcs[c].version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -16,10 +16,12 @@ extern char strbuf[1024];
|
|||||||
|
|
||||||
// Forward declaration for use in function arguments.
|
// Forward declaration for use in function arguments.
|
||||||
//struct devices;
|
//struct devices;
|
||||||
|
struct image;
|
||||||
|
|
||||||
int queue_mode();
|
int queue_mode();
|
||||||
int reverse_extract_pieces(char *dir);
|
int reverse_extract_pieces(char *dir);
|
||||||
void flash_image(const char *filename, const char *piece, const char *device, const char *hwrevs, const char *version);
|
//void flash_image(const char *filename, const char *piece, const char *device, const char *hwrevs, const char *version);
|
||||||
|
void flash_image(struct image * image);
|
||||||
int fiasco_read_image(char *file);
|
int fiasco_read_image(char *file);
|
||||||
//void check_nolo_order();
|
//void check_nolo_order();
|
||||||
extern struct usb_dev_handle *dev;
|
extern struct usb_dev_handle *dev;
|
||||||
|
|||||||
+2
-2
@@ -52,12 +52,12 @@ void process_message(char *msg)
|
|||||||
if (c!=0) {
|
if (c!=0) {
|
||||||
arg[0]='\0';
|
arg[0]='\0';
|
||||||
arg = arg +1;
|
arg = arg +1;
|
||||||
if (!strcmp(str, "flash")) {
|
/* if (!strcmp(str, "flash")) {
|
||||||
const char *type = fpid_file(arg);
|
const char *type = fpid_file(arg);
|
||||||
if (type == NULL) {
|
if (type == NULL) {
|
||||||
squeue_push2(p, "error", "Unknown piece format", 1);
|
squeue_push2(p, "error", "Unknown piece format", 1);
|
||||||
} else flash_image(arg, type, NULL, NULL, NULL);
|
} else flash_image(arg, type, NULL, NULL, NULL);
|
||||||
} else
|
} else*/
|
||||||
if (!strcmp(str, "reset")) {
|
if (!strcmp(str, "reset")) {
|
||||||
if (reboot_board() == 0) {
|
if (reboot_board() == 0) {
|
||||||
squeue_push2(p,"info", "Device reboots", 1);
|
squeue_push2(p,"info", "Device reboots", 1);
|
||||||
|
|||||||
Reference in new issue
Block a user