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

Update QEMU, add llvm-test-suite, add init program to rootfs #32

Merged
merged 10 commits into from
Oct 8, 2024
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ RUN apt update && \
bc \
ninja-build \
cpio \
python3-psutil \
unzip

RUN cat /etc/apt/sources.list | sed "s/^deb\ /deb-src /" >> /etc/apt/sources.list
Expand All @@ -54,7 +55,11 @@ RUN apt update && \
apt build-dep -yy --arch-only qemu clang python3

# From env.sh
ARG QEMU_REPO QEMU_REF ARTIFACT_BASE ARTIFACT_TAG
ARG QEMU_REPO
ARG QEMU_REF=hexagon-sysemu-04-oct-2024

ARG ARTIFACT_BASE
ARG ARTIFACT_TAG

ENV VER 19.1.0
ENV TOOLCHAIN_INSTALL /usr/local/clang+llvm-${VER}-cross-hexagon-unknown-linux-musl/
Expand All @@ -65,6 +70,7 @@ ENV MAKE_TARBALLS 1
#ENV CMAKE_URL https://github.com/Kitware/CMake/releases/download/v3.16.6/cmake-3.16.6-Linux-x86_64.tar.gz

ENV LLVM_SRC_URL https://github.com/llvm/llvm-project/archive/llvmorg-${VER}.tar.gz
ENV LLVM_TESTS_SRC_URL https://github.com/llvm/llvm-test-suite/archive/llvmorg-${VER}.tar.gz
ENV MUSL_SRC_URL https://github.com/quic/musl/archive/d125203fcb134febcde6ca32181554560b67c790.tar.gz
ENV HEXMVM_SRC_URL https://github.com/quic/hexagonMVM/archive/v0.1.1.tar.gz
ENV LINUX_SRC_URL https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.7.11.tar.xz
Expand All @@ -78,6 +84,8 @@ ADD get-src-tarballs.sh /root/hexagon-toolchain/get-src-tarballs.sh
ADD *.cmake /root/hexagon-toolchain/
RUN cd /root/hexagon-toolchain && ./get-src-tarballs.sh ${PWD} ${TOOLCHAIN_INSTALL}/manifest

ADD test_init/test_init.c test_init/Makefile /root/hexagon-toolchain/test_init/

ENV IN_CONTAINER 1
ADD build-toolchain.sh /root/hexagon-toolchain/build-toolchain.sh
RUN cd /root/hexagon-toolchain && ./build-toolchain.sh ${ARTIFACT_TAG}
Expand Down
4 changes: 2 additions & 2 deletions build-in-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fi
DOCKER_BUILD_ARGS="
--build-arg ARTIFACT_BASE=/usr/local/hexagon-artifacts
--build-arg QEMU_REPO=https://github.com/quic/qemu
--build-arg QEMU_REF=hexagon-sysemu-12-dec-2023
--build-arg QEMU_REF=hexagon-sysemu-04-oct-2024
--build-arg ARTIFACT_TAG=${ARTIFACT_TAG}"

#build
Expand All @@ -26,7 +26,7 @@ docker images

#extract artifacts
for name in hexagon hexagon-win; do
docker rm -f tmp_container
docker rm -f tmp_container || /bin/true
docker create --name tmp_container $name:latest
docker cp tmp_container:/usr/local/hexagon-artifacts ./hexagon-artifacts
docker rm tmp_container
Expand Down
26 changes: 24 additions & 2 deletions build-rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ build_minivm() {
install
}

build_init() {
cd ${BASE}
mkdir -p obj_init
cd obj_init
make -C ../test_init install \
DESTDIR=${ROOTFS} \
CC=hexagon-unknown-linux-musl-clang \
LD=hexagon-unknown-linux-musl-clang \

}

build_initramfs() {
# ../scripts/gen_initramfs_list.sh ${ROOTFS} | \
# cpio --create --format newc > initramfs_data.cpio
cd ${ROOTFS}
find . | cpio --create --format newc > ${BASE}/linux/usr/initramfs_data.cpio
}

