- public void flash() throws IOException, FileNotFoundException, InterruptedException {
- if (!check_rom_config())
- throw new IOException("Invalid rom config settings");
- if (image.address + image.data.length > 0x8000)
- throw new IOException(String.format("Flash image too long %d",
- image.address +
- image.data.length));
- if ((image.address & 0x3ff) != 0)
- throw new IOException(String.format("Flash image must start on page boundary (is 0x%x)",
- image.address));
- int ram_address = 0xf000;
- int flash_prog = 0xf400;
-
- /*
- * Store desired config values into image
- */
- rom_config.write(image);
- /*
- * Bring up the clock
- */
- clock_init();
-
- int remain = image.data.length;
- int flash_addr = image.address;
- int image_start = 0;
-
- action("start", 0);
- action(0, image.data.length);
- while (remain > 0 && !aborted) {
- int this_time = remain;
- if (this_time > 0x400)
- this_time = 0x400;
-
- /* write the data */
- debug.write_memory(ram_address, image.data,
- image_start, this_time);
-
- /* write the flash program */
- byte[] flash_page = make_flash_page(flash_addr,
- ram_address,
- this_time);
- debug.write_memory(flash_prog, flash_page);
-
- run(flash_prog);
-
- byte[] check = debug.read_memory(flash_addr, this_time);
- for (int i = 0; i < this_time; i++)
- if (check[i] != image.data[image_start + i])
- throw new IOException(String.format("Flash write failed at 0x%x (%02x != %02x)",
- image.address + image_start + i,
- check[i], image.data[image_start + i]));
- remain -= this_time;
- flash_addr += this_time;
- image_start += this_time;
-
- action(image.data.length - remain, image.data.length);
+ Thread thread;
+
+ public void run() {
+ try {
+ if (!check_rom_config())
+ throw new IOException("Invalid rom config settings");
+ if (image.address + image.data.length > 0x8000)
+ throw new IOException(String.format("Flash image too long %d",
+ image.address +
+ image.data.length));
+ if ((image.address & 0x3ff) != 0)
+ throw new IOException(String.format("Flash image must start on page boundary (is 0x%x)",
+ image.address));
+ int ram_address = 0xf000;
+ int flash_prog = 0xf400;
+
+ /*
+ * Store desired config values into image
+ */
+ rom_config.write(image);
+ /*
+ * Bring up the clock
+ */
+ clock_init();
+
+ int remain = image.data.length;
+ int flash_addr = image.address;
+ int image_start = 0;
+
+ action("start", 0);
+ action(0, image.data.length);
+ while (remain > 0 && !aborted) {
+ int this_time = remain;
+ if (this_time > 0x400)
+ this_time = 0x400;
+
+ if (debug != null) {
+ /* write the data */
+ debug.write_memory(ram_address, image.data,
+ image_start, this_time);
+
+ /* write the flash program */
+ byte[] flash_page = make_flash_page(flash_addr,
+ ram_address,
+ this_time);
+ debug.write_memory(flash_prog, flash_page);
+
+ altos_run(flash_prog);
+ byte[] check = debug.read_memory(flash_addr, this_time);
+ for (int i = 0; i < this_time; i++)
+ if (check[i] != image.data[image_start + i])
+ throw new IOException(String.format("Flash write failed at 0x%x (%02x != %02x)",
+ image.address + image_start + i,
+ check[i], image.data[image_start + i]));
+ } else {
+ Thread.sleep(100);
+ }
+
+ remain -= this_time;
+ flash_addr += this_time;
+ image_start += this_time;
+
+ action(image.data.length - remain, image.data.length);
+ }
+ if (!aborted) {
+ action("done", 100);
+ if (debug != null) {
+ debug.set_pc(image.address);
+ debug.resume();
+ }
+ }
+ if (debug != null)
+ debug.close();
+ } catch (IOException ie) {
+ action(ie.getMessage(), -1);
+ abort();
+ } catch (InterruptedException ie) {
+ abort();