X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altoslib%2FAltosHexfile.java;h=6a66a869454ef05fd77c3170cc4fa3d3d4b5cbd5;hb=master;hp=609d1bcb366f9f3ae747633f1f0a51e8894d04ad;hpb=3c48b0fd504ae97dfaca91d2064b5822ca6e1344;p=fw%2Faltos diff --git a/altoslib/AltosHexfile.java b/altoslib/AltosHexfile.java index 609d1bcb..71882600 100644 --- a/altoslib/AltosHexfile.java +++ b/altoslib/AltosHexfile.java @@ -16,7 +16,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_13; +package org.altusmetrum.altoslib_14; import java.io.*; import java.util.LinkedList; @@ -287,6 +287,8 @@ public class AltosHexfile { return null; } + private static final int look_around[] = { 0, -2, 2, -4, 4 }; + private long find_usb_descriptors() { AltosHexsym usb_descriptors = lookup_symbol("ao_usb_descriptors"); long a; @@ -294,19 +296,22 @@ public class AltosHexfile { if (usb_descriptors == null) return -1; - try { - /* Walk the descriptors looking for the device */ - a = usb_descriptors.address; - while (get_u8(a+1) != AO_USB_DESC_DEVICE) { - int delta = get_u8(a); - a += delta; - if (delta == 0 || a >= max_address) - return -1; + /* The address of this has moved depending on padding + * in the linker script and romconfig symbols. Look + * forward and backwards two and four bytes to see if + * we can find it + */ + a = usb_descriptors.address; + + for (int look : look_around) { + try { + if (get_u8(a + look) == 0x12 && get_u8(a + look + 1) == AO_USB_DESC_DEVICE) + return a; + } catch (ArrayIndexOutOfBoundsException ae) { + continue; } - return a; - } catch (ArrayIndexOutOfBoundsException ae) { - return -1; } + return -1; } public AltosUsbId find_usb_id() {