Skip to content

Commit

Permalink
[board] support lt527x boot
Browse files Browse the repository at this point in the history
  • Loading branch information
YuzukiTsuru committed Feb 3, 2024
1 parent 49c6a90 commit 591f399
Show file tree
Hide file tree
Showing 30 changed files with 2,369 additions and 11 deletions.
4 changes: 2 additions & 2 deletions board/lt527x/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ _start:
.long __spl_size /* spl size */
.long 0x30 /* boot header size */
.long 0x30303033 /* boot header version */
.long 0x00020000 /* return value */
.long 0x00020000 /* run address */
.long 0x00044000 /* return value */
.long 0x00044000 /* run address */
.long 0x0 /* eGON version */
.byte 0x00, 0x00, 0x00, 0x00 /* platform information - 8byte */
.byte 0x34, 0x2e, 0x30, 0x00
Expand Down
Binary file added board/lt527x/syter_boot/bl33/syter_bl33.bin
Binary file not shown.
24 changes: 17 additions & 7 deletions board/lt527x/syter_boot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@
#define CONFIG_BL31_FILENAME "bl31.bin"
#define CONFIG_BL31_LOAD_ADDR (0x48000000)

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

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

#define CONFIG_BL33_FILENAME "syter_bl33.bin"
#define CONFIG_BL33_LOAD_ADDR (0x4a000000)

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

Expand Down Expand Up @@ -88,9 +91,8 @@ 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];
uint8_t *bl33_dest;
char bl33_filename[FILENAME_MAX_LEN];
} image_info_t;

