# Phytium-Standalone-SDK **Repository Path**: jackwl/phytium-standalone-sdk ## Basic Information - **Project Name**: Phytium-Standalone-SDK - **Description**: 本项目发布了Phytium系列CPU的Standalone BSP源码,Baremetal参考例程及其配置构建工具 - **Primary Language**: C - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 52 - **Created**: 2022-11-15 - **Last Updated**: 2022-11-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Phytium-Standalone-SDK **v0.1.3** [ReleaseNote](./doc/ChangeLog.md) --- ## 1. 介绍 本项目发布了 Phytium 系列 CPU 的 BSP 源码,Baremetal 参考例程及其配置编译工具 ![title](https://images.gitee.com/uploads/images/2021/0909/152057_87411a53_8736513.png "屏幕截图.png") --- ## 2. 安装使用 ### 2.1 Ubuntu 20.04 x86_64 环境下使用 Standalone SDK #### 2.1.1 选择在线方式安装 SDK - 通过 Gitee 拉取 Standalone SDK 源代码 ``` $ git clone https://gitee.com/phytium_embedded/phytium-standalobe-sdk.git ~/standalone_sdk $ cd ~/standalone_sdk ``` - 检查 install.sh 的执行权限, 如果没有执行权限`x`,需要利用`chmod +x ./install.sh`添加执行权限 ``` $ ls ./install.sh -l -rwxrwxrwx 1 usr usr 6353 Jul 21 10:13 ./install.sh ``` - 在线下载源代码和编译环境,完成 Standalone SDK 安装 ``` $ ./install.sh -online ``` ![输入图片说明](https://images.gitee.com/uploads/images/2021/0804/094253_5eb385be_8736513.png "屏幕截图.png") - **安装完成后重启系统,生效 Standalone SDK 环境** >请注意使用虚拟机进行开发时不要将sdk安装在挂载的共享文件夹下,否则交叉编译链的部分链接文件可能无法工作 #### 2.1.2 选择离线方式安装 SDK - 下载[Phytium Standalone SDK](https://gitee.com/phytium_embedded/phytium-standalone-sdk)源代码 - 下载[AARCH32](https://gitee.com/phytium_embedded/phytium-standalone-sdk/attach_files/776847/download/gcc-arm-x86_64-none-eabi-10-2020-q4-major.tar.xz)编译器 - 下载[AARCH64](https://gitee.com/phytium_embedded/phytium-standalone-sdk/attach_files/776846/download/gcc-arm-x86_64-aarch64-none-elf-10.2-2020.11.tar.xz)编译器 - 解压 phytium_standalone_sdk.zip 为`~/standalone_sdk`(路径名可以自定义) - 将 AARCH32、AARCH64 编译器压缩包放置在`~/standalone_sdk/tools`(必须放置在 tools 路径下) - 确保 install.sh 有执行权限,`~/standalone_sdk`Standalone SDK 安装 ``` $ ./install.sh ``` ![输入图片说明](https://images.gitee.com/uploads/images/2021/0804/094231_497c9ef2_8736513.png "屏幕截图.png") - **安装完成后重启系统,生效 Standalone SDK 环境** ### 2.2 Kylin OS/Ubuntu 20.04 AARCH64 环境下使用 Standalone SDK #### 2.2.1 选择在线方式安装 SDK 参考 2.1.1 选择在线方式安装 SDK #### 2.2.2 选择离线方式安装 SDK - 下载[Phytium Standalone SDK](https://gitee.com/phytium_embedded/phytium-standalone-sdk)源代码 - 下载[AARCH32](https://gitee.com/phytium_embedded/phytium-standalone-sdk/attach_files/779742/download/gcc-arm-aarch64-none-eabi-10-2020-q4-major.tar.xz)编译器 - 下载[AARCH64](https://gitee.com/phytium_embedded/phytium-standalone-sdk/attach_files/779743/download/gcc-arm-10.2-2020.11-aarch64-aarch64-none-elf.tar.xz)编译器 - 解压 phytium_standalone_sdk.zip 为`~/standalone_sdk`(路径名可以自定义) - 将 AARCH32、AARCH64 编译器压缩包放置在`~/standalone_sdk/tools`(必须放置在 tools 路径下) - 确保 install.sh 有执行权限,`~/standalone_sdk`Standalone SDK 安装 ``` $ ./install.sh ``` ### 2.3 新建一个 baremetal 应用工程 #### 2.3.1 选择工程模板 - 复制`~/standalone-sdk/example/template`目录,作为 baremetal 应用工程 > `*` 表示可选文件 ``` $ ls Kconfig --> 应用工程配置menu文件 makefile --> makefile inc --> 用户头文件* main.c --> 包含main函数 sdkconfig --> 配置输出 sdkconfig.h --> 配置输出 src --> 用户源文件* ``` >请注意使用小写makefile,使用Makefile在部分平台不能被识别 #### 2.3.2 选择目标平台 - 切换目标平台, e.g `FT2000/4 AARCH32`, 加载默认配置 ``` make config_ft2004_aarch32 ``` > 使用`FT2000-4`作为目标编译平台,通过`make config_ft2004_aarch32`和`make config_ft2004_aarch64`加载默认配置 > 使用`D2000`作为目标编译平台,通过`make config_d2000_aarch32`和`make config_d2000_aarch64`加载默认配置 - 编译应用工程, 生成`*.bin`文件用于下载到开发板 ``` $ make $ ls template.bin --> 二进制文件 template.dis --> 反汇编文件 template.elf --> ELF文件 template.map --> 内存布局文件 ``` ![输入图片说明](https://images.gitee.com/uploads/images/2021/0709/141655_f20b6d98_8736513.png "屏幕截图.png") ### 2.4 快速使用例程 > ~/standalone-sdk/example/aarch32_hello_world ![输入图片说明](https://images.gitee.com/uploads/images/2021/0709/145025_398f6501_8736513.png "屏幕截图.png") ### 2.5 下载镜像跳转启动 #### 2.5.1 在 host 侧(Ubuntu 20.04)配置 tftp 服务 - 在开发环境`host`侧安装`tftp`服务 ``` sudo apt-get install tftp-hpa tftpd-hpa sudo apt-get install xinetd ``` - 新建 tftboot 目录, `/mnt/d/tftboot`, 确保 tftboot 目录有执行权限`chmod 777 /**/tftboot` - 配置主机 tftpboot 服务, 新建并配置文件`/etc/xinetd.d/tftp` ``` # /etc/xinetd.d/tftp server tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /mnt/d/tftboot disable = no per_source = 11 cps = 100 2 flags = IPv4 } ``` - 启动主机`tftp`服务,生成默认配置 ``` $ sudo service tftpd-hpa start ``` - 修改主机`tftp`配置,指向`tftboot`目录 修改/etc/default/tftpd-hpa ``` $ sudo nano /etc/default/tftpd-hpa # /etc/default/tftpd-hpa TFTP_USERNAME="tftp" TFTP_DIRECTORY="/mnt/d/tftboot" TFTP_ADDRESS=":69" TFTP_OPTIONS="-l -c -s" ``` - 重启主机`tftp`服务 ``` $ sudo service tftpd-hpa restart ``` - 测试主机`tftp`服务的可用性 > 登录`tftp`服务,获取`tftboot`目录下的一个文件 ``` $ tftp 192.168.4.50 tftp> get test1234 tftp> q ``` #### 2.5.2 配置开发板 ip,连通 host 下载启动镜像 - 将`BIN`文件或者`ELF`文件复制到`tftpboot`目录 ``` $ cp ./baremetal.bin /mnt/d/tftboot ``` ``` $ cp ./baremetal.elf /mnt/d/tftboot ``` - 连通开发板串口,进入`u-boot`界面,配置开发板`ip`,`host`侧`ip`和网关地址 ``` # setenv ipaddr 192.168.4.20 # setenv serverip 192.168.4.50 # setenv gatewayip 192.168.4.1 ``` > 镜像启动的地址为`0x80100000`, 对于`BIN`文件,需要直接加载到`0x80100000`,对于`ELF`文件,启动地址会自动获取,需要加载到`DRAM`中一段可用的地址,这里选择`0x90100000` - 支持使用以下几种方式跳转启动 - 1. `AARCH32/AARCH64`支持加载`BIN`文件到启动地址,刷新缓存后,通过`go`命令跳转启动 ``` # tftpboot 0x80100000 baremetal.bin # dcache flush # go 0x80100000 ``` - 2. `AARCH32/AARCH64`支持加载`ELF`文件到`DRAM`,通过`bootelf`解析跳转启动 ``` # tftpboot 0x90100000 baremetal.elf # bootelf -p 0x90100000 ``` --- ## 3. SDK 源代码结构 ``` . ├── Kconfig --> 配置定义 ├── LICENSE --> 版权声明 ├── README.md ├── standalone.mk ├── baremetal │ └── example --> 裸机例程 | ├── can_test | └── i2c_eeprom | └── sdci_test ... ├── arch --> 架构相关 | ├── armv8 | | ├── aarch32 | | └── aarch64 | └── common ├── common ├── drivers --> 外设驱动 | ├── can | └── eth | └── gic ... ├── board --> 目标平台相关 | ├── d2000 | └── ft2004 | └── e2000 ├── configs --> 各目标平台的默认配置 │ ├── d2000_aarch32_defconfig │ └── d2000_aarch64_defconfig | └── e2000_aarch32_defconfig | └── e2000_aarch64_defconfig | └── ft2004_aarch32_defconfig | └── ft2004_aarch64_defconfig ├── doc │ ├── ChangeLog.md │ └── checklist.md ├── install.sh --> 环境变量安装脚本 ├── lib --> 依赖库 │ ├── Kconfiglib │ ├── libc │ └── nostdlib ├── make --> Makefile文件 ├── scripts --> 相关脚本 ├── third-party --> 第三方库 └── tools --> 编译构建相关工具 ├── README.md ├── gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf ``` --- ## 4. 硬件平台 ### 4.1 FT2000-4 FT-2000/4 是一款面向桌面应用的高性能通用 4 核处理器。每 2 个核构成 1 个处理器核簇(Cluster),并共享 L2 Cache。主要技术特征如下: - 兼容 ARM v8 64 位指令系统,兼容 32 位指令 - 支持单精度、双精度浮点运算指令 - 支持 ASIMD 处理指令 - 集成 2 个 DDR4 通道,可对 DDR 存储数据进行实时加密 - 集成 34 Lane PCIE3.0 接口:2 个 X16(每个可拆分成 2 个 X8),2 个 X1 - 集成 2 个 GMAC,RGMII 接口,支持 10/100/1000 自适应 - 集成 1 个 SD 卡控制器,兼容 SD 2.0 规范 - 集成 1 个 HDAudio,支持音频输出,可同时支持最多 4 个 Codec - 集成 SM2、SM3、SM4 模块 - 集成 4 个 UART,1 个 LPC,32 个 GPIO,4 个 I2C,1 个 QSPI,2 个通 用 SPI,2 个 WDT,16 个外部中断(和 GPIO 共用 IO) - 集成温度传感器 ### 4.2 D2000 D2000 是一款面向桌面应用的高性能通用 8 核处理器。每 2 个核构成 1 个处理器核簇(Cluster),并共享 L2 Cache。存储系统包含 Cache 子系统和 DDR,I/O 系统包含 PCIe、高速 IO 子系统、千兆位以太网 GMAC 和低速 IO 子系统,主要技术特征如下, - 兼容 ARM v8 64 位指令系统,兼容 32 位指令 - 支持单精度、双精度浮点运算指令 - 支持 ASIMD 处理指令 - 集成 2 个 DDR 通道,支持 DDR4 和 LPDDR4,可对 DDR 存储数据进行实时加密 - 集成 34 Lane PCIE3.0 接口:2 个 X16(每个可拆分成 2 个 X8),2 个 X1 - 集成 2 个 GMAC,RGMII 接口,支持 10/100/1000 自适应 - 集成 1 个 SD 卡控制器,兼容 SD 2.0 规范 - 集成 1 个 HDAudio,支持音频输出,可同时支持最多 4 个 Codec - 集成 SM2、SM3、SM4、SM9 模块 - 集成 4 个 UART,1 个 LPC,32 个 GPIO,4 个 I2C,1 个 QSPI,2 个通用 SPI,2 个 WDT,16 个外部中断(和 GPIO 共用 IO) - 集成 2 个温度传感器 --- ## 5. 支持情况 ### 5.1 外设驱动支持情况 | Hardware Interface | Platform Supported | Platform Developing | Component | | ------------------------------ | -------------------------- | ------------------- | -------------------- | | Generic Intrrupt Controller v3 | FT2000/4
E2000
D2000 | | gic/gicv3 | | Generic Timer | FT2000/4
E2000
D2000 | | generic_timer | | UART (PrimeCell PL011) | FT2000/4
E2000
D2000 | | usart/pl011_uart | | 10/100/1000MB-ETHERNET | FT2000/4
D2000 | E2000 | eth/f_gmac | | CAN | FT2000/4 | E2000 | can/ft_can | | GPIO | FT2000/4
E2000
D2000 | | gpio/f_gpio | | I2C | FT2000/4
D2000 | E2000 | i2c/dw_i2c | | IOMUX | FT2000/4
D2000 | | iomux/f_iomux | | QSPI (Nor Flash) | FT2000/4
D2000 | E2000 | qspi/nor_qspi | | SPI | FT2000/4
D2000 | E2000 | spi/f_spi | | TIMER & TACHO | E2000 | | timer/hw_timer_tacho | | SDMMC | FT2000/4
D2000 | | mmc/f_sdmmc | | PCIE | FT2000/4 | E2000
D2000 | pcie/fpcie | | GDMA | E2000 | | dma/gdma | | WDT | FT2000/4
D2000
E2000 | | watchdog/fwdt | | Third-Party | Platform Supported | Platform Developing | Component | | ------------------------------ | -------------------------- | ------------------- | -------------------- | | LWIP 2.1.2 | FT2000/4
D2000 | E2000 | lwip-2.1.2 | | Letter shell 3.1 | FT2000/4
D2000 | E2000 | letter-shell-3.1 | | Libmetal 1.0.0 | FT2000/4
D2000 | E2000 | libmetal-1.0.0 | | Sdmmc | FT2000/4
D2000 | E2000 | sdmmc | --- ## 6. 参考资源 - ARM Architecture Reference Manual - ARM Cortex-A Series Programmer’s Guide - Programmer Guide for ARMv8-A - ARM System Developers Guide Designing and Optimizing System Software - FT-2000/4 软件编程手册-V1.4 - D2000 软件编程手册-V1.0 - Bare-metal programming for ARM —— A hands-on guide - Using the GNU Compiler Collection - Using ld, The GNU Linker - Using as, The GNU Assembler - Armv8-A memory model guide --- ## 7. 贡献方法 请联系飞腾嵌入式软件部 huanghe@phytium.com.cn zhugengyu@phytium.com.cn wangxiaodong1030@phytium.com.cn --- ## 8. 许可协议 Apache-2.0