Added FDMA firmware and try to enable FDMA0 (not successful).

This commit is contained in:
imi415 2022-08-12 09:36:54 +08:00
parent 3d407c43f2
commit d82bb3fb7e
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
7 changed files with 2707 additions and 47 deletions

View File

@ -10,6 +10,7 @@ set(TARGET_SOURCES
"src/main.c"
"src/stx7105_exc.c"
"src/stx7105_utils.c"
"src/stx7105_fdma_fw.c"
"src/syscalls.c"
"startup_stx7105.S"
)

View File

@ -133,25 +133,25 @@ typedef struct {
/* drivers/stm/stx7105.c */
typedef struct {
__IO uint32_t SLIM_ID; /* Offset: 0x0000, SLIM CPU ID register */
__IO uint32_t SLIM_VER; /* Offset: 0x0004, SLIM CPU version register */
__IO uint32_t SLIM_EN; /* Offset: 0x0008, SLIM CPU enable control register */
__IO uint32_t SLIM_CLK_GATE; /* Offset: 0x000C, SLIM CPU clock gate register */
uint32_t UNUSED0[8188]; /* Offset: 0x0010 */
__IO uint8_t SLIM_DMEM[8192]; /* Offset: 0x8000, SLIM CPU data memory */
uint32_t UNUSED1[2018]; /* Offset: 0xA000 */
__IO uint32_t PERIPH_SYNC; /* Offset: 0xBF88, Peripheral sync register */
uint32_t UNUSED2[13]; /* Offset: 0xBF8C */
__IO uint32_t PERIPH_CMD_STA; /* Offset: 0xBFC0, */
__IO uint32_t PERIPH_CMD_SET; /* Offset: 0xBFC4, */
__IO uint32_t PERIPH_CMD_CLR; /* Offset: 0xBFC8, */
__IO uint32_t PERIPH_CMD_MASK; /* Offset: 0xBFCC, */
__IO uint32_t PERIPH_INT_STA; /* Offset: 0xBFD0, */
__IO uint32_t PERIPH_INT_SET; /* Offset: 0xBFD4, */
__IO uint32_t PERIPH_INT_CLR; /* Offset: 0xBFD8, */
__IO uint32_t PERIPH_INT_MASK; /* Offset: 0xBFDC, */
uint32_t UNUSED3[8]; /* Offset: 0xBFE0 */
__IO uint8_t SLIM_IMEM[16384]; /* Offset: 0xC000, SLIM CPU instruction memory */
__IO uint32_t SLIM_ID; /* Offset: 0x0000, SLIM CPU ID register */
__IO uint32_t SLIM_VER; /* Offset: 0x0004, SLIM CPU version register */
__IO uint32_t SLIM_EN; /* Offset: 0x0008, SLIM CPU enable control register */
__IO uint32_t SLIM_CLK_GATE; /* Offset: 0x000C, SLIM CPU clock gate register */
uint32_t UNUSED0[8188]; /* Offset: 0x0010 */
__IO uint8_t SLIM_DMEM[8192]; /* Offset: 0x8000, SLIM CPU data memory */
uint32_t UNUSED1[2018]; /* Offset: 0xA000 */
__IO uint32_t PERIPH_STBUS_SYNC; /* Offset: 0xBF88, STBus sync control register */
uint32_t UNUSED2[13]; /* Offset: 0xBF8C */
__IO uint32_t PERIPH_CMD_STA; /* Offset: 0xBFC0, Command mailbox */
__IO uint32_t PERIPH_CMD_SET; /* Offset: 0xBFC4, Command mailbox */
__IO uint32_t PERIPH_CMD_CLR; /* Offset: 0xBFC8, Command mailbox */
__IO uint32_t PERIPH_CMD_MASK; /* Offset: 0xBFCC, Command mailbox */
__IO uint32_t PERIPH_INT_STA; /* Offset: 0xBFD0, Interrupt mailbox */
__IO uint32_t PERIPH_INT_SET; /* Offset: 0xBFD4, Interrupt mailbox */
__IO uint32_t PERIPH_INT_CLR; /* Offset: 0xBFD8, Interrupt mailbox */
__IO uint32_t PERIPH_INT_MASK; /* Offset: 0xBFDC, Interrupt mailbox */
uint32_t UNUSED3[8]; /* Offset: 0xBFE0 */
__IO uint8_t SLIM_IMEM[16384]; /* Offset: 0xC000, SLIM CPU instruction memory */
} FDMA_TypeDef;
#define PIO0_BASE (0xFD020000U)
@ -206,4 +206,16 @@ typedef struct {
#define INTC_IPRA_IPR_TMU0_Pos 12
#define INTC_IPRA_IPR_TMU0_Msk (0x0FU << INTC_IPRA_IPR_TMU0_Pos)
#define FDMA_SLIM_EN_RUN_Pos 0
#define FDMA_SLIM_EN_RUN_Msk (1U << FDMA_SLIM_EN_RUN_Pos)
#define FDMA_SLIM_CLK_GATE_DIS_Pos 0
#define FDMA_SLIM_CLK_GATE_DIS_Msk (1U << FDMA_SLIM_CLK_GATE_DIS_Pos)
#define FDMA_SLIM_CLK_GATE_RESET_Pos 2
#define FDMA_SLIM_CLK_GATE_RESET_Msk (1U << FDMA_SLIM_CLK_GATE_RESET_Pos)
#define FDMA_PERIPH_STBUS_SYNC_DIS_Pos 0
#define FDMA_PERIPH_STBUS_SYNC_DIS_Msk (1U << FDMA_PERIPH_STBUS_SYNC_DIS_Pos)
#endif

17
include/stx7105_fdma_fw.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef STX7105_FDMA_FW_H
#define STX7105_FDMA_FW_H
#include <stdint.h>
typedef struct {
uint32_t entry_point;
uint32_t text_size;
uint32_t data_size;
uint8_t *text;
uint8_t *data;
} stx7105_fdma_fw_t;
extern stx7105_fdma_fw_t stx7105_fdma0_fw;
extern stx7105_fdma_fw_t stx7105_fdma1_fw;
#endif

View File

@ -1,7 +1,9 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "stx7105.h"
#include "stx7105_fdma_fw.h"
#include "stx7105_utils.h"
#define LED_RED_GPIO PIO0
@ -44,37 +46,26 @@ int main(void) {
printf("Hello world\r\n");
FDMA0->SLIM_CLK_GATE |= (FDMA_SLIM_CLK_GATE_DIS_Msk | FDMA_SLIM_CLK_GATE_RESET_Msk);
FDMA0->PERIPH_STBUS_SYNC |= FDMA_PERIPH_STBUS_SYNC_DIS_Msk;
for(uint32_t i = 0; i < stx7105_fdma0_fw.text_size; i++) {
FDMA0->SLIM_IMEM[i] = stx7105_fdma0_fw.text[i];
}
for(uint32_t i = 0; i < stx7105_fdma0_fw.data_size; i++) {
FDMA0->SLIM_DMEM[i] = stx7105_fdma0_fw.data[i];
}
FDMA0->SLIM_CLK_GATE &= ~FDMA_SLIM_CLK_GATE_DIS_Msk;
FDMA0->PERIPH_INT_CLR = 0xFFFFFFFFU;
FDMA0->PERIPH_CMD_CLR = 0xFFFFFFFFU;
FDMA0->SLIM_EN |= FDMA_SLIM_EN_RUN_Msk;
printf("FDMA0 SLIM ID: 0x%08lx\r\n", FDMA0->SLIM_ID);
printf("FDMA0 SLIM Version: 0x%08lx\r\n", FDMA0->SLIM_VER);
printf("Dumping FDMA0 SLIM DMEM@%p: \r\n", FDMA0->SLIM_DMEM);
for (uint32_t i = 0; i < 2048; i++) {
if (i % 8 == 0) {
printf("0x%04lx: ", i * 4);
}
printf("0x%08lx ", ((uint32_t *)FDMA0->SLIM_DMEM)[i]);
if (i % 8 == 7) {
printf("\r\n");
}
}
printf("Dumping FDMA0 SLIM IMEM @%p: \r\n", FDMA0->SLIM_IMEM);
for (uint32_t i = 0; i < 4096; i++) {
if (i % 8 == 0) {
printf("0x%04lx: ", i * 4);
}
printf("0x%08lx ", ((uint32_t *)FDMA0->SLIM_IMEM)[i]);
if (i % 8 == 7) {
printf("\r\n");
}
}
delay_ms(5000);
for (;;) {

2473
src/stx7105_fdma_fw.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,3 @@
# FDMAFWExtract
This tool can be used to extract firmware data from ELF files.

View File

@ -0,0 +1,163 @@
#include <errno.h>
#include <fcntl.h>
#include <gelf.h>
#include <libelf.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static void print_usage(void) {
fprintf(stderr, "Usage: fdmafwextract ELF_FILENAME\n");
}
static int get_section_idx_by_name(Elf *handle, char *name) {
/* Get total section counts. */
size_t e_nsections;
if (elf_getshdrnum(handle, &e_nsections) < 0) {
int errsv = elf_errno();
fprintf(stderr, "Failed to retrieve section counts, %s\n", elf_errmsg(errsv));
return -1;
}
/* Get string table index. */
size_t e_stridx;
if (elf_getshdrstrndx(handle, &e_stridx) < 0) {
int errsv = elf_errno();
fprintf(stderr, "Failed to get string table index, %s\n", elf_errmsg(errsv));
return -2;
}
/* Search sections for specific name */
for (size_t i = 0; i < e_nsections; i++) {
Elf_Scn *scn = elf_getscn(handle, i);
if (scn == NULL) {
int errsv = elf_errno();
fprintf(stderr, "Failed to get section ID: %d, %s\n", i, elf_errmsg(errsv));
return -3;
}
/* Get section header */
GElf_Shdr shdr_mem;
GElf_Shdr *shdr = gelf_getshdr(scn, &shdr_mem);
if (shdr == NULL) {
int errsv = elf_errno();
fprintf(stderr, "Failed to get section header ID: %d, %s\n", i, elf_errmsg(errsv));
return -4;
}
/* Get section name string from table */
const char *s_name = elf_strptr(handle, e_stridx, shdr->sh_name);
if (s_name == NULL) {
int errsv = elf_errno();
fprintf(stderr, "Failed to get section name for ID: %d, %s\n", i, elf_errmsg(errsv));
return -5;
}
/* Found a match */
if (strcmp(s_name, name) == 0) {
fprintf(stderr, "Found a match for section %s at ID: %d\n", s_name, i);
return i;
}
}
/* Loop completed with no matching sections found. */
fprintf(stderr, "No section named %s found.\n", name);
return -1;
}
static int dump_section_as_c_array(Elf *handle, int idx) {
Elf_Scn *scn = elf_getscn(handle, idx);
if (scn == NULL) {
int es = elf_errno();
fprintf(stderr, "Failed to get section %d: %s\n", idx, elf_errmsg(es));
return -1;
}
Elf_Data *data = elf_rawdata(scn, NULL);
if (data == NULL) {
int es = elf_errno();
fprintf(stderr, "Failed to get section data %d: %s\n", idx, elf_errmsg(es));
return -2;
}
fprintf(stderr, "Section %d size: 0x%x, offset: 0x%x\n", idx, data->d_size, data->d_off);
fprintf(stdout, "\n{\n");
for(int i = 0; i < data->d_size; i++) {
fprintf(stdout, "0x%02x, ", ((uint8_t *)data->d_buf)[i]);
if(i % 16 == 15) {
fprintf(stdout, "\n");
}
}
fprintf(stdout, "};\n");
return 0;
}
int main(int argc, const char *argv[]) {
int ret = 0;
if (argc < 2) {
print_usage();
ret = -1;
return ret;
}
int elf_fd = open(argv[1], O_RDONLY);
if (elf_fd < 0) {
int es = errno;
fprintf(stderr, "Failed to open ELF file: %s\n", strerror(es));
ret = -2;
return ret;
}
elf_version(EV_CURRENT);
Elf *e_handle = elf_begin(elf_fd, ELF_C_READ, NULL);
if (e_handle == NULL) {
int es = elf_errno();
fprintf(stderr, "ELF begin failed: %s\n", elf_errmsg(es));
ret = -3;
goto err_out;
}
ret = get_section_idx_by_name(e_handle, ".text");
if (ret < 0) {
fprintf(stderr, "Failed to find text section.\n");
ret = -4;
goto elf_out;
}
ret = dump_section_as_c_array(e_handle, ret);
ret = get_section_idx_by_name(e_handle, ".data");
if (ret < 0) {
fprintf(stderr, "Failed to find data section.\n");
ret = -5;
goto elf_out;
}
ret = dump_section_as_c_array(e_handle, ret);
elf_out:
elf_end(e_handle);
err_out:
close(elf_fd);
return ret;
}