image_info_t image;
Expand Down Expand Up @@ -180,6 +182,11 @@ static int load_sdcard(image_info_t *image) {
if (ret)
return ret;

printk(LOG_LEVEL_INFO, "FATFS: read %s addr=%x\n", image->bl33_filename, (uint32_t) image->bl33_dest);
ret = fatfs_loadimage(image->bl33_filename, image->bl33_dest);
if (ret)
return ret;

/* umount fs */
fret = f_mount(0, "", 0);
if (fret != FR_OK) {
Expand Down Expand Up @@ -247,7 +254,7 @@ 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->next_boot_base = CONFIG_KERNEL_LOAD_ADDR;
atf_head->next_boot_base = CONFIG_BL33_LOAD_ADDR;
atf_head->dtb_base = CONFIG_DTB_LOAD_ADDR;

atf_head->platform[0] = 0x00;
Expand Down Expand Up @@ -348,10 +355,13 @@ int main(void) {
image.bl31_dest = (uint8_t *) CONFIG_BL31_LOAD_ADDR;
image.of_dest = (uint8_t *) CONFIG_DTB_LOAD_ADDR;
image.kernel_dest = (uint8_t *) CONFIG_KERNEL_LOAD_ADDR;
image.bl33_dest = (uint8_t *) CONFIG_BL33_LOAD_ADDR;

strcpy(image.bl31_filename, CONFIG_BL31_FILENAME);
strcpy(image.of_filename, CONFIG_DTB_FILENAME);
strcpy(image.kernel_filename, CONFIG_KERNEL_FILENAME);
strcpy(image.bl33_filename, CONFIG_BL33_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 Down
2 changes: 1 addition & 1 deletion cmake/board/lt527x.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ set(CMAKE_COMMON_FLAGS "-nostdlib -Os -mcpu=cortex-a55")
set(CMAKE_C_DISABLE_WARN_FLAGS "-Wno-int-to-pointer-cast -Wno-implicit-function-declaration -Wno-discarded-qualifiers")
set(CMAKE_CXX_DISABLE_WARN_FLAGS "-Wno-int-to-pointer-cast")

set(ARCH_BIN_START_ADDRESS "0x00020000")
set(ARCH_BIN_START_ADDRESS "0x00044000")
set(ARCH_BIN_SRAM_LENGTH "128K")

set(ARCH_FEL_START_ADDRESS "0x00020000")
Expand Down
2 changes: 1 addition & 1 deletion include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum {
};

#ifndef LOG_LEVEL_DEFAULT
#define LOG_LEVEL_DEFAULT LOG_LEVEL_DEBUG
#define LOG_LEVEL_DEFAULT LOG_LEVEL_INFO
#endif

void set_timer_count();
Expand Down
33 changes: 33 additions & 0 deletions scripts/genimage_t527.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
image boot.vfat {
vfat {
files = {
"Image",
"sunxi.dtb",
"../board/lt527x/syter_boot/bl31/bl31.bin",
"../utils/bl33/output/syter_bl33.bin"
}
}
size = 128M
}

image sdcard.img {
hdimage {}

partition boot0 {
in-partition-table = "no"
image = "../build/board/lt527x/syter_boot/syter_boot_bin_card.bin"
offset = 8K
}

partition boot0-gpt {
in-partition-table = "no"
image = "../build/board/lt527x/syter_boot/syter_boot_bin_card.bin"
offset = 128K
}

partition kernel {
partition-type = 0xC
bootable = "true"
image = "boot.vfat"
}
}
2 changes: 2 additions & 0 deletions utils/bl33_t527/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
output/
.obj/
118 changes: 118 additions & 0 deletions utils/bl33_t527/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#
# Top makefile
#

CROSS ?= arm-none-eabi-
NAME := syter_bl33

#
# System environment variable.
#
ifeq ($(OS), Windows_NT)
HOSTOS := windows
else
ifneq (,$(findstring Linux, $(shell uname -a)))
HOSTOS := linux
endif
endif

#
# Load default variables.
#
ASFLAGS := -g -ggdb -Wall -O3
CFLAGS := -g -ggdb -Wall -O3
CXXFLAGS := -g -ggdb -Wall -O3
LDFLAGS := -T link.ld -nostdlib
ARFLAGS := -rcs
OCFLAGS := -v -O binary
ODFLAGS :=
MCFLAGS := -nostdinc -nostdlib -mabi=aapcs-linux -march=armv7-a -Wno-builtin-declaration-mismatch -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast

LIBDIRS :=
LIBS :=
INCDIRS :=
SRCDIRS :=

#
# Add external library
#
INCDIRS += include
SRCDIRS += source

#
# You shouldn't need to change anything below this point.
#
AS := $(CROSS)gcc -x assembler-with-cpp
CC := $(CROSS)gcc
CXX := $(CROSS)g++
LD := $(CROSS)ld
AR := $(CROSS)ar
OC := $(CROSS)objcopy
OD := $(CROSS)objdump
MKDIR := mkdir -p
CP := cp -af
RM := rm -fr
CD := cd
FIND := find

#
# X variables
#
G_ASFLAGS := $(MCFLAGS) $(ASFLAGS)
G_CFLAGS := $(MCFLAGS) $(CFLAGS)
G_CXXFLAGS := $(MCFLAGS) $(CXXFLAGS)
G_LDFLAGS := $(LDFLAGS)
G_OCFLAGS := $(OCFLAGS)
G_LIBDIRS := $(LIBDIRS)
G_LIBS := $(LIBS) -lgcc

G_OUT := output
G_NAME := $(patsubst %, $(G_OUT)/%, $(NAME))
G_INCDIRS := $(patsubst %, -I %, $(INCDIRS))
G_SRCDIRS := $(patsubst %, %, $(SRCDIRS))
G_OBJDIRS := $(patsubst %, .obj/%, $(G_SRCDIRS))

G_SFILES := $(foreach dir, $(G_SRCDIRS), $(wildcard $(dir)/*.S))
G_CFILES := $(foreach dir, $(G_SRCDIRS), $(wildcard $(dir)/*.c))
G_CPPFILES := $(foreach dir, $(G_SRCDIRS), $(wildcard $(dir)/*.cpp))

G_SDEPS := $(patsubst %, .obj/%, $(G_SFILES:.S=.o.d))
G_CDEPS := $(patsubst %, .obj/%, $(G_CFILES:.c=.o.d))
G_CPPDEPS := $(patsubst %, .obj/%, $(G_CPPFILES:.cpp=.o.d))
G_DEPS := $(G_SDEPS) $(G_CDEPS) $(G_CPPDEPS)

G_SOBJS := $(patsubst %, .obj/%, $(G_SFILES:.S=.o))
G_COBJS := $(patsubst %, .obj/%, $(G_CFILES:.c=.o))
G_CPPOBJS := $(patsubst %, .obj/%, $(G_CPPFILES:.cpp=.o))
G_OBJS := $(G_SOBJS) $(G_COBJS) $(G_CPPOBJS)

VPATH := $(G_OBJDIRS)

.PHONY: all clean
all : $(G_NAME)

$(G_NAME) : $(G_OBJS)
@echo [LD] Linking $@.elf
@$(CC) $(G_LDFLAGS) $(G_LIBDIRS) -Wl,--cref,-Map=$@.map $^ -o $@.elf $(G_LIBS)
@echo [OC] Objcopying $@.bin
@$(OC) $(G_OCFLAGS) $@.elf $@.bin

$(G_SOBJS) : .obj/%.o : %.S
@echo [AS] $<
@$(AS) $(G_ASFLAGS) -MD -MP -MF $@.d $(G_INCDIRS) -c $< -o $@

$(G_COBJS) : .obj/%.o : %.c
@echo [CC] $<
@$(CC) $(G_CFLAGS) -MD -MP -MF $@.d $(G_INCDIRS) -c $< -o $@

$(G_CPPOBJS) : .obj/%.o : %.cpp
@echo [CXX] $<
@$(CXX) $(G_CXXFLAGS) -MD -MP -MF $@.d $(G_INCDIRS) -c $< -o $@

clean:
@$(RM) .obj $(G_OUT)

#
# Include the dependency files, should be place the last of makefile
#
sinclude $(shell $(MKDIR) $(G_OBJDIRS) $(G_OUT)) $(G_DEPS)
84 changes: 84 additions & 0 deletions utils/bl33_t527/include/byteorder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#ifndef __BYTEORDER_H__
#define __BYTEORDER_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <types.h>
#include <endian.h>

static inline u16_t __swab16(u16_t x)
{
return ( (x<<8) | (x>>8) );
}

static inline u32_t __swab32(u32_t x)
{
return ( (x<<24) | (x>>24) | \
((x & (u32_t)0x0000ff00UL)<<8) | \
((x & (u32_t)0x00ff0000UL)>>8) );
}

static inline u64_t __swab64(u64_t x)
{
return ( (x<<56) | (x>>56) | \
((x & (u64_t)0x000000000000ff00ULL)<<40) | \
((x & (u64_t)0x0000000000ff0000ULL)<<24) | \
((x & (u64_t)0x00000000ff000000ULL)<< 8) | \
((x & (u64_t)0x000000ff00000000ULL)>> 8) | \
((x & (u64_t)0x0000ff0000000000ULL)>>24) | \
((x & (u64_t)0x00ff000000000000ULL)>>40) );
}

/*
* swap bytes bizarrely.
* swahw32 - swap 16-bit half-words in a 32-bit word
*/
static inline u32_t __swahw32(u32_t x)
{
return ( ((x & (u32_t)0x0000ffffUL)<<16) | ((x & (u32_t)0xffff0000UL)>>16) );
}

/*
* swap bytes bizarrely.
* swahb32 - swap 8-bit halves of each 16-bit half-word in a 32-bit word
*/
static inline u32_t __swahb32(u32_t x)
{
return ( ((x & (u32_t)0x00ff00ffUL)<<8) | ((x & (u32_t)0xff00ff00UL)>>8) );
}

#if (BYTE_ORDER == BIG_ENDIAN)
#define cpu_to_le64(x) (__swab64((u64_t)(x)))
#define le64_to_cpu(x) (__swab64((u64_t)(x)))
#define cpu_to_le32(x) (__swab32((u32_t)(x)))
#define le32_to_cpu(x) (__swab32((u32_t)(x)))
#define cpu_to_le16(x) (__swab16((u16_t)(x)))
#define le16_to_cpu(x) (__swab16((u16_t)(x)))
#define cpu_to_be64(x) ((u64_t)(x))
#define be64_to_cpu(x) ((u64_t)(x))
#define cpu_to_be32(x) ((u32_t)(x))
#define be32_to_cpu(x) ((u32_t)(x))
#define cpu_to_be16(x) ((u16_t)(x))
#define be16_to_cpu(x) ((u16_t)(x))
#else
#define cpu_to_le64(x) ((u64_t)(x))
#define le64_to_cpu(x) ((u64_t)(x))
#define cpu_to_le32(x) ((u32_t)(x))
#define le32_to_cpu(x) ((u32_t)(x))
#define cpu_to_le16(x) ((u16_t)(x))
#define le16_to_cpu(x) ((u16_t)(x))
#define cpu_to_be64(x) (__swab64((u64_t)(x)))
#define be64_to_cpu(x) (__swab64((u64_t)(x)))
#define cpu_to_be32(x) (__swab32((u32_t)(x)))
#define be32_to_cpu(x) (__swab32((u32_t)(x)))
#define cpu_to_be16(x) (__swab16((u16_t)(x)))
#define be16_to_cpu(x) (__swab16((u16_t)(x)))
#endif

#ifdef __cplusplus
}
#endif

#endif /* __BYTEORDER_H__ */
27 changes: 27 additions & 0 deletions utils/bl33_t527/include/endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef __ARM32_ENDIAN_H__
#define __ARM32_ENDIAN_H__

#ifdef __cplusplus
extern "C" {
#endif

#define LITTLE_ENDIAN (0x1234)
#define BIG_ENDIAN (0x4321)

#if ( !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN) )
#define __LITTLE_ENDIAN
#endif

#if defined(__LITTLE_ENDIAN)
#define BYTE_ORDER LITTLE_ENDIAN
#elif defined(__BIG_ENDIAN)
#define BYTE_ORDER BIG_ENDIAN
#else
#error "Unknown byte order!"
#endif

#ifdef __cplusplus
}
#endif

#endif /* __ARM32_ENDIAN_H__ */
Loading

0 comments on commit 591f399

Please sign in to comment.