From: Keith Packard Date: Mon, 9 Dec 2013 04:33:22 +0000 (-0800) Subject: altoslib: Don't require radio_cal or usb_descriptors in AltosRomconfig X-Git-Tag: 1.3~55 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=fd92bb8ff3be257925bf6e969d93a7f9dd941fb8;hp=68adbf5bf08ed8af2f34c0d95d9c3d457574372d altoslib: Don't require radio_cal or usb_descriptors in AltosRomconfig Not all products will have these values, so allow them to be missing Signed-off-by: Keith Packard --- diff --git a/altoslib/AltosRomconfig.java b/altoslib/AltosRomconfig.java index 7d9cc096..2f106deb 100644 --- a/altoslib/AltosRomconfig.java +++ b/altoslib/AltosRomconfig.java @@ -118,7 +118,11 @@ public class AltosRomconfig { case 2: case 1: serial_number = get_int(hexfile, ao_serial_number, 2); - radio_calibration = get_int(hexfile, ao_radio_cal, 4); + try { + radio_calibration = get_int(hexfile, ao_radio_cal, 4); + } catch (AltosNoSymbol missing) { + radio_calibration = 0; + } valid = true; break; } @@ -128,19 +132,37 @@ public class AltosRomconfig { } } - final static String[] fetch_names = { + private final static String[] fetch_names = { ao_romconfig_version, ao_romconfig_check, ao_serial_number, ao_radio_cal }; + private final static String[] required_names = { + ao_romconfig_version, + ao_romconfig_check, + ao_serial_number + }; + + private static boolean name_required(String name) { + for (String required : required_names) + if (name.equals(required)) + return true; + return false; + } + public static int fetch_base(AltosHexfile hexfile) throws AltosNoSymbol { int base = 0x7fffffff; for (String name : fetch_names) { - int addr = find_offset(hexfile, name, 2) + hexfile.address; - if (addr < base) - base = addr; + try { + int addr = find_offset(hexfile, name, 2) + hexfile.address; + if (addr < base) + base = addr; + } catch (AltosNoSymbol ns) { + if (name_required(name)) + throw (ns); + } } return base; } @@ -148,9 +170,14 @@ public class AltosRomconfig { public static int fetch_bounds(AltosHexfile hexfile) throws AltosNoSymbol { int bounds = 0; for (String name : fetch_names) { - int addr = find_offset(hexfile, name, 2) + hexfile.address; - if (addr > bounds) - bounds = addr; + try { + int addr = find_offset(hexfile, name, 2) + hexfile.address; + if (addr > bounds) + bounds = addr; + } catch (AltosNoSymbol ns) { + if (name_required(name)) + throw (ns); + } } return bounds + 2; } @@ -166,10 +193,17 @@ public class AltosRomconfig { try { switch (existing.version) { case 2: - put_usb_serial(serial_number, hexfile, ao_usb_descriptors); + try { + put_usb_serial(serial_number, hexfile, ao_usb_descriptors); + } catch (AltosNoSymbol missing) { + } + /* fall through ... */ case 1: put_int(serial_number, hexfile, ao_serial_number, 2); - put_int(radio_calibration, hexfile, ao_radio_cal, 4); + try { + put_int(radio_calibration, hexfile, ao_radio_cal, 4); + } catch (AltosNoSymbol missing) { + } break; } } catch (AltosNoSymbol missing) {