altoslib: Don't require radio_cal or usb_descriptors in AltosRomconfig
[fw/altos] / altoslib / AltosRomconfig.java
index 7d9cc09611ebc9412918abc573980627d658d4c5..2f106deb8223aca4be55d391d091da5a4ef6ff1a 100644 (file)
@@ -118,7 +118,11 @@ public class AltosRomconfig {
                                case 2:
                                case 1:
                                        serial_number = get_int(hexfile, ao_serial_number, 2);
                                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;
                                }
                                        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
        };
 
                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) {
        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;
        }
                }
                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) {
        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;
        }
                }
                return bounds + 2;
        }
@@ -166,10 +193,17 @@ public class AltosRomconfig {
                try {
                        switch (existing.version) {
                        case 2:
                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);
                        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) {
                                break;
                        }
                } catch (AltosNoSymbol missing) {