Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README, and probably get ready for C艹 #6

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions CMakeLists.txt
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I don't set(CMAKE_SYSTEM_NAME Generic), it seems trying to build a win32 test program with the arm toolchain on Windows.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ cmake_minimum_required(VERSION 3.10)

include(ExternalProject)

set(CMAKE_SYSTEM_NAME Generic)

# Define the path to the board loader files
set(BOARD_FLOADER_PATH ${CMAKE_SOURCE_DIR}/cmake/board/)
# Define the path to the mksunxi tool
Expand Down Expand Up @@ -81,16 +83,18 @@ configure_file(
"${PROJECT_BINARY_DIR}/config.h"
)

# Create an external project and build it
ExternalProject_Add(
mksunxi
PREFIX mksunxi
SOURCE_DIR "${PROJECT_SOURCE_DIR}/tools"
INSTALL_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND make -C ${PROJECT_SOURCE_DIR}/tools
BUILD_IN_SOURCE 1
)
if(NOT WIN32)
# Create an external project and build it
ExternalProject_Add(
mksunxi
PREFIX mksunxi
SOURCE_DIR "${PROJECT_SOURCE_DIR}/tools"
INSTALL_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND make -C ${PROJECT_SOURCE_DIR}/tools
BUILD_IN_SOURCE 1
)
endif()

# Set tools required for the build process
set(CMAKE_AR "${CROSS_COMPILE}ar")
Expand Down
102 changes: 91 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,58 @@ SyterKit is a bare-metal framework designed for development boards like TinyVisi

### Building SyterKit From Scratch

Building SyterKit is a straightforward process that only requires setting up the environment for compilation on a Linux operating system. The software packages required by SyterKit include:
Building SyterKit is a straightforward process that only requires setting up the environment for compilation on GNU/Linux, Windows or macOS(untested). The software packages required by SyterKit include:

- `gcc-arm-none-eabi`
- `gcc-arm-none-eabi` (`gcc-linaro-arm-eabi` works as well)
- `CMake`
- `GNU Make`

#### Prepare Building Environment on GNU/Linux
For commonly used Ubuntu systems, they can be installed using the following command:

```shell
sudo apt-get update
sudo apt-get install gcc-arm-none-eabi cmake build-essential -y
```

