Skip to content

Commit

Permalink
[v831]update v831 payload and add efuse extra command
Browse files Browse the repository at this point in the history
  • Loading branch information
jianjunjiang committed Jul 11, 2023
1 parent 0587e4a commit 189cf4c
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 32 deletions.
127 changes: 95 additions & 32 deletions chips/v831.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,71 @@ static int chip_detect(struct xfel_ctx_t * ctx, uint32_t id)
return 0;
}

static int chip_reset(struct xfel_ctx_t * ctx)
static uint32_t payload_read32(struct xfel_ctx_t * ctx, uint32_t addr)
{
static const uint8_t payload[] = {
0x00, 0x00, 0xa0, 0xe3, 0x17, 0x0f, 0x08, 0xee, 0x15, 0x0f, 0x07, 0xee,
0xd5, 0x0f, 0x07, 0xee, 0x9a, 0x0f, 0x07, 0xee, 0x95, 0x0f, 0x07, 0xee,
0xff, 0xff, 0xff, 0xea, 0x0c, 0x00, 0x9f, 0xe5, 0x0c, 0x10, 0x8f, 0xe2,
0x00, 0x20, 0x90, 0xe5, 0x00, 0x20, 0x81, 0xe5, 0x1e, 0xff, 0x2f, 0xe1,
};
uint32_t adr = cpu_to_le32(addr);
uint32_t val;

val = R32(0x030090a0 + 0x18);
val &= ~(0xf << 4);
val |= (1 << 4) | (0x1 << 0);
W32(0x030090a0 + 0x18, val);
W32(0x030090a0 + 0x10, (0xa57 << 1) | (1 << 0));
return 1;
fel_write(ctx, ctx->version.scratchpad, (void *)payload, sizeof(payload));
fel_write(ctx, ctx->version.scratchpad + sizeof(payload), (void *)&adr, sizeof(adr));
fel_exec(ctx, ctx->version.scratchpad);
fel_read(ctx, ctx->version.scratchpad + sizeof(payload) + sizeof(adr), (void *)&val, sizeof(val));
return le32_to_cpu(val);
}

