ao-tools: Create general elf and hex library routines
[fw/altos] / ao-tools / ao-stmload / ao-selfload.c
index b3105b211beebe8f046d62286b5b7d8c0c884cae..dee1c3cbd6d3ac151e9279eb0f0e63d5423bca86 100644 (file)
 #include "ccdbg.h"
 #include "ao-stmload.h"
 
+int    ao_self_verbose;
+
+#define TRACE(...) if (ao_self_verbose) printf (__VA_ARGS__)
+
 void
 ao_self_block_read(struct cc_usb *cc, uint32_t address, uint8_t block[256])
 {
        int                     byte;
        cc_usb_sync(cc);
        cc_usb_printf(cc, "R %x\n", address);
-//     printf ("read %08x\n", address);
        for (byte = 0; byte < 0x100; byte++) {
                block[byte] = cc_usb_getchar(cc);
-//             printf (" %02x", block[byte]);
-//             if ((byte & 0xf) == 0xf)
-//                     printf ("\n");
+       }
+       TRACE ("\nread %08x\n", address);
+       for (byte = 0; byte < 0x100; byte++) {
+               TRACE (" %02x", block[byte]);
+               if ((byte & 0xf) == 0xf)
+                       TRACE ("\n");
        }
 }
 
@@ -47,25 +53,27 @@ ao_self_block_write(struct cc_usb *cc, uint32_t address, uint8_t block[256])
        int                     byte;
        cc_usb_sync(cc);
        cc_usb_printf(cc, "W %x\n", address);
-//     printf ("write %08x\n", address);
+       TRACE ("write %08x\n", address);
+       for (byte = 0; byte < 0x100; byte++) {
+               TRACE (" %02x", block[byte]);
+               if ((byte & 0xf) == 0xf)
+                       TRACE ("\n");
+       }
        for (byte = 0; byte < 0x100; byte++) {
                cc_usb_printf(cc, "%c", block[byte]);
-//             printf (" %02x", block[byte]);
-//             if ((byte & 0xf) == 0xf)
-//                     printf ("\n");
        }
 }
 
-struct hex_image *
+struct ao_hex_image *
 ao_self_read(struct cc_usb *cc, uint32_t address, uint32_t length)
 {
-       struct hex_image        *image;
+       struct ao_hex_image     *image;
        int                     pages;
        int                     page;
        uint32_t                base = address & ~0xff;
        uint32_t                bound = (address + length + 0xff) & ~0xff;
 
-       image = calloc(sizeof (struct hex_image) + (bound - base), 1);
+       image = calloc(sizeof (struct ao_hex_image) + (bound - base), 1);
        image->address = base;
        image->length = bound - base;
        pages = image->length / 0x100;
@@ -75,7 +83,7 @@ ao_self_read(struct cc_usb *cc, uint32_t address, uint32_t length)
 }
 
 int
-ao_self_write(struct cc_usb *cc, struct hex_image *image)
+ao_self_write(struct cc_usb *cc, struct ao_hex_image *image)
 {
        uint8_t         block[256];
        uint8_t         check[256];
@@ -114,5 +122,6 @@ ao_self_write(struct cc_usb *cc, struct hex_image *image)
                putchar('.'); fflush(stdout);
        }
        printf("done\n");
+       cc_usb_printf(cc,"a\n");
        return 1;
 }