forked from selfcustody/krux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
162 lines (134 loc) · 5.16 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# The MIT License (MIT)
# Copyright (c) 2021-2023 Krux contributors
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# syntax=docker/dockerfile:1
############
# build-base
# install kendryte (k210), cmake and python dependencies
############
FROM gcc:9.4.0-buster AS build-base
RUN apt-get update -y && \
apt-get install --no-install-recommends -y -q \
wget \
tar \
zip \
unzip \
build-essential \
libtool \
autoconf \
automake \
autotools-dev \
curl \
libmpc-dev \
libmpfr-dev \
libgmp-dev \
gawk \
bison \
flex \
texinfo \
gperf \
libtool \
patchutils \
bc \
zlib1g-dev \
libexpat-dev \
libisl-dev \
python3 \
python3-pip \
python3-setuptools
RUN mkdir -p /opt && \
git clone --depth 1 --recurse-submodules --shallow-submodules --branch v8.2.0-20190409 https://github.com/kendryte/kendryte-gnu-toolchain
RUN cd kendryte-gnu-toolchain && \
export PATH=$PATH:/opt/kendryte-toolchain/bin && \
./configure --prefix=/opt/kendryte-toolchain --with-cmodel=medany --with-arch=rv64imafc --with-abi=lp64f --enable-threads=posix --enable-libatomic && \
make -j8
RUN wget https://github.com/Kitware/CMake/releases/download/v3.21.0/cmake-3.21.0.tar.gz && \
echo "4a42d56449a51f4d3809ab4d3b61fd4a96a469e56266e896ce1009b5768bd2ab cmake-3.21.0.tar.gz" | sha256sum -c && \
tar -xzvf cmake-3.21.0.tar.gz && \
cd cmake-3.21.0 && ./bootstrap && make && make install
RUN pip3 install astor
RUN pip3 install pyserial==3.4
############
# build-software
# copy vendor, firmware and Krux (src) files
# install embit dependency
############
FROM build-base AS build-software
ARG DEVICE="maixpy_m5stickv"
ENV DEVICE_BUILTIN="firmware/MaixPy/projects/${DEVICE}/builtin_py"
RUN mkdir /src
WORKDIR /src
# copy vendor to WORKDIR (src)
COPY ./vendor vendor
# clean vendor/urtypes
RUN find vendor/urtypes -type d -name '__pycache__' -exec rm -rv {} + -depth
# clean vendor/foundation-ur-py
RUN find vendor/foundation-ur-py -type d -name '__pycache__' -exec rm -rv {} + -depth
# install vendor/embit
RUN cd vendor/embit && pip3 install -e .
# clean vendor/embit
RUN rm -rf vendor/embit/src/embit/util/prebuilt && \
rm -rf vendor/embit/src/embit/liquid && \
rm -f vendor/embit/src/embit/psbtview.py && \
rm -f vendor/embit/src/embit/slip39.py && \
rm -f vendor/embit/src/embit/wordlists/slip39.py && \
rm -f vendor/embit/src/embit/util/ctypes_secp256k1.py && \
rm -f vendor/embit/src/embit/util/py_secp256k1.py && \
rm -f vendor/embit/src/embit/util/py_ripemd160.py && \
find vendor/embit -type d -name '__pycache__' -exec rm -rv {} + -depth
# copy firmware to WORKDIR (src)
COPY ./firmware firmware
# clean firmware
RUN find firmware -type d -name '__pycache__' -exec rm -rv {} + -depth
# copy all vendors to DEVICE_BUILTIN
RUN cp -r vendor/urtypes/src/urtypes "${DEVICE_BUILTIN}"
RUN cp -r vendor/foundation-ur-py/src/ur "${DEVICE_BUILTIN}"
RUN cp -r vendor/embit/src/embit "${DEVICE_BUILTIN}"
# copy Krux (src) to WORKDIR (src)
COPY ./src src
# rename boot.py
RUN mv src/boot.py src/_boot.py
# clean it
RUN find src -type d -name '__pycache__' -exec rm -rv {} + -depth
# copy it to DEVICE_BUILTIN
RUN cp -r src/. "${DEVICE_BUILTIN}"
############
# build-firmware
# python compilation of Krux and its dependencies inside MaixPy
# creation of the firmware.bin
############
FROM build-software AS build-firmware
ARG DEVICE="maixpy_m5stickv"
WORKDIR /src/firmware/MaixPy
# overrides the DEVICE specific font.c in componets/micropython
RUN cp -rf projects/"${DEVICE}"/compile/overrides/. ./
RUN cd projects/"${DEVICE}" && \
python3 project.py clean && \
python3 project.py distclean && \
python3 project.py build && \
mv build/maixpy.bin build/firmware.bin
############
# build
# creation of kboot.kfpkg using firmware.bin
############
FROM build-firmware AS build
ARG DEVICE="maixpy_m5stickv"
WORKDIR /src/firmware/Kboot/build
RUN cp /src/firmware/MaixPy/projects/"${DEVICE}"/build/firmware.bin .
# replace possible windows line endings
RUN sed -i -e 's/\r$//' *.sh
RUN ./CLEAN.sh && ./BUILD.sh