Arduino Boot-Cloner

The boot cloner doesn't read the bootstrap from the device. It has the bootstrap code compiled into the sketch. You can stick in any bootstrap code you like with a handy program to format it into C source.

I didn't find anything in the boot cloner to do it, but this little bit of code will take a .hex file and format it nicely for inclusion in the bootcloner sketch.

#include <stdio.h>
#include <string.h>

main()
{
    char buf[4096];
    int n = 0;

    while( fgets(buf, sizeof(buf)-1, stdin)) {
        int len = strlen(buf);
        char *b;

        if ( len < 9) continue;
        buf[len-4] = 0;

        for ( b = buf+9; *b != 0; b += 2) {
            printf("0x%c%c, ", b[0], b[1]);
            n++;
        }
        printf("\n");
    }
    printf("/* %d bytes */\n", n);
}