Skip to content

Commit

Permalink
[board] 100ask ros r818 board support syter boot
Browse files Browse the repository at this point in the history
  • Loading branch information
YuzukiTsuru committed Jan 14, 2024
1 parent fec1a58 commit 6db9b5b
Show file tree
Hide file tree
Showing 11 changed files with 1,767 additions and 1,490 deletions.
1 change: 1 addition & 0 deletions board/100ask-ros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(APP_COMMON_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/board.c
${CMAKE_CURRENT_SOURCE_DIR}/eabi_compat.c
${CMAKE_CURRENT_SOURCE_DIR}/payloads/init_dram_bin.c
${CMAKE_CURRENT_SOURCE_DIR}/payloads/ar100s.c
)

add_subdirectory(hello_world)
Expand Down
40 changes: 40 additions & 0 deletions board/100ask-ros/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,43 @@ void clean_syterkit_data(void) {
arm32_interrupt_disable();
printk(LOG_LEVEL_INFO, "free interrupt ok...\n");
}

#define RTC_DATA_COLD_START (7)
#define CPUS_CODE_LENGTH (0x1000)
#define CPUS_VECTOR_LENGTH (0x4000)

extern uint8_t ar100code_bin[];
extern uint32_t ar100code_bin_len;

int ar100s_gpu_fix(void) {
uint32_t value;
uint32_t id = (readl(SUNXI_SYSCRL_BASE + 0x24)) & 0x07;
printk(LOG_LEVEL_DEBUG, "SUNXI_SYSCRL_BASE + 0x24 = 0x%08x, id = %d, RTC_DATA_COLD_START = %d\n",
readl(SUNXI_SYSCRL_BASE + 0x24), id, rtc_read_data(RTC_DATA_COLD_START));
if (((id == 0) || (id == 3) || (id == 4) || (id == 5))) {
if (rtc_read_data(RTC_DATA_COLD_START) == 0) {
rtc_write_data(RTC_DATA_COLD_START, 0x1);

value = readl(SUNXI_RCPUCFG_BASE + 0x0);
value &= ~1;
writel(value, SUNXI_RCPUCFG_BASE + 0x0);

memcpy((void *) SCP_SRAM_BASE, (void *) ar100code_bin, CPUS_CODE_LENGTH);
memcpy((void *) (SCP_SRAM_BASE + CPUS_VECTOR_LENGTH), (char *) ar100code_bin + CPUS_CODE_LENGTH, ar100code_bin_len - CPUS_CODE_LENGTH);
asm volatile("dsb");

value = readl(SUNXI_RCPUCFG_BASE + 0x0);
value &= ~1;
writel(value, SUNXI_RCPUCFG_BASE + 0x0);
value = readl(SUNXI_RCPUCFG_BASE + 0x0);
value |= 1;
writel(value, SUNXI_RCPUCFG_BASE + 0x0);
while (1)
asm volatile("WFI");
} else {
rtc_write_data(RTC_DATA_COLD_START, 0x0);
}
}

return 0;
}
492 changes: 492 additions & 0 deletions board/100ask-ros/payloads/ar100s.c

Large diffs are not rendered by default.

2,552 changes: 1,088 additions & 1,464 deletions board/100ask-ros/payloads/init_dram_bin.c

Large diffs are not rendered by default.

101 changes: 80 additions & 21 deletions board/100ask-ros/syter_boot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
#define CONFIG_BL31_LOAD_ADDR (0x48000000)

#define CONFIG_DTB_FILENAME "sunxi.dtb"
#define CONFIG_DTB_LOAD_ADDR (0x4a200000)
#define CONFIG_DTB_LOAD_ADDR (0x41f00000)

#define CONFIG_KERNEL_FILENAME "Image"
#define CONFIG_KERNEL_LOAD_ADDR (0x40080000)

#define CONFIG_SDMMC_SPEED_TEST_SIZE 1024// (unit: 512B sectors)

#define CONFIG_DEFAULT_BOOTDELAY 3

#define CONFIG_HEAP_BASE (0x40800000)
#define CONFIG_HEAP_SIZE (16 * 1024 * 1024)

Expand All @@ -53,14 +55,16 @@ extern sunxi_i2c_t i2c_pmu;

