Skip to content
Open
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
31 changes: 18 additions & 13 deletions bin/ecos
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,28 @@ show_help() {
echo "Usage: ecos <command> [options]"
echo ""
echo "Available commands:"
echo " set_board <board_name> Set the board configuration"
echo " init_project <project_name>|list Initialize a project or list available projects"
echo " flash Flash the compiled firmware to the device"
echo " monitor Open serial monitor using minicom"
echo " help Show this help message"
echo " set_board <board_name> Set the board configuration"
echo " init_project <project_name>|list Initialize a project or list available projects"
echo " flash Flash the compiled firmware to the device"
echo " monitor Open serial monitor using minicom"
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 "Isolated:"
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 "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 flash Flash the compiled firmware to the device"
echo " ecos monitor Open the default serial port at 115200 baud"
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 isolated project named 'hello'"
echo " ecos flash Flash the compiled firmware to the device"
echo " ecos monitor Open the default serial port at 115200 baud"
echo ""
}

Expand Down
Empty file modified bin/ecos-completion.zsh
100644 → 100755
Empty file.
72 changes: 67 additions & 5 deletions bin/ecos-init_project
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down Expand Up @@ -109,6 +110,55 @@ 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}"
local LibraryDir="$isolated_project_name/Library"
local StartupDir="$isolated_project_name/Startup"
local UserDir="$isolated_project_name/User"
local HardwareDir="$isolated_project_name/Hardware"
local SystemDir="$isolated_project_name/System"

# 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 "$LibraryDir"
mkdir -p "$StartupDir"
mkdir -p "$UserDir"
mkdir -p "$HardwareDir"
mkdir -p "$SystemDir"

find "$SDK_ROOT/components/libc" -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' -exec cp {} "$LibraryDir" \;
find "$SDK_ROOT/components/libgcc" -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' -exec cp {} "$LibraryDir" \;
find "$SDK_ROOT/hal" -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' -exec cp {} "$LibraryDir" \;

# due to diversity of the device drivers, copy its whole structure
find "$SDK_ROOT/devices" -maxdepth 1 -mindepth 1 -type d -exec cp -r {} "$HardwareDir" \;
cp "$SDK_ROOT/docs/isolated_project.md" "$isolated_project_name"


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 once before your project isolation"
}

# Main entry point for the subcommand
if [[ $# -eq 0 ]]; then
err "Missing project name or 'list' argument"
Expand All @@ -118,12 +168,16 @@ 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"
echo " ecos init_project my_project -isolated -name my_new_project -target c2"
exit 1
fi

template_name=""
new_project_name=""
target_board=""
isIsolated=false

while [[ $# -gt 0 ]]; do
case "$1" in
Expand All @@ -135,10 +189,14 @@ while [[ $# -gt 0 ]]; do
target_board="$2"
shift 2
;;
-isolated)
isIsolated=true
shift 1
;;
*)
if [[ -z "$template_name" ]]; then
template_name="$1"
shift
shift 1
else
err "Unknown argument: $1"
exit 1
Expand All @@ -152,4 +210,8 @@ if [[ -z "$template_name" ]]; then
exit 1
fi

init_project "$template_name" "${new_project_name:-$template_name}" "${target_board:-c1}"
if [[ "${isIsolated:-false}" == false ]]; then
init_project "$template_name" "${new_project_name:-$template_name}" "${target_board:-c2}"
else
init_project_isolated "${new_project_name:-$template_name}" "${target_board:-c2}"
fi
163 changes: 163 additions & 0 deletions bin/ecos-set_board_isolated
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/usr/bin/env bash
set -euo pipefail

# ECOS `set_board` subcommand
# Sets the board configuration for the project

# WARN: only C2 was checked!!!
# TODO: support C1 / L3

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")
warn "TODO"
exit 1
;;
"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 driver_source_path="$SDK_ROOT/board/StarrySkyC2/driver"
local main_source_path="$SDK_ROOT/templates/hello/c2"

local board_target_path="./Library/board.h"
local make_target_path="./Makefile"
local lds_target_path="./Startup/sections.lds"
local start_target_path="./Startup/start.S"
local driver_target_path="./Library"
local main_target_path="./User"

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

# Copy Drivers
if [[ -d "$driver_source_path" ]]; then
find "$driver_source_path" -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' -exec cp {} "$driver_target_path" \;
log "Set drivers: $driver_target_path"
else
warn "Drivers not found for C2: $driver_source_path"
fi

# Copy Main files
if [[ -d "$main_source_path" ]]; then
find "$main_source_path" -type f -name "main.*" -exec cp {} "$main_target_path" \;
log "Set drivers: $main_target_path"
else
warn "Drivers not found for C2: $main_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")
warn "TODO"
exit 1
;;
*)
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 for isolated project."
exit 1
fi

set_board "$1"
Loading