flash: Rewrite flash_image code to use struct * image

This commit is contained in:
Pali Rohár committed 2012-08-09 20:38:47 +02:00
1 parent 0d76941600
commit 29084d4acf
4 files changed
+29 -21

No files matched your search

+23 -17
View File
@@ -23,6 +23,8 @@
#include <string.h>
#include <stdlib.h>
#include "image.h"
/*void check_nolo_order_failed()
{
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();
}*/
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 request;
/*/ 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 char bsize[4], tmp;
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);
piece = fpid_file(filename);
// piece = fpid_file(filename);
if (piece == NULL) {
printf("Unknown piece type\n");
return;
}
printf("Piece type: %s\n", piece);
}
// printf("Piece type: %s\n", piece);
// }
/* if (piece != NULL) {
if (!strcmp(piece, "fiasco")) {
@@ -105,11 +109,11 @@ void flash_image(const char *filename, const char *piece, const char *device, co
if (version)
vlen = strlen(version)+1;
fd = fopen(filename, "rb");
if (fd == NULL) {
printf("Cannot open file\n");
exit(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
@@ -119,7 +123,8 @@ void flash_image(const char *filename, const char *piece, const char *device, co
memcpy(fquery+7, piece, strlen(piece)); // XXX ??!??
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[1] = (size & 0x00ff0000) >> 16;
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];
int bread, bsize = size-off;
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)
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);
// fclose(fd);
return;
}
progressbar(off, size);
if (bread<0) {
printf("\n");
perror(" -ee- ");
fclose(fd);
// fclose(fd);
return;
}
fflush(stdout);
}
fclose(fd);
// fclose(fd);
/*/ EOF */
usb_bulk_write(dev, 2, (char *)nolofiller, 0, 1000);
progressbar(1, 1);
+1 -1
View File
@@ -584,7 +584,7 @@ int main(int argc, char **argv)
for(c=0;c<pcs_n;c++) {
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
View File
@@ -16,10 +16,12 @@ extern char strbuf[1024];
// Forward declaration for use in function arguments.
//struct devices;
struct image;
int queue_mode();
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);
//void check_nolo_order();
extern struct usb_dev_handle *dev;
+2 -2
View File
@@ -52,12 +52,12 @@ void process_message(char *msg)
if (c!=0) {
arg[0]='\0';
arg = arg +1;
if (!strcmp(str, "flash")) {
/* if (!strcmp(str, "flash")) {
const char *type = fpid_file(arg);
if (type == NULL) {
squeue_push2(p, "error", "Unknown piece format", 1);
} else flash_image(arg, type, NULL, NULL, NULL);
} else
} else*/
if (!strcmp(str, "reset")) {
if (reboot_board() == 0) {
squeue_push2(p,"info", "Device reboots", 1);