Browse Source

update sdk

pull/151/head
liushengming1118 6 months ago
parent
commit
548923b362
  1. 12
      doc/ChangeLog.md
  2. 23
      example/system/amp/amp_tools_example/amp/README.md
  3. BIN
      example/system/amp/amp_tools_example/amp/fig/template_test.png
  4. 36
      example/system/amp/amp_tools_example/amp/main.c
  5. 32
      example/system/amp/amp_tools_example/amp1/main.c
  6. 33
      example/system/amp/amp_tools_example/amp2/main.c
  7. 4
      lib/libc/system_call.c
  8. 6
      soc/common/fspin.c
  9. 6
      soc/common/fspin.h
  10. 53
      tools/build/boot_code/sdkconfig
  11. 52
      tools/build/boot_code/sdkconfig.h

12
doc/ChangeLog.md

@ -1,3 +1,15 @@
# Phytium Standalone SDK 2024-05-15 ChangeLog
Change Log since 2024-05-14
## example
- add spinlock in amp_tools_example
## soc
- fix spinlock bug in fspin
# Phytium Standalone SDK 2024-05-14 ChangeLog
Change Log since 2024-05-14

23
example/system/amp/amp_tools_example/amp/README.md

@ -4,7 +4,10 @@
> `<font size="1">`介绍例程的用途,使用场景,相关基本概念,描述用户可以使用例程完成哪些工作 `</font><br />`
本例程示范了standalone环境下的工程模板。本例程作为AMP打包部署的主例程,主要起到运行脚本,编译打包其他例程的作用,您也可在其他例程中按照上层目录README.md的描述配置主例程
- 本例程作为AMP打包部署的主例程,主要起到运行脚本,编译打包其他例程的作用,您也可在其他例程中按照上层目录README.md的描述配置主例程
- 本例程与其他例程测试多核自旋锁,通过串口打印信息测试可以验证standalone环境下多核自旋锁的正确性。
- 注意多个核心自旋锁的FSPIN_LOCK_ADDR地址需要保持一致,并且使用地址避免与其他镜像加载以及运行地址冲突,否则会导致自旋锁失效。
- spinlock用于在多核环境下,确保同一时刻只有核心可以访问共享资源,比如使用FSPIN_LOCK_ADDR位置的自旋锁保护串口1打印,其他核心当使用串口1前,需要判断其他核心是否存在占有。本机测试通过串口打印信息验证多核自旋锁的正确性,当一个core拿到自旋锁后,其他核只能等待当前拿到自旋锁的core释放自旋锁后才能拿到自旋锁,保证了打印信息的正确性。
## 2. 如何使用例程
@ -13,6 +16,7 @@
本例程需要以下硬件,
- E2000D/Q Demo,D2000,FT2000/4,PhytiumPi
- 串口连接电脑,USB转串口模块
### 2.1 硬件配置方法
@ -26,13 +30,9 @@
- 本例子已经提供好具体的编译指令,以下进行介绍:
1. make 将目录下的工程进行编译
2. make clean 将目录下的工程进行清理
3. make image 将目录下的工程进行编译,并将生成的elf 复制到目标地址
4. make list_kconfig 当前工程支持哪些配置文件
5. make load_kconfig LOAD_CONFIG_NAME=`<kconfig configuration files>` 将预设配置加载至工程中
6. make menuconfig 配置目录下的参数变量
7. make backup_kconfig 将目录下的sdkconfig 备份到./configs下
1. make clean 将目录下的工程进行清理
2. make menuconfig 配置目录下的参数变量
3. make backup_kconfig 将目录下的sdkconfig 备份到./configs下
- 本例程提供AMP相关的命令:
@ -49,10 +49,10 @@
- 在host侧完成配置
> 配置成E2000D,如E2000d 32位,根据amp_config.conf文件的配置,为config3:
> 配置成E2000Q,如E2000Q 64位,根据amp_config.conf文件的配置,为config0:
```
$ make amp_make AMP_CONFIG=config3
$ make amp_make AMP_CONFIG=config0
```
- host侧设置重启host侧tftp服务器
@ -79,6 +79,9 @@ bootelf -p 0x90100000
![template_test](./fig/template_test.png)
- 通过串口查看多核自旋锁的输出,可以看到打印信息,在图中红色框内,各个核心拿到自旋锁后打印信息,然后释放自旋锁,各个核打印信息交替出现。
- 结束自旋锁打印阶段后,各个核打印信息出现了相互抢占串口的现象。
## 3. 如何解决问题
> `<font size="1">`主要记录使用例程中可能会遇到的问题,给出相应的解决方案 `</font><br />`

