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

WiP: Migrating to Alpine build env #1169

Merged
merged 13 commits into from
Jan 9, 2022
Merged
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
48 changes: 16 additions & 32 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,23 @@ on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-20.04
container:
image: alpine:3.15
strategy:
matrix:
model: ["TS100", "TS80", "TS80P", "Pinecil", "MHP30"]
fail-fast: true

steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Install dependencies (apk)
run: apk add --no-cache gcc-riscv-none-elf gcc-arm-none-eabi newlib-riscv-none-elf newlib-arm-none-eabi findutils python3 py3-pip make git bash

- name: chmod
run: chmod +x setup.sh && chmod +x source/build.sh && sudo mkdir -p /build/cache && sudo chmod -R 777 /build
- name: Install dependencies (python)
run: python3 -m pip install bdflib

- name: Cached compiler source files
uses: actions/cache@v2.1.7
env:
cache-name: cache-compilers
- uses: actions/checkout@v2
with:
path: /build/cache
key: ${{ runner.os }}-build-${{ env.cache-name }}
restore-keys: |
${{ runner.os }}-

- name: setup
run: ./setup.sh
submodules: true

- name: build ${{ matrix.model }}
run: cd source && ./build.sh -m ${{ matrix.model }}
Expand All @@ -52,32 +44,23 @@ jobs:

build_multi-lang:
runs-on: ubuntu-20.04
container:
image: alpine:3.15
strategy:
matrix:
model: ["Pinecil"]
fail-fast: true

steps:
- name: Install dependencies (apk)
run: apk add --no-cache gcc-riscv-none-elf gcc-arm-none-eabi newlib-riscv-none-elf newlib-arm-none-eabi findutils python3 py3-pip make git bash musl-dev
- name: Install dependencies (python)
run: python3 -m pip install bdflib

- uses: actions/checkout@v2
with:
submodules: true

- name: chmod
run: chmod +x setup.sh && chmod +x source/build.sh && sudo mkdir -p /build/cache && sudo chmod -R 777 /build

- name: Cached compiler source files
uses: actions/cache@v2.1.7
env:
cache-name: cache-compilers
with:
path: /build/cache
key: ${{ runner.os }}-build-${{ env.cache-name }}
restore-keys: |
${{ runner.os }}-

- name: setup
run: ./setup.sh

- name: build ${{ matrix.model }}
run: cd source && make -j$(nproc) model="${{ matrix.model }}" firmware-multi_compressed_European firmware-multi_compressed_Bulgarian+Russian+Serbian+Ukrainian firmware-multi_Chinese+Japanese

Expand Down Expand Up @@ -142,6 +125,7 @@ jobs:

- name: setup
run: sudo apt-get update && sudo apt-get install -y make clang git python3 python3-pip && python3 -m pip install bdflib black flake8

- name: Check formatting with clang-format
run: cd source && make clean && make check-style

Expand Down
38 changes: 13 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
FROM ubuntu:20.04
FROM alpine:3.15
LABEL maintainer="Ben V. Brown <ralim@ralimtek.com>"

WORKDIR /build
# Add extra mirrors for options
RUN echo "deb mirror://mirrors.ubuntu.com/mirrors.txt focal main restricted universe multiverse" > /etc/apt/sources.list && \
echo "deb mirror://mirrors.ubuntu.com/mirrors.txt focal-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
echo "deb mirror://mirrors.ubuntu.com/mirrors.txt focal-security main restricted universe multiverse" >> /etc/apt/sources.list && \
DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ca-certificates
# Install dependencies to build the firmware
RUN apt-get install -y \
make \
bzip2 \
git \
python3 \
python3-pip \
clang-format \
dfu-util \
wget --no-install-recommends && \
apt-get clean
RUN python3 -m pip install bdflib
# Download the two compilers
RUN wget -qO- "https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2" | tar -xj
# This is the same as the one from Nuclei, just mirrored on Github as their download server is horrifically slow
RUN wget -qO- "https://github.com/Ralim/nuclei-compiler/releases/download/2020.08/nuclei_riscv_newlibc_prebuilt_linux64_2020.08.tar.bz2" | tar -xj
# Installing the two compilers, python3, python3 pip, clang format
# Compilders ->gcc-* newlib-*
# Python3 -> py*
# Misc -> findutils make git
# musl-dev is required for the multi lang firmwares
# clang is required for clang-format (for dev)

