Skip to content

Commit

Permalink
[efuse]add some efuse command for t113
Browse files Browse the repository at this point in the history
  • Loading branch information
jianjunjiang committed Jul 11, 2023
1 parent 137e61b commit fad2a97
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 10 deletions.
2 changes: 1 addition & 1 deletion chips/a40i_r40.c
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ static int chip_extra(struct xfel_ctx_t * ctx, int argc, char * argv[])
uint32_t count = sids[n].size_bits / 32;
for(int i = 0; i < count; i++)
buffer[i] = payload_read32(ctx, 0x01c1b200 + sids[n].offset + i * 4);
printf("%s:", sids[n].name);
printf("%s:(0x%04x %d-bits)", sids[n].name, sids[n].offset, sids[n].size_bits);
for(int i = 0; i < count; i++)
{
if(i >= 0 && ((i % 8) == 0))
Expand Down
2 changes: 1 addition & 1 deletion chips/r128.c
Original file line number Diff line number Diff line change
Expand Up @@ -5985,7 +5985,7 @@ static int chip_extra(struct xfel_ctx_t * ctx, int argc, char * argv[])
uint32_t count = sids[n].size_bits / 32;
for(int i = 0; i < count; i++)
buffer[i] = payload_read32(ctx, 0x4004e600 + sids[n].offset + i * 4);
printf("%s:", sids[n].name);
printf("%s:(0x%04x %d-bits)", sids[n].name, sids[n].offset, sids[n].size_bits);
for(int i = 0; i < count; i++)
{
if(i >= 0 && ((i % 8) == 0))
Expand Down
78 changes: 73 additions & 5 deletions chips/r528_t113.c
Original file line number Diff line number Diff line change
Expand Up @@ -4442,13 +4442,66 @@ static int chip_spi_run(struct xfel_ctx_t * ctx, uint8_t * cbuf, uint32_t clen)
return 1;
}

enum {
SID_PRCTL = 0x03006000 + 0x040,
SID_PRKEY = 0x03006000 + 0x050,
SID_RDKEY = 0x03006000 + 0x060,
EFUSE_HV_SWITCH = 0x07090000 + 0x204,
};

static uint32_t efuse_read_key(struct xfel_ctx_t * ctx, uint32_t key)
{
uint32_t val;

val = payload_read32(ctx, SID_PRCTL);
val &= ~((0x1ff << 16) | 0x3);
val |= key << 16;
payload_write32(ctx, SID_PRCTL, val);
val &= ~((0xff << 8) | 0x3);
val |= (0xac << 8) | 0x2;
payload_write32(ctx, SID_PRCTL, val);
while(payload_read32(ctx, SID_PRCTL) & 0x2);
val &= ~((0x1ff << 16) | (0xff << 8) | 0x3);
payload_write32(ctx, SID_PRCTL, val);
val = payload_read32(ctx, SID_RDKEY);

return val;
}

static void efuse_program_key(struct xfel_ctx_t * ctx, uint32_t key, uint32_t value)
{
uint32_t val;

payload_write32(ctx, EFUSE_HV_SWITCH, 0x1);
payload_write32(ctx, SID_PRKEY, value);
val = payload_read32(ctx, SID_PRCTL);
val &= ~((0x1ff << 16) | 0x3);
val |= key << 16;
payload_write32(ctx, SID_PRCTL, val);
val &= ~((0xff << 8) | 0x3);
val |= (0xac << 8) | 0x1;
payload_write32(ctx, SID_PRCTL, val);
while(payload_read32(ctx, SID_PRCTL) & 0x1);
val &= ~((0x1ff << 16) | (0xff << 8) | 0x3);
payload_write32(ctx, SID_PRCTL, val);
payload_write32(ctx, EFUSE_HV_SWITCH, 0x0);
}

static const struct sid_section_t {
char * name;
uint32_t offset;
uint32_t size_bits;
} sids[] = {
{ "chipid", 0x0000, 128 },
{ "unknown", 0x0010, 1920 },
{ "chipid", 0x0000, 128 },
{ "brom-conf-try", 0x0010, 32 },
{ "thermal-sensor", 0x0014, 64 },
{ "ft-zone", 0x001c, 128 },
{ "tvout", 0x002c, 32 },
{ "tvout-gamma", 0x0030, 64 },
{ "oem-program", 0x0038, 64 },
{ "write-protect", 0x0040, 32 },
{ "read-protect", 0x0044, 32 },
{ "reserved", 0x0048, 1472 },
};

static int chip_extra(struct xfel_ctx_t * ctx, int argc, char * argv[])
Expand All @@ -4468,8 +4521,8 @@ static int chip_extra(struct xfel_ctx_t * ctx, int argc, char * argv[])
{
uint32_t count = sids[n].size_bits / 32;
for(int i = 0; i < count; i++)
buffer[i] = payload_read32(ctx, 0x03006200 + sids[n].offset + i * 4);
printf("%s:", sids[n].name);
buffer[i] = efuse_read_key(ctx, sids[n].offset + i * 4);
printf("%s:(0x%04x %d-bits)", sids[n].name, sids[n].offset, sids[n].size_bits);
for(int i = 0; i < count; i++)
{
if(i >= 0 && ((i % 8) == 0))
Expand All @@ -4480,11 +4533,26 @@ static int chip_extra(struct xfel_ctx_t * ctx, int argc, char * argv[])
}
return 1;
}
else if(!strcmp(argv[0], "read32") && (argc == 2))
{
uint32_t key = strtoul(argv[1], NULL, 0);
printf("0x%08x\r\n", efuse_read_key(ctx, key));
return 1;
}
else if(!strcmp(argv[0], "write32") && (argc == 3))
{
uint32_t key = strtoul(argv[1], NULL, 0);
size_t value = strtoul(argv[2], NULL, 0);
efuse_program_key(ctx, key, value);
return 1;
}
}
}
}
printf("usage:\r\n");
printf(" xfel extra efuse dump - Dump all of the efuse information\r\n");
printf(" xfel extra efuse dump - Dump all of the efuse information\r\n");
printf(" xfel extra efuse read32 <key> - Read 32-bits value from efuse\r\n");
printf(" xfel extra efuse write32 <key> <value> - Write 32-bits value to efuse\r\n");
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion chips/v3s_s3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ static int chip_extra(struct xfel_ctx_t * ctx, int argc, char * argv[])
uint32_t count = sids[n].size_bits / 32;
for(int i = 0; i < count; i++)
buffer[i] = payload_read32(ctx, 0x01c23800 + sids[n].offset + i * 4);
printf("%s:", sids[n].name);
printf("%s:(0x%04x %d-bits)", sids[n].name, sids[n].offset, sids[n].size_bits);
for(int i = 0; i < count; i++)
{
if(i >= 0 && ((i % 8) == 0))
Expand Down
2 changes: 1 addition & 1 deletion chips/v831.c
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ static int chip_extra(struct xfel_ctx_t * ctx, int argc, char * argv[])
uint32_t count = sids[n].size_bits / 32;
for(int i = 0; i < count; i++)
buffer[i] = payload_read32(ctx, 0x03006200 + sids[n].offset + i * 4);
printf("%s:", sids[n].name);
printf("%s:(0x%04x %d-bits)", sids[n].name, sids[n].offset, sids[n].size_bits);
for(int i = 0; i < count; i++)
{
if(i >= 0 && ((i % 8) == 0))
Expand Down
2 changes: 1 addition & 1 deletion chips/v851_v853.c
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ static int chip_extra(struct xfel_ctx_t * ctx, int argc, char * argv[])
uint32_t count = sids[n].size_bits / 32;
for(int i = 0; i < count; i++)
buffer[i] = payload_read32(ctx, 0x03006200 + sids[n].offset + i * 4);
printf("%s:", sids[n].name);
printf("%s:(0x%04x %d-bits)", sids[n].name, sids[n].offset, sids[n].size_bits);
for(int i = 0; i < count; i++)
{
if(i >= 0 && ((i % 8) == 0))
Expand Down

0 comments on commit fad2a97

Please sign in to comment.