Skip to content

Commit

Permalink
[3298 - patch 34] When loading a firmware during flash initialization…
Browse files Browse the repository at this point in the history
…, check for the KINPOUPDATEIMAGE signature, and fail if it's missing

[3298 - patch 35] When selecting a firmware interactively, show errors in a message window and retry
The user may not even have a terminal open to catch the error message, so the previous behavior was basically a silent failure to them.
[3298 - patch 36] Add newRPL keyboard layouts via new calculator types "hp49gp/newrpl" and "hp50g/newrpl"
Also fixes an old bug causing only a single keyboard layout to be used, regardless of selected calculator type.
It appears nobody noticed this bug because the only two layouts present before this commit were almost identical.
  • Loading branch information
claudiol committed Oct 10, 2018
1 parent 48d0c97 commit 0df95a3
Show file tree
Hide file tree
Showing 3 changed files with 851 additions and 59 deletions.
100 changes: 87 additions & 13 deletions flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ flash_load(x49gp_module_t *module, GKeyFile *key)
int error;
int i;
char bank_marker[5] = {0xf0, 0x02, 0x00, 0x00, 0x00};
int bytes_read;

#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
Expand Down Expand Up @@ -521,7 +522,8 @@ flash_load(x49gp_module_t *module, GKeyFile *key)
flash->size - st.st_size);

bootfd = x49gp_module_open_rodata(module,
calc == UI_CALCULATOR_HP49GP ?
calc == UI_CALCULATOR_HP49GP ||
calc == UI_CALCULATOR_HP49GP_NEWRPL ?
"boot-49g+.bin" :
"boot-50g.bin",
&bootfile);
Expand Down Expand Up @@ -568,6 +570,7 @@ flash_load(x49gp_module_t *module, GKeyFile *key)
}
}

retry:
filename = NULL;
if (x49gp->firmware != NULL) {
filename = g_strdup(x49gp->firmware);
Expand All @@ -580,35 +583,106 @@ flash_load(x49gp_module_t *module, GKeyFile *key)
fprintf(stderr, "%s: %s:%u: open %s: %s\n",
module->name, __FUNCTION__, __LINE__,
filename, strerror(errno));
fprintf(stderr, "Warning: Could not open "
"selected firmware, falling back to "
"bootloader recovery tools\n");
/* Mark firmware as invalid if there is one */
memset(phys_ram_base + flash->offset +
BOOT_SIZE, 0, 16);
if (x49gp->firmware != NULL) {
fprintf(stderr, "Warning: Could not "
"open selected firmware, "
"falling back to bootloader "
"recovery tools\n");
} else {
x49gp_ui_show_error(x49gp,
"Could not open "
"selected "
"firmware!");
goto retry;
}
} else {
bytes_read = read(fwfd, phys_ram_base +
flash->offset + BOOT_SIZE,
16);
if (bytes_read < 0) {
fprintf(stderr, "%s: %s:%u: read %s: %s\n",
module->name, __FUNCTION__,
__LINE__, filename,
strerror(errno));
/* Mark firmware as invalid
if there is one */
memset(phys_ram_base + flash->offset +
BOOT_SIZE, 0, 16);
if (x49gp->firmware != NULL) {
fprintf(stderr, "Warning: "
"Could not read "
"selected firmware, "
"falling back to "
"bootloader recovery "
"tools\n");
} else {
x49gp_ui_show_error(x49gp,
"Could not "
"read "
"selected "
"firmware!");
goto retry;
}
} else if (bytes_read < 16 ||
memcmp(phys_ram_base +
flash->offset + BOOT_SIZE,
"KINPOUPDATEIMAGE", 16)
!= 0) {
/* Mark firmware as invalid */
memset(phys_ram_base + flash->offset +
BOOT_SIZE, 0, 16);
if (x49gp->firmware != NULL) {
fprintf(stderr, "Warning: "
"Firmware is invalid, "
"falling back to "
"bootloader recovery "
"tools\n");
} else {
x49gp_ui_show_error(x49gp,
"Selected "
"firmware "
"is "
"invalid!");
goto retry;
}
/* The firmware may be shorter than
SST29VF160_SIZE - BOOT_SIZE, but if so,
read will just give us what it sees.
The space after that will remain empty. */
if (read(fwfd, phys_ram_base + flash->offset +
BOOT_SIZE,
SST29VF160_SIZE - BOOT_SIZE) < 0) {
} else if (read(fwfd, phys_ram_base +
flash->offset + BOOT_SIZE + 16,
SST29VF160_SIZE -
(BOOT_SIZE + 16))
< 0) {
fprintf(stderr, "%s: %s:%u: read %s: %s\n",
module->name, __FUNCTION__,
__LINE__, filename,
strerror(errno));
fprintf(stderr, "Warning: Could not "
"read selected firmware, "
"falling back to bootloader "
"recovery tools\n");
/* Mark firmware as invalid
if there is one */
memset(phys_ram_base + flash->offset +
BOOT_SIZE, 0, 16);
if (x49gp->firmware != NULL) {
fprintf(stderr, "Warning: "
"Could not read "
"selected firmware, "
"falling back to "
"bootloader recovery "
"tools\n");
} else {
x49gp_ui_show_error(x49gp,
"Could not "
"read "
"selected "
"firmware!");
goto retry;
}
} else {
/* Mark the firmware as valid in the
same way the bootloader does */
/* Mark firmware as valid in the same
way the bootloader does */
memcpy(phys_ram_base + flash->offset +
BOOT_SIZE, "Kinposhcopyright",
16);
Expand Down
5 changes: 4 additions & 1 deletion include/x49gp_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ typedef enum {

typedef enum {
UI_CALCULATOR_HP49GP = 0,
UI_CALCULATOR_HP50G
UI_CALCULATOR_HP49GP_NEWRPL,
UI_CALCULATOR_HP50G,
UI_CALCULATOR_HP50G_NEWRPL
} x49gp_ui_calculator_t;


Expand Down Expand Up @@ -143,6 +145,7 @@ struct __x49gp_ui_s__ {
};

int x49gp_ui_init(x49gp_t *x49gp);
void x49gp_ui_show_error(x49gp_t *x49gp, const char *text);
void x49gp_ui_open_firmware(x49gp_t *x49gp, char **filename);

#endif /* !(_X49GP_UI_H) */
Loading

0 comments on commit 0df95a3

Please sign in to comment.