mirror of
https://github.com/raphnet/gc_n64_usb-v3
synced 2024-12-22 15:28:52 -05:00
WIP on firmware update
- Verify signature
This commit is contained in:
parent
b312d1466d
commit
05a30a21ba
@ -24,6 +24,7 @@ gboolean updateDonefunc(gpointer data)
|
|||||||
|
|
||||||
rebuild_device_list_store(data);
|
rebuild_device_list_store(data);
|
||||||
updateGuiFromAdapter(app);
|
updateGuiFromAdapter(app);
|
||||||
|
app->inhibit_periodic_updates = 0;
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -58,6 +59,8 @@ gpointer updateThreadFunc(gpointer data)
|
|||||||
char cmd[256];
|
char cmd[256];
|
||||||
int retries = 10;
|
int retries = 10;
|
||||||
|
|
||||||
|
app->inhibit_periodic_updates = 1;
|
||||||
|
|
||||||
app->update_status = "Starting...";
|
app->update_status = "Starting...";
|
||||||
app->update_percent = 1;
|
app->update_percent = 1;
|
||||||
gdk_threads_add_idle(updateProgress, data);
|
gdk_threads_add_idle(updateProgress, data);
|
||||||
@ -267,24 +270,36 @@ G_MODULE_EXPORT void update_usbadapter_firmware(GtkWidget *w, gpointer data)
|
|||||||
{
|
{
|
||||||
struct application *app = data;
|
struct application *app = data;
|
||||||
gint res;
|
gint res;
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog = NULL;
|
||||||
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
||||||
GET_UI_ELEMENT(GtkFileFilter, hexfilter);
|
GET_UI_ELEMENT(GtkFileFilter, hexfilter);
|
||||||
GET_UI_ELEMENT(GtkDialog, firmware_update_dialog);
|
GET_UI_ELEMENT(GtkDialog, firmware_update_dialog);
|
||||||
GET_UI_ELEMENT(GtkLabel, lbl_firmware_filename);
|
GET_UI_ELEMENT(GtkLabel, lbl_firmware_filename);
|
||||||
GET_UI_ELEMENT(GtkButtonBox, update_dialog_btnBox);
|
GET_UI_ELEMENT(GtkButtonBox, update_dialog_btnBox);
|
||||||
FILE *dfu_fp;
|
FILE *dfu_fp;
|
||||||
|
char *filename = NULL, *basename = NULL;
|
||||||
|
char adap_sig[64];
|
||||||
|
|
||||||
|
if (gcn64lib_getSignature(app->current_adapter_handle, adap_sig, sizeof(adap_sig))) {
|
||||||
|
errorPopup(app, "Could not read adapter signature - This file may not be meant for it (Bricking hazard!)");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Adapter signature: %s\n", adap_sig);
|
||||||
|
|
||||||
/* Test for dfu-programmer presence in path*/
|
/* Test for dfu-programmer presence in path*/
|
||||||
dfu_fp = popen("dfu-programmer --help", "r");
|
dfu_fp = popen("dfu-programmer --version", "r");
|
||||||
if (!dfu_fp) {
|
if (!dfu_fp) {
|
||||||
perror("popen");
|
perror("popen");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pclose(dfu_fp)) {
|
res = pclose(dfu_fp);
|
||||||
|
if (!WIFEXITED(res) || (WEXITSTATUS(res)!=1)) {
|
||||||
|
if (res) {
|
||||||
errorPopup(app, "dfu-programmmer not found. Cannot perform update.");
|
errorPopup(app, "dfu-programmmer not found. Cannot perform update.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dialog = gtk_file_chooser_dialog_new("Open .hex file",
|
dialog = gtk_file_chooser_dialog_new("Open .hex file",
|
||||||
app->mainwindow,
|
app->mainwindow,
|
||||||
@ -299,7 +314,6 @@ G_MODULE_EXPORT void update_usbadapter_firmware(GtkWidget *w, gpointer data)
|
|||||||
|
|
||||||
res = gtk_dialog_run (GTK_DIALOG(dialog));
|
res = gtk_dialog_run (GTK_DIALOG(dialog));
|
||||||
if (res == GTK_RESPONSE_ACCEPT) {
|
if (res == GTK_RESPONSE_ACCEPT) {
|
||||||
char *filename, *basename;
|
|
||||||
GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog);
|
GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog);
|
||||||
|
|
||||||
filename = gtk_file_chooser_get_filename(chooser);
|
filename = gtk_file_chooser_get_filename(chooser);
|
||||||
@ -308,8 +322,11 @@ G_MODULE_EXPORT void update_usbadapter_firmware(GtkWidget *w, gpointer data)
|
|||||||
printf("File selected: %s\n", filename);
|
printf("File selected: %s\n", filename);
|
||||||
app->updateHexFile = filename;
|
app->updateHexFile = filename;
|
||||||
|
|
||||||
if (!check_ihex_for_signature(filename, "9c3ea8b8-753f-11e5-a0dc-001bfca3c593")) {
|
printf("Adapter signature: %s\n", adap_sig);
|
||||||
|
//if (!check_ihex_for_signature(filename, "9c3ea8b8-753f-11e5-a0dc-001bfca3c593")) {
|
||||||
|
if (!check_ihex_for_signature(filename, adap_sig)) {
|
||||||
errorPopup(app, "Signature not found - This file is invalid or not meant for this adapter");
|
errorPopup(app, "Signature not found - This file is invalid or not meant for this adapter");
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare the update dialog widgets... */
|
/* Prepare the update dialog widgets... */
|
||||||
@ -328,10 +345,14 @@ G_MODULE_EXPORT void update_usbadapter_firmware(GtkWidget *w, gpointer data)
|
|||||||
}
|
}
|
||||||
printf("Update dialog done\n");
|
printf("Update dialog done\n");
|
||||||
|
|
||||||
g_free(filename);
|
|
||||||
g_free(basename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
if (filename)
|
||||||
|
g_free(filename);
|
||||||
|
if (basename)
|
||||||
|
g_free(basename);
|
||||||
|
if (dialog)
|
||||||
gtk_widget_destroy(dialog);
|
gtk_widget_destroy(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,15 +377,20 @@ static void updateGuiFromAdapter(struct application *app)
|
|||||||
GET_UI_ELEMENT(GtkLabel, label_usb_id);
|
GET_UI_ELEMENT(GtkLabel, label_usb_id);
|
||||||
GET_UI_ELEMENT(GtkLabel, label_device_path);
|
GET_UI_ELEMENT(GtkLabel, label_device_path);
|
||||||
GET_UI_ELEMENT(GtkLabel, label_controller_type);
|
GET_UI_ELEMENT(GtkLabel, label_controller_type);
|
||||||
|
GET_UI_ELEMENT(GtkSpinButton, pollInterval0);
|
||||||
int i;
|
int i;
|
||||||
struct gcn64_info *info = &app->current_adapter_info;
|
struct gcn64_info *info = &app->current_adapter_info;
|
||||||
|
char adap_sig[64];
|
||||||
|
|
||||||
if (!app->current_adapter_handle) {
|
if (!app->current_adapter_handle) {
|
||||||
deselect_adapter(app);
|
deselect_adapter(app);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkSpinButton *pollInterval0 = GTK_SPIN_BUTTON( gtk_builder_get_object(app->builder, "pollInterval0") );
|
if (gcn64lib_getSignature(app->current_adapter_handle, adap_sig, sizeof(adap_sig))) {
|
||||||
|
} else {
|
||||||
|
printf("Adapter signature: %s\n", adap_sig);
|
||||||
|
}
|
||||||
|
|
||||||
n = gcn64lib_getConfig(app->current_adapter_handle, CFG_PARAM_POLL_INTERVAL0, buf, sizeof(buf));
|
n = gcn64lib_getConfig(app->current_adapter_handle, CFG_PARAM_POLL_INTERVAL0, buf, sizeof(buf));
|
||||||
if (n == 1) {
|
if (n == 1) {
|
||||||
@ -372,6 +398,13 @@ static void updateGuiFromAdapter(struct application *app)
|
|||||||
gtk_spin_button_set_value(pollInterval0, (gdouble)buf[0]);
|
gtk_spin_button_set_value(pollInterval0, (gdouble)buf[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("Adapter signature: %s\n", adap_sig);
|
||||||
|
if (gcn64lib_getSignature(app->current_adapter_handle, adap_sig, sizeof(adap_sig))) {
|
||||||
|
} else {
|
||||||
|
printf("Adapter signature: %s\n", adap_sig);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
for (i=0; configurable_bits[i].chkbtn; i++) {
|
for (i=0; configurable_bits[i].chkbtn; i++) {
|
||||||
gcn64lib_getConfig(app->current_adapter_handle, configurable_bits[i].cfg_param, buf, sizeof(buf));
|
gcn64lib_getConfig(app->current_adapter_handle, configurable_bits[i].cfg_param, buf, sizeof(buf));
|
||||||
printf("config param %02x is %d\n", configurable_bits[i].cfg_param, buf[0]);
|
printf("config param %02x is %d\n", configurable_bits[i].cfg_param, buf[0]);
|
||||||
@ -406,7 +439,7 @@ gboolean periodic_updater(gpointer data)
|
|||||||
GET_UI_ELEMENT(GtkLabel, label_controller_type);
|
GET_UI_ELEMENT(GtkLabel, label_controller_type);
|
||||||
int controller_type;
|
int controller_type;
|
||||||
|
|
||||||
if (app->current_adapter_handle) {
|
if (app->current_adapter_handle && !app->inhibit_periodic_updates) {
|
||||||
controller_type = gcn64lib_getControllerType(app->current_adapter_handle, 0);
|
controller_type = gcn64lib_getControllerType(app->current_adapter_handle, 0);
|
||||||
gtk_label_set_text(label_controller_type, gcn64lib_controllerName(controller_type));
|
gtk_label_set_text(label_controller_type, gcn64lib_controllerName(controller_type));
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ struct application {
|
|||||||
|
|
||||||
struct mpkedit_data *mpke;
|
struct mpkedit_data *mpke;
|
||||||
int stop_reading_mempak;
|
int stop_reading_mempak;
|
||||||
|
int inhibit_periodic_updates;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user