Skip to content

Commit

Permalink
add rockhip support
Browse files Browse the repository at this point in the history
  • Loading branch information
henkwiedig committed Nov 22, 2024
1 parent c1ffa36 commit d3404ba
Show file tree
Hide file tree
Showing 9 changed files with 509 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +37,7 @@ jobs:
msposd_star6b0
msposd_star6e
msposd_x86
msposd_rockchip
- name: Versioned release
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -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'
Expand All @@ -59,3 +62,4 @@ jobs:
msposd_star6b0
msposd_star6e
msposd_x86
msposd_rockchip
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ toolchain/
majestic.yaml
/msposd
firmware/
aarch64/
disk.raw
msposd_goke
msposd_hisi
msposd_star6b0
msposd_star6e
msposd_x86
msposd_x86
msposd_rockchip
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ version.h:
all: version.h

clean:
rm -f *.o msposd_x86 msposd_goke msposd_hisi msposd_star6b0 msposd_star6e
rm -f *.o msposd_x86 msposd_goke msposd_hisi msposd_star6b0 msposd_star6e msposd_rockchip

goke: version.h
$(eval SDK = ./sdk/gk7205v300)
Expand Down Expand Up @@ -59,3 +59,10 @@ x86: version.h

$(eval BUILD = $(CC) $(SRCS) -I $(SDK)/include -L $(DRV) $(CFLAGS) $(LIB) -levent_core -O0 -g -o $(OUTPUT))
$(BUILD)

