Skip to content

Commit

Permalink
Support mipsel
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorxda committed May 26, 2024
1 parent ae5f53c commit 4f17b61
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 30 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:

- name: Build
run: |
sh build.sh divinus-musl
sh build.sh divinus-muslhf
sh build.sh divinus-glibc
sh build.sh arm-musl
sh build.sh arm-muslhf
sh build.sh arm-glibc
sh build.sh mips-musl
21 changes: 12 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ DL="https://github.com/openipc/firmware/releases/download/latest"

toolchain() {
if [ ! -e toolchain/$1 ]; then
wget -c -q --show-progress $DL/$1.tgz -P $PWD
wget -c -nv --show-progress $DL/$1.tgz -P $PWD
mkdir -p toolchain/$1
tar -xf $1.tgz -C toolchain/$1 --strip-components=1 || exit 1
rm -f $1.tgz
fi
GCC=$PWD/toolchain/$1/bin/arm-linux-gcc
GCC=$PWD/toolchain/$1/bin/$2-linux-gcc
}

if [ "$2" = "debug" ]; then
Expand All @@ -17,16 +17,19 @@ else
OPT="-Os -s"
fi

if [ "$1" = "divinus-musl" ]; then
toolchain cortex_a7_thumb2-gcc13-musl-4_9
if [ "$1" = "arm-musl" ]; then
toolchain cortex_a7_thumb2-gcc13-musl-4_9 arm
make -C src -B CC=$GCC OPT="$OPT"
elif [ "$1" = "divinus-muslhf" ]; then
toolchain cortex_a7_thumb2_hf-gcc13-musl-4_9
elif [ "$1" = "arm-muslhf" ]; then
toolchain cortex_a7_thumb2_hf-gcc13-musl-4_9 arm
make -C src -B CC=$GCC OPT="$OPT"
elif [ "$1" = "divinus-glibc" ]; then
toolchain cortex_a7_thumb2_hf-gcc13-glibc-4_9
elif [ "$1" = "arm-glibc" ]; then
toolchain cortex_a7_thumb2_hf-gcc13-glibc-4_9 arm
make -C src -B CC=$GCC OPT="$OPT -lm"
elif [ "$1" = "mips-musl" ]; then
toolchain mips_xburst-gcc13-musl-3_10 mipsel
make -C src -B CC=$GCC OPT="$OPT"
else
echo "Usage: $0 [divinus-musl|divinus-muslhf|divinus-glibc]"
echo "Usage: $0 [arm-musl|arm-muslhf|arm-glibc|mips-musl]"
exit 1
fi
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SRC := $(shell find ./ -name '*.c')

divinus:
$(CC) $(SRC) -I src -rdynamic -Wl,--wrap=mmap $(OPT) -o ../$@
$(CC) $(SRC) -I src -rdynamic $(OPT) -o ../$@
9 changes: 5 additions & 4 deletions src/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ float __expf_finite(float x) { return expf(x); }
int __fgetc_unlocked(FILE *stream) { return fgetc(stream); }
double __log_finite(double x) { return log(x); }