extern sdhci_t sdhci0;

extern int ar100s_gpu_fix(void);

typedef struct atf_head {
uint32_t jump_instruction; /* jumping to real code */
uint8_t magic[8]; /* ="u-boot" */
uint32_t scp_base; /* generated by PC */
uint32_t next_boot_base; /* align size in byte */
uint32_t nos_base; /* the size of all file */
uint32_t secureos_base; /* the size of uboot */
uint8_t version[8]; /* uboot version */
uint32_t scp_base; /* scp openrisc core bin */
uint32_t next_boot_base; /* next boot base for uboot */
uint32_t nos_base; /* ARM SVC RUNOS base */
uint32_t secureos_base; /* optee base */
uint8_t version[8]; /* atf version */
uint8_t platform[8]; /* platform information */
uint32_t reserved[1]; /* stamp space, 16bytes align */
uint32_t dram_para[32]; /* the dram param */
Expand All @@ -77,6 +81,10 @@ typedef struct {

uint8_t *of_dest;
char of_filename[FILENAME_MAX_LEN];

uint8_t *config_dest;
uint8_t is_config;
char config_filename[FILENAME_MAX_LEN];
} image_info_t;

image_info_t image;
Expand Down Expand Up @@ -215,9 +223,68 @@ static void set_pmu_fin_voltage(char *power_name, uint32_t voltage) {
mdelay(30); /* Delay 300ms for pmu bootup */
}

static int abortboot_single_key(int bootdelay) {
int abort = 0;
unsigned long ts;

printk(LOG_LEVEL_INFO, "Hit any key to stop autoboot: %2d ", bootdelay);

/* Check if key already pressed */
if (tstc()) { /* we got a key press */
uart_getchar(); /* consume input */
printk(LOG_LEVEL_MUTE, "\b\b\b%2d", bootdelay);
abort = 1; /* don't auto boot */
}

while ((bootdelay > 0) && (!abort)) {
--bootdelay;
/* delay 1000 ms */
ts = time_ms();
do {
if (tstc()) { /* we got a key press */
abort = 1; /* don't auto boot */
break;
}
udelay(10000);
} while (!abort && time_ms() - ts < 1000);
printk(LOG_LEVEL_MUTE, "\b\b\b%2d ", bootdelay);
}
uart_putchar('\n');
return abort;
}

msh_declare_command(boot);
msh_define_help(boot, "boot to linux", "Usage: boot\n");
int cmd_boot(int argc, const char **argv) {
atf_head_t *atf_head = (atf_head_t *) image.bl31_dest;

atf_head->nos_base = CONFIG_KERNEL_LOAD_ADDR;
atf_head->dtb_base = CONFIG_DTB_LOAD_ADDR;

printk(LOG_LEVEL_INFO, "ATF: Kernel addr: 0x%08x\n", atf_head->nos_base);
printk(LOG_LEVEL_INFO, "ATF: Kernel DTB addr: 0x%08x\n", atf_head->dtb_base);

clean_syterkit_data();

jmp_to_arm64(CONFIG_BL31_LOAD_ADDR);

printk(LOG_LEVEL_INFO, "Back to SyterKit\n");

// if kernel boot not success, jump to fel.
jmp_to_fel();
return 0;
}

const msh_command_entry commands[] = {
msh_define_command(boot),
msh_command_end,
};

int main(void) {
sunxi_serial_init(&uart_dbg);

ar100s_gpu_fix();

show_banner();

sunxi_clk_init();
Expand Down Expand Up @@ -251,7 +318,6 @@ int main(void) {
strcpy(image.bl31_filename, CONFIG_BL31_FILENAME);
strcpy(image.of_filename, CONFIG_DTB_FILENAME);
strcpy(image.kernel_filename, CONFIG_KERNEL_FILENAME);

/* Initialize the SD host controller. */
if (sunxi_sdhci_init(&sdhci0) != 0) {
printk(LOG_LEVEL_ERROR, "SMHC: %s controller init failed\n", sdhci0.name);
Expand All @@ -272,24 +338,17 @@ int main(void) {
goto _shell;
}

atf_head_t *atf_head = (atf_head_t *) image.bl31_dest;

atf_head->next_boot_base = CONFIG_KERNEL_LOAD_ADDR;
atf_head->dtb_base = CONFIG_DTB_LOAD_ADDR;

printk(LOG_LEVEL_INFO, "ATF: jump_instruction: 0x%08x\n", atf_head->jump_instruction);
printk(LOG_LEVEL_INFO, "ATF: magic: %s\n", atf_head->magic);
printk(LOG_LEVEL_INFO, "ATF: scp_base: 0x%08x\n", atf_head->scp_base);
printk(LOG_LEVEL_INFO, "ATF: next_boot_base: 0x%08x\n", atf_head->next_boot_base);

clean_syterkit_data();
int bootdelay = CONFIG_DEFAULT_BOOTDELAY;

jmp_to_arm64(CONFIG_BL31_LOAD_ADDR);
/* Showing boot delays */
if (abortboot_single_key(bootdelay)) {
goto _shell;
}

printk(LOG_LEVEL_INFO, "Back to SyterKit\n");
cmd_boot(0, NULL);

_shell:
abort();
syterkit_shell_attach(commands);

return 0;
}
16 changes: 16 additions & 0 deletions include/drivers/sun50iw10/reg/reg-ncat.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,20 @@
#define GPIO_3_3V_MODE 0
#define GPIO_1_8V_MODE 1

/* sram layout*/
#define CONFIG_SYS_SRAM_BASE (0x20000)
#define CONFIG_SYS_SRAM_SIZE (0x4000)
#define CONFIG_SYS_SRAMA2_BASE (0x100000)
#define CONFIG_SYS_SRAMA2_SIZE (0x14000)
#define CONFIG_SYS_SRAMC_BASE (0x24000)
#define CONFIG_SYS_SRAMC_SIZE (0x21000)

/* scp mem layout */
#define SCP_DRAM_SIZE (0x0000) /* no cpus dram code on sun50iw10 */
#define SCP_DTS_SIZE (0x40000)
#define SCP_CODE_DRAM_OFFSET (0x14000)
#define SCP_SRAM_BASE (CONFIG_SYS_SRAMA2_BASE)
#define SCP_SRAM_SIZE (CONFIG_SYS_SRAMA2_SIZE)
#define HEADER_OFFSET (0x4000)

#endif// __SUN50IW10_REG_NCAT_H__
2 changes: 1 addition & 1 deletion payloads
9 changes: 8 additions & 1 deletion scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
*.bin
*.img
*.img
*.vfat
*.txt
*.zip
Image
zImage
*.dtb
*.7z
38 changes: 38 additions & 0 deletions scripts/genimage_100ask-roc.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
image boot.vfat {
vfat {
files = {
"Image",
"sunxi.dtb",
"config.txt",
"bl31.bin"
}
}
size = 32M
}

image 100ask-ros-sdcard.img {
hdimage {}

partition boot0 {
in-partition-table = "no"
image = "syter_boot_bin_card.bin"
offset = 8K
}

partition boot0-gpt {
in-partition-table = "no"
image = "syter_boot_bin_card.bin"
offset = 128K
}

partition kernel {
partition-type = 0xC
bootable = "true"
image = "boot.vfat"
}

partition rootfs {
partition-type = 0x83
image = "rootfs.img"
}
}
2 changes: 1 addition & 1 deletion src/drivers/sun50iw10/sys-dram.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <sys-dram.h>
#include <sys-rtc.h>

#define INIT_DRAM_BIN_BASE 0x104000
#define INIT_DRAM_BIN_BASE 0x3E900

#define SUNXI_RTC_BASE (0x07000000)
#define SUNXI_RTC_DATA_BASE (SUNXI_RTC_BASE + 0x100)
Expand Down
4 changes: 2 additions & 2 deletions src/image/uimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
#define KERNEL_CODE_OFFSET_IN_UIMAGE 0x40

int uImage_loader(uint8_t *addr, uint32_t *entry) {
*entry = addr + KERNEL_CODE_OFFSET_IN_UIMAGE;
return 1;
*entry = (uint8_t *) (addr + KERNEL_CODE_OFFSET_IN_UIMAGE);
return 1;
}

0 comments on commit 6db9b5b

Please sign in to comment.