From 5bdf8eeb1cdc1a50c9abd0f8962533f6970bd7f0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 3 Dec 2019 19:31:34 -0800 Subject: [PATCH] altoslib: Linker script changed -> the USB desc is two bytes off The USB descriptor used to be at 0x0800110c in previous releases and is now at 0x0800110a, presumably because the linker script changed the padding requirements of those sections. Search forward and backwards two bytes to see if we can't find the descriptors by checking for the descriptor value and size at each location. Signed-off-by: Keith Packard --- altoslib/AltosHexfile.java | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/altoslib/AltosHexfile.java b/altoslib/AltosHexfile.java index 609d1bcb..cf99cded 100644 --- a/altoslib/AltosHexfile.java +++ b/altoslib/AltosHexfile.java @@ -295,15 +295,20 @@ public class AltosHexfile { return -1; try { - /* Walk the descriptors looking for the device */ + /* The address of this has moved depending on + * padding in the linker script. Look forward + * and backwards two bytes to see if we can find it + */ 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; - } - return a; + + if (get_u8(a) == 0x12 && get_u8(a+1) == AO_USB_DESC_DEVICE) + return a; + else if (get_u8(a+1) == 0x12 && get_u8(a+3) == AO_USB_DESC_DEVICE) + return a + 2; + else if (get_u8(a-2) == 0x12 && get_u8(a-1) == AO_USB_DESC_DEVICE) + return a - 2; + + return -1; } catch (ArrayIndexOutOfBoundsException ae) { return -1; } -- 2.30.2