BIN
example/system/amp/amp_tools_example/amp/fig/template_test.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 226 KiB

After

Width:  |  Height:  |  Size: 332 KiB

36
example/system/amp/amp_tools_example/amp/main.c

@ -31,18 +31,42 @@
#include <stdio.h>
#include "fcpu_info.h"
#include "fsleep.h"
#include "fcache.h"
#include "fspin.h"
#include "fatomic.h"
#define PRINT_CNT 10
#define FSPIN_LOCK_ADDR 0xC0000000 /* 锁地址 */
static FCpuLock *lock_private = (FCpuLock *)FSPIN_LOCK_ADDR;
int main()
{
/* 按照混合异构部署的启动逻辑amp_config.json,此核心首先启动,所以对FSPIN_LOCK_ADDR的锁进行初始化操作 */
FATOMIC_UNLOCK(lock_private->v);/* initialize, unlock the lock */
u32 cpu_id ;
u32 cnt = 0 ;
GetCpuId(&cpu_id);
fsleep_seconds(1);
/* if shell command is not enabled, run example one by one */
printf("\n\n*********************************************************\n");
printf("core[%d] Hello 0, Phytium Standalone SDk!\r\n",cpu_id);
printf("*********************************************************\n");
fsleep_millisec(10) ;/* 等待10ms,确保其他核心启动完毕,避免打印收到干扰 */
while (cnt < PRINT_CNT)
{
while(FATOMIC_LOCK(lock_private->v,1));/* 等待锁空闲,再进行上锁操作 */
printf("lock test core[%d] Hello %d, Phytium Standalone SDk!\r\n",cpu_id,cnt);
cnt ++ ;
FATOMIC_UNLOCK(lock_private->v);
}
fsleep_millisec(100) ;/* 等待100ms,确保其他核心自旋锁阶段打印完毕 */
cnt = 0;
while (cnt < PRINT_CNT)
{
printf("not lock test core[%d] Hello %d, Phytium Standalone SDk!\r\n",cpu_id,cnt);
cnt ++ ;
}
printf("core[%d] test is over **********\n",cpu_id);
return 0;
}

32
example/system/amp/amp_tools_example/amp1/main.c

@ -31,19 +31,39 @@
#include <stdio.h>
#include "fcpu_info.h"
#include "fsleep.h"
#include "fcache.h"
#include "fspin.h"
#include "fatomic.h"
#define PRINT_CNT 10
#define FSPIN_LOCK_ADDR 0xC0000000 /*与 ../amp/main.c 中的地址保持一致*/
static FCpuLock *lock_private = (FCpuLock *)FSPIN_LOCK_ADDR;
int main()
{
u32 cpu_id ;
u32 cnt = 0 ;
GetCpuId(&cpu_id);
fsleep_seconds(2);
fsleep_millisec(10) ;/* 等待10ms,确保核心启动完毕,避免打印收到干扰 */
/* if shell command is not enabled, run example one by one */
printf("\n\n*********************************************************\n");
printf("core[%d] Hello 1, Phytium Standalone SDk!\r\n",cpu_id);
printf("*********************************************************\n");
while (cnt < PRINT_CNT)
{
while(FATOMIC_LOCK(lock_private->v,1));
printf("lock test core[%d] Hello %d, Phytium Standalone SDk!\r\n",cpu_id,cnt);
cnt ++ ;
FATOMIC_UNLOCK(lock_private->v);
}
fsleep_millisec(50) ;/* 等待50ms,确保打印任务都执行完毕,因为是第二个启动核心,所以延时缩短,确保能其他核心的打印任务冲突 */
cnt = 0;
while (cnt < PRINT_CNT)
{
printf("not lock test core[%d] Hello %d, Phytium Standalone SDk!\r\n",cpu_id,cnt);
cnt ++ ;
}
printf("core[%d] test is over **********\n",cpu_id);
return 0;
}

