diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 75af672..6f4d348 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/build.sh b/build.sh index 81e6251..f7f9aa0 100755 --- a/build.sh +++ b/build.sh @@ -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 -q $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 @@ -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 diff --git a/src/Makefile b/src/Makefile index 70876b7..3ec3149 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ SRC := $(shell find ./ -name '*.c') divinus: - $(CC) $(SRC) -I src -rdynamic -Wl,--wrap=mmap $(OPT) -o ../$@ \ No newline at end of file + $(CC) $(SRC) -I src -rdynamic $(OPT) -o ../$@ diff --git a/src/compat.c b/src/compat.c index 4b73294..c830bc3 100644 --- a/src/compat.c +++ b/src/compat.c @@ -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); -} \ No newline at end of file diff --git a/src/gpio.c b/src/gpio.c index ef9348e..7038647 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -12,6 +12,7 @@ void gpio_deinit(void) { fd_gpio = 0; } +#ifdef __arm__ int gpio_init(void) { while (*path++) { if (access(*path, 0)) continue; @@ -78,4 +79,17 @@ int gpio_write(char pin, bool value) { close(req.fd); return EXIT_SUCCESS; -} \ No newline at end of file +} +#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 diff --git a/src/gpio.h b/src/gpio.h index 1bf7c53..6489945 100644 --- a/src/gpio.h +++ b/src/gpio.h @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -7,9 +6,13 @@ #include #include +#ifdef __arm__ +#include +#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); \ No newline at end of file +int gpio_write(char pin, bool value); diff --git a/src/hal/support.c b/src/hal/support.c index 390b1c7..3dc03d6 100644 --- a/src/hal/support.c +++ b/src/hal/support.c @@ -1,7 +1,5 @@ #include "support.h" -extern void* __real_mmap(); - void *isp_thread = NULL; void *venc_thread = NULL; @@ -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); @@ -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)) @@ -119,4 +124,4 @@ void hal_identify(void) { chnState = (hal_chnstate*)v4_state; isp_thread = v4_image_thread; venc_thread = v4_video_thread; -} \ No newline at end of file +} diff --git a/src/hal/support.h b/src/hal/support.h index a322b1b..8a1ecc8 100644 --- a/src/hal/support.h +++ b/src/hal/support.h @@ -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); \ No newline at end of file +void hal_identify(void); + +void *mmap64(void *start, size_t len, int prot, int flags, int fd, off_t off); diff --git a/src/hal/types.h b/src/hal/types.h index ceff80e..09f3314 100644 --- a/src/hal/types.h +++ b/src/hal/types.h @@ -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; @@ -100,4 +101,4 @@ typedef struct { hal_vidpack *pack; unsigned int count; unsigned int seq; -} hal_vidstream; \ No newline at end of file +} hal_vidstream; diff --git a/src/main.c b/src/main.c index ed8fc1e..ef6db5a 100644 --- a/src/main.c +++ b/src/main.c @@ -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: