Skip to content

Commit

Permalink
Merge pull request #28 from YuzukiHD/dev
Browse files Browse the repository at this point in the history
[feat] update boot header to auto head define
  • Loading branch information
YuzukiTsuru committed Feb 23, 2024
2 parents 3cbc546 + d1cdc06 commit b7458da
Show file tree
Hide file tree
Showing 44 changed files with 826 additions and 517 deletions.
1 change: 1 addition & 0 deletions board/100ask-d1-h/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(APP_COMMON_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/start.S
${CMAKE_CURRENT_SOURCE_DIR}/board.c
${CMAKE_CURRENT_SOURCE_DIR}/eabi_compat.c
${CMAKE_CURRENT_SOURCE_DIR}/head.c
)

add_subdirectory(hello_world)
Expand Down
70 changes: 70 additions & 0 deletions board/100ask-d1-h/head.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <types.h>

typedef struct boot_file_head {
uint32_t jump_instruction; /* one intruction jumping to real code */
uint8_t magic[8]; /* ="eGON.BT0" */
uint32_t check_sum; /* generated by PC */
uint32_t *length; /* generated by LD */
uint32_t pub_head_size; /* the size of boot_file_head_t */
uint8_t pub_head_vsn[4]; /* the version of boot_file_head_t */
uint32_t *ret_addr; /* the return value */
uint32_t *run_addr; /* run addr */
uint32_t boot_cpu; /* eGON version */
uint8_t platform[8]; /* platform information */
} boot_file_head_t;

/*
* This code is used to calculate some values related to the size of a file header
* and combine these values to form a jump instruction:
*
* * BROM_FILE_HEAD_SIZE: Defines a mask for the size of the file header
* and uses the bitwise & operator with 0x00FFFFF to truncate and obtain the size of the file header.
*
* * BROM_FILE_HEAD_BIT_10_1, BROM_FILE_HEAD_BIT_11, BROM_FILE_HEAD_BIT_19_12, BROM_FILE_HEAD_BIT_20:
* These macros define the values of various bit segments of the file header size.
*
* * BROM_FILE_HEAD_SIZE_OFFSET: This macro combines the bit segments of the file header size
* calculated above to form an offset.
*
* * JUMP_INSTRUCTION: This macro uses the calculated offset from above and performs a bitwise
* OR operation with 0x6f to create a jump instruction.
*
* This code calculates an offset corresponding to the size of the file header through a series of
* bitwise operations and utilizes it to construct a jump instruction.
*/

#define BROM_FILE_HEAD_SIZE (sizeof(boot_file_head_t) & 0x00FFFFF)
#define BROM_FILE_HEAD_BIT_10_1 ((BROM_FILE_HEAD_SIZE & 0x7FE) >> 1)
#define BROM_FILE_HEAD_BIT_11 ((BROM_FILE_HEAD_SIZE & 0x800) >> 11)
#define BROM_FILE_HEAD_BIT_19_12 ((BROM_FILE_HEAD_SIZE & 0xFF000) >> 12)
#define BROM_FILE_HEAD_BIT_20 ((BROM_FILE_HEAD_SIZE & 0x100000) >> 20)

#define BROM_FILE_HEAD_SIZE_OFFSET ((BROM_FILE_HEAD_BIT_20 << 31) | \
(BROM_FILE_HEAD_BIT_10_1 << 21) | \
(BROM_FILE_HEAD_BIT_11 << 20) | \
(BROM_FILE_HEAD_BIT_19_12 << 12))

#define JUMP_INSTRUCTION (BROM_FILE_HEAD_SIZE_OFFSET | 0x6f)

#define BOOT0_MAGIC "eGON.BT0"
#define STAMP_VALUE (0x12345678)
#define BOOT_PUB_HEAD_VERSION "3000"

extern uint32_t __spl_size[];
extern uint32_t __code_start_address[];

const __attribute__((section(".boot0_head"))) boot_file_head_t boot_head = {
.jump_instruction = JUMP_INSTRUCTION,
.magic = BOOT0_MAGIC,
.check_sum = STAMP_VALUE,
.length = __spl_size,
.pub_head_size = sizeof(boot_file_head_t),
.pub_head_vsn = BOOT_PUB_HEAD_VERSION,
.ret_addr = __code_start_address,
.run_addr = __code_start_address,
.boot_cpu = 0,
.platform = {0, 0, '3', '.', '0', '.', '0', 0},
};
18 changes: 1 addition & 17 deletions board/100ask-d1-h/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,9 @@
#include <csr.h>

.text
.align 4
.globl _start
_start:
/* Boot head information for BROM */
.long 0x0300006f
.byte 'e', 'G', 'O', 'N', '.', 'B', 'T', '0'
.long 0x12345678 /* checksum */
.long __spl_size /* spl size */
.long 0x30 /* boot header size */
.long 0x30303033 /* boot header version */
.long 0x00020000 /* return value */
.long 0x00028000 /* run address */
.long 0x0 /* eGON version */
.byte 0x00, 0x00, 0x00, 0x00 /* platform information - 8byte */
.byte 0x34, 0x2e, 0x30, 0x00

.align 4
.globl reset
reset:
/* disable interrupt */
csrw mie, zero

Expand Down Expand Up @@ -76,7 +61,6 @@ clbss_1:
blt t0, t1, clbss_1
ret


/*
* Exception vectors.
*/
Expand Down
1 change: 1 addition & 0 deletions board/100ask-ros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(APP_COMMON_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/eabi_compat.c
${CMAKE_CURRENT_SOURCE_DIR}/payloads/init_dram_bin.c
${CMAKE_CURRENT_SOURCE_DIR}/payloads/ar100s.c
${CMAKE_CURRENT_SOURCE_DIR}/head.c
)

add_subdirectory(hello_world)
Expand Down
40 changes: 40 additions & 0 deletions board/100ask-ros/head.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <types.h>

typedef struct boot_file_head {
uint32_t jump_instruction; /* one intruction jumping to real code */
uint8_t magic[8]; /* ="eGON.BT0" */
uint32_t check_sum; /* generated by PC */
uint32_t *length; /* generated by LD */
uint32_t pub_head_size; /* the size of boot_file_head_t */
uint8_t pub_head_vsn[4]; /* the version of boot_file_head_t */
uint32_t *ret_addr; /* the return value */
uint32_t *run_addr; /* run addr */
uint32_t boot_cpu; /* eGON version */
uint8_t platform[8]; /* platform information */
} boot_file_head_t;

#define BROM_FILE_HEAD_SIZE_OFFSET (((sizeof(boot_file_head_t) + sizeof(int)) / sizeof(int) + 1))
#define JUMP_INSTRUCTION (BROM_FILE_HEAD_SIZE_OFFSET | 0xEA000000)

#define BOOT0_MAGIC "eGON.BT0"
#define STAMP_VALUE (0x12345678)
#define BOOT_PUB_HEAD_VERSION "3000"

extern uint32_t __spl_size[];
extern uint32_t __code_start_address[];

const __attribute__((section(".boot0_head"))) boot_file_head_t boot_head = {
.jump_instruction = JUMP_INSTRUCTION,
.magic = BOOT0_MAGIC,
.check_sum = STAMP_VALUE,
.length = __spl_size,
.pub_head_size = sizeof(boot_file_head_t),
.pub_head_vsn = BOOT_PUB_HEAD_VERSION,
.ret_addr = __code_start_address,
.run_addr = __code_start_address,
.boot_cpu = 0,
.platform = {0, 0, '3', '.', '0', '.', '0', 0},
};
16 changes: 2 additions & 14 deletions board/100ask-ros/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,10 @@
.text

_start:
/* Boot head information for BROM */
.long 0xea000016
.byte 'e', 'G', 'O', 'N', '.', 'B', 'T', '0'
.long 0x12345678 /* checksum */
.long __spl_size /* spl size */
.long 0x30 /* boot header size */
.long 0x30303033 /* boot header version */
.long 0x00020000 /* return value */
.long 0x00028000 /* run address */
.long 0x0 /* eGON version */
.byte 0x00, 0x00, 0x00, 0x00 /* platform information - 8byte */
.byte 0x34, 0x2e, 0x30, 0x00

b reset

