diff options
| author | Bdale Garbee <bdale@gag.com> | 2018-03-18 15:50:16 -0600 | 
|---|---|---|
| committer | Bdale Garbee <bdale@gag.com> | 2018-03-18 15:50:16 -0600 | 
| commit | 55b62bb5d6a9d6b484bcd0d802964d529dd5f9bb (patch) | |
| tree | 1a93442d43fcad172879d76629d4ed47ce3d6575 /altoslib/AltosRomconfig.java | |
| parent | 558d2c94fe8c49d0544a3e7bc5ba11b60c4faa1e (diff) | |
| parent | 59e23c27c2a85d7d748223e444b24d19937afe47 (diff) | |
Merge branch 'branch-1.8' into debian
Diffstat (limited to 'altoslib/AltosRomconfig.java')
| -rw-r--r-- | altoslib/AltosRomconfig.java | 71 | 
1 files changed, 56 insertions, 15 deletions
diff --git a/altoslib/AltosRomconfig.java b/altoslib/AltosRomconfig.java index 46ee2b6e..1fbb4115 100644 --- a/altoslib/AltosRomconfig.java +++ b/altoslib/AltosRomconfig.java @@ -26,20 +26,31 @@ public class AltosRomconfig {  	public int	check;  	public int	serial_number;  	public int	radio_calibration; +	public AltosUsbId	usb_id; +	public String		usb_product; -	static private int find_offset(AltosHexfile hexfile, String name, int len) throws AltosNoSymbol { +	static private long find_address(AltosHexfile hexfile, String name, int len) throws AltosNoSymbol {  		AltosHexsym symbol = hexfile.lookup_symbol(name); -		if (symbol == null) -			throw new AltosNoSymbol(name); -		int offset = (int) symbol.address - hexfile.address; -		if (offset < 0 || hexfile.data.length < offset + len) +		if (symbol == null) { +			System.out.printf("no symbol %s\n", name);  			throw new AltosNoSymbol(name); -		return offset; +		} +		if (hexfile.address <= symbol.address && symbol.address + len < hexfile.max_address) { +			System.out.printf("%s: %x\n", name, symbol.address); +			return symbol.address; +		} +		System.out.printf("invalid symbol addr %x range is %x - %x\n", +				  symbol.address, hexfile.address, hexfile.max_address); +		throw new AltosNoSymbol(name); +	} + +	static private int find_offset(AltosHexfile hexfile, String name, int len) throws AltosNoSymbol { +		return (int) (find_address(hexfile, name, len) - hexfile.address);  	}  	static int get_int(AltosHexfile hexfile, String name, int len) throws AltosNoSymbol {  		byte[] bytes = hexfile.data; -		int start = find_offset(hexfile, name, len); +		int start = (int) find_offset(hexfile, name, len);  		int	v = 0;  		int	o = 0; @@ -112,13 +123,17 @@ public class AltosRomconfig {  	public AltosRomconfig(AltosHexfile hexfile) {  		try { +			System.out.printf("Attempting symbols\n");  			version = get_int(hexfile, ao_romconfig_version, 2); +			System.out.printf("version %d\n", version);  			check = get_int(hexfile, ao_romconfig_check, 2); +			System.out.printf("check %d\n", check);  			if (check == (~version & 0xffff)) {  				switch (version) {  				case 2:  				case 1:  					serial_number = get_int(hexfile, ao_serial_number, 2); +					System.out.printf("serial %d\n", serial_number);  					try {  						radio_calibration = get_int(hexfile, ao_radio_cal, 4);  					} catch (AltosNoSymbol missing) { @@ -128,6 +143,19 @@ public class AltosRomconfig {  					break;  				}  			} +			System.out.printf("attempting usbid\n"); +			usb_id = hexfile.find_usb_id(); +			if (usb_id == null) +				System.out.printf("No usb id\n"); +			else +				System.out.printf("usb id: %04x:%04x\n", +						  usb_id.vid, usb_id.pid); +			usb_product = hexfile.find_usb_product(); +			if (usb_product == null) +				System.out.printf("No usb product\n"); +			else +				System.out.printf("usb product: %s\n", usb_product); +  		} catch (AltosNoSymbol missing) {  			valid = false;  		} @@ -137,9 +165,16 @@ public class AltosRomconfig {  		ao_romconfig_version,  		ao_romconfig_check,  		ao_serial_number, -		ao_radio_cal +		ao_radio_cal, +		ao_usb_descriptors,  	}; +	private static int fetch_len(String name) { +		if (name.equals(ao_usb_descriptors)) +			return 256; +		return 2; +	} +  	private final static String[] required_names = {  		ao_romconfig_version,  		ao_romconfig_check, @@ -153,13 +188,16 @@ public class AltosRomconfig {  		return false;  	} -	public static int fetch_base(AltosHexfile hexfile) throws AltosNoSymbol { -		int	base = 0x7fffffff; +	public static long fetch_base(AltosHexfile hexfile) throws AltosNoSymbol { +		long	base = 0xffffffffL;  		for (String name : fetch_names) {  			try { -				int	addr = find_offset(hexfile, name, 2) + hexfile.address; +				int	len = fetch_len(name); +				long	addr = find_address(hexfile, name, len); +  				if (addr < base)  					base = addr; +				System.out.printf("symbol %s at %x base %x\n", name, addr, base);  			} catch (AltosNoSymbol ns) {  				if (name_required(name))  					throw (ns); @@ -168,19 +206,22 @@ public class AltosRomconfig {  		return base;  	} -	public static int fetch_bounds(AltosHexfile hexfile) throws AltosNoSymbol { -		int	bounds = 0; +	public static long fetch_bounds(AltosHexfile hexfile) throws AltosNoSymbol { +		long	bounds = 0;  		for (String name : fetch_names) {  			try { -				int	addr = find_offset(hexfile, name, 2) + hexfile.address; +				int	len = fetch_len(name); +				long	addr = find_address(hexfile, name, len) + len;  				if (addr > bounds)  					bounds = addr; +				System.out.printf("symbol %s at %x bounds %x\n", name, addr, bounds);  			} catch (AltosNoSymbol ns) {  				if (name_required(name))  					throw (ns);  			}  		} -		return bounds + 2; + +		return bounds;  	}  	public void write (AltosHexfile hexfile) throws IOException {  | 
