-
-
Notifications
You must be signed in to change notification settings - Fork 64
hisi: read the V5 die ID from the OTP shadow #188
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -685,15 +685,16 @@ static void hisi_ev300_sensor_clock(cJSON *j_inner) { | |
| } | ||
| } | ||
|
|
||
| bool hisi_ev300_get_die_id(char *buf, ssize_t len) { | ||
| if (chip_generation != HISI_V4) { | ||
| static bool hisi_ev300_get_die_id(char *buf, size_t len) { | ||
| const uint32_t base_id_addr = 0x12020400; | ||
| const int words = 6; | ||
|
|
||
| if (len < (size_t)words * 8 + 1) | ||
| return false; | ||
| } | ||
|
|
||
| uint32_t base_id_addr = 0x12020400; | ||
| char *ptr = buf; | ||
| for (uint32_t id_addr = base_id_addr + 5 * 4; id_addr >= base_id_addr; | ||
| id_addr -= 4) { | ||
| for (uint32_t id_addr = base_id_addr + (words - 1) * 4; | ||
| id_addr >= base_id_addr; id_addr -= 4) { | ||
| uint32_t val; | ||
| if (!mem_reg(id_addr, &val, OP_READ)) | ||
| return false; | ||
|
|
@@ -714,6 +715,92 @@ bool hisi_ev300_get_die_id(char *buf, ssize_t len) { | |
| return true; | ||
| } | ||
|
|
||
| /* Per-die identity on V5 (HISI_OT). | ||
| * | ||
| * V5 has no counterpart to the V4 die-ID block at 0x12020400. The vendor keeps | ||
| * the die ID in OTP and reaches it through a bootrom call (otp_get_die_id() in | ||
| * gsl/drivers/share_drivers/share_drivers.c), but every OTP row is also | ||
| * shadowed into a register window at the same offset it occupies in OTP, so | ||
| * the 16 bytes of OTP_DIE_ID appear at OTP_SHADOW_BASE + 0xF0. | ||
| * | ||
| * Both vendor SDKs that cover the five HISI_OT parts agree on the window: | ||
| * Hi3516CV610_SDK_V1.0.2.0, covering 3516CV608/CV610/CV613: | ||
| * gsl/include/platform.h OTP_SHADOW_BASE = SCPU_OTPC_BASE_ADDR | ||
| * = 0x101E0000 | ||
| * gsl/drivers/otp/otp.h OTP_DIE_ID 0xF0, 16 bytes | ||
| * Hi3519DV500 SDK R11, covering both DV500 parts in one bsp tree (see | ||
| * bsp/pub/hi3516dv500_image_glibc and svb.h's OTP_16D/OTP_19D ids): | ||
| * gsl/include/platform.h OTP_SHADOW_BASE = SCPU_OTPC_BASE_ADDR | ||
| * = 0x101E0000 | ||
| * gsl/drivers/otp/otp.h OTP_DIE_ID 0xF0, 16 bytes | ||
| * | ||
| * The window is readable from the non-secure side: the OEM's own hwconf.ko | ||
| * ioremaps the ATE chip version register in it from an ordinary kernel module | ||
| * (OTP_VERSION_ID_REG, +0x10C on the CV6xx parts and +0x120 on the DV500s). | ||
| */ | ||
| #define V5_OTP_SHADOW_BASE 0x101E0000u | ||
| #define V5_OTP_DIE_ID 0xF0 | ||
| #define V5_DIE_ID_WORDS 4 | ||
|
|
||
| static bool hisi_ot_get_die_id(char *buf, size_t len) { | ||
| uint32_t id[V5_DIE_ID_WORDS]; | ||
| uint8_t bytes[sizeof id]; | ||
|
|
||
| if (len < 2 * sizeof bytes + 1) | ||
| return false; | ||
|
|
||
| for (size_t i = 0; i < V5_DIE_ID_WORDS; i++) { | ||
| if (!mem_reg(V5_OTP_SHADOW_BASE + V5_OTP_DIE_ID + i * 4, &id[i], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blocking. This base is verified on one CV608, and the SDK it comes from covers CV608/CV610/CV613, but it runs on every Two failure modes if
Suggest gating the reader on the chip IDs the CV610 SDK covers until a DV500 or 3519DV500 has been measured. The read is harmless, so this is the whole test: for a in 0x101E00F0 0x101E00F4 0x101E00F8 0x101E00FC 0x101E010C; do devmem $a 32; done
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The DV500 SDK answers this, and it says the base is not CV610-only.
Identical to the CV610 SDK's One correction to the probe, which matters if you run it: for a in 0x101E00F0 0x101E00F4 0x101E00F8 0x101E00FC 0x101E0120; do devmem $a 32; doneAs written it would have read a wrong offset on the lab 3519DV500 and looked like a failure. If you want belt-and-braces anyway after that, the honest version is a runtime self-check rather than a model list: read the version id and require it to look like its family's (
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, the DV500 SDK citations settle it: two vendor trees, all five Thanks also for the offset correction. I'd skip the runtime version-id self-check. It cannot help the bus-error half, and it would reintroduce the per-family table by another route. Per-die versus per-model stays open until a second gen5 board is read. Our lab CV608 and 3519DV500 were unreachable both days; we will run the probe on whichever comes back first and report here. |
||
| OP_READ)) | ||
| return false; | ||
| // Bytes are emitted in OTP order. The shadow words are little-endian, | ||
| // so byte i of what otp_get_die_id() would hand back is | ||
| // word[i / 4] >> (8 * (i % 4)). | ||
| for (size_t b = 0; b < 4; b++) | ||
| bytes[i * 4 + b] = (id[i] >> (8 * b)) & 0xFF; | ||
| } | ||
|
|
||
| for (size_t i = 0; i < sizeof bytes; i++) | ||
| snprintf(buf + 2 * i, len - 2 * i, "%02x", bytes[i]); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /* An OTP row that is unfused, locked or unbacked reads all-zeroes or all-ones, | ||
| * and a partially fused one reads a mixture of the two -- as does a V4 die-ID | ||
| * block on a part that never had one fused, which the trailing-zero strip above | ||
| * leaves as a string of zeroes rather than rejecting. | ||
| * | ||
| * None of those is an identity, and callers turn this string into a MAC | ||
| * address: handing one out would give every board in a fleet the same address. | ||
| * Rejecting on the digits rather than on whole words keeps the partially fused | ||
| * mixture out too, while still accepting a legitimate id that contains a zero | ||
| * word. | ||
| */ | ||
| static bool die_id_is_usable(const char *buf) { | ||
| for (const char *p = buf; *p; p++) | ||
| if (*p != '0' && *p != 'f') | ||
| return true; | ||
| return false; | ||
| } | ||
|
|
||
| bool hisi_get_die_id(char *buf, size_t len) { | ||
| bool ok; | ||
|
|
||
| switch (chip_generation) { | ||
| case HISI_V4: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The V4 arm skips the all-zero/all-ones rejection that the V5 arm gets at line 757. Since the invariant this PR introduces is "callers derive a MAC from this", the check belongs here in the dispatcher so both arms honour it. |
||
| ok = hisi_ev300_get_die_id(buf, len); | ||
| break; | ||
| case HISI_OT: | ||
| ok = hisi_ot_get_die_id(buf, len); | ||
| break; | ||
| default: | ||
| return false; | ||
| } | ||
|
|
||
| return ok && die_id_is_usable(buf); | ||
| } | ||
|
|
||
| #define CV300_ISP_AF_CFG_ADDR 0x12200 | ||
| struct CV300_ISP_AF_CFG { | ||
| bool en : 1; | ||
|
|
@@ -927,7 +1014,7 @@ struct PT_OFFSET { | |
|
|
||
| void hisi_chip_properties(cJSON *j_inner) { | ||
| char buf[1024]; | ||
| if (hisi_ev300_get_die_id(buf, sizeof buf)) { | ||
| if (hisi_get_die_id(buf, sizeof buf)) { | ||
| ADD_PARAM("id", buf); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-existing, but this PR puts
ipcinfo -ion every V5 boot's rcS path, so flagging it:getchipvendor()runssetup_hal_hisi(), which writes0 0 0 0to/proc/sys/kernel/printkand onHISI_OTforce-enables the sensor clock (CRG8464/CRG8472).ipcinfonever callshal_cleanup()on any exit path (onlysensors.candi2cspi.cdo), so the console stays silent and the CRG stays modified for the rest of boot.One
hal_cleanup()before each exit, or anatexit()registered aftergetchipname(), fixes it.