RUN apk add --no-cache gcc-riscv-none-elf gcc-arm-none-eabi newlib-riscv-none-elf newlib-arm-none-eabi findutils python3 py3-pip make git musl-dev clang bash

# Install Python3 packages

RUN python3 -m pip install bdflib black

# Add compiler to the path
ENV PATH "/build/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH"
ENV PATH "/build/gcc/bin/:$PATH"
COPY . /build/source
COPY ./ci /build/ci
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
tty: true
build:
context: .
command: /bin/bash
command: /bin/sh
volumes:
- ./ci:/build/ci:Z
- ./:/build/source:Z
100 changes: 44 additions & 56 deletions source/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ HOST_CC := gcc
endif
HOST_OUTPUT_DIR=Objects/host

# DFU packing address to use
DEVICE_DFU_ADDRESS=0x08000000
DEVICE_DFU_VID_PID=0x28E9:0x0189
# Enumerate all of the include directories
Expand All @@ -63,27 +64,29 @@ MHP30_STARTUP_DIR = ./Startup
MHP30_INC_DIR = ./Core/BSP/MHP30
MHP30_LD_FILE = ./Core/BSP/MHP30/stm32f103.ld

FRTOS_CMIS_INC_DIR = ./Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS
FRTOS_INC_DIR = ./Middlewares/Third_Party/FreeRTOS/Source/include
DRIVER_INC_DIR =./Core/Drivers
BSP_INC_DIR = ./Core/BSP
THREADS_INC_DIR = ./Core/Threads
PINE_INC_DIR = ./Core/BSP/Pine64
PINE_VENDOR_INC_DIR = ./Core/BSP/Pine64/Vendor/SoC/gd32vf103/Common/Include
PINE_VENDOR_USB_INC_DIR = ./Core/BSP/Pine64/Vendor/SoC/gd32vf103/Common/Include/Usb
PINE_NMSIS_INC_DIR = ./Core/BSP/Pine64/Vendor/NMSIS/Core/Include
PINE_FREERTOS_PORT_INC_DIR = ./Core/BSP/Pine64/Vendor/OS/FreeRTOS/Source/portable/GCC

SOURCE_MIDDLEWARES_DIR = ./Middlewares
FRTOS_CMIS_INC_DIR = ./Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS
FRTOS_INC_DIR = ./Middlewares/Third_Party/FreeRTOS/Source/include
DRIVER_INC_DIR =./Core/Drivers
BSP_INC_DIR = ./Core/BSP
THREADS_INC_DIR = ./Core/Threads

SOURCE_THREADS_DIR = ./Core/Threads
SOURCE_CORE_DIR = ./Core/Src
SOURCE_BRIEFLZ_DIR = ./Core/brieflz
SOURCE_DRIVERS_DIR = ./Core/Drivers
INC_PD_DRIVERS_DIR = ./Core/Drivers/usb-pd/include
PD_DRIVER_TESTS_DIR = ./Core/Drivers/usb-pd/tests
PD_DRIVER_DIR = ./Core/Drivers/usb-pd
SOURCE_MIDDLEWARES_DIR = ./Middlewares
# Find-all's used for formatting
ALL_INCLUDES = $(shell find ./Core -type d \( -path $(BRIEFLZ_INC_DIR) -o -path $(PD_DRIVER_DIR) \) -prune -false -o \( -type f \( -name '*.h' -o -name '*.hpp' \) \) )

ALL_INCLUDES = $(shell find ./Core -type d \( -path $(BRIEFLZ_INC_DIR) -o -path $(PD_DRIVER_DIR) \) -prune -false -o \( -type f \( -name '*.h' -o -name '*.hpp' \) \) )
ALL_SOURCE = $(shell find ./Core -type d \( -path $(SOURCE_BRIEFLZ_DIR) -o -path $(PD_DRIVER_DIR) \) -prune -false -o \( -type f \( -name '*.c' -o -name '*.cpp' \) \) )

