Option to include sketch in flash?

OK, took some time today, ran a few tests with essentially some variations on the following code.

volatile char UUID[]  = "<UUID=da51a9f0-9a49-11e0-aa80-0800200c9a66>";

char version[] = "UUID_TEST 0.04";

void setup()
{
  Serial.begin(115200);
  Serial.println(version);
  UUID[0] = UUID[0];
}

void loop(){}

Then I retrieved the whole 32K image with [dosbox windows 7]

cd C:\Program Files (x86)\arduino-0021\hardware\tools\avr\bin>
avrdude -C "C:\Program Files (x86)\arduino-0022\hardware\tools\avr\etc\avrdude.conf" -v -v -v -v -p atmega328p -c stk500 -U flash:r:"C:/arduino.bin":r -P\\.\COM5 -b57600

viewing the binary easily reveals the UUID. See picture attached.

Some notes:
The UUID array must be volatile and the assignment UUID[0] = UUID[0] are needed both otherwise the compiler optimizes it away.

size without UUID string: 1908 bytes
size with UUID string: 1960 bytes

so this proof of concept implementation took 52 bytes.

  • Remove the tag structure <UUID=...> (-7) => 45 bytes
  • Remove - signs in the UUID (-4) => 41 bytes
  • Make the UUID binary (-17) => 24 bytes.

proof is in the pudding test:

volatile uint8_t UUID[] = { 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 
                          0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65 };  // character e 16 times
                          
char version[] = "UUID_TEST 0.06";

void setup()
{
  Serial.begin(115200);
  Serial.println(version);
  UUID[0] = UUID[0];
}

void loop(){}

size without UUID uint8_t array : 1908 bytes
size with UUID uint8_t array: 1932 bytes
so UUID signature now takes 24 bytes.

OK tinkered enough :wink:
Rob