Skip to content

Commit 7072e61

Browse files
committed
Add firmware, docker build scripts
1 parent 6bacf1b commit 7072e61

File tree

9 files changed

+1312
-0
lines changed

9 files changed

+1312
-0
lines changed

docker/Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM docker.io/library/ubuntu:23.04 as base
2+
3+
RUN apt-get -qq update -y
4+
5+
RUN DEBIAN_FRONTEND=noninteractive \
6+
apt-get install -y --no-install-recommends \
7+
build-essential \
8+
libusb-1.0.0-dev \
9+
git \
10+
sdcc \
11+
ca-certificates
12+
13+
# Cleanup cached apt stuff
14+
RUN rm -rf /var/lib/apt/lists/*
15+
16+
FROM base as toolsbuilder
17+
18+
# Tools that needs to be built from source
19+
20+
RUN git clone https://github.com/ole00/chprog.git /src
21+
WORKDIR /src
22+
RUN ./build_linux.sh
23+
RUN cp ./chprog /usr/local/bin
24+
25+
From base
26+
COPY --from=toolsbuilder /usr/local/ /usr/local
27+
28+
RUN apt-get -qq update -y
29+
30+
# Needed for git --describe to work
31+
RUN git config --global --add safe.directory /build

docker/Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
all:
2+
@echo "Build targets: "
3+
@echo "build-docker Build an image for building tools with Docker"
4+
@echo "build Build project assets from within Docker container"
5+
@echo "run Run a shell using the above image with Docker"
6+
7+
build-docker:
8+
docker build -t ch55x_programmer-builder -f Dockerfile .
9+
10+
COMMON = run \
11+
--rm \
12+
--mount type=bind,source="`pwd`/../src",target=/build \
13+
-w /build \
14+
15+
reset_controller.bin:
16+
docker ${COMMON} \
17+
-it ch55x_programmer-builder \
18+
/usr/bin/bash -c "make"
19+
20+
build: reset_controller.bin
21+
22+
flash: reset_controller.bin
23+
docker ${COMMON} \
24+
--privileged -v /dev/bus/usb:/dev/bus/usb \
25+
-it ch55x_programmer-builder \
26+
/usr/bin/bash -c "chprog reset_controller.bin"
27+
28+
run:
29+
docker ${COMMON} \
30+
-it ch55x_programmer-builder \
31+
/usr/bin/bash
32+

src/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.asm
2+
*.lst
3+
*.rel
4+
*.rst
5+
*.sym
6+
*.bin
7+
*.ihx
8+
*.lk
9+
*.map
10+
*.mem

src/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
TARGET = reset_controller
2+
FREQ_SYS = 16000000
3+
4+
C_FILES = \
5+
main.c \
6+
include/debug.c
7+
8+
pre-flash:
9+
10+
11+
include include/Makefile.include

src/include/Makefile.include

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#######################################################
2+
3+
# toolchain
4+
CC = sdcc
5+
OBJCOPY = objcopy
6+
PACK_HEX = packihx
7+
WCHISP ?= wchisptool -g -f
8+
9+
#######################################################
10+
11+
FREQ_SYS ?= 24000000
12+
13+
XRAM_SIZE ?= 0x0400
14+
15+
XRAM_LOC ?= 0x0000
16+
17+
CODE_SIZE ?= 0x3800
18+
19+
ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
20+
21+
CFLAGS := -V -mmcs51 --model-small \
22+
--xram-size $(XRAM_SIZE) --xram-loc $(XRAM_LOC) \
23+
--code-size $(CODE_SIZE) \
24+
-I$(ROOT_DIR)../include -DFREQ_SYS=$(FREQ_SYS) \
25+
$(EXTRA_FLAGS)
26+
27+
LFLAGS := $(CFLAGS)
28+
29+
RELS := $(C_FILES:.c=.rel)
30+
31+
print-% : ; @echo $* = $($*)
32+
33+
%.rel : %.c
34+
$(CC) -c $(CFLAGS) $<
35+
36+
# Note: SDCC will dump all of the temporary files into this one, so strip the paths from RELS
37+
# For now, get around this by stripping the paths off of the RELS list.
38+
39+
$(TARGET).ihx: $(RELS)
40+
$(CC) $(notdir $(RELS)) $(LFLAGS) -o $(TARGET).ihx
41+
42+
$(TARGET).hex: $(TARGET).ihx
43+
$(PACK_HEX) $(TARGET).ihx > $(TARGET).hex
44+
45+
$(TARGET).bin: $(TARGET).ihx
46+
$(OBJCOPY) -I ihex -O binary $(TARGET).ihx $(TARGET).bin
47+
48+
flash: $(TARGET).bin pre-flash
49+
$(WCHISP) $(TARGET).bin
50+
51+
.DEFAULT_GOAL := all
52+
all: $(TARGET).bin $(TARGET).hex
53+
54+
clean:
55+
rm -f \
56+
$(notdir $(RELS:.rel=.asm)) \
57+
$(notdir $(RELS:.rel=.lst)) \
58+
$(notdir $(RELS:.rel=.mem)) \
59+
$(notdir $(RELS:.rel=.rel)) \
60+
$(notdir $(RELS:.rel=.rst)) \
61+
$(notdir $(RELS:.rel=.sym)) \
62+
$(notdir $(RELS:.rel=.adb)) \
63+
$(TARGET).lk \
64+
$(TARGET).map \
65+
$(TARGET).mem \
66+
$(TARGET).ihx \
67+
$(TARGET).hex \
68+
$(TARGET).bin

0 commit comments

Comments
 (0)