# Device dependent settings
Expand All @@ -100,14 +103,10 @@ LDSCRIPT=$(MINIWARE_LD_FILE)
DEV_GLOBAL_DEFS= -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D GCC_ARMCM3 \
-D ARM_MATH_CM3 \
-D STM32F10X_MD
DEV_LDFLAGS=-lm -Wl,--gc-sections
DEV_LDFLAGS=
DEV_AFLAGS=
DEV_CFLAGS= -D GCC_ARMCM3 \
-D ARM_MATH_CM3 \
-D STM32F10X_MD
DEV_CXXFLAGS= -D GCC_ARMCM3 \
-D ARM_MATH_CM3 \
-D STM32F10X_MD
DEV_CFLAGS=
DEV_CXXFLAGS=
CPUFLAGS= -mcpu=cortex-m3 \
-mthumb \
-mfloat-abi=soft
Expand All @@ -130,14 +129,10 @@ LDSCRIPT=$(MHP30_LD_FILE)
DEV_GLOBAL_DEFS= -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D GCC_ARMCM3 \
-D ARM_MATH_CM3 \
-D STM32F10X_MD
DEV_LDFLAGS=-lm -Wl,--gc-sections
DEV_LDFLAGS=
DEV_AFLAGS=
DEV_CFLAGS= -D GCC_ARMCM3 \
-D ARM_MATH_CM3 \
-D STM32F10X_MD
DEV_CXXFLAGS= -D GCC_ARMCM3 \
-D ARM_MATH_CM3 \
-D STM32F10X_MD
DEV_CFLAGS=
DEV_CXXFLAGS=
CPUFLAGS= -mcpu=cortex-m3 \
-mthumb \
-mfloat-abi=soft
Expand All @@ -146,6 +141,8 @@ bootldr_size=32k
DEVICE_DFU_ADDRESS=0x08008000
DEVICE_DFU_VID_PID=0x1209:0xDB42
endif


ifeq ($(model),$(ALL_PINE_MODELS))
$(info Building for Pine64 )
DEVICE_INCLUDES = -I$(PINE_INC_DIR) \
Expand All @@ -163,14 +160,12 @@ bootldr_size=0x0
# Flags
CPUFLAGS= -march=rv32imac \
-mabi=ilp32 \
-mcmodel=medany -fsigned-char -fno-builtin -fsingle-precision-constant \
-DRTOS_FREERTOS -DDOWNLOAD_MODE=DOWNLOAD_MODE_FLASHXIP

DEV_LDFLAGS= -lstdc++ -nostartfiles -Xlinker --gc-sections --specs=nosys.specs -u _isatty -u _write -u _sbrk -u _read -u _close -u _fstat -u _lseek
DEV_AFLAGS= -nostartfiles -ffreestanding -fno-common -Os -flto
DEV_GLOBAL_DEFS=
DEV_CFLAGS= -MMD -MP -MF "$(@:%.o=%.d)" -MT "$@"
DEV_CXXFLAGS= -MMD -MP -MF "$(@:%.o=%.d)" -MT "$@"
-mcmodel=medany -fsigned-char -fno-builtin -nostartfiles
DEV_LDFLAGS=-nostartfiles --specs=patch.specs
DEV_AFLAGS=
DEV_GLOBAL_DEFS= -DRTOS_FREERTOS -DDOWNLOAD_MODE=DOWNLOAD_MODE_FLASHXIP
DEV_CFLAGS=
DEV_CXXFLAGS=
endif

INCLUDES = -I$(APP_INC_DIR) \
Expand All @@ -197,12 +192,12 @@ $(shell find $(DEVICE_BSP_DIR) -type f -name '*.cpp') \
$(shell find $(SOURCE_MIDDLEWARES_DIR) -type f -name '*.cpp')

# code optimisation ------------------------------------------------------------
OPTIM=-Os -flto -finline-small-functions -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections -fshort-enums
OPTIM=-Os -flto -finline-small-functions -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections -fshort-enums -fsingle-precision-constant -ffreestanding -fno-common

# global defines ---------------------------------------------------------------
GLOBAL_DEFINES += $(DEV_GLOBAL_DEFS) -D USE_RTOS_SYSTICK -D MODEL_$(model) -D VECT_TAB_OFFSET=$(bootldr_size)U

