Skip to content

Instantly share code, notes, and snippets.

@mnml
Last active September 21, 2024 15:38
Show Gist options
  • Save mnml/12f75bbf16eac4def15ba72cf1b11926 to your computer and use it in GitHub Desktop.
Save mnml/12f75bbf16eac4def15ba72cf1b11926 to your computer and use it in GitHub Desktop.
Building m8c for RG35XX Plus/H/SP on KNULLI (Scroll down for zip)
#!/bin/bash
#
# build kernel modules
#
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.9.170.tar.gz
tar xzf linux-4.9.170.tar.gz
cd linux-4.9.170
wget -O .config https://raw.githubusercontent.com/knulli-cfw/distribution/refs/heads/knulli-main/board/batocera/allwinner/h700/linux-sunxi64-legacy.config
sed -i 's/# CONFIG_SND_USB_AUDIO is not set/CONFIG_SND_USB_AUDIO=m/g' .config
sed -i 's/# CONFIG_USB_ACM is not set/CONFIG_USB_ACM=m/g' .config
sed -i 's/^YYLTYPE yylloc;$/extern YYLTYPE yylloc;/g' scripts/dtc/dtc-lexer.lex.c_shipped
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- olddefconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- modules_prepare
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- M=drivers/usb/class
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- M=sound/core
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- M=sound/usb
cd ..
#
# setup toolchain
#
wget https://github.com/knulli-cfw/toolchains/releases/download/rg35xx-plush-sdk-20240421/aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz
tar xzf aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz
aarch64-buildroot-linux-gnu_sdk-buildroot/relocate-sdk.sh
#
# build m8c
#
export XTOOL=$(realpath aarch64-buildroot-linux-gnu_sdk-buildroot)
export XHOST=aarch64-buildroot-linux-gnu
export PATH=$PATH:$XTOOL/bin
export SYSROOT=$XTOOL/$XHOST/sysroot
export PKG_CONFIG_PATH=$SYSROOT/usr/lib/pkgconfig
export PKG_CONFIG_SYSROOT_DIR=$SYSROOT
git clone https://github.com/laamaa/m8c
cd m8c
git pull
make CC=$XHOST-gcc
cd ..
#
# collect files
#
mkdir -p build/m8c
cp linux-4.9.170/drivers/usb/class/cdc-acm.ko build/m8c
cp linux-4.9.170/sound/core/snd-hwdep.ko build/m8c
cp linux-4.9.170/sound/usb/snd-usbmidi-lib.ko build/m8c
cp linux-4.9.170/sound/usb/snd-usb-audio.ko build/m8c
cp m8c/m8c build/m8c
cat << 'EOF' > build/m8c.sh
#!/bin/sh
export HOME=$(dirname $(realpath $0))/m8c
cd $HOME
cp *.ko /lib/modules/4.9.170
depmod
modprobe -a cdc-acm snd-hwdep snd-usbmidi-lib snd-usb-audio
pw-loopback -C alsa_input.usb-DirtyWave_M8_14900360-02.analog-stereo -P alsa_output._sys_devices_platform_soc_soc_03000000_codec_mach_sound_card0.stereo-fallback &
SDL_GAMECONTROLLERCONFIG="19000000010000000100000000010000,Deeplay-keys,a:b3,b:b4,x:b6,y:b5,leftshoulder:b7,rightshoulder:b8,lefttrigger:b13,righttrigger:b14,guide:b11,start:b10,back:b9,dpup:h0.1,dpleft:h0.8,dpright:h0.2,dpdown:h0.4,volumedown:b1,volumeup:b2,leftx:a0,lefty:a1,leftstick:b12,rightx:a2,righty:a3,rightstick:b15,platform:Linux," ./m8c
kill $(jobs -p)
EOF
This file has been truncated, but you can view the full file.
@DRCRecoveryData
Copy link

DRCRecoveryData commented Sep 21, 2024

Fixed m8c not start on RG40XX H by grant access via chmod +x ./m8c

#!/bin/bash