build_kernel() {
cd ${BASE}
mkdir -p obj_linux
Expand Down Expand Up @@ -188,8 +206,8 @@ cp -ra ${HEX_SYSROOT}/usr ${ROOTFS}/
get_src_tarballs

build_minivm
build_kernel
build_busybox
build_init

#build_dropbear
#build_cpython
Expand All @@ -203,10 +221,14 @@ mount -t proc none /proc
mount -t sysfs none /sys
mount -t debugfs none /sys/kernel/debug

exec /bin/sh
exec /bin/test_init
EOF
chmod +x ${ROOTFS}/init

build_initramfs
build_kernel


if [[ ${MAKE_TARBALLS-0} -eq 1 ]]; then
tar c -C $(dirname ${ROOT_INSTALL_REL}) $(basename ${ROOT_INSTALL_REL}) | xz -e9T0 > ${RESULTS_DIR}/hexagon_rootfs_${STAMP}.tar.xz
# XZ_OPT="-8 --threads=0" tar c ${RESULTS_DIR}/hexagon_rootfs_${STAMP}.tar.xz -C $(dirname ${ROOT_INSTALL_REL}) $(basename ${ROOT_INSTALL_REL})
Expand Down
1 change: 1 addition & 0 deletions build-toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ build_libs() {
-DCMAKE_CXX_COMPILER_FORCED:BOOL=ON \
-C ./hexagon-linux-cross.cmake \
-C ./hexagon-linux-runtimes.cmake \
-C ./hexagon-linux-clangrt.cmake \
-B ./obj_libs \
-S ./llvm-project/runtimes

Expand Down
7 changes: 5 additions & 2 deletions cross-win/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN for url in https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-glib2-2.74.
https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-pixman-0.42.2-1-any.pkg.tar.zst \
https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-libpng-1.6.40-1-any.pkg.tar.zst \
https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-gettext-0.21.1-2-any.pkg.tar.zst \
https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-pcre2-10.41-1-any.pkg.tar.zst \
https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-pcre2-10.44-1-any.pkg.tar.zst \
https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-libiconv-1.17-3-any.pkg.tar.zst; do \
wget $url && tar xvf $(basename $url) || exit 1; \
done && \
Expand All @@ -35,7 +35,10 @@ RUN winecfg || true
COPY cross-win/wine/* /root/.wine/

# From env.sh
ARG QEMU_REPO QEMU_REF ARTIFACT_BASE ARTIFACT_TAG
ARG QEMU_REPO
ARG QEMU_REF
ARG ARTIFACT_BASE
ARG ARTIFACT_TAG

ARG QEMU_INSTALL_DIR=qemu-hexagon-x86_64-win
ARG QEMU_CLONE_DIR=/root/qemu
Expand Down
8 changes: 8 additions & 0 deletions get-src-tarballs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ get_src_tarballs() {
echo ${LLVM_SRC_URL} > ${MANIFEST_DIR}/llvm-project.txt
cd -

wget --quiet ${LLVM_TESTS_SRC_URL} -O llvm-test-suite.tar.xz
mkdir llvm-test-suite
cd llvm-test-suite
tar xf ../llvm-test-suite.tar.xz --strip-components=1
rm ../llvm-test-suite.tar.xz
echo ${LLVM_TESTS_SRC_URL} > ${MANIFEST_DIR}/llvm-test-suite.txt
cd -

git clone --branch ${QEMU_REF} ${QEMU_REPO}
cd qemu
git remote -v > ${MANIFEST_DIR}/qemu.txt
Expand Down
3 changes: 2 additions & 1 deletion hexagon-linux-builtins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ set(CMAKE_ASM_FLAGS "-G0 -mlong-calls -fno-pic" CACHE STRING "")

set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR OFF CACHE BOOL "")
set(LLVM_TARGET_TRIPLE hexagon-unknown-linux-musl CACHE STRING "")
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE hexagon-unknown-linux-musl CACHE STRING "")

set(COMPILER_RT_DEFAULT_ARCH hexagon CACHE STRING "")
set(COMPILER_RT_BUILD_BUILTINS ON CACHE BOOL "")
set(COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
Expand Down
14 changes: 14 additions & 0 deletions hexagon-linux-clangrt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR OFF CACHE BOOL "")
set(LLVM_DEFAULT_TARGET_TRIPLE hexagon-unknown-linux-musl CACHE STRING "")

set(COMPILER_RT_USE_LLVM_UNWINDER ON CACHE BOOL "")

# Some build failures here, including the inline asm in
# `compiler-rt/lib/sanitizer_common/sanitizer_redefine_builtins.h`, so
# we can just disable these for now:
set(COMPILER_RT_BUILD_BUILTINS OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_MEMPROF OFF CACHE BOOL "")

10 changes: 0 additions & 10 deletions hexagon-linux-runtimes.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

set(LLVM_DEFAULT_TARGET_TRIPLE hexagon-unknown-linux-musl CACHE STRING "")
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR OFF CACHE BOOL "")
androm3da marked this conversation as resolved.
Show resolved Hide resolved
set(LLVM_ENABLE_RUNTIMES libcxx;libcxxabi;libunwind;compiler-rt CACHE STRING "")
set(LIBCXX_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
Expand All @@ -9,17 +8,8 @@ set(LIBCXXABI_INCLUDE_TESTS OFF CACHE BOOL "")
set(LIBUNWIND_INCLUDE_TESTS OFF CACHE BOOL "")
set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
set(COMPILER_RT_USE_LLVM_UNWINDER ON CACHE BOOL "")
set(LIBCXXABI_ENABLE_SHARED ON CACHE BOOL "")

set(COMPILER_RT_BUILD_BUILTINS OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_MEMPROF OFF CACHE BOOL "")

set(LIBCXX_HAS_ATOMIC_LIB OFF CACHE BOOL "")
set(LIBCXXABI_HAS_ATOMIC_LIB OFF CACHE BOOL "")
set(LIBUNWIND_HAS_ATOMIC_LIB OFF CACHE BOOL "")
androm3da marked this conversation as resolved.
Show resolved Hide resolved
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
12 changes: 12 additions & 0 deletions test_init/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

.PHONY: install all

CFLAGS=-mcpu=hexagonv68
LDFLAGS=-static -mcpu=hexagonv68

all: test_init

test_init: test_init.o

install: test_init
install -D $^ $(DESTDIR)/bin/$^
20 changes: 20 additions & 0 deletions test_init/test_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <linux/reboot.h>
#include <sys/syscall.h>
#include <sys/reboot.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdbool.h>

int main() {
/* For now, let's immediately shutdown. */
int ret = reboot(LINUX_REBOOT_CMD_HALT);
if (!ret) {
perror("reboot");
}

/* Since we're an init process, we should stay
* running.
*/
while (true) { /* spin */ }
}
Loading