33
example/system/amp/amp_tools_example/amp2/main.c

@ -31,19 +31,40 @@
#include <stdio.h>
#include "fcpu_info.h"
#include "fsleep.h"
#include "fcache.h"
#include "fspin.h"
#include "fatomic.h"
#define PRINT_CNT 10
#define FSPIN_LOCK_ADDR 0xC0000000 /*与 ../amp/main.c 中的地址保持一致*/
static FCpuLock *lock_private = (FCpuLock *)FSPIN_LOCK_ADDR;
int main()
{
u32 cpu_id ;
u32 cnt = 0 ;
GetCpuId(&cpu_id);
fsleep_seconds(3);
/* if shell command is not enabled, run example one by one */
printf("\n\n*********************************************************\n");
printf("core[%d] Hello 2, Phytium Standalone SDk!\r\n",cpu_id);
printf("*********************************************************\n");
fsleep_millisec(10) ;/* 等待10ms,确保核心启动完毕,避免打印收到干扰 */
while (cnt < PRINT_CNT)
{
while(FATOMIC_LOCK(lock_private->v,1));
printf("lock test core[%d] Hello %d, Phytium Standalone SDk!\r\n",cpu_id,cnt);
cnt ++ ;
FATOMIC_UNLOCK(lock_private->v);
}
/* 无等待,因为是第三个启动核心,确保能与其他核心的打印任务冲突 */
cnt = 0;
while (cnt < PRINT_CNT)
{
printf("not lock test core[%d] Hello %d, Phytium Standalone SDk!\r\n",cpu_id,cnt);
cnt ++ ;
}
printf("core[%d] test is over **********\n",cpu_id);
return 0;
}

4
lib/libc/system_call.c

@ -34,7 +34,6 @@
#include <stdio.h>
#include "fearly_uart.h"
#include "sdkconfig.h"
#include "fspin.h"
#include "ftypes.h"
/* _exit - Simple implementation. Does not return.
@ -454,8 +453,6 @@ __attribute__((weak)) s32 _write(s32 fd, char *buf, s32 nbytes)
char *LocalBuf = buf;
(void)fd;
SpinLock();
for (i = 0; i < nbytes; i++)
{
if (LocalBuf != NULL)
@ -477,7 +474,6 @@ __attribute__((weak)) s32 _write(s32 fd, char *buf, s32 nbytes)
}
}
SpinUnlock();
return (nbytes);
#else
(void)fd;

6
soc/common/fspin.c

@ -29,10 +29,6 @@
#include "fatomic.h"
typedef struct
{
int v;
}FCpuLock;
static FCpuLock *_lock = NULL;
@ -56,5 +52,5 @@ _WEAK void SpinInit(void)
void SpinlLockSet(uintptr addr)
{
_lock = (FCpuLock *)addr ;
_lock->v = 0;
FATOMIC_UNLOCK(_lock->v);
}

6
soc/common/fspin.h

@ -34,6 +34,12 @@ extern "C"
{
#endif
typedef struct
{
int v;
}FCpuLock;
void SpinInit(void);
void SpinLock(void);
void SpinUnlock(void);

53
tools/build/boot_code/sdkconfig

@ -10,8 +10,8 @@ CONFIG_ARCH_NAME="armv8"
#
# Arm architecture configuration
#
# CONFIG_ARCH_ARMV8_AARCH64 is not set
CONFIG_ARCH_ARMV8_AARCH32=y
CONFIG_ARCH_ARMV8_AARCH64=y
# CONFIG_ARCH_ARMV8_AARCH32 is not set
#
# Compiler configuration
@ -19,28 +19,22 @@ CONFIG_ARCH_ARMV8_AARCH32=y
CONFIG_ARM_GCC_SELECT=y
# CONFIG_ARM_CLANG_SELECT is not set
CONFIG_TOOLCHAIN_NAME="gcc"
CONFIG_TARGET_ARMV8_AARCH32=y
CONFIG_ARCH_EXECUTION_STATE="aarch32"
#
# Fpu configuration
#
CONFIG_CRYPTO_NEON_FP_ARMV8=y
# CONFIG_VFPV4 is not set
# CONFIG_VFPV4_D16 is not set
# CONFIG_VFPV3 is not set
# CONFIG_VFPV3_D16 is not set
CONFIG_ARM_MFPU="crypto-neon-fp-armv8"
CONFIG_MFLOAT_ABI_HARD=y
# CONFIG_MFLOAT_ABI_SOFTFP is not set
CONFIG_ARM_MFLOAT_ABI="hard"
# end of Fpu configuration
CONFIG_TARGET_ARMV8_AARCH64=y
CONFIG_ARCH_EXECUTION_STATE="aarch64"
CONFIG_ARM_NEON=y
CONFIG_ARM_CRC=y
CONFIG_ARM_CRYPTO=y
CONFIG_ARM_FLOAT_POINT=y
# CONFIG_GCC_CODE_MODEL_TINY is not set
CONFIG_GCC_CODE_MODEL_SMALL=y
# CONFIG_GCC_CODE_MODEL_LARGE is not set
# end of Compiler configuration
CONFIG_USE_CACHE=y
CONFIG_USE_L3CACHE=y
CONFIG_USE_MMU=y
CONFIG_USE_AARCH64_L1_TO_AARCH32=y
CONFIG_BOOT_WITH_FLUSH_CACHE=y
# CONFIG_MMU_DEBUG_PRINTS is not set
CONFIG_FPEN=y
# end of Arm architecture configuration
# end of Arch configuration
@ -48,7 +42,11 @@ CONFIG_FPEN=y
#
# Soc configuration
#
# CONFIG_TARGET_PHYTIUMPI is not set
# CONFIG_TARGET_E2000Q is not set
# CONFIG_TARGET_E2000D is not set
# CONFIG_TARGET_E2000S is not set
# CONFIG_TARGET_FT2004 is not set
CONFIG_F32BIT_MEMORY_ADDRESS=0x80000000
CONFIG_F32BIT_MEMORY_LENGTH=0x80000000
CONFIG_F64BIT_MEMORY_ADDRESS=0x2000000000
@ -62,7 +60,6 @@ CONFIG_DEFAULT_DEBUG_PRINT_UART1=y
#
# Board Configuration
#
CONFIG_BOARD_NAME="demo"
#
# IO mux configuration when board start up
@ -72,7 +69,7 @@ CONFIG_BOARD_NAME="demo"
#
# Build project name
#
CONFIG_TARGET_NAME="template"
CONFIG_TARGET_NAME="boot"
# end of Build project name
# end of Board Configuration
@ -214,14 +211,10 @@ CONFIG_DEFAULT_LINKER_SCRIPT=y
CONFIG_IMAGE_LOAD_ADDRESS=0xb0120000
CONFIG_IMAGE_MAX_LENGTH=0x2000000
CONFIG_HEAP_SIZE=1
CONFIG_SVC_STACK_SIZE=0x1000
CONFIG_SYS_STACK_SIZE=0x1000
CONFIG_IRQ_STACK_SIZE=0x1000
CONFIG_ABORT_STACK_SIZE=0x1000
CONFIG_FIQ_STACK_SIZE=0x1000
CONFIG_UNDEF_STACK_SIZE=0x1000
CONFIG_STACK_SIZE=0x400
CONFIG_FPU_STACK_SIZE=0x1000
# end of Linker Options
# end of Build setup
CONFIG_SOC_NAME="e2000"
CONFIG_TARGET_TYPE_NAME="q"
CONFIG_SOC_NAME="phytiumpi"
CONFIG_SOC_CORE_NUM=4
CONFIG_BOARD_NAME="firefly"

52
tools/build/boot_code/sdkconfig.h

@ -10,40 +10,40 @@
/* Arm architecture configuration */
/* CONFIG_ARCH_ARMV8_AARCH64 is not set */
#define CONFIG_ARCH_ARMV8_AARCH32
#define CONFIG_ARCH_ARMV8_AARCH64
/* CONFIG_ARCH_ARMV8_AARCH32 is not set */
/* Compiler configuration */
#define CONFIG_ARM_GCC_SELECT
/* CONFIG_ARM_CLANG_SELECT is not set */
#define CONFIG_TOOLCHAIN_NAME "gcc"
#define CONFIG_TARGET_ARMV8_AARCH32
#define CONFIG_ARCH_EXECUTION_STATE "aarch32"
/* Fpu configuration */
#define CONFIG_CRYPTO_NEON_FP_ARMV8
/* CONFIG_VFPV4 is not set */
/* CONFIG_VFPV4_D16 is not set */
/* CONFIG_VFPV3 is not set */
/* CONFIG_VFPV3_D16 is not set */
#define CONFIG_ARM_MFPU "crypto-neon-fp-armv8"
#define CONFIG_MFLOAT_ABI_HARD
/* CONFIG_MFLOAT_ABI_SOFTFP is not set */
#define CONFIG_ARM_MFLOAT_ABI "hard"
/* end of Fpu configuration */
#define CONFIG_TARGET_ARMV8_AARCH64
#define CONFIG_ARCH_EXECUTION_STATE "aarch64"
#define CONFIG_ARM_NEON
#define CONFIG_ARM_CRC
#define CONFIG_ARM_CRYPTO
#define CONFIG_ARM_FLOAT_POINT
/* CONFIG_GCC_CODE_MODEL_TINY is not set */
#define CONFIG_GCC_CODE_MODEL_SMALL
/* CONFIG_GCC_CODE_MODEL_LARGE is not set */
/* end of Compiler configuration */
#define CONFIG_USE_CACHE
#define CONFIG_USE_L3CACHE
#define CONFIG_USE_MMU
#define CONFIG_USE_AARCH64_L1_TO_AARCH32
#define CONFIG_BOOT_WITH_FLUSH_CACHE
/* CONFIG_MMU_DEBUG_PRINTS is not set */
#define CONFIG_FPEN
/* end of Arm architecture configuration */
/* end of Arch configuration */
/* Soc configuration */
/* CONFIG_TARGET_PHYTIUMPI is not set */
/* CONFIG_TARGET_E2000Q is not set */
/* CONFIG_TARGET_E2000D is not set */
/* CONFIG_TARGET_E2000S is not set */
/* CONFIG_TARGET_FT2004 is not set */
#define CONFIG_F32BIT_MEMORY_ADDRESS 0x80000000
#define CONFIG_F32BIT_MEMORY_LENGTH 0x80000000
#define CONFIG_F64BIT_MEMORY_ADDRESS 0x2000000000
@ -56,15 +56,13 @@
/* Board Configuration */
#define CONFIG_BOARD_NAME "demo"
/* IO mux configuration when board start up */
/* CONFIG_CUS_DEMO_BOARD is not set */
/* Build project name */
#define CONFIG_TARGET_NAME "template"
#define CONFIG_TARGET_NAME "boot"
/* end of Build project name */
/* end of Board Configuration */
@ -192,16 +190,12 @@
#define CONFIG_IMAGE_LOAD_ADDRESS 0xb0120000
#define CONFIG_IMAGE_MAX_LENGTH 0x2000000
#define CONFIG_HEAP_SIZE 1
#define CONFIG_SVC_STACK_SIZE 0x1000
#define CONFIG_SYS_STACK_SIZE 0x1000
#define CONFIG_IRQ_STACK_SIZE 0x1000
#define CONFIG_ABORT_STACK_SIZE 0x1000
#define CONFIG_FIQ_STACK_SIZE 0x1000
#define CONFIG_UNDEF_STACK_SIZE 0x1000
#define CONFIG_STACK_SIZE 0x400
#define CONFIG_FPU_STACK_SIZE 0x1000
/* end of Linker Options */
/* end of Build setup */
#define CONFIG_SOC_NAME "e2000"
#define CONFIG_TARGET_TYPE_NAME "q"
#define CONFIG_SOC_NAME "phytiumpi"
#define CONFIG_SOC_CORE_NUM 4
#define CONFIG_BOARD_NAME "firefly"
#endif

Loading…
Cancel
Save