#
# build kernel modules
#
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.9.170.tar.gz
tar xzf linux-4.9.170.tar.gz
cd linux-4.9.170

wget -O .config https://raw.githubusercontent.com/knulli-cfw/distribution/knulli-main/board/batocera/allwinner/h700/rg35xx-plus/linux-sunxi64-legacy.config
sed -i 's/# CONFIG_SND_USB_AUDIO is not set/CONFIG_SND_USB_AUDIO=m/g' .config
sed -i 's/# CONFIG_USB_ACM is not set/CONFIG_USB_ACM=m/g' .config

sed -i 's/^YYLTYPE yylloc;$/extern YYLTYPE yylloc;/g' scripts/dtc/dtc-lexer.lex.c_shipped
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- olddefconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- modules_prepare

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- M=drivers/usb/class
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- M=sound/core
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- M=sound/usb

cd ..

#
# setup toolchain
#
wget https://github.com/knulli-cfw/toolchains/releases/download/rg35xx-plush-sdk-20240421/aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz
tar xzf aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz
aarch64-buildroot-linux-gnu_sdk-buildroot/relocate-sdk.sh

#
# build m8c
#
export XTOOL=$(realpath aarch64-buildroot-linux-gnu_sdk-buildroot)
export XHOST=aarch64-buildroot-linux-gnu
export PATH=$PATH:$XTOOL/bin
export SYSROOT=$XTOOL/$XHOST/sysroot
export PKG_CONFIG_PATH=$SYSROOT/usr/lib/pkgconfig
export PKG_CONFIG_SYSROOT_DIR=$SYSROOT

git clone https://github.com/laamaa/m8c
cd m8c
git pull
make CC=$XHOST-gcc

cd ..

#
# collect files
#
mkdir -p build/m8c

cp linux-4.9.170/drivers/usb/class/cdc-acm.ko build/m8c
cp linux-4.9.170/sound/core/snd-hwdep.ko build/m8c
cp linux-4.9.170/sound/usb/snd-usbmidi-lib.ko build/m8c
cp linux-4.9.170/sound/usb/snd-usb-audio.ko build/m8c

cp m8c/m8c build/m8c

cat << 'EOF' > build/m8c.sh
#!/bin/sh

export HOME=$(dirname $(realpath $0))/m8c
cd $HOME

chmod +x ./m8c

cp *.ko /lib/modules/4.9.170
depmod
modprobe -a cdc-acm snd-hwdep snd-usbmidi-lib snd-usb-audio

pw-loopback -C alsa_input.usb-DirtyWave_M8_14900360-02.analog-stereo -P alsa_output._sys_devices_platform_soc_soc_03000000_codec_mach_sound_card0.stereo-fallback &

SDL_GAMECONTROLLERCONFIG="19000000010000000100000000010000,Deeplay-keys,a:b3,b:b4,x:b6,y:b5,leftshoulder:b7,rightshoulder:b8,lefttrigger:b13,righttrigger:b14,guide:b11,start:b10,back:b9,dpup:h0.1,dpleft:h0.8,dpright:h0.2,dpdown:h0.4,volumedown:b1,volumeup:b2,leftx:a0,lefty:a1,leftstick:b12,rightx:a2,righty:a3,rightstick:b15,platform:Linux," ./m8c

kill $(jobs -p)
EOF

Confirmed working on RG40XX H

@DRCRecoveryData
Copy link

This file doesn't exists anymore: https://raw.githubusercontent.com/knulli-cfw/distribution/knulli-main/board/batocera/allwinner/h700/rg35xx-plus/linux-sunxi64-legacy.config

I guess it moved to https://raw.githubusercontent.com/knulli-cfw/distribution/refs/heads/knulli-main/board/batocera/allwinner/h700/linux-sunxi64-legacy.config

I have test on MuOS of RG40XX H but your guide of folder .m8c not working, only build method of knulli paste to MuOS working

One more issue how to quit the m8c app back to menu of anbernic. Because only way is press Reset button to exit app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment