Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed Serial Number #4

Open
JohnAZoidberg opened this issue Jan 5, 2023 · 4 comments
Open

Embed Serial Number #4

JohnAZoidberg opened this issue Jan 5, 2023 · 4 comments
Labels
cleanup Working but needs cleanup in progress work in progress pvt Should be ready for PVT stale

Comments

@JohnAZoidberg
Copy link
Member

JohnAZoidberg commented Jan 5, 2023

Put somewhere it won't be overridden by the customer flashing their own firmware.

Two options:

  • Embed with linker script
  • Embed with UF2

For both we have to create a build script that builds a different variant of the firmware.
The script accepts the serial number and embeds it in the image.

The regular build script that customers would use builds an image that doesn't include this section with the serial number. And it also must avoid overriding the serial number when flashing.

Linker Script

The serial number could be embedded in the executable via a linker script. QMK let's you easily use your own linker script.
@kiram9 you suggested this. How would we avoid the customer overwriting the serial number when they flash their own binary?

WIP branch: https://github.com/FrameworkComputer/qmk_firmware/commits/lotus-ld

UF2

A UF2 file is just a series of independent 512B blocks that each say which address they should be flashed to and include the data.
I think if we put a block at the end it won't interfere with the firmware. But the script must check that there is enough empty space.
We can reserve one of these blocks for the serial number. The factory build script includes this block in the UF2 file, the regular script doesn't.

This way the serial number is preserved if the customer uses the default build script that we'll upstream to QMK.
They could modify it to overwrite the entire flash.

@JohnAZoidberg
Copy link
Member Author

UF2 should be able to be concatenated.
So the factory file could be created by running a script on the regular binary:

./embed_serial --bin .build/lotus_ansi_default.uf2 --serial 123456789

@JohnAZoidberg
Copy link
Member Author

If we put the serial number at the end of the flash, users won't accidentally overwrite it if they create a bigger binary.
Only if it fills the entire flash.

The flash chip we use supports locking 4K sections. So we could even lock it to avoid it being overwritten.

@JohnAZoidberg
Copy link
Member Author

JohnAZoidberg commented Jan 16, 2023

Current solution:

  • Use separate UF2 file that flashes at 0x100ff000. Which is 4KB below 1MB.

UF2 generation and flashing is done like:

echo -n 'FRALDLENA120110001' > serial.bin
./util/uf2conv.py serial.bin -o serial.uf2 -b 0x100ff000 -f rp2040 --convert
sudo cp serial.uf2 /media/zoid/RPI-RP2/

TODO:

  • Create diagram of full memory map including EEPROM emulated area
  • See if we can combine both UF2 files. I tried but the serial number isn't properly written.
  • Make sure the factory script has everything is needs. Serial number generation?
  • Cleaner hook into USB subsystem for iSerialNumber so that we can upstream it
    • And read from flash only once
    • Implement for tmk_core/protocol/vusb/vusb.c
  • Try to write-protect the region
  • Use dummy serial number FRALDLvvccxxxxxxxx if the flash was completely erased

@JohnAZoidberg JohnAZoidberg added the cleanup Working but needs cleanup label Jan 16, 2023
@JohnAZoidberg
Copy link
Member Author

VIA puts configuration in emulated eeprom at the end of flash. Might conflict with the serial number.

@JohnAZoidberg JohnAZoidberg added the pvt Should be ready for PVT label Feb 8, 2023
@github-actions github-actions bot added the stale label May 10, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2023
@JohnAZoidberg JohnAZoidberg reopened this Jul 21, 2023
@github-actions github-actions bot removed the stale label Jul 22, 2023
@github-actions github-actions bot added the stale label Oct 21, 2023
@JohnAZoidberg JohnAZoidberg added the in progress work in progress label Oct 25, 2023
@FrameworkComputer FrameworkComputer deleted a comment from github-actions bot Oct 25, 2023
@FrameworkComputer FrameworkComputer deleted a comment from github-actions bot Oct 25, 2023
@FrameworkComputer FrameworkComputer deleted a comment from github-actions bot Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Working but needs cleanup in progress work in progress pvt Should be ready for PVT stale
Projects
None yet
Development

No branches or pull requests

1 participant