* import of the 'set-get-query_header' from Robert Schuster
1) name the simple functions get_foo and set_foo (and make them more consistent e.g. set_rd_mode and get_rd_mode). 2) moved remaining simple queries from main.c into query.c 3) created separate query.h header and included it in main.c 4) implemented get_usb_mode (they do not have this in the proprietary flasher) and added this function to a normal run (-> you will see the current USB mode when running with -i)
This commit is contained in:
1 parent
196f1f7abb
commit
60f2337927
4 files changed
+122
-68
No files matched your search
+10
-26
@@ -19,6 +19,8 @@
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "query.h"
|
||||
|
||||
#include <usb.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -176,26 +178,6 @@ void unpack_fiasco_image(char *file)
|
||||
// TODO
|
||||
}
|
||||
|
||||
int query_sw_version()
|
||||
{
|
||||
int ret;
|
||||
char bytes[1024];
|
||||
|
||||
strcpy(bytes, "version:sw-release");
|
||||
ret = usb_control_msg(dev, CMD_WRITE, 18, 0, 0, (char *)&bytes, 18, 2000);
|
||||
if (ret<0) {
|
||||
fprintf(stderr, "error: cannot write query 18\n");
|
||||
return 0;
|
||||
}
|
||||
ret = usb_control_msg(dev, CMD_QUERY, 20, 0, 0, (char *)&bytes, 512, 2000);
|
||||
if (ret<0) {
|
||||
fprintf(stderr, "error: b0rken swversion read!\n");
|
||||
return 0;
|
||||
}
|
||||
printf("SWVERSION GOT: %s\n", bytes); //???+strlen(bytes)+1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct usb_device_descriptor udd;
|
||||
@@ -320,16 +302,18 @@ int main(int argc, char **argv)
|
||||
|
||||
// if (info)
|
||||
sleep(1); // take breath
|
||||
query_root_device(); // only for flashing
|
||||
query_rdmode_device();
|
||||
query_hw_revision(); // get hardware revision:
|
||||
get_root_device(); // only for flashing
|
||||
get_rd_mode();
|
||||
get_usb_mode();
|
||||
|
||||
get_hw_revision(); // get hardware revision:
|
||||
|
||||
if (pcs_n) {
|
||||
int c;
|
||||
|
||||
check_nolo_order();
|
||||
query_sw_version();
|
||||
query_nolo_version();
|
||||
get_sw_version();
|
||||
get_nolo_version();
|
||||
|
||||
for(c=0;c<pcs_n;c++) {
|
||||
printf("Flashing %s (%s)\n", pcs[c].type, pcs[c].name);
|
||||
@@ -341,7 +325,7 @@ int main(int argc, char **argv)
|
||||
set_root_device(root_device);
|
||||
|
||||
if (usb_mode!=-1)
|
||||
set_usb_host_mode(usb_mode);
|
||||
set_usb_mode(usb_mode);
|
||||
|
||||
if (boot_cmdline)
|
||||
boot_board(boot_cmdline);
|
||||
|
||||
+1
-14
@@ -1,3 +1,4 @@
|
||||
|
||||
#ifndef _INCLUDE_MAIN_H_
|
||||
#define _INCLUDE_MAIN_H_
|
||||
|
||||
@@ -11,21 +12,7 @@ void check_nolo_order();
|
||||
extern struct usb_dev_handle *dev;
|
||||
unsigned long get_file_size(char *file);
|
||||
void progressbar(unsigned long long part, unsigned long long total);
|
||||
int get_status();
|
||||
int get_peripheral_host_mode(int foo);
|
||||
int boot_board(char *cmdline);
|
||||
int boot_board(char *cmdline);
|
||||
int reboot_board();
|
||||
char *fpid_file(char *filename);
|
||||
int set_rd_mode(unsigned short mode);
|
||||
int set_usb_host_mode(unsigned short mode);
|
||||
int query_hw_revision();
|
||||
int query_rdmode_device();
|
||||
|
||||
int query_root_device();
|
||||
int set_root_device(unsigned short);
|
||||
|
||||
int query_nolo_version();
|
||||
int add_piece(char *piece);
|
||||
|
||||
#define D if (verbose)
|
||||
|
||||
+58
-28
@@ -36,26 +36,48 @@ int get_status()
|
||||
return ret;
|
||||
}
|
||||
|
||||
int get_peripheral_host_mode(int foo)
|
||||
/**
|
||||
* request type: CMD_WRITE
|
||||
* request : 16
|
||||
* value : 0|1 (=> client|host)
|
||||
* index : 2
|
||||
*/
|
||||
int set_usb_mode(unsigned int mode)
|
||||
{
|
||||
//unsigned short mode = 0;
|
||||
if (usb_control_msg(dev, CMD_WRITE, 16, mode, 2, 0, 0, 2000) == -1) {
|
||||
fprintf(stderr, "Cannot set USB mode.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// XXX BROKEN
|
||||
#if 0
|
||||
if (usb_control_msg(dev, 64, 16, 2, 0, 2, 0, 0, 2000)) {
|
||||
printf("Set USB mode to: '%s'.\n", (mode) ? "host" : "client");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* request type: CMD_QUERY
|
||||
* request : 17
|
||||
* index : 2
|
||||
*
|
||||
* return value: 0|1 (=> client|host)
|
||||
*/
|
||||
int get_usb_mode()
|
||||
{
|
||||
unsigned short mode = 0;
|
||||
|
||||
if (usb_control_msg(dev, CMD_QUERY, 17, 0, 2, &mode, sizeof(mode), 2000) == -1) {
|
||||
fprintf(stderr, "Cannot query device.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Device is in \"%s\" mode (%hd)\n", (mode)?"host":"peripheral", mode);
|
||||
#endif
|
||||
printf("Device's USB mode is '%s'\n", (mode) ? "host" : "client");
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* boot the omap mobo
|
||||
*/
|
||||
|
||||
/*
|
||||
* Boots the Kernel with the given command-line.
|
||||
*/
|
||||
int boot_board(char *cmdline)
|
||||
{
|
||||
if (usb_control_msg(dev, CMD_WRITE, 130, 0, 0, cmdline, strlen(cmdline), 2000) == -1) {
|
||||
@@ -70,7 +92,7 @@ int boot_board(char *cmdline)
|
||||
}
|
||||
|
||||
/*
|
||||
* reboot the omap mobo
|
||||
* Reboots the omap mobo.
|
||||
*/
|
||||
int reboot_board()
|
||||
{
|
||||
@@ -100,23 +122,10 @@ int set_rd_mode(unsigned short mode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// mode = 1 || 0
|
||||
int set_usb_host_mode(unsigned short mode)
|
||||
{
|
||||
if (usb_control_msg(dev, CMD_WRITE, 16, mode, 2, 0, 0, 2000) == -1) {
|
||||
fprintf(stderr, "Cannot change the usb-host mode.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("USB host mode is %s.\n", mode?"enabled":"disabled");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* query root device
|
||||
*/
|
||||
int query_hw_revision()
|
||||
int get_hw_revision()
|
||||
{
|
||||
unsigned char string[512];
|
||||
int i = 0;
|
||||
@@ -140,7 +149,7 @@ int query_hw_revision()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int query_rdmode_device()
|
||||
int get_rd_mode()
|
||||
{
|
||||
char isrd = 1;
|
||||
|
||||
@@ -153,7 +162,7 @@ int query_rdmode_device()
|
||||
return isrd;
|
||||
}
|
||||
|
||||
int query_root_device()
|
||||
int get_root_device()
|
||||
{
|
||||
unsigned char opcode;
|
||||
|
||||
@@ -194,7 +203,7 @@ int set_root_device(unsigned short root_device)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int query_nolo_version()
|
||||
int get_nolo_version()
|
||||
{
|
||||
unsigned int version; // ensure uint is at least 32 bits
|
||||
|
||||
@@ -214,3 +223,24 @@ int query_nolo_version()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_sw_version()
|
||||
{
|
||||
int ret;
|
||||
char bytes[1024];
|
||||
|
||||
strcpy(bytes, "version:sw-release");
|
||||
ret = usb_control_msg(dev, CMD_WRITE, 18, 0, 0, (char *)&bytes, 18, 2000);
|
||||
if (ret<0) {
|
||||
fprintf(stderr, "error: cannot write query 18\n");
|
||||
return 0;
|
||||
}
|
||||
ret = usb_control_msg(dev, CMD_QUERY, 20, 0, 0, (char *)&bytes, 512, 2000);
|
||||
if (ret<0) {
|
||||
fprintf(stderr, "error: b0rken swversion read!\n");
|
||||
return 0;
|
||||
}
|
||||
printf("SWVERSION GOT: %s\n", bytes); //???+strlen(bytes)+1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user