From 8412273caf84665cdbf742a6944dbfdd34fef479 Mon Sep 17 00:00:00 2001 From: Henk Wiedig Date: Fri, 22 Nov 2024 21:22:31 +0100 Subject: [PATCH] xbuild rockchip --- .github/workflows/build.yml | 4 +++ .gitignore | 5 +++- Dockerfile_xcompile | 32 -------------------- Makefile | 6 ++-- build.sh | 21 +++++--------- build_rockchip.sh | 58 +++++++++++++++++++++++++++++++++++++ msposd.c | 1 - 7 files changed, 76 insertions(+), 51 deletions(-) delete mode 100644 Dockerfile_xcompile create mode 100755 build_rockchip.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 548f6b1..8309ce6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,6 +26,7 @@ jobs: ./build.sh star6b0 ./build.sh star6e ./build.sh x86 + ./build.sh rockchip - name: Upload binary uses: actions/upload-artifact@v4 @@ -36,6 +37,7 @@ jobs: msposd_star6b0 msposd_star6e msposd_x86 + msposd_rockchip - name: Versioned release if: startsWith(github.ref, 'refs/tags/') @@ -47,6 +49,7 @@ jobs: msposd_star6b0 msposd_star6e msposd_x86 + msposd_rockchip - name: Upload latest if: github.ref == 'refs/heads/main' && github.event_name == 'push' @@ -59,3 +62,4 @@ jobs: msposd_star6b0 msposd_star6e msposd_x86 + msposd_rockchip diff --git a/.gitignore b/.gitignore index 2eb068e..27c3ef6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,11 @@ toolchain/ majestic.yaml /msposd firmware/ +aarch64/ +disk.raw msposd_goke msposd_hisi msposd_star6b0 msposd_star6e -msposd_x86 \ No newline at end of file +msposd_x86 +msposd_rockchip diff --git a/Dockerfile_xcompile b/Dockerfile_xcompile deleted file mode 100644 index 3436a64..0000000 --- a/Dockerfile_xcompile +++ /dev/null @@ -1,32 +0,0 @@ -# On host run: -# -# $ sudo apt-get install -y qemu-user-static -# $ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes -# $ docker build --platform linux/arm64 -f Dockerfile_xcompile -t build-msposd . -# $ docker run --platform linux/arm64 --rm -it -v $(pwd):/home/build build-msposd -FROM arm64v8/debian:bullseye - -RUN apt-get update && apt-get install -y curl wget - -# install radxa APT repo, see https://radxa-repo.github.io/bullseye/ -RUN keyring="/tmp/keyring.deb" && \ - version="$(curl -L https://github.com/radxa-pkg/radxa-archive-keyring/releases/latest/download/VERSION)" && \ - echo $version && \ - curl -L --output "$keyring" "https://github.com/radxa-pkg/radxa-archive-keyring/releases/download/${version}/radxa-archive-keyring_${version}_all.deb" && \ - dpkg -i "$keyring" && \ - echo "deb [signed-by=/usr/share/keyrings/radxa-archive-keyring.gpg] https://radxa-repo.github.io/bullseye/ bullseye main" > /etc/apt/sources.list.d/70-radxa.list && \ - echo "deb [signed-by=/usr/share/keyrings/radxa-archive-keyring.gpg] https://radxa-repo.github.io/bullseye rockchip-bullseye main" > /etc/apt/sources.list.d/80-rockchip.list && \ - apt-get update && \ - apt-get install -y cmake g++ git pkg-config librockchip-mpp-dev libcairo-dev libdrm-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libspdlog-dev nlohmann-json3-dev && \ - apt clean - -RUN apt-get update && apt-get install -y \ - cmake g++ git pkg-config \ - librockchip-mpp-dev libcairo-dev libdrm-dev \ - libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \ - libspdlog-dev nlohmann-json3-dev libevent-dev && \ - apt-get clean - -WORKDIR /home/build - -CMD ./build.sh rockchip \ No newline at end of file diff --git a/Makefile b/Makefile index 2ee7d3b..fc4a429 100644 --- a/Makefile +++ b/Makefile @@ -60,9 +60,9 @@ x86: version.h $(eval BUILD = $(CC) $(SRCS) -I $(SDK)/include -L $(DRV) $(CFLAGS) $(LIB) -levent_core -O0 -g -o $(OUTPUT)) $(BUILD) -rockchip: +rockchip: version.h $(eval SDK = ./sdk/gk7205v300) $(eval CFLAGS += -D__ROCKCHIP__) - $(eval LIB = -levent_core -lcairo -lrt -lm) + $(eval LIB = `pkg-config --libs cairo x11` -lm -lrt) $(eval BUILD = $(CC) $(SRCS) -I $(SDK)/include -L $(DRV) $(CFLAGS) $(LIB) -levent_core -O0 -g -o $(OUTPUT)) - $(BUILD) \ No newline at end of file + $(BUILD) diff --git a/build.sh b/build.sh index b0cca43..78b0fb4 100755 --- a/build.sh +++ b/build.sh @@ -1,8 +1,5 @@ #!/bin/bash DL="https://github.com/openipc/firmware/releases/download/latest" -SUFFIX=tgz -TAR="tar -xf" -ARCH=arm-linux if [[ "$1" == *"star6b0" ]]; then CC=cortex_a7_thumb2_hf-gcc13-musl-4_9 @@ -14,16 +11,15 @@ elif [[ "$1" == *"hisi" ]]; then CC=cortex_a7_thumb2-gcc13-musl-4_9 fi -GCC=$PWD/toolchain/$CC/bin/$ARCH-gcc +GCC=$PWD/toolchain/$CC/bin/arm-linux-gcc OUT=msposd_$1 -if [[ "$1" != *"jetson"* && "$1" != *"x86"* ]]; then -fi +if [[ "$1" != *"jetson"* && "$1" != *"x86"* && "$1" != *"rockhip"* ]]; then if [ ! -e toolchain/$CC ]; then - wget -c -q --show-progress $DL/$CC.$SUFFIX -P $PWD + wget -c -q --show-progress $DL/$CC.tgz -P $PWD mkdir -p toolchain/$CC - $TAR $CC.$SUFFIX -C toolchain/$CC --strip-components=1 || exit 1 - rm -f $CC.$SUFFIX + tar -xf $CC.tgz -C toolchain/$CC --strip-components=1 || exit 1 + rm -f $CC.tgz fi fi @@ -50,11 +46,8 @@ elif [ "$1" = "x86" ]; then DRV=$PWD make DRV=$DRV OUTPUT=$OUT $1 elif [ "$1" = "rockchip" ]; then - GCC=gcc - DRV=$PWD - make CC=$GCC DRV=$DRV TOOLCHAIN=$PWD/toolchain/$CC OUTPUT=$OUT $1 - + ./build_rockchip.sh $1 else echo "Usage: $0 [goke|hisi|star6b0|star6e|jetson|x86|rockchip]" exit 1 -fi +fi \ No newline at end of file diff --git a/build_rockchip.sh b/build_rockchip.sh new file mode 100755 index 0000000..bd013f0 --- /dev/null +++ b/build_rockchip.sh @@ -0,0 +1,58 @@ +#!/bin/sh +output=aarch64 + +# We run arm binary's under x86, crazy, right ;) +which qemu-arm-static 2>/dev/null > /dev/null || sudo apt-get install -y qemu-user-static + +# download and unpack debian arm image +host=https://cloud.debian.org/images/cloud/bullseye +release=latest +system=debian-11-generic-arm64.tar +if [ ! -f disk.raw ]; then + wget -nv ${host}/${release}/${system}.xz + tar -xf ${system}.xz + rm ${system}.xz +fi + +# loop mount the image +if [ ! -d output/tmp ]; then + mkdir -p $output + device=$(sudo losetup -P --show -f disk.raw) + sudo mount ${device}p1 $output + sudo mkdir -p $output/usr/src/msposd + sudo mount -o bind $(pwd) $output/usr/src/msposd +fi + +if [ ! -f $output/tmp/prepare_chroot.done ]; then + cat > prepare_chroot.sh << EOL + #!/bin/bash + cd /home + # install radxa APT repo, see https://radxa-repo.github.io/bullseye/ + keyring="/home/keyring.deb" + version="\$(curl -L https://github.com/radxa-pkg/radxa-archive-keyring/releases/latest/download/VERSION)" + curl -L --output "\$keyring" "https://github.com/radxa-pkg/radxa-archive-keyring/releases/download/\${version}/radxa-archive-keyring_\${version}_all.deb" + dpkg -i \$keyring + echo 'deb [signed-by=/usr/share/keyrings/radxa-archive-keyring.gpg] https://radxa-repo.github.io/bullseye/ bullseye main' > /etc/apt/sources.list.d/70-radxa.list + echo 'deb [signed-by=/usr/share/keyrings/radxa-archive-keyring.gpg] https://radxa-repo.github.io/bullseye rockchip-bullseye main' > /etc/apt/sources.list.d/80-rockchip.list + + apt-get update + apt-get install -y git gcc make pkg-config libspdlog-dev libevent-dev libcairo-dev + apt clean + touch /tmp/prepare_chroot.done +EOL + chmod +x prepare_chroot.sh + sudo cp prepare_chroot.sh $output/home + sudo rm $output/etc/resolv.conf + echo nameserver 1.1.1.1 | sudo tee $output/etc/resolv.conf + sudo chroot $output /home/prepare_chroot.sh + rm prepare_chroot.sh +fi + +if [ "$(uname -m)" = "x86_64" ]; then + sudo chroot aarch64 make OUTPUT=msposd_$1 $1 -C /usr/src/msposd +else + make OUTPUT=$OUT $1 +fi +sudo umount $output/usr/src/msposd +sudo umount $output +sudo losetup -d ${device} diff --git a/msposd.c b/msposd.c index 77ac98b..61199c8 100644 --- a/msposd.c +++ b/msposd.c @@ -1204,7 +1204,6 @@ int main(int argc, char **argv) int r; int long_index = 0; int rc_channel_no = 0; - int r; while ((opt = getopt_long_only(argc, argv, "", long_options, &long_index)) != -1) { switch (opt) {