*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-package org.altusmetrum.altoslib_2;
+package org.altusmetrum.altoslib_12;
import java.io.*;
int b;
byte[] data = new byte[len];
+ System.out.printf("read_memory %x %d\n", addr, len);
for (int offset = 0; offset < len; offset += 0x100) {
link.printf("R %x\n", addr + offset);
byte[] reply = link.get_binary_reply(5000, 0x100);
-
+
if (reply == null)
throw new IOException("Read device memory timeout");
- for (b = 0; b < len; b++)
+ for (b = 0; b < 0x100 && b + offset < len; b++)
data[b+offset] = reply[b];
}
return data;
}
-
+
+ AltosHexfile read_hexfile(long addr, int len) throws InterruptedException {
+ try {
+ byte[] mem = read_memory(addr, len);
+
+ AltosHexfile hexfile = new AltosHexfile(mem, addr);
+
+ if (image != null)
+ hexfile.add_symbols(image);
+ return hexfile;
+ } catch (IOException ie) {
+ return null;
+ }
+ }
+
void write_memory(long addr, byte[] data, int start, int len) {
int b;
- System.out.printf ("write_memory %x %d\n", addr, len);
link.printf("W %x\n", addr);
link.flush_output();
for (b = 0; b < len; b++)
}
void reboot() {
- System.out.printf("reboot\n");
link.printf("a\n");
link.flush_output();
}
action(image.data.length - remain, image.data.length);
}
if (!aborted) {
- System.out.printf ("done\n");
action("done", 100);
}
close();
public void close() {
if (link != null) {
reboot();
- link.close();
+ try {
+ link.close();
+ } catch (InterruptedException ie) {
+ }
link = null;
}
}
close();
}
- private AltosHexfile get_rom() {
- System.out.printf("get rom\n");
+ private AltosHexfile get_rom() throws InterruptedException {
try {
- int base = AltosRomconfig.fetch_base(image);
- int bounds = AltosRomconfig.fetch_bounds(image);
- byte[] data = read_memory(base, bounds - base);
- AltosHexfile hexfile = new AltosHexfile(data, base);
- hexfile.add_symbols(image);
- return hexfile;
- } catch (AltosNoSymbol none) {
- System.out.printf("no symbol %s\n", none.getMessage());
- return null;
- } catch (InterruptedException ie) {
- return null;
- } catch (IOException ie) {
+ long base = AltosRomconfig.fetch_base(image);
+ long bounds = AltosRomconfig.fetch_bounds(image);
+
+ System.out.printf("rom base %x bounds %x\n", base, bounds);
+ return read_hexfile(base, (int) (bounds - base));
+ } catch (AltosNoSymbol ns) {
return null;
}
-
}
- public boolean check_rom_config() {
+ public boolean check_rom_config() throws InterruptedException {
if (link == null) {
- System.out.printf ("no link\n");
return true;
}
if (rom_config == null) {
rom_config = romconfig;
}
- public AltosRomconfig romconfig() {
- System.out.printf("fetch romconfig\n");
+ public AltosRomconfig target_romconfig() throws InterruptedException {
if (!check_rom_config())
return null;
return rom_config;
}
+ public AltosRomconfig image_romconfig() {
+ return new AltosRomconfig(image);
+ }
+
public AltosSelfFlash(File file, AltosLink link, AltosFlashListener listener)
throws IOException, FileNotFoundException, InterruptedException {
this.file = file;
this.listener = listener;
input = new FileInputStream(file);
image = new AltosHexfile(input);
- System.out.printf ("AltosSelfFlash %x\n", image.address);
}
-}
\ No newline at end of file
+}