DEBUG=-g3
DEBUG=-g3
ifdef swd_enable
GLOBAL_DEFINES += -DSWD_ENABLE
endif
Expand All @@ -221,33 +216,30 @@ ifeq ($(model),$(filter $(model),$(ALL_MINIWARE_MODELS) $(ALL_MHP30_MODELS)))
COMPILER_PREFIX=arm-none-eabi
endif
ifeq ($(model),$(ALL_PINE_MODELS))
COMPILER_PREFIX=riscv-nuclei-elf
COMPILER_PREFIX=riscv-none-elf
endif
# programs ---------------------------------------------------------------------
CC=$(COMPILER_PREFIX)-gcc
CPP=$(COMPILER_PREFIX)-g++
AS=$(COMPILER_PREFIX)-as
OBJCOPY=$(COMPILER_PREFIX)-objcopy
OBJDUMP=$(COMPILER_PREFIX)-objdump
SIZE=$(COMPILER_PREFIX)-size

# For the Pinecil, use gcc in assembler mode
ifeq ($(model),$(ALL_PINE_MODELS))
# use gcc in assembler mode so we can use defines etc in assembly
AS=$(COMPILER_PREFIX)-gcc -x assembler-with-cpp
endif

# linker flags -----------------------------------------------------------------
LINKER_FLAGS= -Wl,--gc-sections \
-Wl,--wrap=malloc \
-Wl,--wrap=free \
-lm \
-Wl,--undefined=vTaskSwitchContext \
-Wl,--undefined=pxCurrentTCB \
-Wl,--defsym=__FLASH_SIZE__=$(flash_size) \
-Wl,--defsym=__BOOTLDR_SIZE__=$(bootldr_size) \
$(DEV_LDFLAGS) \
-Wl,--print-memory-usage \
-flto \
--specs=nano.specs
--specs=nosys.specs \
--specs=nano.specs \
$(DEV_LDFLAGS)

# compiler flags ---------------------------------------------------------------

Expand Down Expand Up @@ -296,8 +288,6 @@ CXXFLAGS=$(DEV_CXXFLAGS) \
$(CHECKOPTIONS) \
-std=c++14 \
$(OPTIM) \
-fno-common \
-ffreestanding \
-fno-rtti \
-fno-exceptions \
-fno-non-call-exceptions \
Expand All @@ -309,27 +299,27 @@ CXXFLAGS=$(DEV_CXXFLAGS) \
-T$(LDSCRIPT)


CFLAGS=$(DEV_CFLAGS) \
$(CPUFLAGS) \
$(DEBUG) \
CFLAGS=$(DEV_CFLAGS) \
$(CPUFLAGS) \
$(DEBUG) \
$(INCLUDES) \
$(CHECKOPTIONS_C) \
$(GLOBAL_DEFINES) \
-D${COMPILER} \
-MMD \
-std=gnu99 \
$(OPTIM) \
-fno-common \
-ffreestanding \
-MMD \
-std=gnu99 \
$(OPTIM) \
-T$(LDSCRIPT) \
-c



AFLAGS= $(CPUFLAGS) \
$(DEV_AFLAGS) \
$(DEBUG) \
$(ASM_INC) \
AFLAGS= $(CPUFLAGS) \
$(DEV_AFLAGS) \
$(GLOBAL_DEFINES) \
$(OPTIM) \
$(DEBUG) \
$(ASM_INC) \
$(INCLUDES)


Expand All @@ -351,8 +341,6 @@ default : firmware-EN
firmware-%: $(HEXFILE_DIR)/$(model)_%.hex $(HEXFILE_DIR)/$(model)_%.bin $(HEXFILE_DIR)/$(model)_%.dfu
@true

ALL_FIRMWARE_TARGETS=$(addprefix firmware-,$(ALL_LANGUAGES))
all: $(ALL_FIRMWARE_TARGETS)

#
# The rule to create the target directory
Expand Down
2 changes: 2 additions & 0 deletions source/patch.specs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*link:
%(nano_link) %:replace-outfile(-lm_nano -lm)