* Implement and test direct file FIASCO flash - openfiasco receives options for grepping for pieces and be verbose - fixed flashing order using grep options xloader, secondary, kernel, initfs, rootfs - Tested and working - Added parser for the hw revision string
* Autodetect device hw revision and setup the subversion string on the fly.
This commit is contained in:
1 parent
3d427bfd77
commit
5a96158322
7 files changed
+89
-25
No files matched your search
+6
-1
@@ -46,8 +46,13 @@ void cmd_help(char *line)
|
|||||||
|
|
||||||
void cmd_info(char *line)
|
void cmd_info(char *line)
|
||||||
{
|
{
|
||||||
|
char *p, str[128];
|
||||||
get_sw_version();
|
get_sw_version();
|
||||||
get_hw_revision(); // get hardware revision:
|
get_hw_revision(str, 128); // get hardware revision:
|
||||||
|
p = strstr(str, "hw_rev:");
|
||||||
|
if (p) // TODO: delimit string by comma
|
||||||
|
printf("SubVersionString autodetected: '%s'\n", p+7);
|
||||||
|
else printf("SubVersionString autodetected: (error)\n");
|
||||||
get_root_device(); // only for flashing
|
get_root_device(); // only for flashing
|
||||||
get_usb_mode();
|
get_usb_mode();
|
||||||
get_rd_mode();
|
get_rd_mode();
|
||||||
|
|||||||
+19
-7
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
int (*fiasco_callback)(struct header_t *header) = NULL;
|
int (*fiasco_callback)(struct header_t *header) = NULL;
|
||||||
|
|
||||||
int openfiasco(char *name)
|
int openfiasco(char *name, char *piece_grep, int v)
|
||||||
{
|
{
|
||||||
struct header_t header;
|
struct header_t header;
|
||||||
unsigned char buf[128];
|
unsigned char buf[128];
|
||||||
@@ -38,6 +38,7 @@ int openfiasco(char *name)
|
|||||||
unsigned int namelen;
|
unsigned int namelen;
|
||||||
off_t off, here;
|
off_t off, here;
|
||||||
int i,j;
|
int i,j;
|
||||||
|
|
||||||
header.fd = open(name, O_RDONLY);
|
header.fd = open(name, O_RDONLY);
|
||||||
|
|
||||||
if (header.fd == -1) {
|
if (header.fd == -1) {
|
||||||
@@ -60,8 +61,9 @@ int openfiasco(char *name)
|
|||||||
memset(buf,'\0', 128);
|
memset(buf,'\0', 128);
|
||||||
read(header.fd, buf, namelen);
|
read(header.fd, buf, namelen);
|
||||||
|
|
||||||
printf("Fiasco version: %2d\n", buf[3]);
|
if (v) printf("Fiasco version: %2d\n", buf[3]);
|
||||||
strcpy(header.fwname, (char *)buf+6);
|
strcpy(header.fwname, (char *)buf+6);
|
||||||
|
if (v)
|
||||||
for(i=6;i<namelen;i+=strlen((char *)(buf+i))+1)
|
for(i=6;i<namelen;i+=strlen((char *)(buf+i))+1)
|
||||||
printf("Name: %s\n", buf+i);
|
printf("Name: %s\n", buf+i);
|
||||||
|
|
||||||
@@ -80,7 +82,7 @@ int openfiasco(char *name)
|
|||||||
return close(header.fd);
|
return close(header.fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("Skipping %d padding bytes\n", i);
|
if (v) printf("Skipping %d padding bytes\n", i);
|
||||||
lseek(header.fd, -1, SEEK_CUR);
|
lseek(header.fd, -1, SEEK_CUR);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -94,16 +96,18 @@ int openfiasco(char *name)
|
|||||||
if (data[0] == 0xff) {
|
if (data[0] == 0xff) {
|
||||||
printf(" [eof]\n");
|
printf(" [eof]\n");
|
||||||
break;
|
break;
|
||||||
} else printf(" %s\n", data);
|
} else if (v) printf(" %s\n", data);
|
||||||
strcpy(header.name, (char *)data);
|
strcpy(header.name, (char *)data);
|
||||||
|
|
||||||
if (read(header.fd, buf, 9)<9)
|
if (read(header.fd, buf, 9)<9)
|
||||||
break;
|
break;
|
||||||
memcpy(&header.size, buf,4);
|
memcpy(&header.size, buf,4);
|
||||||
header.size = ntohl(header.size);
|
header.size = ntohl(header.size);
|
||||||
|
if (v) {
|
||||||
printf(" offset: 0x%08x\n", (unsigned int)here);
|
printf(" offset: 0x%08x\n", (unsigned int)here);
|
||||||
printf(" size: %d bytes\n", header.size);
|
printf(" size: %d bytes\n", header.size);
|
||||||
printf(" hash: %04x\n", header.hash);
|
printf(" hash: %04x\n", header.hash);
|
||||||
|
}
|
||||||
//printf("BYTE: %02x %02x %02x %02x %02x\n",
|
//printf("BYTE: %02x %02x %02x %02x %02x\n",
|
||||||
// buf[4], buf[5], buf[6], buf[7], buf[8]);
|
// buf[4], buf[5], buf[6], buf[7], buf[8]);
|
||||||
/* XXX this is not ok */
|
/* XXX this is not ok */
|
||||||
@@ -115,13 +119,15 @@ int openfiasco(char *name)
|
|||||||
if (read(header.fd, data, i)<i)
|
if (read(header.fd, data, i)<i)
|
||||||
break;
|
break;
|
||||||
if (data[0]) {
|
if (data[0]) {
|
||||||
|
if (v) {
|
||||||
printf(" version-length: %d\n", i);
|
printf(" version-length: %d\n", i);
|
||||||
printf(" version: %s\n", data);
|
printf(" version: %s\n", data);
|
||||||
|
}
|
||||||
pdata = data;
|
pdata = data;
|
||||||
while(pdata<data+i) {
|
while(pdata<data+i) {
|
||||||
strcat(header.name,pdata==data?"-":",");
|
strcat(header.name,pdata==data?"-":",");
|
||||||
strcat(header.name, (char*)pdata);
|
strcat(header.name, (char*)pdata);
|
||||||
printf(" sub-version: %s\n", pdata);
|
if (v) printf(" sub-version: %s\n", pdata);
|
||||||
pdata = pdata+strlen((char*)pdata)+1;
|
pdata = pdata+strlen((char*)pdata)+1;
|
||||||
for(;*pdata=='\0'&&pdata<data+i;pdata=pdata+1);
|
for(;*pdata=='\0'&&pdata<data+i;pdata=pdata+1);
|
||||||
}
|
}
|
||||||
@@ -130,21 +136,27 @@ int openfiasco(char *name)
|
|||||||
if (read(header.fd, buf+8, 1)<1)
|
if (read(header.fd, buf+8, 1)<1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf(" name: %s\n", header.name);
|
|
||||||
/* callback */
|
/* callback */
|
||||||
off = lseek(header.fd, 0, SEEK_CUR);
|
off = lseek(header.fd, 0, SEEK_CUR);
|
||||||
|
if (v) {
|
||||||
|
printf(" name: %s\n", header.name);
|
||||||
printf(" body-at: 0x%08x\n", (unsigned int)off);
|
printf(" body-at: 0x%08x\n", (unsigned int)off);
|
||||||
|
}
|
||||||
|
if (piece_grep==NULL || (strstr(header.name, piece_grep))) {
|
||||||
|
printf("==> (%s) %s\n", piece_grep, header.name);
|
||||||
if (fiasco_callback != NULL) {
|
if (fiasco_callback != NULL) {
|
||||||
fiasco_callback(&header);
|
fiasco_callback(&header);
|
||||||
free(header.data);
|
free(header.data);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
// ??huh
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// XXX dup
|
// XXX dup
|
||||||
lseek(header.fd, off, SEEK_SET);
|
lseek(header.fd, off, SEEK_SET);
|
||||||
lseek(header.fd, header.size, SEEK_CUR);
|
lseek(header.fd, header.size, SEEK_CUR);
|
||||||
}
|
}
|
||||||
return 0;
|
return close(header.fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fiasco_data_read(struct header_t *header)
|
void fiasco_data_read(struct header_t *header)
|
||||||
|
|||||||
+10
@@ -86,6 +86,16 @@ void flash_image(const char *filename, const char *piece, const char *version)
|
|||||||
unsigned char nolofiller[128];
|
unsigned char nolofiller[128];
|
||||||
ushort hash = do_hash_file(filename);
|
ushort hash = do_hash_file(filename);
|
||||||
|
|
||||||
|
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 (version)
|
if (version)
|
||||||
vlen = strlen(version)+1;
|
vlen = strlen(version)+1;
|
||||||
|
|
||||||
|
|||||||
+41
-5
@@ -159,17 +159,41 @@ void unpack_fiasco_image(char *file)
|
|||||||
{
|
{
|
||||||
printf("Dumping firmware pieces to disk.\n");
|
printf("Dumping firmware pieces to disk.\n");
|
||||||
fiasco_callback = &unpack_callback;
|
fiasco_callback = &unpack_callback;
|
||||||
openfiasco( file );
|
openfiasco(file, NULL ,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fiasco_flash(char *file)
|
int fiasco_flash(char *file)
|
||||||
{
|
{
|
||||||
|
char *p,version[64];
|
||||||
|
|
||||||
|
if (connect_via_usb()) {
|
||||||
|
fprintf(stderr, "Cannot connect to device. It is possibly not in boot stage.\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (info)
|
||||||
|
cmd_info("");
|
||||||
|
|
||||||
check_nolo_order();
|
check_nolo_order();
|
||||||
get_sw_version();
|
get_sw_version();
|
||||||
|
get_hw_revision(version, 44);
|
||||||
|
|
||||||
|
if (subverstr == NULL) {
|
||||||
|
p = strstr(version, "hw_rev:");
|
||||||
|
if (p) {
|
||||||
|
subverstr = strdup(p+7);
|
||||||
|
// TODO: delimit string by comma
|
||||||
|
printf("SubVersionString autodetected: '%s'\n", subverstr);
|
||||||
|
}
|
||||||
|
}
|
||||||
get_nolo_version();
|
get_nolo_version();
|
||||||
|
|
||||||
fiasco_callback = &flash_callback;
|
fiasco_callback = &flash_callback;
|
||||||
openfiasco( file );
|
openfiasco(file, "xloader", 0);
|
||||||
|
openfiasco(file, "secondary", 0);
|
||||||
|
openfiasco(file, "kernel", 0);
|
||||||
|
openfiasco(file, "initfs", 0);
|
||||||
|
openfiasco(file, "rootfs", 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -277,7 +301,8 @@ int main(int argc, char **argv)
|
|||||||
usb_mode = atoi(optarg);
|
usb_mode = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
return fiasco_flash(optarg);
|
fiasco_image = optarg;
|
||||||
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
sscanf(optarg, "%04hx:%04hx",
|
sscanf(optarg, "%04hx:%04hx",
|
||||||
&supported_devices[SUPPORTED_DEVICES-2].vendor_id,
|
&supported_devices[SUPPORTED_DEVICES-2].vendor_id,
|
||||||
@@ -350,6 +375,9 @@ int main(int argc, char **argv)
|
|||||||
if (qmode)
|
if (qmode)
|
||||||
return queue_mode();
|
return queue_mode();
|
||||||
|
|
||||||
|
if (!unpack && fiasco_image)
|
||||||
|
return fiasco_flash(fiasco_image);
|
||||||
|
|
||||||
if (identify)
|
if (identify)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -395,10 +423,18 @@ int main(int argc, char **argv)
|
|||||||
cmd_info("");
|
cmd_info("");
|
||||||
|
|
||||||
if (pcs_n) {
|
if (pcs_n) {
|
||||||
int c;
|
char version[64];
|
||||||
|
|
||||||
check_nolo_order();
|
check_nolo_order();
|
||||||
get_sw_version();
|
get_sw_version();
|
||||||
|
get_hw_revision(version, 44);
|
||||||
|
if (subverstr == NULL) {
|
||||||
|
char *p = strstr(version, "hw_rev:");
|
||||||
|
if (p) {
|
||||||
|
subverstr = strdup(p+7);
|
||||||
|
// TODO: delimit string by comma
|
||||||
|
printf("SubVersionString autodetected: '%s'\n", subverstr);
|
||||||
|
}
|
||||||
|
}
|
||||||
get_nolo_version();
|
get_nolo_version();
|
||||||
|
|
||||||
for(c=0;c<pcs_n;c++) {
|
for(c=0;c<pcs_n;c++) {
|
||||||
|
|||||||
+1
-1
@@ -102,7 +102,7 @@ extern char *modes[];
|
|||||||
extern char *root_devices[];
|
extern char *root_devices[];
|
||||||
|
|
||||||
// fiasco
|
// fiasco
|
||||||
int openfiasco(char *name);
|
int openfiasco(char *name, char *grep, int v);
|
||||||
int fiasco_new(const char *filename, const char *name);
|
int fiasco_new(const char *filename, const char *name);
|
||||||
void fiasco_data_read(struct header_t *header);
|
void fiasco_data_read(struct header_t *header);
|
||||||
int fiasco_add_eof(int fd);
|
int fiasco_add_eof(int fd);
|
||||||
|
|||||||
+11
-10
@@ -134,27 +134,28 @@ int set_rd_mode(unsigned short mode)
|
|||||||
/*
|
/*
|
||||||
* query root device
|
* query root device
|
||||||
*/
|
*/
|
||||||
int get_hw_revision()
|
int get_hw_revision(char *str, int len)
|
||||||
{
|
{
|
||||||
unsigned char string[512];
|
unsigned char string[512];
|
||||||
int i = 0;
|
char tmpstr[64];
|
||||||
|
int i = 0, j=0, mod=0;
|
||||||
|
|
||||||
|
if (str == NULL)
|
||||||
|
str = tmpstr;
|
||||||
memset(string,'\0',512);
|
memset(string,'\0',512);
|
||||||
if (usb_control_msg(dev, CMD_QUERY, NOLO_GET_HWVERSION, 0, 0, (char *)string, 512, 2000) == -1) {
|
if (usb_control_msg(dev, CMD_QUERY, NOLO_GET_HWVERSION, 0, 0, (char *)string, 512, 2000) == -1) {
|
||||||
fprintf(stderr, "Cannot query hw revision.\n");
|
fprintf(stderr, "Cannot query hw revision.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("HW revision string: '");
|
for(i=0;i<44&&i<len;i++) { // XXX ??
|
||||||
for(i=0;i<44;i++) { // XXX ??
|
if (string[i]>19) {
|
||||||
if (string[i]==0) {
|
if (i>0 && string[i-1]<19)
|
||||||
printf(" ");
|
str[j++] = (++mod%2)?':':',';
|
||||||
} else {
|
str[j++] = string[i];
|
||||||
if (string[i]>19)
|
|
||||||
printf("%c", string[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("'\n");
|
printf("HW revision string: '%s'\n", str);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ int set_rd_mode(unsigned short mode);
|
|||||||
int get_rd_flags();
|
int get_rd_flags();
|
||||||
int set_rd_flags(unsigned short flags);
|
int set_rd_flags(unsigned short flags);
|
||||||
|
|
||||||
int get_hw_revision();
|
int get_hw_revision(char *str, int len);
|
||||||
|
|
||||||
int get_root_device();
|
int get_root_device();
|
||||||
int set_root_device(unsigned short);
|
int set_root_device(unsigned short);
|
||||||
|
|||||||
Reference in new issue
Block a user