- 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;