Read serial number from flash
Write there with OpenOCD and GDB: ``` (gdb) monitor flash write_bank 0 serial.bin 0x00ff000 Writing 18 bytes starting at 0xff000 wrote 18 bytes from file serial.bin to flash bank 0 at offset 0x000ff000 in 0.206887s (0.085 KiB/s) ``` Signed-off-by: Daniel Schaefer <dhs@frame.work>
This commit is contained in:
parent
c97f3cd6d8
commit
3f5388f97f
@ -10,6 +10,7 @@
|
||||
enum factory_commands {
|
||||
f_emu_keypress = 0x01, // Next byte is keycode
|
||||
f_adc = 0x03, // ADC trigger
|
||||
f_serialnum = 0x04, // Read device serial number
|
||||
f_bootloader = 0xFE,
|
||||
};
|
||||
|
||||
@ -26,11 +27,19 @@ void emulate_rgb_keycode_press(uint16_t target_keycode) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#define FLASH_OFFSET 0x10000000
|
||||
#define LAST_4K_BLOCK 0xff000
|
||||
#define SERIALNUM_LEN 18
|
||||
|
||||
void handle_factory_command(uint8_t *data) {
|
||||
uint8_t factory_command_id = data[0];
|
||||
uint8_t *command_data = &(data[1]);
|
||||
uprintf("handle_factory_command(command: %u)\n", factory_command_id);
|
||||
|
||||
char serialnum[SERIALNUM_LEN+1];
|
||||
serialnum[SERIALNUM_LEN] = '\0';
|
||||
char *serialnum_ptr = (char*) (FLASH_OFFSET + LAST_4K_BLOCK);
|
||||
|
||||
switch (factory_command_id) {
|
||||
case f_bootloader:
|
||||
print("bootloader_jump\n");
|
||||
@ -47,6 +56,13 @@ void handle_factory_command(uint8_t *data) {
|
||||
case f_adc:
|
||||
factory_trigger_adc();
|
||||
break;
|
||||
case f_serialnum:
|
||||
print("Reading Device serial number\n");
|
||||
|
||||
memcpy(serialnum, serialnum_ptr, SERIALNUM_LEN);
|
||||
|
||||
uprintf("Serial number: %s\n", serialnum);
|
||||
break;
|
||||
default:
|
||||
uprintf("Unknown factory command: %u\n", factory_command_id);
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user