.align 5
_vector:
b reset
ldr pc, _undefined_instruction
ldr pc, _software_interrupt
ldr pc, _prefetch_abort
Expand Down
1 change: 1 addition & 0 deletions board/100ask-t113i/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(APP_COMMON_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/start.S
${CMAKE_CURRENT_SOURCE_DIR}/board.c
${CMAKE_CURRENT_SOURCE_DIR}/eabi_compat.c
${CMAKE_CURRENT_SOURCE_DIR}/head.c
)

add_subdirectory(hello_world)
Expand Down
40 changes: 40 additions & 0 deletions board/100ask-t113i/head.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <types.h>

typedef struct boot_file_head {
uint32_t jump_instruction; /* one intruction jumping to real code */
uint8_t magic[8]; /* ="eGON.BT0" */
uint32_t check_sum; /* generated by PC */
uint32_t *length; /* generated by LD */
uint32_t pub_head_size; /* the size of boot_file_head_t */
uint8_t pub_head_vsn[4]; /* the version of boot_file_head_t */
uint32_t *ret_addr; /* the return value */
uint32_t *run_addr; /* run addr */
uint32_t boot_cpu; /* eGON version */
uint8_t platform[8]; /* platform information */
} boot_file_head_t;

#define BROM_FILE_HEAD_SIZE_OFFSET (((sizeof(boot_file_head_t) + sizeof(int)) / sizeof(int) + 1))
#define JUMP_INSTRUCTION (BROM_FILE_HEAD_SIZE_OFFSET | 0xEA000000)

#define BOOT0_MAGIC "eGON.BT0"
#define STAMP_VALUE (0x12345678)
#define BOOT_PUB_HEAD_VERSION "3000"

extern uint32_t __spl_size[];
extern uint32_t __code_start_address[];

const __attribute__((section(".boot0_head"))) boot_file_head_t boot_head = {
.jump_instruction = JUMP_INSTRUCTION,
.magic = BOOT0_MAGIC,
.check_sum = STAMP_VALUE,
.length = __spl_size,
.pub_head_size = sizeof(boot_file_head_t),
.pub_head_vsn = BOOT_PUB_HEAD_VERSION,
.ret_addr = __code_start_address,
.run_addr = __code_start_address,
.boot_cpu = 0,
.platform = {0, 0, '3', '.', '0', '.', '0', 0},
};
16 changes: 2 additions & 14 deletions board/100ask-t113i/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,10 @@
.text

_start:
/* Boot head information for BROM */
.long 0xea000016
.byte 'e', 'G', 'O', 'N', '.', 'B', 'T', '0'
.long 0x12345678 /* checksum */
.long __spl_size /* spl size */
.long 0x30 /* boot header size */
.long 0x30303033 /* boot header version */
.long 0x00020000 /* return value */
.long 0x00028000 /* run address */
.long 0x0 /* eGON version */
.byte 0x00, 0x00, 0x00, 0x00 /* platform information - 8byte */
.byte 0x34, 0x2e, 0x30, 0x00

b reset

.align 5
_vector:
b reset
ldr pc, _undefined_instruction
ldr pc, _software_interrupt
ldr pc, _prefetch_abort
Expand Down
1 change: 1 addition & 0 deletions board/100ask-t113s3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(APP_COMMON_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/start.S
${CMAKE_CURRENT_SOURCE_DIR}/board.c
${CMAKE_CURRENT_SOURCE_DIR}/eabi_compat.c
${CMAKE_CURRENT_SOURCE_DIR}/head.c
)

add_subdirectory(hello_world)
Expand Down
40 changes: 40 additions & 0 deletions board/100ask-t113s3/head.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <types.h>

typedef struct boot_file_head {
uint32_t jump_instruction; /* one intruction jumping to real code */
uint8_t magic[8]; /* ="eGON.BT0" */
uint32_t check_sum; /* generated by PC */
uint32_t *length; /* generated by LD */
uint32_t pub_head_size; /* the size of boot_file_head_t */
uint8_t pub_head_vsn[4]; /* the version of boot_file_head_t */
uint32_t *ret_addr; /* the return value */
uint32_t *run_addr; /* run addr */
uint32_t boot_cpu; /* eGON version */
uint8_t platform[8]; /* platform information */
} boot_file_head_t;

