Switch to EFI boot and use official release for QEMU and GDB

This commit is contained in:
Zhang Junyang
2023-10-08 17:38:24 +08:00
committed by Tate, Hongliang Tian
parent aea8f38dc1
commit cdc2b960dc
26 changed files with 433 additions and 315 deletions

View File

@ -1,25 +1,34 @@
FROM ubuntu:22.04 as ubuntu-22.04-with-bazel
FROM ubuntu:22.04 as build-base
SHELL ["/bin/bash", "-c"]
ARG DEBIAN_FRONTEND=noninteractive
# Install all Bazel dependent packages
RUN apt update && apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
curl \
git-core \
gnupg \
libssl-dev \
python-is-python3 \
python3-pip
python3-pip \
wget \
gnupg
#= Build syscall test =========================================================
FROM build-base as build-bazel
# Install bazel, which is required by the system call test suite from Gvisor project
COPY regression/syscall_test/install_bazel.sh /tmp/
WORKDIR /tmp
RUN ./install_bazel.sh && rm -f /tmp/install_bazel.sh
WORKDIR /root/bazel
RUN curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
RUN mv bazel.gpg /etc/apt/trusted.gpg.d
RUN echo 'deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8' | tee /etc/apt/sources.list.d/bazel.list
RUN apt update && apt install bazel=5.4.0 -y
RUN apt clean && rm -rf /var/lib/apt/lists/*
WORKDIR /root
RUN rm -rf bazel
FROM ubuntu-22.04-with-bazel as syscall_test
FROM build-bazel as syscall_test
# Build the syscall test binaries
COPY regression/syscall_test /root/syscall_test
@ -27,38 +36,110 @@ WORKDIR /root/syscall_test
RUN export BUILD_DIR=build && \
make ${BUILD_DIR}/syscall_test_bins
FROM ubuntu-22.04-with-bazel
#= Build QEMU =================================================================
FROM build-base as build-qemu
# Install all Jinux dependent packages
RUN apt update && apt-get install -y --no-install-recommends \
cpio \
cpuid \
file \
g++ \
gdb \
grub-common \
grub-pc \
grub-pc-dbg \
libssl-dev \
net-tools \
openssh-server \
pkg-config \
qemu-system-x86 \
strace \
sudo \
unzip \
vim \
wget \
xorriso \
zip
libgcrypt-dev `# optional build dependency` \
libglib2.0-dev `# build dependency` \
libpixman-1-dev `# build dependency` \
libusb-dev `# optional build dependency` \
meson \
ninja-build
RUN apt clean && rm -rf /var/lib/apt/lists/*
# Clean apt cache
RUN apt clean \
&& rm -rf /var/lib/apt/lists/*
FROM build-qemu as qemu
# Prepare the system call test suite
COPY --from=syscall_test /root/syscall_test/build/syscall_test_bins /root/syscall_test_bins
ENV JINUX_PREBUILT_SYSCALL_TEST=/root/syscall_test_bins
# Fetch and install QEMU from https://download.qemu.org/qemu-8.1.1.tar.xz
#
# The QEMU version in the Ubuntu 22.04 repository is 6.*, which has a bug to cause OVMF debug to fail.
# The libslirp dependency is for QEMU's network backend.
WORKDIR /root
RUN wget -O qemu.tar.xz https://download.qemu.org/qemu-8.1.1.tar.xz \
&& mkdir /root/qemu \
&& tar xf qemu.tar.xz --strip-components=1 -C /root/qemu \
&& rm qemu.tar.xz
WORKDIR /root/qemu
RUN ./configure --target-list=x86_64-softmmu --prefix=/usr/local/qemu --enable-slirp \
&& make -j \
&& make install
WORKDIR /root
RUN rm -rf /root/qemu
#= Build OVMF =================================================================
FROM build-base as build-ovmf
RUN apt update && apt-get install -y --no-install-recommends \
bison \
flex \
iasl \
nasm \
uuid-dev
RUN apt clean && rm -rf /var/lib/apt/lists/*
FROM build-ovmf as ovmf
# Fetch and build OVMF from the EDK2 official source
WORKDIR /root
RUN git clone --depth 1 --branch edk2-stable202308 --recurse-submodules --shallow-submodules https://github.com/tianocore/edk2.git
WORKDIR /root/edk2
RUN source ./edksetup.sh \
&& make -C BaseTools \
&& build -a X64 -t GCC5 -b DEBUG -p OvmfPkg/OvmfPkgX64.dsc -D DEBUG_ON_SERIAL_PORT \
&& build -a X64 -t GCC5 -b RELEASE -p OvmfPkg/OvmfPkgX64.dsc
#= Build GRUB =================================================================
FROM build-base as build-grub
RUN apt update && apt-get install -y --no-install-recommends \
bison \
flex
RUN apt clean && rm -rf /var/lib/apt/lists/*
FROM build-grub as grub
# Fetch and install GRUB from the GNU official source
#
# We have installed grub-efi-amd64-bin just for the unicode.pf2 file, which is not included
# in the GRUB release. The Ubuntu release notoriously modifies the GRUB source code and enforce
# EFI handover boot, which is deprecated. So we have to build GRUB from source.
WORKDIR /root
RUN wget -O grub.tar.xz https://ftp.gnu.org/gnu/grub/grub-2.06.tar.xz \
&& mkdir /root/grub \
&& tar xf grub.tar.xz --strip-components=1 -C /root/grub \
&& rm grub.tar.xz
WORKDIR /root/grub
RUN ./configure --target=x86_64 --with-platform=efi --prefix=/usr/local/grub \
&& make -j \
&& make install
WORKDIR /root
RUN rm -rf /root/grub
#= Build busybox ==============================================================
FROM build-base as build-busybox
RUN apt clean && rm -rf /var/lib/apt/lists/*
FROM build-busybox as busybox
WORKDIR /root
RUN wget -O busybox.tar.bz2 https://busybox.net/downloads/busybox-1.35.0.tar.bz2 \
&& mkdir /root/busybox \
&& tar xf busybox.tar.bz2 --strip-components=1 -C /root/busybox \
&& rm busybox.tar.bz2
WORKDIR /root/busybox
RUN make defconfig \
&& sed -i "s/# CONFIG_STATIC is not set/CONFIG_STATIC=y/g" .config \
&& sed -i "s/# CONFIG_FEATURE_SH_STANDALONE is not set/CONFIG_FEATURE_SH_STANDALONE=y/g" .config \
&& make -j
#= The final stages to produce the Jinux development image ====================
FROM build-base as rust
# Install Rust
ENV PATH="/root/.cargo/bin:${PATH}"
@ -70,24 +151,59 @@ RUN curl https://sh.rustup.rs -sSf | \
&& rustup component add rust-src rustc-dev llvm-tools-preview
# Install cargo tools
RUN cargo install mdbook \
&& cargo install cargo-binutils
RUN cargo install \
cargo-binutils \
mdbook
FROM rust
# Install all Jinux dependent packages
RUN apt update && apt-get install -y --no-install-recommends \
cpio \
cpuid \
file \
gdb \
grub-efi-amd64-bin \
libpixman-1-dev `# running dependency for QEMU` \
mtools `# used by grub-mkrescue` \
net-tools \
openssh-server \
ovmf `# provide an alternative stable firmware`\
pkg-config \
strace \
sudo \
unzip \
vim \
xorriso \
zip
# Clean apt cache
RUN apt clean && rm -rf /var/lib/apt/lists/*
# Prepare the system call test suite
COPY --from=syscall_test /root/syscall_test/build/syscall_test_bins /root/syscall_test_bins
ENV JINUX_PREBUILT_SYSCALL_TEST=/root/syscall_test_bins
# Install QEMU built from the previous stages
COPY --from=qemu /usr/local/qemu /usr/local/qemu
ENV PATH="/usr/local/qemu/bin:${PATH}"
ENV LD_LIBRARY_PATH="/usr/local/qemu/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}"
# Install OVMF built from the previous stages
COPY --from=ovmf /root/edk2/Build/OvmfX64/DEBUG_GCC5/FV/ /root/ovmf/debug
COPY --from=ovmf /root/edk2/Build/OvmfX64/RELEASE_GCC5/FV/ /root/ovmf/release
# Install GRUB built from the previous stages
COPY --from=grub /usr/local/grub /usr/local/grub
ENV PATH="/usr/local/grub/bin:${PATH}"
# Make a symbolic link for `unicode.pf2` from Ubuntu 22.04 package
RUN ln -sf /usr/share/grub/unicode.pf2 /usr/local/grub/share/grub/unicode.pf2
# Install Busybox built from the previous stages
COPY --from=busybox /root/busybox/busybox /bin/busybox
# Add the path of jinux tools
ENV PATH="/root/jinux/target/bin:${PATH}"
# Build busybox
RUN curl --output busybox.tar.bz2 https://busybox.net/downloads/busybox-1.35.0.tar.bz2 \
&& mkdir /root/busybox \
&& tar xf busybox.tar.bz2 --strip-components=1 -C /root/busybox \
&& rm busybox.tar.bz2
WORKDIR /root/busybox
RUN make defconfig \
&& sed -i "s/# CONFIG_STATIC is not set/CONFIG_STATIC=y/g" .config \
&& sed -i "s/# CONFIG_FEATURE_SH_STANDALONE is not set/CONFIG_FEATURE_SH_STANDALONE=y/g" .config \
&& make -j \
&& cp /root/busybox/busybox /bin/busybox
VOLUME [ "/root/jinux" ]
WORKDIR /root/jinux