Then create a folder to store the compiled output files and navigate to it:
#### Prepare Building Environment on Windows
On Windows, the packages are required to be installed by hand:
- [gcc-arm-eabi](https://releases.linaro.org/components/toolchain/binaries)
- [CMake](https://cmake.org/download/)
- [GNU Make](https://gnuwin32.sourceforge.net/packages/make.htm)

*Note: it's a good idea to add the bin directories of above into `PATH` variable to avoid trouble.*

#### Start building
Create a folder to store the compiled output files and navigate to it:

```shell
mkdir build
cd build
```

Finally, run the following commands to compile SyterKit:
Run the following command to configure CMake cache:

```shell
cmake .. -DCMAKE_BOARD_FILE="tinyvision.cmake"
```

Where `tinyvision` is the target board you want to build SyterKit for. Remove this parameter to see available boards.
*If you are using Windows, you may need to add parameter `-G 'Unix Makefiles'`, like*

```shell
cmake .. -DCMAKE_BOARD_FILE="tinyvision.cmake" -G 'Unix Makefiles'
```

*This parameter may be not required, add it when CMake is trying to generate a Visual Studio project or something else.*

Run the following commands to build SyterKit
```shell
cmake ..
make
cd build
cmake --build . # You can add "-j" to enable multi-thread compilation
```


The compiled executable files will be located in `build/app`.

![image-20231206212123866](assets/post/README/image-20231206212123866.png)
Expand All @@ -59,6 +85,8 @@ The SyterKit project will compile two versions: firmware ending with `.elf` is f
- For SD Card, You need to flash the `xxx_card.bin`
- For SPI NAND/SPI NOR, You need to flash the `xxx_spi.bin`

To boot from USB or flash the boot image into SPI flash chips, you need to install the [XFEL](https://xboot.org/xfel) tool.

### Creating TF Card Boot Firmware

After build the firmware, you can flash it into the TF card. For the V851s platform, you can write it to either an 8K offset or a 128K offset. Generally, if the TF card uses MBR format, write it with an 8K offset. If it uses GPT format, write it with a 128K offset. Assuming `/dev/sdb` is the target TF card, you can use the following command to write it with an 8K offset:
Expand Down Expand Up @@ -119,6 +147,17 @@ Use the xfel tool to flash the created firmware into SPI NOR:
xfel spinor write 0x0 spi.img
```

### Booting from USB
Allwinner SoCs support `FEL` mode, which enables them to boot from USB, which is a convenient way to test SyterKit. Make sure you have installed XFEL tool,then you can load the fel image into the chip's memory and boot it:

For example, to boot the `hello_world` firmware, you can use the following

```shell
xfel write 0x28000 syter_boot_elf.bin # load the firmware into memory, 0x28000 is the beginning address of the SRAM of Allwinner V85x.

xfel exec 0x28000 # boot the firmware
```
Then you can see the output of the firmware from UART0.

# SyterKit

Expand All @@ -144,30 +183,58 @@ SyterKit 是一个纯裸机框架,用于 TinyVision 或者其他 v851se/v851s/

### 从零构建 SyterKit

构建 SyterKit 非常简单,只需要在 Linux 操作系统中安装配置环境即可编译。SyterKit 需要的软件包有:
构建 SyterKit 非常简单,只需要在 GNU/Linux, Windows或macOS(未测试) 操作系统中安装配置环境即可编译。SyterKit 需要的软件包有:

- `gcc-arm-none-eabi`
- `CMake`
- `GNU Make`

#### 在 GNU/Linux 上准备构建环境
对于常用的 Ubuntu 系统,可以通过如下命令安装

```shell
sudo apt-get update
sudo apt-get install gcc-arm-none-eabi cmake build-essential -y
```

然后新建一个文件夹存放编译的输出文件,并且进入这个文件夹
#### 在 Windows 上准备构建环境
在 Windows 上,需要手动安装软件包:
- [gcc-arm-eabi](https://releases.linaro.org/components/toolchain/binaries)
- [CMake](https://cmake.org/download/)
- [GNU Make](https://gnuwin32.sourceforge.net/packages/make.htm)

*注意:建议将上述软件包的 bin 目录添加到 `PATH` 环境变量中,以免出现麻烦。*

#### 开始构建

新建一个文件夹存放编译的输出文件,并且进入这个文件夹

```shell
mkdir build
cd build
```

然后运行命令编译 SyterKit
运行以下命令配置 CMake 缓存

```shell
cmake .. -DCMAKE_BOARD_FILE="tinyvision.cmake"
```
其中`tinyvision`是要构建SyterKit的目标开发板,可以通过去掉这个参数来查看可用的开发板列表。

*如果你使用的是 Windows,你可能需要添加`-G 'Unix Makefiles'`参数,例如:*

```shell
cmake .. -DCMAKE_BOARD_FILE="tinyvision.cmake" -G 'Unix Makefiles'
```

*这个参数可能不是必须的,当 CMake 尝试生成 Visual Studio 项目或其他项目时添加它。*


运行命令构建 SyterKit

```shell
cmake ..
make
cd build
cmake --build . # 可以添加 "-j" 开启多线程编译
```

编译后的可执行文件位于 `build/app` 中
Expand All @@ -179,6 +246,7 @@ make
- 对于 SD 卡,你需要刷写 `xxx_card.bin` 文件。
- 对于 SPI NAND/SPI NOR,你需要刷写 `xxx_spi.bin` 文件。

要通过 USB 引导或者刷写 SPI Flash 的固件,你需要安装 [XFEL](https://xboot.org/xfel) 工具。

### 制作 TF 卡启动固件

Expand Down Expand Up @@ -239,3 +307,15 @@ dd if=zImage of=spi.img bs=2k seek=256 # Kernel on page 256
```shell
xfel spinor write 0x0 spi.img
```

### 通过 USB 引导

Allwinner SoC 支持 `FEL` 模式,可以通过 USB 引导,这是一个方便的测试 SyterKit 的方式。确保你已经安装了 XFEL 工具,然后可以将 fel 镜像加载到芯片的内存中并启动它。

例如,要引导 `hello_world` 固件,可以使用以下命令

```shell
xfel write 0x28000 syter_boot_elf.bin # 把固件加载到内存中,0x28000 是 Allwinner V85x 的 SRAM 的起始地址。

xfel exec 0x28000 # 启动固件
```
8 changes: 8 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#ifndef __COMMON_H__
#define __COMMON_H__

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Expand Down Expand Up @@ -40,4 +44,8 @@ int raise(int signum);

void show_banner(void);

#ifdef __cplusplus
}
#endif // __cplusplus

#endif// __COMMON_H__
8 changes: 7 additions & 1 deletion include/ctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#ifndef __CTYPE_H__
#define __CTYPE_H__

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
int isalnum(int c);

int isalpha(int c);
Expand Down Expand Up @@ -35,4 +37,8 @@ int tolower(int c);

int toupper(int c);

#ifdef __cplusplus
}
#endif // __cplusplus

#endif /* __CTYPE_H__ */
8 changes: 8 additions & 0 deletions include/drivers/pmu/axp.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

#include <sys-i2c.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

typedef struct _axp_step_info {
uint32_t step_min_vol;
uint32_t step_max_vol;
Expand Down Expand Up @@ -37,4 +41,8 @@ int pmu_axp1530_set_vol(sunxi_i2c_t *i2c_dev, char *name, int set_vol, int onoff

void pmu_axp1530_dump(sunxi_i2c_t *i2c_dev);

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // __G_AXP_H__
8 changes: 8 additions & 0 deletions include/drivers/sun50iw9/sys-clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@

#include "reg/reg-ccu.h"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void sunxi_clk_init(void);

void sunxi_clk_reset(void);

void sunxi_clk_dump(void);

#ifdef __cplusplus
}
#endif // __cplusplus

#endif// __SUN50IW9_CLK_H__
8 changes: 8 additions & 0 deletions include/drivers/sun50iw9/sys-dram.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

#define SDRAM_BASE (0x40000000)

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

uint64_t sunxi_dram_init();

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // __SUN50IW9_SYS_DRAM_H__
8 changes: 8 additions & 0 deletions include/drivers/sun50iw9/sys-sid.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

#include <reg-ncat.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

static const struct sid_section_t {
char *name;
uint32_t offset;
Expand Down Expand Up @@ -60,4 +64,8 @@ void syter_efuse_write(uint32_t offset, uint32_t value);

void syter_efuse_dump(void);

#ifdef __cplusplus
}
#endif // __cplusplus

#endif// __SUN50IW9_SYS_SID_H__
8 changes: 8 additions & 0 deletions include/drivers/sun8iw20/sys-clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@

#include "reg/reg-ccu.h"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void sunxi_clk_init(void);

void sunxi_clk_reset(void);

void sunxi_clk_dump(void);

#ifdef __cplusplus
}
#endif // __cplusplus

#endif// __SUN8IW20_CLK_H__
8 changes: 8 additions & 0 deletions include/drivers/sun8iw20/sys-dram.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

#define SDRAM_BASE (0x40000000)

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

enum sunxi_dram_type {
SUNXI_DRAM_TYPE_DDR2 = 2,
SUNXI_DRAM_TYPE_DDR3 = 3,
Expand Down Expand Up @@ -58,4 +62,8 @@ int init_DRAM(int type, dram_para_t *para);

uint64_t sunxi_dram_init(dram_para_t *para);

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // __SUN8IW20_SYS_DRAM_H__
8 changes: 8 additions & 0 deletions include/drivers/sun8iw20/sys-rproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@

#include "reg/reg-rproc.h"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void sunxi_c906_clock_init(uint32_t addr);

void sunxi_c906_clock_reset(void);

#ifdef __cplusplus
}
#endif // __cplusplus

#endif// __SUN8IW20_SYS_RPROC_H__
Loading