forked from cksystemsteaching/selfie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
212 lines (173 loc) · 6.08 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#############################
# Selfie Docker Image #
# selfie.cs.uni-salzburg.at #
#############################
###################################
# PK (Proxy kernel) builder image #
###################################
FROM ubuntu:latest AS pkbuilder
# specify work directory and RISC-V install directory
ENV TOP=/opt RISCV=/opt/riscv PATH=$PATH:/opt/riscv/bin
WORKDIR $TOP
# install tools to build pk
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
make git \
gcc-riscv64-linux-gnu libc-dev-riscv64-cross \
&& rm -rf /var/lib/apt/lists/*
# get sources from HEAD
RUN git clone https://github.com/riscv/riscv-pk
# set build flags compatible with Ubuntu's riscv64-* build flags,
# otherwise compilation fails with linker errors related to stack protection
# also, use multiple cores to speed up compilation
ENV CFLAGS="-fstack-protector -fstack-protector-explicit -U_FORTIFY_SOURCE" \
CPPFLAGS="-fstack-protector -fstack-protector-explicit -U_FORTIFY_SOURCE" \
MAKEFLAGS=-j4
# build proxy kernel
# note that at the end, we move the compiled binaries from riscv64-linux-gnu to riscv64-unknown-elf,
# because when running the proxy kernel with 'spike pk', it looks at that path by default
RUN mkdir -p $RISCV \
&& mkdir -p riscv-pk/build \
&& cd riscv-pk/build \
&& ../configure --prefix=$RISCV --host=riscv64-linux-gnu \
&& make \
&& make install \
&& mv $RISCV/riscv64-linux-gnu $RISCV/riscv64-unknown-elf
#######################################
# Spike (ISA simulator) builder image #
#######################################
FROM ubuntu:latest AS spikebuilder
# specify work directory and RISC-V install directory
ENV TOP=/opt RISCV=/opt/riscv PATH=$PATH:/opt/riscv/bin
WORKDIR $TOP
# install tools to build RISC-V spike
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
make git \
g++ device-tree-compiler \
&& rm -rf /var/lib/apt/lists/*
# get sources from HEAD
RUN git clone https://github.com/riscv/riscv-isa-sim.git
# use multiple cores to speed up compilation
ENV MAKEFLAGS=-j4
# build spike ISA simulator
RUN mkdir -p $RISCV \
&& mkdir -p riscv-isa-sim/build \
&& cd riscv-isa-sim/build \
&& ../configure --prefix=$RISCV \
&& make \
&& make install
######################
# QEMU builder image #
######################
FROM ubuntu:latest AS qemubuilder
# specify work directory and RISC-V install directory
ENV TOP=/opt RISCV=/opt/riscv PATH=$PATH:/opt/riscv/bin
WORKDIR $TOP
# install statically linked QEMU (so it's easier to move it to another image)
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
qemu-user-static qemu-system-misc \
&& rm -rf /var/lib/apt/lists/*
# copy QEMU RISC-V statically linked binary to common output folder
RUN mkdir -p $RISCV/bin \
&& cp /usr/bin/qemu-riscv64-static $RISCV/bin \
&& cp /usr/bin/qemu-system-riscv64 $RISCV/bin \
&& cp /usr/bin/qemu-riscv32-static $RISCV/bin \
&& cp /usr/bin/qemu-system-riscv32 $RISCV/bin
########################################
# Boolector (SMT solver) builder image #
########################################
FROM ubuntu:latest AS boolectorbuilder
# specify work directory and RISC-V install directory
ENV TOP=/opt RISCV=/opt/riscv PATH=$PATH:/opt/riscv/bin
WORKDIR $TOP
# Setting non-interactive mode
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
# install tools to build boolector
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
make git \
g++ \
curl cmake \
&& rm -rf /var/lib/apt/lists/*
# get sources from HEAD
RUN git clone https://github.com/Boolector/boolector
# use multiple cores to speed up compilation
ENV MAKEFLAGS=-j4
# build boolector and dependencies
RUN mkdir -p $RISCV \
&& cd boolector \
&& ./contrib/setup-lingeling.sh \
&& ./contrib/setup-btor2tools.sh \
&& ./configure.sh --prefix $RISCV \
&& cd build \
&& make \
&& make install
#########################
# OpenOCD builder image #
#########################
FROM ubuntu:latest AS openocdbuilder
ENV TOP=/opt RISCV=/opt/riscv PATH=$PATH:/opt/riscv/bin
WORKDIR $TOP
# install tools to build OpenOCD
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
make git \
gcc libtool libusb-dev \
automake pkg-config \
&& rm -rf /var/lib/apt/lists/*
RUN git clone https://github.com/riscv/riscv-openocd.git
# use multiple cores to speed up compilation
ENV MAKEFLAGS=-j4
RUN mkdir -p $RISCV \
&& cd riscv-openocd \
&& ./bootstrap \
&& ./configure \
--prefix=$RISCV \
--program-prefix=riscv64- \
&& make \
&& make install
##################################
# Selfie interactive final image #
##################################
FROM ubuntu:latest AS selfiebuilder
# specify work directory and RISC-V install directory
ENV TOP=/opt RISCV=/opt/riscv PATH=$PATH:/opt/riscv/bin
WORKDIR $TOP
# Setting non-interactive mode
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
# install tools for selfie
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
make git \
gcc gdb libc6-dev-i386-amd64-cross lib32gcc-9-dev \
python3.8 \
device-tree-compiler gcc-riscv64-linux-gnu \
&& update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 \
&& apt-get install -y --no-install-recommends \
binutils-riscv64-linux-gnu libc-dev-riscv64-cross \
libusb-dev libhidapi-dev \
xxd gettext curl \
&& rm -rf /var/lib/apt/lists/*
# copy spike, pk, qemu and boolector from builder images
COPY --from=pkbuilder $RISCV/ $RISCV/
COPY --from=spikebuilder $RISCV/ $RISCV/
COPY --from=qemubuilder $RISCV/ $RISCV/
COPY --from=boolectorbuilder $RISCV/ $RISCV/
COPY --from=openocdbuilder $RISCV/ $RISCV/
# add selfie sources to the image
COPY . /opt/selfie/
# specify user work directory
WORKDIR /opt/selfie
# build selfie
RUN make selfie
# build machine files
RUN make --directory machine/
# default command
CMD /bin/bash