void* mmap(void *start, size_t len, int prot, int flags, int fd, uint32_t off) {
void *mmap(void *start, size_t len, int prot, int flags, int fd, uint32_t off) {
return (void*)syscall(SYS_mmap2, start, len, prot, flags, fd, off >> 12);
}

void *mmap64(void *start, size_t len, int prot, int flags, int fd, off_t off) {
return (void*)syscall(SYS_mmap2, start, len, prot, flags, fd, off >> 12);
}
void* __wrap_mmap(void *start, size_t len, int prot, int flags, int fd, uint32_t off) {
return mmap(start, len, prot, flags, fd, off);
}
16 changes: 15 additions & 1 deletion src/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void gpio_deinit(void) {
fd_gpio = 0;
}

#ifdef __arm__
int gpio_init(void) {
while (*path++) {
if (access(*path, 0)) continue;
Expand Down Expand Up @@ -78,4 +79,17 @@ int gpio_write(char pin, bool value) {

close(req.fd);
return EXIT_SUCCESS;
}
}
#else
int gpio_init(void) {
return EXIT_SUCCESS;
}

int gpio_read(char pin, bool *value) {
return EXIT_SUCCESS;
}

int gpio_write(char pin, bool value) {
return EXIT_SUCCESS;
}
#endif
7 changes: 5 additions & 2 deletions src/gpio.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#include <fcntl.h>
#include <linux/gpio.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>

#ifdef __arm__
#include <linux/gpio.h>
#endif

#define GPIO_ERROR(x, ...) fprintf(stderr, "%s \033[31m%s\033[0m\n", "[gpio] (x)", ##__VA_ARGS__)

void gpio_deinit(void);
int gpio_init(void);
int gpio_read(char pin, bool *value);
int gpio_write(char pin, bool value);
int gpio_write(char pin, bool value);
19 changes: 12 additions & 7 deletions src/hal/support.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "support.h"

extern void* __real_mmap();

void *isp_thread = NULL;
void *venc_thread = NULL;

Expand Down Expand Up @@ -34,7 +32,7 @@ bool hal_registry(unsigned int addr, unsigned int *data, hal_register_op op) {

volatile char *mapped_area;
if (offset != loaded_offset) {
mapped_area = __real_mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, offset);
mapped_area = mmap64(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, offset);
if (mapped_area == MAP_FAILED) {
fprintf(stderr, "hal_registry mmap error: %s (%d)\n",
strerror(errno), errno);
Expand Down Expand Up @@ -86,9 +84,16 @@ void hal_identify(void) {
venc_thread = i6f_video_thread;
return;
}
else if (!access("/proc/jz", 0)) {
plat = HAL_PLATFORM_TX;
}
else if (!access("/proc/jz", 0) &&
hal_registry(0x1300002C, &val, OP_READ))
switch ((val >> 12) & 0xFF) {
case 0x21:
plat = HAL_PLATFORM_T21;
return;
case 0x31:
plat = HAL_PLATFORM_T31;
return;
}

if (file = fopen("/proc/iomem", "r"))
while (fgets(line, 200, file))
Expand Down Expand Up @@ -119,4 +124,4 @@ void hal_identify(void) {
chnState = (hal_chnstate*)v4_state;
isp_thread = v4_image_thread;
venc_thread = v4_video_thread;
}
}
4 changes: 3 additions & 1 deletion src/hal/support.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ extern void *i6f_encoder_thread(void);
extern hal_chnstate i6f_state[I6F_VENC_CHN_NUM];

bool hal_registry(unsigned int addr, unsigned int *data, hal_register_op op);
void hal_identify(void);
void hal_identify(void);

void *mmap64(void *start, size_t len, int prot, int flags, int fd, off_t off);
5 changes: 3 additions & 2 deletions src/hal/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ typedef enum {
HAL_PLATFORM_I6C,
HAL_PLATFORM_I6E,
HAL_PLATFORM_I6F,
HAL_PLATFORM_TX,
HAL_PLATFORM_T21,
HAL_PLATFORM_T31,
HAL_PLATFORM_V4
} hal_platform;

Expand Down Expand Up @@ -100,4 +101,4 @@ typedef struct {
hal_vidpack *pack;
unsigned int count;
unsigned int seq;
} hal_vidstream;
} hal_vidstream;
4 changes: 4 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "Divinus for infinity6e\n"); break;
case HAL_PLATFORM_I6F:
fprintf(stderr, "Divinus for infinity6f\n"); break;
case HAL_PLATFORM_T21:
fprintf(stderr, "Divinus for ingenic t21\n"); break;
case HAL_PLATFORM_T31:
fprintf(stderr, "Divinus for ingenic t31\n"); break;
case HAL_PLATFORM_V4:
fprintf(stderr, "Divinus for hisi-gen4\n"); break;
default:
Expand Down

0 comments on commit 4f17b61

Please sign in to comment.