rockchip: version.h
$(eval SDK = ./sdk/gk7205v300)
$(eval CFLAGS += -D__ROCKCHIP__)
$(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)
4 changes: 2 additions & 2 deletions bmp/region.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const double inv16 = 1.0 / 16.0;
int create_region(int *handle, int x, int y, int width, int height)
{
int s32Ret = -1;
#ifndef _x86
#if !defined(_x86) && !defined(__ROCKCHIP__)
#ifdef __SIGMASTAR__
MI_RGN_ChnPort_t stChn;

Expand Down Expand Up @@ -313,7 +313,7 @@ int prepare_bitmap(const char *filename, BITMAP *bitmap, int bFil, unsigned int
int set_bitmap(int handle, BITMAP *bitmap)
{
int s32Ret=0;
#ifndef _x86
#if !defined(_x86) && !defined(__ROCKCHIP__)
#ifdef __SIGMASTAR__
s32Ret = MI_RGN_SetBitMap(handle, (MI_RGN_Bitmap_t *)(bitmap));
#elif __GOKE__
Expand Down
9 changes: 5 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fi
GCC=$PWD/toolchain/$CC/bin/arm-linux-gcc
OUT=msposd_$1

if [[ "$1" != *"jetson"* && "$1" != *"x86"* ]]; then
if [[ "$1" != *"jetson"* && "$1" != *"x86"* && "$1" != *"rockhip"* ]]; then
if [ ! -e toolchain/$CC ]; then
wget -c -q --show-progress $DL/$CC.tgz -P $PWD
mkdir -p toolchain/$CC
Expand All @@ -23,7 +23,6 @@ if [[ "$1" != *"jetson"* && "$1" != *"x86"* ]]; then
fi
fi


if [ ! -e firmware ]; then
git clone https://github.com/openipc/firmware --depth=1
fi
Expand All @@ -46,7 +45,9 @@ elif [ "$1" = "jetson" ]; then
elif [ "$1" = "x86" ]; then
DRV=$PWD
make DRV=$DRV OUTPUT=$OUT $1
elif [ "$1" = "rockchip" ]; then
./build_rockchip.sh $1
else
echo "Usage: $0 [goke|hisi|star6b0|star6e|jetson|x86]"
echo "Usage: $0 [goke|hisi|star6b0|star6e|jetson|x86|rockchip]"
exit 1
fi
fi
58 changes: 58 additions & 0 deletions build_rockchip.sh
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
int __ctype_b;
int __stdin;

#ifndef _x86
#if !defined(_x86) && !defined(__ROCKCHIP__)
int __fgetc_unlocked(FILE *stream) {
return fgetc(stream);
}
Expand Down
31 changes: 18 additions & 13 deletions osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@
#include "osd/msp/msp.h"
#include "osd/msp/msp_displayport.h"

#ifdef _x86
#if defined(_x86) || defined(__ROCKCHIP__)
// #include <cairo/cairo.h>
// #include <cairo/cairo-xlib.h>
// #include <X11/Xlib.h>
// #include <X11/Xutil.h>
// #include <X11/Xatom.h>
// #include <stdio.h>
// #include <stdbool.h>
#if defined(_x86)
#include "osd/util/Render_x86.c"
#elif defined(__ROCKCHIP__)
#include "osd/util/Render_Rockchip.c"
#endif
#else
#include "bmp/region.h"
#include "bmp/common.h"
Expand Down Expand Up @@ -670,7 +674,7 @@ int y_end = 500;
}

void LineDirect(uint8_t* bmpData, uint32_t width, uint32_t height, int x0, int y0, int x1, int y1, uint8_t color, int thickness) {
#ifdef _x86
#if defined(_x86) || defined(__ROCKCHIP__)

drawLine_x86(x0, y0, x1, y1, getcolor(color), thickness, false);
#else
Expand All @@ -680,7 +684,7 @@ int y_end = 500;


void LineTranspose(uint8_t* bmpData, int posX0, int posY0, int posX1, int posY1, uint8_t color, int thickness) {
#ifdef _x86
#if defined(_x86) || defined(__ROCKCHIP__)
drawLine_x86(posX0, posY0, posX1, posY1, getcolor(color), thickness, true);
#else
drawLine( bmpData, posX0, posY0, posX1, posY1, color, thickness);
Expand Down Expand Up @@ -938,7 +942,7 @@ void LineTranspose(uint8_t* bmpData, int posX0, int posY0, int posX1, int posY1,
sprintf(buffer, "%+02d°", -last_pitch/10);

int osd_font_size=18;
#ifdef _x86
#if defined(_x86) || defined(__ROCKCHIP__)
uint32_t color = getcolor(COLOR_YELLOW);
if ((-50 < last_pitch) && (last_pitch <50))
color = getcolor(COLOR_WHITE);
Expand Down Expand Up @@ -1011,7 +1015,7 @@ void LineTranspose(uint8_t* bmpData, int posX0, int posY0, int posX1, int posY1,
//needed since we may have already painted the icons
}
}
#ifdef _x86
#if defined(_x86) || defined(__ROCKCHIP__)
Render_x86_rect(bmpBuff.pData,bmpBuff.u32Width, bmpBuff.u32Height,xR,yR,xR,yR,s_width,s_height);
#endif

Expand Down Expand Up @@ -1465,7 +1469,7 @@ bool Convert2SmallGlyph(BITMAP *fnt , u_int16_t *s_left, u_int16_t *s_top, u_in
//Not needed, but somehow parsing DrawString in InjectChars sometimes does not work.
static bool ReplaceWidgets_Slow(int* x, int* y){

#ifdef _x86
#if defined(_x86) || defined(__ROCKCHIP__)
if (character_map[*x][*y]=='!' && character_map[*x+1][*y]=='R' && character_map[*x+2][*y]=='C' && character_map[*x+3][*y]=='!'){
RCWidgetX = *x *current_display_info.font_width;
RCWidgetY = current_display_info.font_height * *y;
Expand Down Expand Up @@ -1638,7 +1642,7 @@ static void draw_screenBMP(){
}

step2=get_time_ms();
#ifndef _x86
#if !defined(_x86) && !defined(__ROCKCHIP__)

if (AHI_Enabled==2)
draw_AHI();
Expand All @@ -1657,7 +1661,7 @@ static void draw_screenBMP(){

stat_screen_refresh_count++;
uint64_t step3=get_time_ms();
#ifdef _x86
#if defined(_x86) || defined(__ROCKCHIP__)

if (bmp_x86==NULL)//lets cache it
bmp_x86 = malloc(bmpBuff.u32Width * bmpBuff.u32Height * 4); // Allocate memory for RGBA data
Expand Down Expand Up @@ -1833,7 +1837,7 @@ unsigned char* loadPngToBMP(const char* filename, unsigned int* width, unsigned
else if (PIXEL_FORMAT_DEFAULT==PIXEL_FORMAT_8888){
// memcpy(bmpData,pngData,bmpSize);
convertRGBAToARGB( pngData, *width , *height, bmpData);
#ifdef _x86
#if defined(_x86) || defined(__ROCKCHIP__)
premultiplyAlpha((uint32_t*) bmpData, *width, *height);//RGBA format needs to be converted when using transparency?
#endif
}else
Expand Down Expand Up @@ -1954,7 +1958,7 @@ static void InitMSPHook(){
PIXEL_FORMAT_DEFAULT=PIXEL_FORMAT_I4;//I4 format, 4 bits per pixel
PIXEL_FORMAT_BitsPerPixel = 4;
#endif
#ifdef _x86
#if defined(_x86) || defined(__ROCKCHIP__)
//enable this to test simulate preocessing on SigmaStar
//PIXEL_FORMAT_DEFAULT=PIXEL_FORMAT_I4;//I4 format, 4 bits per pixel
//PIXEL_FORMAT_BitsPerPixel = 4;
Expand All @@ -1965,10 +1969,11 @@ static void InitMSPHook(){

int height = GetMajesticVideoConfig(&majestic_width);

#ifdef _x86
#if defined(_x86) || defined(__ROCKCHIP__)
if (DrawOSD)
Init_x86(&OVERLAY_WIDTH, &OVERLAY_HEIGHT);
height=OVERLAY_HEIGHT;
printf("OSD is %ix%i pixels\n",OVERLAY_WIDTH,OVERLAY_HEIGHT);
#endif

//Get video resolution
Expand Down Expand Up @@ -2166,7 +2171,7 @@ On sigmastar the BMP row stride is aligned to 8 bytes, that is 16 pixels in PIXE
printf("Set Goke Font Review %d:%d\r\n", bitmap.u32Width, bitmap.u32Height);

set_bitmap(osds[FULL_OVERLAY_ID].hand, &bitmap);//bitmap must match region dimensions!
#elif _x86
#elif defined(_x86) || defined(__ROCKCHIP__)
//sfRenderWindow_clear(window, sfColor_fromRGB(255, 255, 0));

unsigned char* rgbaData = malloc(bitmap.u32Width * bitmap.u32Height * 4); // Allocate memory for RGBA data
Expand Down Expand Up @@ -2222,7 +2227,7 @@ static void CloseMSP(){
if (deinit)
printf("[%s:%d]RGN_DeInit failed with %#x!\n", __func__, __LINE__, s32Ret);
#endif
#ifdef _x86
#if defined(_x86) || defined(__ROCKCHIP__)
Close_x86();
#endif

Expand Down
Loading

0 comments on commit d3404ba

Please sign in to comment.