static uint32_t payload_arm_read32(struct xfel_ctx_t * ctx, uint32_t addr)
static void payload_write32(struct xfel_ctx_t * ctx, uint32_t addr, uint32_t val)
{
uint32_t payload[] = {
cpu_to_le32(0xe59f000c), /* ldr r0, [pc, #12] */
cpu_to_le32(0xe28f100c), /* add r1, pc, #12 */
cpu_to_le32(0xe4902000), /* ldr r2, [r0], #0 */
cpu_to_le32(0xe4812000), /* str r2, [r1], #0 */
cpu_to_le32(0xe12fff1e), /* bx lr */
static const uint8_t payload[] = {
0x00, 0x00, 0xa0, 0xe3, 0x17, 0x0f, 0x08, 0xee, 0x15, 0x0f, 0x07, 0xee,
0xd5, 0x0f, 0x07, 0xee, 0x9a, 0x0f, 0x07, 0xee, 0x95, 0x0f, 0x07, 0xee,
0xff, 0xff, 0xff, 0xea, 0x08, 0x00, 0x9f, 0xe5, 0x08, 0x10, 0x9f, 0xe5,
0x00, 0x10, 0x80, 0xe5, 0x1e, 0xff, 0x2f, 0xe1,
};
uint32_t params[2] = {
cpu_to_le32(addr),
cpu_to_le32(val),
};
uint32_t val;

fel_write(ctx, ctx->version.scratchpad, (void *)payload, sizeof(payload));
fel_write(ctx, ctx->version.scratchpad + sizeof(payload), (void *)params, sizeof(params));
fel_exec(ctx, ctx->version.scratchpad);
fel_read(ctx, ctx->version.scratchpad + sizeof(payload), (void *)&val, sizeof(val));
return le32_to_cpu(val);
}

static int chip_reset(struct xfel_ctx_t * ctx)
{
uint32_t val;

val = payload_read32(ctx, 0x030090a0 + 0x18);
val &= ~(0xf << 4);
val |= (1 << 4) | (0x1 << 0);
payload_write32(ctx, 0x030090a0 + 0x18, val);
payload_write32(ctx, 0x030090a0 + 0x10, (0xa57 << 1) | (1 << 0));
return 1;
}

static int chip_sid(struct xfel_ctx_t * ctx, char * sid)
{
uint32_t id[4];

id[0] = payload_arm_read32(ctx, 0x03006200 + 0x0);
id[1] = payload_arm_read32(ctx, 0x03006200 + 0x4);
id[2] = payload_arm_read32(ctx, 0x03006200 + 0x8);
id[3] = payload_arm_read32(ctx, 0x03006200 + 0xc);
id[0] = payload_read32(ctx, 0x03006200 + 0x0);
id[1] = payload_read32(ctx, 0x03006200 + 0x4);
id[2] = payload_read32(ctx, 0x03006200 + 0x8);
id[3] = payload_read32(ctx, 0x03006200 + 0xc);
sprintf(sid, "%08x%08x%08x%08x", id[0], id[1], id[2], id[3]);
return 1;
}

static int chip_jtag(struct xfel_ctx_t * ctx)
{
static const uint8_t payload[] = {
0x00, 0x00, 0xa0, 0xe3, 0x17, 0x0f, 0x08, 0xee, 0x15, 0x0f, 0x07, 0xee,
0xd5, 0x0f, 0x07, 0xee, 0x9a, 0x0f, 0x07, 0xee, 0x95, 0x0f, 0x07, 0xee,
0xff, 0xff, 0xff, 0xea, 0x58, 0x00, 0x9f, 0xe5, 0x00, 0xd0, 0x80, 0xe5,
0x04, 0xe0, 0x80, 0xe5, 0x00, 0xe0, 0x0f, 0xe1, 0x08, 0xe0, 0x80, 0xe5,
0x10, 0xef, 0x11, 0xee, 0x0c, 0xe0, 0x80, 0xe5, 0x10, 0xef, 0x1c, 0xee,
Expand All @@ -68,24 +88,24 @@ static int chip_jtag(struct xfel_ctx_t * ctx)
0xb4, 0x20, 0x83, 0xe5, 0xb4, 0x20, 0x93, 0xe5, 0x0f, 0x26, 0xc2, 0xe3,
0x03, 0x26, 0x82, 0xe3, 0xb4, 0x20, 0x83, 0xe5, 0x1e, 0xff, 0x2f, 0xe1,
0x04, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x47, 0x4e, 0x55, 0x00, 0x90, 0xef, 0xd5, 0xd4, 0xf9, 0x31, 0x90, 0x65,
0x03, 0xd6, 0xb2, 0x35, 0x09, 0xe0, 0x16, 0x82, 0x15, 0xe2, 0xb6, 0xcc,
0x47, 0x4e, 0x55, 0x00, 0x09, 0xd0, 0xba, 0x36, 0x1c, 0xcc, 0x6b, 0x64,
0xc9, 0x91, 0x95, 0xfd, 0x5a, 0xd8, 0x85, 0x3e, 0xe9, 0x1d, 0x1f, 0x00,
0x2f, 0x6c, 0x69, 0x62, 0x2f, 0x6c, 0x64, 0x2d, 0x6c, 0x69, 0x6e, 0x75,
0x78, 0x2d, 0x61, 0x72, 0x6d, 0x68, 0x66, 0x2e, 0x73, 0x6f, 0x2e, 0x33,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xf5, 0xfe, 0xff, 0x6f, 0x08, 0x21, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00,
0x04, 0x21, 0x02, 0x00, 0x06, 0x00, 0x00, 0x00, 0xf4, 0x20, 0x02, 0x00,
0xf5, 0xfe, 0xff, 0x6f, 0x20, 0x21, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00,
0x1c, 0x21, 0x02, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0c, 0x21, 0x02, 0x00,
0x0a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1e, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xfb, 0xff, 0xff, 0x6f,
0x01, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x20, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x38, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
fel_write(ctx, 0x00022000, (void *)&payload[0], sizeof(payload));
Expand Down Expand Up @@ -1217,6 +1237,8 @@ static int chip_ddr(struct xfel_ctx_t * ctx, const char * type)
static int chip_spi_init(struct xfel_ctx_t * ctx, uint32_t * swapbuf, uint32_t * swaplen, uint32_t * cmdlen)
{
static const uint8_t payload[] = {
0x00, 0x00, 0xa0, 0xe3, 0x17, 0x0f, 0x08, 0xee, 0x15, 0x0f, 0x07, 0xee,
0xd5, 0x0f, 0x07, 0xee, 0x9a, 0x0f, 0x07, 0xee, 0x95, 0x0f, 0x07, 0xee,
0xff, 0xff, 0xff, 0xea, 0x5c, 0x00, 0x9f, 0xe5, 0x00, 0xd0, 0x80, 0xe5,
0x04, 0xe0, 0x80, 0xe5, 0x00, 0xe0, 0x0f, 0xe1, 0x08, 0xe0, 0x80, 0xe5,
0x10, 0xef, 0x11, 0xee, 0x0c, 0xe0, 0x80, 0xe5, 0x10, 0xef, 0x1c, 0xee,
Expand Down Expand Up @@ -1321,25 +1343,25 @@ static int chip_spi_init(struct xfel_ctx_t * ctx, uint32_t * swapbuf, uint32_t *
0x08, 0x30, 0xdd, 0xe5, 0x01, 0x00, 0x13, 0xe3, 0xf6, 0xff, 0xff, 0x1a,
0x04, 0x60, 0xa0, 0xe1, 0x7f, 0xff, 0xff, 0xea, 0x14, 0xd0, 0x8d, 0xe2,
0xf0, 0x83, 0xbd, 0xe8, 0x04, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x47, 0x4e, 0x55, 0x00, 0xba, 0x3f, 0x41, 0xd6,
0x1f, 0xeb, 0xc2, 0xc9, 0x80, 0xfc, 0xf1, 0xda, 0x4c, 0x88, 0x12, 0x78,
0xc8, 0x11, 0x11, 0xe5, 0x2f, 0x6c, 0x69, 0x62, 0x2f, 0x6c, 0x64, 0x2d,
0x03, 0x00, 0x00, 0x00, 0x47, 0x4e, 0x55, 0x00, 0x7e, 0xf1, 0x42, 0x24,
0x25, 0xf1, 0x0c, 0x1b, 0x69, 0xe5, 0x0b, 0x13, 0x65, 0x6b, 0x15, 0x0a,
0xcb, 0x0f, 0xb5, 0xcb, 0x2f, 0x6c, 0x69, 0x62, 0x2f, 0x6c, 0x64, 0x2d,
0x6c, 0x69, 0x6e, 0x75, 0x78, 0x2d, 0x61, 0x72, 0x6d, 0x68, 0x66, 0x2e,
0x73, 0x6f, 0x2e, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf5, 0xfe, 0xff, 0x6f,
0x2c, 0x25, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x28, 0x25, 0x02, 0x00,
0x06, 0x00, 0x00, 0x00, 0x18, 0x25, 0x02, 0x00, 0x0a, 0x00, 0x00, 0x00,
0x44, 0x25, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x40, 0x25, 0x02, 0x00,
0x06, 0x00, 0x00, 0x00, 0x30, 0x25, 0x02, 0x00, 0x0a, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0xfb, 0xff, 0xff, 0x6f, 0x01, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x48, 0x25, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x60, 0x25, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
fel_write(ctx, 0x00022000, (void *)&payload[0], sizeof(payload));
if(swapbuf)
Expand All @@ -1358,8 +1380,49 @@ static int chip_spi_run(struct xfel_ctx_t * ctx, uint8_t * cbuf, uint32_t clen)
return 1;
}

static const struct sid_section_t {
char * name;
uint32_t offset;
uint32_t size_bits;
} sids[] = {
{ "chipid", 0x0000, 128 },
{ "unknown", 0x0010, 1920 },
};

static int chip_extra(struct xfel_ctx_t * ctx, int argc, char * argv[])
{
if(argc > 0)
{
if(!strcmp(argv[0], "efuse"))
{
argc -= 1;
argv += 1;
if(argc > 0)
{
if(!strcmp(argv[0], "dump") && (argc == 1))
{
uint32_t buffer[2048 / 4];
for(int n = 0; n < ARRAY_SIZE(sids); n++)
{
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);
for(int i = 0; i < count; i++)
{
if(i >= 0 && ((i % 8) == 0))
printf("\r\n%-4s", "");
printf("%08x ", buffer[i]);
}
printf("\r\n");
}
return 1;
}
}
}
}
printf("usage:\r\n");
printf(" xfel extra efuse dump - Dump all of the efuse information\r\n");
return 0;
}

Expand Down
6 changes: 6 additions & 0 deletions payloads/v831/jtag/source/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@

.global _start
_start:
mov r0, #0
mcr p15, 0, r0, c8, c7, 0
mcr p15, 0, r0, c7, c5, 0
mcr p15, 0, r0, c7, c5, 6
mcr p15, 0, r0, c7, c10, 4
mcr p15, 0, r0, c7, c5, 4
b reset

reset:
Expand Down
6 changes: 6 additions & 0 deletions payloads/v831/spi/source/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@

.global _start
_start:
mov r0, #0
mcr p15, 0, r0, c8, c7, 0
mcr p15, 0, r0, c7, c5, 0
mcr p15, 0, r0, c7, c5, 6
mcr p15, 0, r0, c7, c10, 4
mcr p15, 0, r0, c7, c5, 4
b reset

reset:
Expand Down

0 comments on commit 189cf4c

Please sign in to comment.