Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[fw/altos] / altoslib / AltosSelfFlash.java
index 537821729fc9a03adb4885d4d38337f2cede870b..c7ea147f97d70bd667b165e093ba6afef0652944 100644 (file)
@@ -45,18 +45,33 @@ public class AltosSelfFlash extends AltosProgrammer {
                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;
                link.printf("W %x\n", addr);
@@ -143,18 +158,14 @@ public class AltosSelfFlash extends AltosProgrammer {
 
        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) {
-                       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() throws InterruptedException {
@@ -173,12 +184,16 @@ public class AltosSelfFlash extends AltosProgrammer {
                rom_config = romconfig;
        }
 
-       public AltosRomconfig romconfig() throws InterruptedException {
+       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;
@@ -187,4 +202,4 @@ public class AltosSelfFlash extends AltosProgrammer {
                input = new FileInputStream(file);
                image = new AltosHexfile(input);
        }
-}
\ No newline at end of file
+}