Programming the 8051: Step1, the Compiler

First, we need to build SDCC (8051 compiler) for C906 to compile for 8051 on Duo.

I am using a custom compiled Toolchain (from GitHub - riscv-collab/riscv-gnu-toolchain: GNU toolchain for RISC-V, including GCC with just default options with multilib and glibc) BECAUSE NOTHING PREBUILT F*CKING WORKS RIGHT (I had obscure nonsensical errors building sdcc before I rebuilt the toolchain myself, it fixed the issue, i lost like 6 hours on this, do not use the official archlinux packaged toolchain for riscv64 or any other options like that)

For milk-v’s toolchain mtune and march will be different (and it might not work at all for this, I have not tried), look into the buildroot for examples of them.

All the files I created for this as well as the final result will be at the end to reference

But we have a couple dependencies that need to be built for riscv64:

zlib:

mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=$PWD/out -DCMAKE_TOOLCHAIN_FILE=/home/vdragon/dev/DUO/toolchain_c906.cmake ..
make -j16
make install

and boost:

# Build and setup boost.build (ONLY boost.build) for your system (google)
# then:
mkdir build
cd build
./build.sh

And finally SDCC:

mkdir build
cd build
# build libs for sdcc devices, we need sdcc for that and it does it by itself, so build for host
../configure --disable-pic14-port --disable-pic16-port
make -j16
make DESTDIR=$PWD/out install
rm -r $PWD/out/usr/local/bin $PWD/out/usr/local/libexec
make clean
# and then delete everything but out and our scripts becasue make has the dumbs and will try to use the x86_64 files
#build for riscv64 immediatly after
./configure.sh
./build.sh
make DESTDIR=$PWD/out install

Because I changed Toolchain midway, my out folder is a mess, but the idea is to end up with bin, libexec, and share (the one from the host compilation) folders from the out folder in the build folder.

Grab those files, put them in your system image in the appropriate folders (copying the 3 folders in /usr/local is a good option)

Check SDCC runs (if you didnt put it in /usr/local you might want to add where you put the bin folder to PATH):

I also grabbed a example to test functionality:

The next step will be to transfer programs compiled with SDCC to the 8051 and use the dedicated RTC Uart controller to print Hello World.

Compiled SDCC with nano included: https://vyndragon.github.io/data/SDCC.tar.gz
Shell files used to compile SDCC and its dependencies: https://vyndragon.github.io/data/SDCC_files.tar.gz

6 Likes