From e6651438372e71388c5e8e37127a9c4b19e0c074 Mon Sep 17 00:00:00 2001 From: FINALx <3085378853@qq.com> Date: Sat, 7 Mar 2026 06:00:59 +0800 Subject: [PATCH 1/6] feat: add isolated project generation --- bin/ecos | 6 + bin/ecos-init_project_isolated | 91 +++++++++ bin/ecos-set_board_isolated | 244 +++++++++++++++++++++++++ board/StarrySkyC2/Makefile_isolated | 101 ++++++++++ board/StarrySkyC2/{start.S => start.s} | 0 components/main.c | 8 + components/main.h | 21 +++ 7 files changed, 471 insertions(+) create mode 100755 bin/ecos-init_project_isolated create mode 100755 bin/ecos-set_board_isolated create mode 100644 board/StarrySkyC2/Makefile_isolated rename board/StarrySkyC2/{start.S => start.s} (100%) create mode 100644 components/main.c create mode 100644 components/main.h diff --git a/bin/ecos b/bin/ecos index c143392..fcd8045 100755 --- a/bin/ecos +++ b/bin/ecos @@ -20,9 +20,15 @@ show_help() { echo "" echo "Available commands:" echo " set_board Set the board configuration" + echo " set_board_isolated Set the isolated-board configuration" echo " init_project |list Initialize a project or list available projects" + echo " init_project_isolated Initialize a isolated-project" echo " help Show this help message" echo "" + echo "Isolated:" + echo " This operation gathers all the resource so that you can compile your project without sdk" + echo " But the riscv-toolchain is still indispensable" + echo "" echo "Board list:" echo " c1 StarrySky C1 board" echo " c2 StarrySky C2 board" diff --git a/bin/ecos-init_project_isolated b/bin/ecos-init_project_isolated new file mode 100755 index 0000000..6147cdc --- /dev/null +++ b/bin/ecos-init_project_isolated @@ -0,0 +1,91 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ECOS `init_project` subcommand +# Initializes a new isolated project + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SDK_ROOT="$(dirname "$SCRIPT_DIR")" + +# Color output +log () { echo -e "\033[1;32m[ECOS]\033[0m $*"; } +warn() { echo -e "\033[1;33m[WARN]\033[0m $*"; } +err () { echo -e "\033[1;31m[ERROR]\033[0m $*"; } +tips() { echo -e "\033[1;94m[ECOS]\033[0m $*"; } + +# The actual init_project logic +init_project() { + local new_project_name="${1:-HelloWorld}" + local target_board="${2:-c1}" + + # Check if project directory exists + if [[ -d "$new_project_name" ]]; then + err "Project directory already exists: $new_project_name" + exit 1 + fi + + # Copy project source must needed from sdk + log "Initializing project '$new_project_name' isolated..." + mkdir -p "$new_project_name/Workspace/Library" + mkdir -p "$new_project_name/Workspace/Startup" + mkdir -p "$new_project_name/Workspace/User" + mkdir -p "$new_project_name/Workspace/Hardware" + mkdir -p "$new_project_name/Workspace/System" + find "$SDK_ROOT/components" -mindepth 2 -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' \ + -exec cp {} "$new_project_name/Workspace/Library" \; + find "$SDK_ROOT/components" -maxdepth 1 -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' \ + -exec cp {} "$new_project_name/Workspace/User" \; + echo "cd .. && make" > "$new_project_name/Workspace/compile.sh" + chmod +x "$new_project_name/Workspace/compile.sh" + + + cd "$new_project_name" + # Initialize project config file + local board_to_set="${target_board:-c1}" + echo "BOARD=${board_to_set}" > ".ecos-project" + log "Initialized project: $new_project_name" + log "Config file: .ecos-project" + + # Set default board + ecos set_board_isolated "${board_to_set}" + + # Create configs directory and copy scripts + mkdir -p configs + cp -r "$SDK_ROOT/tools/scripts/" "." + log "Project '$new_project_name' created successfully in './$new_project_name'" + tips "Please set menuconfig before project isolation" +} + +# Main entry point for the subcommand +if [[ $# -eq 0 ]]; then + err "Missing project name argument" + echo "" + echo "Usage: ecos init_project [-target target_board]" + echo " ecos init_project list" + echo "Example: ecos init_project hello" + echo " ecos init_project hello -target l3" + exit 1 +fi + +new_project_name="" +target_board="" + +while [[ $# -gt 0 ]]; do + case "$1" in + -target) + target_board="$2" + shift 2 + ;; + *) + if [[ -z "$new_project_name" ]]; then + new_project_name="$1" + shift + else + err "Unknown argument: $1" + exit 1 + fi + ;; + esac +done + +init_project "${new_project_name}" "${target_board}" diff --git a/bin/ecos-set_board_isolated b/bin/ecos-set_board_isolated new file mode 100755 index 0000000..2dba1f1 --- /dev/null +++ b/bin/ecos-set_board_isolated @@ -0,0 +1,244 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ECOS `set_board` subcommand +# Sets the board configuration for the project + +# WARN: only C2 was checked!!! +# TODO: fix C1 start_file / L3 loader dir + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SDK_ROOT="$(dirname "$SCRIPT_DIR")" + +# Color output +log() { echo -e "\033[1;32m[ECOS]\033[0m $*"; } +warn() { echo -e "\033[1;33m[WARN]\033[0m $*"; } +err() { echo -e "\033[1;31m[ERROR]\033[0m $*"; } + +board_name="" +project_type="" + +# Check if inside a project directory +check_project_dir() { + if [[ ! -f "Makefile" ]] && [[ ! -f ".ecos-project" ]]; then + err "Not an ECOS project directory." + err "Run this command in a directory containing a Makefile or .ecos-project file." + exit 1 + fi +} + +get_config() { + source .ecos-project + + board_name="${BOARD}" + project_type="${TYPE:-}" + + echo "Project type: $project_type" + echo "Board name: $board_name" +} + +rewrite_config() { + echo "BOARD=$target_board_name" > ".ecos-project" + echo "TYPE=$project_type" >> ".ecos-project" +} +# Set board configuration +set_board() { + local target_board_name="$1" + + check_project_dir + rewrite_config + get_config + + if [[ "$project_type" == "asm" ]]; then + rm -f Makefile + log "Removed Makefile for assembly project." + log "Board configuration set to: $target_board_name" + cp "$SDK_ROOT/board/${target_board_name}/Makefile_asm" "./Makefile" + exit 0 + fi + + case "$target_board_name" in + "c1") + local board_file="board.h" + local make_file="Makefile_isolated" + local lds_file="sections.lds" + # local start_file="start.s" # C1 might not have start.s in board dir yet, checking... + + local board_source_path="$SDK_ROOT/board/StarrySkyC1/$board_file" + local make_source_path="$SDK_ROOT/board/StarrySkyC1/$make_file" + local lds_source_path="$SDK_ROOT/board/StarrySkyC1/$lds_file" + + local board_target_path="./Workspace/Library/board.h" + local make_target_path="./Makefile" + local lds_target_path="./Workspace/Startup/sections.lds" + + if [[ ! -f "$board_source_path" ]]; then + err "Board config file not found: $board_source_path" + exit 1 + fi + + # Copy board config file + cp "$board_source_path" "$board_target_path" + log "Set board configuration to: starrysky_c1" + log "Config file: $board_target_path" + + # Copy Makefile + cp "$make_source_path" "$make_target_path" + log "Set Makefile: $make_target_path" + + # Copy Linker Script + if [[ -f "$lds_source_path" ]]; then + cp "$lds_source_path" "$lds_target_path" + log "Set Linker Script: $lds_target_path" + fi + + # Copy start.s if exists (C1 support) + if [[ -f "$SDK_ROOT/board/StarrySkyC1/start.s" ]]; then + cp "$SDK_ROOT/board/StarrySkyC1/start.s" "./Workspace/Startup/start.s" + log "Set startup code: ./Workspace/Startup/start.s" + fi + + # Update project config file if it exists + if [[ -f ".ecos-project" ]]; then + if grep -q "BOARD=" ".ecos-project"; then + sed -i "s/BOARD=.*/BOARD=$target_board_name/" ".ecos-project" + else + echo "BOARD=$target_board_name" >> ".ecos-project" + fi + log "Updated project configuration file." + fi + ;; + "c2") + local board_file="board.h" + local make_file="Makefile_isolated" + local lds_file="sections.lds" + local start_file="start.s" + + local board_source_path="$SDK_ROOT/board/StarrySkyC2/$board_file" + local make_source_path="$SDK_ROOT/board/StarrySkyC2/$make_file" + local lds_source_path="$SDK_ROOT/board/StarrySkyC2/$lds_file" + local start_source_path="$SDK_ROOT/board/StarrySkyC2/$start_file" + + local board_target_path="./Workspace/Library/board.h" + local make_target_path="./Makefile" + local lds_target_path="./Workspace/Startup/sections.lds" + local start_target_path="./Workspace/Startup/start.s" + + if [[ ! -f "$board_source_path" ]]; then + err "Board config file not found: $board_source_path" + exit 1 + fi + + # Copy board config file + cp "$board_source_path" "$board_target_path" + log "Set board configuration to: starrysky_c2" + log "Config file: $board_target_path" + + # Copy Makefile + cp "$make_source_path" "$make_target_path" + log "Set Makefile: $make_target_path" + + # Copy Linker Script + if [[ -f "$lds_source_path" ]]; then + cp "$lds_source_path" "$lds_target_path" + log "Set Linker Script: $lds_target_path" + else + warn "Linker script not found for C2: $lds_source_path" + fi + + # Copy startup code + if [[ -f "$start_source_path" ]]; then + cp "$start_source_path" "$start_target_path" + log "Set startup code: $start_target_path" + else + warn "Startup code not found for C2: $start_source_path" + fi + + # Update project config file if it exists + if [[ -f ".ecos-project" ]]; then + if grep -q "BOARD=" ".ecos-project"; then + sed -i "s/BOARD=.*/BOARD=$target_board_name/" ".ecos-project" + else + echo "BOARD=$target_board_name" >> ".ecos-project" + fi + log "Updated project configuration file." + fi + ;; + "l3") + local board_file="board.h" + local make_file="Makefile_isolated" + local lds_file="sections.lds" + + local board_source_path="$SDK_ROOT/board/StarrySkyL3/$board_file" + local make_source_path="$SDK_ROOT/board/StarrySkyL3/$make_file" + local lds_source_path="$SDK_ROOT/board/StarrySkyL3/$lds_file" + + local board_target_path="./Workspace/Library/board.h" + local make_target_path="./Makefile" + local lds_target_path="./Workspace/Startup/sections.lds" + local start_target_path="./Workspace/Startup/start.s" + + if [[ ! -f "$board_source_path" ]]; then + err "Board config file not found: $board_source_path" + exit 1 + fi + + # Copy board config file + cp "$board_source_path" "$board_target_path" + log "Set board configuration to: starrysky_l3" + log "Config file: $board_target_path" + + # Copy Makefile + cp "$make_source_path" "$make_target_path" + log "Set Makefile: $make_target_path" + + # Copy Linker Script + if [[ -f "$lds_source_path" ]]; then + cp "$lds_source_path" "$lds_target_path" + log "Set Linker Script: $lds_target_path" + fi + + # Copy start.s if exists + if [[ -f "$SDK_ROOT/board/StarrySkyL3/start.s" ]]; then + cp "$SDK_ROOT/board/StarrySkyL3/start.s" "./start.s" + log "Set startup code: ./start.s" + fi + + # Copy bootloader + local bootloader_source_path="$SDK_ROOT/board/StarrySkyL3/loader" + local bootloader_target_path="./Workspace/Startup/loader" + cp -r "$bootloader_source_path" "$bootloader_target_path" + log "Set bootloader: $bootloader_target_path" + + # Update project config file if it exists + if [[ -f ".ecos-project" ]]; then + if grep -q "BOARD=" ".ecos-project"; then + sed -i "s/BOARD=.*/BOARD=$target_board_name/" ".ecos-project" + else + echo "BOARD=$target_board_name" >> ".ecos-project" + fi + log "Updated project configuration file." + fi + ;; + *) + err "Unsupported board: $board_name" + echo "" + echo "Supported boards:" + echo " c1 StarrySky C1 board" + echo " c2 StarrySky C2 board" + echo " l3 StarrySky L3 board" + exit 1 + ;; + esac +} + +# Main entry point for the subcommand +if [[ $# -eq 0 ]]; then + err "Missing board name argument." + echo "" + echo "Usage: ecos set_board " + echo "Example: ecos set_board c1" + exit 1 +fi + +set_board "$1" \ No newline at end of file diff --git a/board/StarrySkyC2/Makefile_isolated b/board/StarrySkyC2/Makefile_isolated new file mode 100644 index 0000000..4622603 --- /dev/null +++ b/board/StarrySkyC2/Makefile_isolated @@ -0,0 +1,101 @@ +# retroSoC 固件构建脚本 +# 用于编译基于RISC-V架构的嵌入式固件 + +# RISC-V 交叉编译工具链前缀 +CROSS=riscv64-unknown-elf- +BUILD_DIR := build +PROJECT_PATH := $(shell pwd) +# 包含配置文件 +-include configs/.config + +# 编译器标志配置 +# -mabi=ilp32: 使用ILP32 ABI +# -march=rv32im: RV32I基础指令集 + M乘除法扩展 +# -ffreestanding: 独立环境编译 +# -nostdlib: 不链接标准库 +CFLAGS := -mabi=ilp32 \ + -march=rv32im \ + -Wl,-Bstatic,-T,$(BUILD_DIR)/retrosoc_sections.lds,--strip-debug \ + -Wl,-Map=$(BUILD_DIR)/$(FIRMWARE_NAME).map,--cref \ + -ffreestanding \ + -nostdlib + +# 根据配置文件设置链接选项 +ifdef CONFIG_LINK_RAM_REGION_SRAM +LDFLAGS += -DCONFIG_LINK_RAM_REGION_SRAM +CFLAGS += -DCONFIG_LINK_RAM_REGION_SRAM +endif + +ifdef CONFIG_LINK_RAM_REGION_PSRAM +LDFLAGS += -DCONFIG_LINK_RAM_REGION_PSRAM +CFLAGS += -DCONFIG_LINK_RAM_REGION_PSRAM +endif + +# 根据配置文件添加编译优化选项 +ifdef CONFIG_BUILD_OPT_FLAGS +CFLAGS += $(subst ",,$(CONFIG_BUILD_OPT_FLAGS)) +endif + +# 根据配置文件添加调试选项 +ifdef CONFIG_BUILD_DEBUG +CFLAGS += -g -DDEBUG +endif + +# 根据配置文件添加详细输出选项 +ifdef CONFIG_BUILD_VERBOSE +VERBOSE := 1 +endif + +# 固件名称 - 从配置文件读取,如果未定义则使用默认值 +ifdef CONFIG_FIRMWARE_NAME +FIRMWARE_NAME := $(subst ",,$(CONFIG_FIRMWARE_NAME)) +else +FIRMWARE_NAME := main +endif + +# 源文件列表 +SRC_PATH := $(shell find Workspace -type f -name "*.c") + +CFLAGS += -I./configs +CFLAGS += $(addprefix -I,$(shell find Workspace -type d)) + +# 链接脚本路径 +LDS_PATH := $(shell find Workspace -type f -name "sections.lds") + +# 包含内存报告工具 +-include ./scripts/mem_report.mk + +# 主要构建目标:生成固件的所有格式文件 +$(FIRMWARE_NAME): + @echo "Building $(FIRMWARE_NAME)..." + @mkdir -p $(BUILD_DIR) + @$(CROSS)cpp -P -o $(BUILD_DIR)/retrosoc_sections.lds $(LDS_PATH) + @$(CROSS)gcc $(CFLAGS) -I./ -o $(BUILD_DIR)/$@ $(SRC_PATH) + @echo "Linking $(FIRMWARE_NAME)..." + @$(CROSS)objcopy -O verilog $(BUILD_DIR)/$@ $(BUILD_DIR)/$(FIRMWARE_NAME).hex + @echo "Post-processing $(FIRMWARE_NAME).hex..." + @sed -i 's/@30000000/@00000000/g' $(BUILD_DIR)/$(FIRMWARE_NAME).hex + @echo "Generating $(FIRMWARE_NAME).bin..." + @$(CROSS)objcopy -O binary $(BUILD_DIR)/$@ $(BUILD_DIR)/$(FIRMWARE_NAME).bin + @echo "Generating $(FIRMWARE_NAME).txt..." + @$(CROSS)objdump -d $(BUILD_DIR)/$@ > $(BUILD_DIR)/$(FIRMWARE_NAME).txt + $(call show_mem_usage, $(BUILD_DIR)/$@) + @echo "Done." + +# 清理构建产物 +clean: + rm -rf $(BUILD_DIR) + +clean_config: + rm -rf configs/generated configs/config configs/.config configs/.config.old + +clean_all: + rm -rf $(BUILD_DIR) + rm -rf configs/generated configs/config configs/.config configs/.config.old + rm -rf $(PROJECT_PATH)/tools/fixdep/build + rm -rf $(PROJECT_PATH)/tools/kconfig/build + + +-include scripts/config.mk +# 声明伪目标 +.PHONY: $(FIRMWARE_NAME).elf clean diff --git a/board/StarrySkyC2/start.S b/board/StarrySkyC2/start.s similarity index 100% rename from board/StarrySkyC2/start.S rename to board/StarrySkyC2/start.s diff --git a/components/main.c b/components/main.c new file mode 100644 index 0000000..d79b2db --- /dev/null +++ b/components/main.c @@ -0,0 +1,8 @@ +#include "main.h" + +void main(void){ + + sys_uart_init(); + printf("Hello, World!\n"); + +} \ No newline at end of file diff --git a/components/main.h b/components/main.h new file mode 100644 index 0000000..46f8de5 --- /dev/null +++ b/components/main.h @@ -0,0 +1,21 @@ +// System Headers +#include "string.h" +#include "stdio.h" +#include "libgcc.h" + +// System Configuration +#include "generated/autoconf.h" + +// Components headers +// #include "timer.h" +// #include "qspi.h" +// #include "gpio.h" +// #include "pwm.h" +// #include "hp_uart.h" +// #include "i2c.h" + +// Device headers +// #include "st7735.h" +// #include "sgp30.h" + +#define PSRAM_SCKL_FREQ_MHZ (CONFIG_CPU_FREQ_MHZ / CONFIG_PSRAM_NUM) \ No newline at end of file From 447651a8f2ac08d2e4eaf7781a5fd5919bc4b8b9 Mon Sep 17 00:00:00 2001 From: FINALx <3085378853@qq.com> Date: Sat, 7 Mar 2026 06:38:41 +0800 Subject: [PATCH 2/6] fix: fix makefile_isolated link order --- bin/ecos-init_project_isolated | 2 ++ board/StarrySkyC2/Makefile_isolated | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/ecos-init_project_isolated b/bin/ecos-init_project_isolated index 6147cdc..acddc18 100755 --- a/bin/ecos-init_project_isolated +++ b/bin/ecos-init_project_isolated @@ -37,6 +37,8 @@ init_project() { -exec cp {} "$new_project_name/Workspace/User" \; echo "cd .. && make" > "$new_project_name/Workspace/compile.sh" chmod +x "$new_project_name/Workspace/compile.sh" + echo "cd .. && make menuconfig" > "$new_project_name/Workspace/menuconfig.sh" + chmod +x "$new_project_name/Workspace/menuconfig.sh" cd "$new_project_name" diff --git a/board/StarrySkyC2/Makefile_isolated b/board/StarrySkyC2/Makefile_isolated index 4622603..72a6562 100644 --- a/board/StarrySkyC2/Makefile_isolated +++ b/board/StarrySkyC2/Makefile_isolated @@ -54,7 +54,8 @@ FIRMWARE_NAME := main endif # 源文件列表 -SRC_PATH := $(shell find Workspace -type f -name "*.c") +SRC_PATH := $(shell find Workspace -type f -name "*.s") +SRC_PATH += $(shell find Workspace -type f -name "*.c") CFLAGS += -I./configs CFLAGS += $(addprefix -I,$(shell find Workspace -type d)) From ef995ce93fa6520395855294105b8a6d97c905d1 Mon Sep 17 00:00:00 2001 From: FINALx <3085378853@qq.com> Date: Thu, 12 Mar 2026 11:45:01 +0800 Subject: [PATCH 3/6] feat: combine isolated with normal op --- bin/ecos | 26 ++++++------- bin/ecos-init_project | 60 +++++++++++++++++++++++++++-- bin/ecos-init_project_isolated | 27 ++++++------- bin/ecos-set_board_isolated | 22 +++++------ board/StarrySkyC2/Makefile_isolated | 11 ++++-- 5 files changed, 96 insertions(+), 50 deletions(-) diff --git a/bin/ecos b/bin/ecos index fcd8045..c0c17ba 100755 --- a/bin/ecos +++ b/bin/ecos @@ -19,25 +19,21 @@ show_help() { echo "Usage: ecos [options]" echo "" echo "Available commands:" - echo " set_board Set the board configuration" - echo " set_board_isolated Set the isolated-board configuration" - echo " init_project |list Initialize a project or list available projects" - echo " init_project_isolated Initialize a isolated-project" - echo " help Show this help message" - echo "" - echo "Isolated:" - echo " This operation gathers all the resource so that you can compile your project without sdk" - echo " But the riscv-toolchain is still indispensable" + echo " set_board Set the board configuration" + echo " init_project |list Initialize a project or list available projects" + echo " init_project_isolated Initialize a isolated-project" + echo " help Show this help message" echo "" echo "Board list:" - echo " c1 StarrySky C1 board" - echo " c2 StarrySky C2 board" - echo " l3 StarrySky L3 board" + echo " c1 StarrySky C1 board" + echo " c2 StarrySky C2 board" + echo " l3 StarrySky L3 board" echo "" echo "Examples:" - echo " ecos set_board c1 Set the board to StarrySky C1" - echo " ecos init_project hello Initialize a new project named 'hello'" - echo " ecos init_project list List all available project templates" + echo " ecos set_board c1 Set the board to StarrySky C1" + echo " ecos init_project hello Initialize a new project named 'hello'" + echo " ecos init_project list List all available project templates" + echo " ecos init_project hello -isolated Initialize a new project named 'hello'" echo "" } diff --git a/bin/ecos-init_project b/bin/ecos-init_project index 37b042e..db5d7f9 100755 --- a/bin/ecos-init_project +++ b/bin/ecos-init_project @@ -8,9 +8,10 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SDK_ROOT="$(dirname "$SCRIPT_DIR")" # Color output -log() { echo -e "\033[1;32m[ECOS]\033[0m $*"; } -warn() { echo -e "\033[1;33m[WARN]\033[0m $*"; } -err() { echo -e "\033[1;31m[ERROR]\033[0m $*"; } +log() { echo -e "\033[1;32m[ECOS]\033[0m $*"; } +warn() { echo -e "\033[1;33m[WARN]\033[0m $*"; } +err() { echo -e "\033[1;31m[ERROR]\033[0m $*"; } +tips() { echo -e "\033[1;94m[ECOS]\033[0m $*"; } echo_available_templates() { log "Available project templates:" @@ -97,6 +98,46 @@ init_project() { log "Project '$new_project_name' created successfully in './$new_project_name'" } +init_project_isolated() { + local isolated_project_name="${1:-HelloWorld}" + local target_board="${2:-c2}" + + # Check if project directory exists + if [[ -d "$isolated_project_name" ]]; then + err "Project directory already exists: $isolated_project_name" + exit 1 + fi + + # Copy project source must needed from sdk + log "Initializing project '$isolated_project_name' isolated..." + mkdir -p "$isolated_project_name/Library" + mkdir -p "$isolated_project_name/Startup" + mkdir -p "$isolated_project_name/User" + mkdir -p "$isolated_project_name/Hardware" + mkdir -p "$isolated_project_name/System" + find "$SDK_ROOT/components" -mindepth 2 -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' \ + -exec cp {} "$isolated_project_name/Library" \; + find "$SDK_ROOT/components" -maxdepth 1 -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' \ + -exec cp {} "$isolated_project_name/User" \; + + + cd "$isolated_project_name" + # Initialize project config file + local board_to_set="${target_board:-c2}" + echo "BOARD=${board_to_set}" > ".ecos-project" + log "Initialized project: $isolated_project_name" + log "Config file: .ecos-project" + + # Set default board + ecos set_board_isolated "${board_to_set}" + + # Create configs directory and copy scripts + mkdir -p configs + cp -r "$SDK_ROOT/tools/scripts/" "." + log "Project '$isolated_project_name' created successfully in './$isolated_project_name'" + tips "Please set menuconfig before project isolation" +} + # Main entry point for the subcommand if [[ $# -eq 0 ]]; then err "Missing project name or 'list' argument" @@ -106,12 +147,15 @@ if [[ $# -eq 0 ]]; then echo "Example: ecos init_project hello" echo " ecos init_project hello -name my_new_hello" echo " ecos init_project hello -name my_new_hello -target l3" + echo " ecos init_project my_project -isolated" + echo " ecos init_project my_project -isolated -target c2" exit 1 fi template_name="" new_project_name="" target_board="" +isIsolated=false while [[ $# -gt 0 ]]; do case "$1" in @@ -123,6 +167,10 @@ while [[ $# -gt 0 ]]; do target_board="$2" shift 2 ;; + -isolated) + isIsolated=true + shift 1 + ;; *) if [[ -z "$template_name" ]]; then template_name="$1" @@ -140,4 +188,8 @@ if [[ -z "$template_name" ]]; then exit 1 fi -init_project "$template_name" "${new_project_name:-$template_name}" "${target_board:-c1}" +if [[isIsolated]]; then + init_project "$template_name" "${new_project_name:-$template_name}" "${target_board:-c2}" +else + init_project_isolated "$template_name" "${target_board:-c2}" +fi diff --git a/bin/ecos-init_project_isolated b/bin/ecos-init_project_isolated index acddc18..99b1ad2 100755 --- a/bin/ecos-init_project_isolated +++ b/bin/ecos-init_project_isolated @@ -14,7 +14,7 @@ err () { echo -e "\033[1;31m[ERROR]\033[0m $*"; } tips() { echo -e "\033[1;94m[ECOS]\033[0m $*"; } # The actual init_project logic -init_project() { +init_project_isolated() { local new_project_name="${1:-HelloWorld}" local target_board="${2:-c1}" @@ -26,19 +26,15 @@ init_project() { # Copy project source must needed from sdk log "Initializing project '$new_project_name' isolated..." - mkdir -p "$new_project_name/Workspace/Library" - mkdir -p "$new_project_name/Workspace/Startup" - mkdir -p "$new_project_name/Workspace/User" - mkdir -p "$new_project_name/Workspace/Hardware" - mkdir -p "$new_project_name/Workspace/System" + mkdir -p "$new_project_name/Library" + mkdir -p "$new_project_name/Startup" + mkdir -p "$new_project_name/User" + mkdir -p "$new_project_name/Hardware" + mkdir -p "$new_project_name/System" find "$SDK_ROOT/components" -mindepth 2 -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' \ - -exec cp {} "$new_project_name/Workspace/Library" \; + -exec cp {} "$new_project_name/Library" \; find "$SDK_ROOT/components" -maxdepth 1 -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' \ - -exec cp {} "$new_project_name/Workspace/User" \; - echo "cd .. && make" > "$new_project_name/Workspace/compile.sh" - chmod +x "$new_project_name/Workspace/compile.sh" - echo "cd .. && make menuconfig" > "$new_project_name/Workspace/menuconfig.sh" - chmod +x "$new_project_name/Workspace/menuconfig.sh" + -exec cp {} "$new_project_name/User" \; cd "$new_project_name" @@ -62,10 +58,9 @@ init_project() { if [[ $# -eq 0 ]]; then err "Missing project name argument" echo "" - echo "Usage: ecos init_project [-target target_board]" - echo " ecos init_project list" - echo "Example: ecos init_project hello" - echo " ecos init_project hello -target l3" + echo "Usage: ecos init_project -isolated [-target target_board]" + echo "Example: ecos init_project hello -isolated" + echo " ecos init_project hello -isolated -target c2" exit 1 fi diff --git a/bin/ecos-set_board_isolated b/bin/ecos-set_board_isolated index 2dba1f1..74f2fe2 100755 --- a/bin/ecos-set_board_isolated +++ b/bin/ecos-set_board_isolated @@ -68,9 +68,9 @@ set_board() { local make_source_path="$SDK_ROOT/board/StarrySkyC1/$make_file" local lds_source_path="$SDK_ROOT/board/StarrySkyC1/$lds_file" - local board_target_path="./Workspace/Library/board.h" + local board_target_path="./Library/board.h" local make_target_path="./Makefile" - local lds_target_path="./Workspace/Startup/sections.lds" + local lds_target_path="./Startup/sections.lds" if [[ ! -f "$board_source_path" ]]; then err "Board config file not found: $board_source_path" @@ -94,8 +94,8 @@ set_board() { # Copy start.s if exists (C1 support) if [[ -f "$SDK_ROOT/board/StarrySkyC1/start.s" ]]; then - cp "$SDK_ROOT/board/StarrySkyC1/start.s" "./Workspace/Startup/start.s" - log "Set startup code: ./Workspace/Startup/start.s" + cp "$SDK_ROOT/board/StarrySkyC1/start.s" "./Startup/start.s" + log "Set startup code: ./Startup/start.s" fi # Update project config file if it exists @@ -119,10 +119,10 @@ set_board() { local lds_source_path="$SDK_ROOT/board/StarrySkyC2/$lds_file" local start_source_path="$SDK_ROOT/board/StarrySkyC2/$start_file" - local board_target_path="./Workspace/Library/board.h" + local board_target_path="./Library/board.h" local make_target_path="./Makefile" - local lds_target_path="./Workspace/Startup/sections.lds" - local start_target_path="./Workspace/Startup/start.s" + local lds_target_path="./Startup/sections.lds" + local start_target_path="./Startup/start.s" if [[ ! -f "$board_source_path" ]]; then err "Board config file not found: $board_source_path" @@ -173,10 +173,10 @@ set_board() { local make_source_path="$SDK_ROOT/board/StarrySkyL3/$make_file" local lds_source_path="$SDK_ROOT/board/StarrySkyL3/$lds_file" - local board_target_path="./Workspace/Library/board.h" + local board_target_path="./Library/board.h" local make_target_path="./Makefile" - local lds_target_path="./Workspace/Startup/sections.lds" - local start_target_path="./Workspace/Startup/start.s" + local lds_target_path="./Startup/sections.lds" + local start_target_path="./Startup/start.s" if [[ ! -f "$board_source_path" ]]; then err "Board config file not found: $board_source_path" @@ -206,7 +206,7 @@ set_board() { # Copy bootloader local bootloader_source_path="$SDK_ROOT/board/StarrySkyL3/loader" - local bootloader_target_path="./Workspace/Startup/loader" + local bootloader_target_path="./Startup/loader" cp -r "$bootloader_source_path" "$bootloader_target_path" log "Set bootloader: $bootloader_target_path" diff --git a/board/StarrySkyC2/Makefile_isolated b/board/StarrySkyC2/Makefile_isolated index 72a6562..2474c06 100644 --- a/board/StarrySkyC2/Makefile_isolated +++ b/board/StarrySkyC2/Makefile_isolated @@ -53,15 +53,18 @@ else FIRMWARE_NAME := main endif +# find排除文件参数 +EXCLUDE_DIRS := \( -path "configs" -o -path "scripts" -path "build" \) -prune + # 源文件列表 -SRC_PATH := $(shell find Workspace -type f -name "*.s") -SRC_PATH += $(shell find Workspace -type f -name "*.c") +SRC_PATH := $(shell find . $(EXCLUDE_DIRS) -o -type f -name "*.s") +SRC_PATH += $(shell find . $(EXCLUDE_DIRS) -o -type f -name "*.c") CFLAGS += -I./configs -CFLAGS += $(addprefix -I,$(shell find Workspace -type d)) +CFLAGS += $(addprefix -I,$(shell find . $(EXCLUDE_DIRS) -o -type d)) # 链接脚本路径 -LDS_PATH := $(shell find Workspace -type f -name "sections.lds") +LDS_PATH := $(shell find . $(EXCLUDE_DIRS) -o -type f -name "sections.lds") # 包含内存报告工具 -include ./scripts/mem_report.mk From d94a8c9b0b218fc231bfbada3a7d8dc577d8987b Mon Sep 17 00:00:00 2001 From: FINALx <3085378853@qq.com> Date: Thu, 12 Mar 2026 11:57:46 +0800 Subject: [PATCH 4/6] fix: fix isolated selection and clean unused file --- bin/ecos-init_project | 4 +- bin/ecos-init_project_isolated | 88 ---------------------------------- 2 files changed, 2 insertions(+), 90 deletions(-) delete mode 100755 bin/ecos-init_project_isolated diff --git a/bin/ecos-init_project b/bin/ecos-init_project index db5d7f9..acc6ed3 100755 --- a/bin/ecos-init_project +++ b/bin/ecos-init_project @@ -188,8 +188,8 @@ if [[ -z "$template_name" ]]; then exit 1 fi -if [[isIsolated]]; then +if [[ "${isIsolated:-false}" == false ]]; then init_project "$template_name" "${new_project_name:-$template_name}" "${target_board:-c2}" else - init_project_isolated "$template_name" "${target_board:-c2}" + init_project_isolated "${new_project_name:-$template_name}" "${target_board:-c2}" fi diff --git a/bin/ecos-init_project_isolated b/bin/ecos-init_project_isolated deleted file mode 100755 index 99b1ad2..0000000 --- a/bin/ecos-init_project_isolated +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# ECOS `init_project` subcommand -# Initializes a new isolated project - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -SDK_ROOT="$(dirname "$SCRIPT_DIR")" - -# Color output -log () { echo -e "\033[1;32m[ECOS]\033[0m $*"; } -warn() { echo -e "\033[1;33m[WARN]\033[0m $*"; } -err () { echo -e "\033[1;31m[ERROR]\033[0m $*"; } -tips() { echo -e "\033[1;94m[ECOS]\033[0m $*"; } - -# The actual init_project logic -init_project_isolated() { - local new_project_name="${1:-HelloWorld}" - local target_board="${2:-c1}" - - # Check if project directory exists - if [[ -d "$new_project_name" ]]; then - err "Project directory already exists: $new_project_name" - exit 1 - fi - - # Copy project source must needed from sdk - log "Initializing project '$new_project_name' isolated..." - mkdir -p "$new_project_name/Library" - mkdir -p "$new_project_name/Startup" - mkdir -p "$new_project_name/User" - mkdir -p "$new_project_name/Hardware" - mkdir -p "$new_project_name/System" - find "$SDK_ROOT/components" -mindepth 2 -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' \ - -exec cp {} "$new_project_name/Library" \; - find "$SDK_ROOT/components" -maxdepth 1 -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' \ - -exec cp {} "$new_project_name/User" \; - - - cd "$new_project_name" - # Initialize project config file - local board_to_set="${target_board:-c1}" - echo "BOARD=${board_to_set}" > ".ecos-project" - log "Initialized project: $new_project_name" - log "Config file: .ecos-project" - - # Set default board - ecos set_board_isolated "${board_to_set}" - - # Create configs directory and copy scripts - mkdir -p configs - cp -r "$SDK_ROOT/tools/scripts/" "." - log "Project '$new_project_name' created successfully in './$new_project_name'" - tips "Please set menuconfig before project isolation" -} - -# Main entry point for the subcommand -if [[ $# -eq 0 ]]; then - err "Missing project name argument" - echo "" - echo "Usage: ecos init_project -isolated [-target target_board]" - echo "Example: ecos init_project hello -isolated" - echo " ecos init_project hello -isolated -target c2" - exit 1 -fi - -new_project_name="" -target_board="" - -while [[ $# -gt 0 ]]; do - case "$1" in - -target) - target_board="$2" - shift 2 - ;; - *) - if [[ -z "$new_project_name" ]]; then - new_project_name="$1" - shift - else - err "Unknown argument: $1" - exit 1 - fi - ;; - esac -done - -init_project "${new_project_name}" "${target_board}" From 14ae0b4e98fb393098dbccb310cbe26c36cf9a36 Mon Sep 17 00:00:00 2001 From: FINALx <3085378853@qq.com> Date: Thu, 12 Mar 2026 12:42:24 +0800 Subject: [PATCH 5/6] feat: add guide and import sdk-offered drivers --- bin/ecos | 4 ++++ bin/ecos-init_project | 3 +++ docs/isolated_guide.md | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 docs/isolated_guide.md diff --git a/bin/ecos b/bin/ecos index c0c17ba..b3c3b48 100755 --- a/bin/ecos +++ b/bin/ecos @@ -24,6 +24,10 @@ show_help() { echo " init_project_isolated Initialize a isolated-project" echo " help Show this help message" echo "" + echo "Isolated:" + echo " This operation gathers all the resource so that you can compile your project without sdk" + echo " But the riscv-toolchain is still indispensable" + echo "" echo "Board list:" echo " c1 StarrySky C1 board" echo " c2 StarrySky C2 board" diff --git a/bin/ecos-init_project b/bin/ecos-init_project index acc6ed3..a4c2ac8 100755 --- a/bin/ecos-init_project +++ b/bin/ecos-init_project @@ -119,6 +119,9 @@ init_project_isolated() { -exec cp {} "$isolated_project_name/Library" \; find "$SDK_ROOT/components" -maxdepth 1 -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' \ -exec cp {} "$isolated_project_name/User" \; + find "$SDK_ROOT/devices" -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' \ + -exec cp {} "$isolated_project_name/Hardware" \; + cp "$SDK_ROOT/docs/isolated_guide.md" "$isolated_project_name" cd "$isolated_project_name" diff --git a/docs/isolated_guide.md b/docs/isolated_guide.md new file mode 100644 index 0000000..0ba4639 --- /dev/null +++ b/docs/isolated_guide.md @@ -0,0 +1,22 @@ +# 分离式项目 + +## 项目概述 +生成分离式项目将会按照板卡类型,收集 SDK 中所有可用资源,使得无需 SDK 即可编译项目。 +但 riscv-toolchain 仍然是不可缺少的组件。 + +## 项目结构 +``` +ECOS_Isolated_Project/ +├── README.md # 项目说明文档 +├── Makefile # 构建配置 +├── script/ # 构建工具 +├── configs/ # 构建的编译清单 +├── build/ # 生成的SoC固件 +├── Library/ # 工作区: 包含与Core相关的文件、SDK提供的标准库文件 +├── Startup/ # 工作区: 包含与系统链接与链接相关的文件 +├── User/ # 工作区: 包含自定义的程序入口 +├── System/ # 工作区: 包含自定义的片上资源驱动 +└── Hardware/ # 工作区: 包含自定义的片外资源驱动 +``` + +工作区中,除了Library、Startup、User是正常运行所必须的文件夹以外,其他文件夹可以任意自定义 \ No newline at end of file From fb56abc903d557ce1738d5c50dd56e4c649c5644 Mon Sep 17 00:00:00 2001 From: FINALx <3085378853@qq.com> Date: Thu, 12 Mar 2026 15:21:24 +0800 Subject: [PATCH 6/6] fix: fix import structure --- bin/ecos | 5 ++--- bin/ecos-init_project | 7 ++++--- bin/ecos-set_board_isolated | 5 +---- board/StarrySkyC2/Makefile_isolated | 12 ++++++------ 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/bin/ecos b/bin/ecos index b3c3b48..4dedbe3 100755 --- a/bin/ecos +++ b/bin/ecos @@ -21,11 +21,10 @@ show_help() { echo "Available commands:" echo " set_board Set the board configuration" echo " init_project |list Initialize a project or list available projects" - echo " init_project_isolated Initialize a isolated-project" echo " help Show this help message" echo "" echo "Isolated:" - echo " This operation gathers all the resource so that you can compile your project without sdk" + echo " Isolated project gathers all the resource so that you can compile your project without SDK" echo " But the riscv-toolchain is still indispensable" echo "" echo "Board list:" @@ -37,7 +36,7 @@ show_help() { echo " ecos set_board c1 Set the board to StarrySky C1" echo " ecos init_project hello Initialize a new project named 'hello'" echo " ecos init_project list List all available project templates" - echo " ecos init_project hello -isolated Initialize a new project named 'hello'" + echo " ecos init_project hello -isolated Initialize a new isolated project named 'hello'" echo "" } diff --git a/bin/ecos-init_project b/bin/ecos-init_project index a4c2ac8..9cbbb6f 100755 --- a/bin/ecos-init_project +++ b/bin/ecos-init_project @@ -119,8 +119,8 @@ init_project_isolated() { -exec cp {} "$isolated_project_name/Library" \; find "$SDK_ROOT/components" -maxdepth 1 -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' \ -exec cp {} "$isolated_project_name/User" \; - find "$SDK_ROOT/devices" -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' \ - -exec cp {} "$isolated_project_name/Hardware" \; + # due to diversity of the device drivers, copy its whole structure + find "$SDK_ROOT/devices" -maxdepth 1 -mindepth 1 -type d -exec cp -r {} "$isolated_project_name/Hardware" \; cp "$SDK_ROOT/docs/isolated_guide.md" "$isolated_project_name" @@ -145,13 +145,14 @@ init_project_isolated() { if [[ $# -eq 0 ]]; then err "Missing project name or 'list' argument" echo "" - echo "Usage: ecos init_project [-name new_project_name] [-target target_board]" + echo "Usage: ecos init_project [-isolated] [-name new_project_name] [-target target_board]" echo " ecos init_project list" echo "Example: ecos init_project hello" echo " ecos init_project hello -name my_new_hello" echo " ecos init_project hello -name my_new_hello -target l3" echo " ecos init_project my_project -isolated" echo " ecos init_project my_project -isolated -target c2" + echo " ecos init_project my_project -isolated -name my_new_project -target c2" exit 1 fi diff --git a/bin/ecos-set_board_isolated b/bin/ecos-set_board_isolated index 74f2fe2..0091751 100755 --- a/bin/ecos-set_board_isolated +++ b/bin/ecos-set_board_isolated @@ -234,10 +234,7 @@ set_board() { # Main entry point for the subcommand if [[ $# -eq 0 ]]; then - err "Missing board name argument." - echo "" - echo "Usage: ecos set_board " - echo "Example: ecos set_board c1" + err "Missing board name argument for isolated project." exit 1 fi diff --git a/board/StarrySkyC2/Makefile_isolated b/board/StarrySkyC2/Makefile_isolated index 2474c06..2bdfe4a 100644 --- a/board/StarrySkyC2/Makefile_isolated +++ b/board/StarrySkyC2/Makefile_isolated @@ -53,18 +53,18 @@ else FIRMWARE_NAME := main endif -# find排除文件参数 -EXCLUDE_DIRS := \( -path "configs" -o -path "scripts" -path "build" \) -prune +# find包含目录 +INCLUDE_DIRS := Library Startup User Hardware System # 源文件列表 -SRC_PATH := $(shell find . $(EXCLUDE_DIRS) -o -type f -name "*.s") -SRC_PATH += $(shell find . $(EXCLUDE_DIRS) -o -type f -name "*.c") +SRC_PATH := $(shell find $(INCLUDE_DIRS) -type f -name "*.s") +SRC_PATH += $(shell find $(INCLUDE_DIRS) -type f -name "*.c") CFLAGS += -I./configs -CFLAGS += $(addprefix -I,$(shell find . $(EXCLUDE_DIRS) -o -type d)) +CFLAGS += $(addprefix -I,$(shell find $(INCLUDE_DIRS) -type d)) # 链接脚本路径 -LDS_PATH := $(shell find . $(EXCLUDE_DIRS) -o -type f -name "sections.lds") +LDS_PATH := $(shell find $(INCLUDE_DIRS) -type f -name "sections.lds") # 包含内存报告工具 -include ./scripts/mem_report.mk