#define BROM_FILE_HEAD_SIZE_OFFSET (((sizeof(boot_file_head_t) + sizeof(int)) / sizeof(int) + 1))
#define JUMP_INSTRUCTION (BROM_FILE_HEAD_SIZE_OFFSET | 0xEA000000)

#define BOOT0_MAGIC "eGON.BT0"
#define STAMP_VALUE (0x12345678)
#define BOOT_PUB_HEAD_VERSION "3000"

extern uint32_t __spl_size[];
extern uint32_t __code_start_address[];

const __attribute__((section(".boot0_head"))) boot_file_head_t boot_head = {
.jump_instruction = JUMP_INSTRUCTION,
.magic = BOOT0_MAGIC,
.check_sum = STAMP_VALUE,
.length = __spl_size,
.pub_head_size = sizeof(boot_file_head_t),
.pub_head_vsn = BOOT_PUB_HEAD_VERSION,
.ret_addr = __code_start_address,
.run_addr = __code_start_address,
.boot_cpu = 0,
.platform = {0, 0, '3', '.', '0', '.', '0', 0},
};
13 changes: 9 additions & 4 deletions board/100ask-t113s3/load_hifi4/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <elf_loader.h>
#include <ff.h>

#define CONFIG_HIFI4_ELF_FILENAME "t113_i_dsp0_evb1.elf"
#define CONFIG_HIFI4_ELF_FILENAME "dsp.elf"
#define CONFIG_HIFI4_ELF_LOADADDR (0x45000000)

#define CONFIG_SDMMC_SPEED_TEST_SIZE 1024// (unit: 512B sectors)
Expand Down Expand Up @@ -138,6 +138,8 @@ msh_declare_command(boot);
msh_define_help(boot, "boot to linux", "Usage: boot\n");
int cmd_boot(int argc, const char **argv) {
sunxi_hifi4_start();

abort();
return 0;
}

Expand All @@ -153,8 +155,7 @@ int main(void) {

sunxi_clk_init();// Initialize clock configurations

uint64_t dram_size = sunxi_dram_init(&dram_para);
arm32_mmu_enable(SDRAM_BASE, dram_size);
sunxi_dram_init(&dram_para);

sunxi_clk_dump();// Dump clock information

Expand Down Expand Up @@ -186,7 +187,7 @@ int main(void) {
return 0;
}

// sunxi_hifi4_clock_reset();
sunxi_hifi4_clock_reset();

/* HIFI4 need to remap addresses for some addr. */
vaddr_range_t hifi4_addr_mapping_range[] = {
Expand All @@ -210,8 +211,12 @@ int main(void) {
printk(LOG_LEVEL_ERROR, "HIFI4 ELF load FAIL\n");
}

dump_c906_clock();

printk(LOG_LEVEL_INFO, "HIFI4 Core now Running... \n");

cmd_boot(0, NULL);

syterkit_shell_attach(commands);

jmp_to_fel();// Jump to FEL mode
Expand Down
16 changes: 2 additions & 14 deletions board/100ask-t113s3/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,10 @@
.text

_start:
/* Boot head information for BROM */
.long 0xea000016
.byte 'e', 'G', 'O', 'N', '.', 'B', 'T', '0'
.long 0x12345678 /* checksum */
.long __spl_size /* spl size */
.long 0x30 /* boot header size */
.long 0x30303033 /* boot header version */
.long 0x00020000 /* return value */
.long 0x00028000 /* run address */
.long 0x0 /* eGON version */
.byte 0x00, 0x00, 0x00, 0x00 /* platform information - 8byte */
.byte 0x34, 0x2e, 0x30, 0x00

b reset

.align 5
_vector:
b reset
ldr pc, _undefined_instruction
ldr pc, _software_interrupt
ldr pc, _prefetch_abort
Expand Down
1 change: 1 addition & 0 deletions board/bingpi-m1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(APP_COMMON_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/start.S
${CMAKE_CURRENT_SOURCE_DIR}/board.c
${CMAKE_CURRENT_SOURCE_DIR}/eabi_compat.c
${CMAKE_CURRENT_SOURCE_DIR}/head.c
)

add_subdirectory(hello_world)
Loading

0 comments on commit b7458da

Please sign in to comment.