From: Grazvydas Ignotas Date: Sun, 10 Apr 2016 19:29:31 +0000 (+0300) Subject: libbcmhost-shim: new shim library for r-pi's bcm stuff X-Git-Tag: sz_175~16 X-Git-Url: https://git.openpandora.org/cgi-bin/gitweb.cgi?p=openpandora.oe.git;a=commitdiff_plain;h=68c7cf507bc87302e2598d43d85a3315e6958ae8 libbcmhost-shim: new shim library for r-pi's bcm stuff --- diff --git a/recipes/armhf/libbcmhost-shim/Makefile b/recipes/armhf/libbcmhost-shim/Makefile new file mode 100644 index 0000000..26486ac --- /dev/null +++ b/recipes/armhf/libbcmhost-shim/Makefile @@ -0,0 +1,17 @@ +CC = $(CROSS_COMPILE)gcc +CFLAGS += -Wall -O2 -g -fPIC +LDFLAGS += -Wl,-z -Wl,defs +LDLIBS += -ldl + +TARGET = libbcm_host.so +OBJS = bcm_host_shim.o + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) -shared -o $@ $^ $(LDFLAGS) $(LDLIBS) + +clean: + $(RM) $(TARGET) $(OBJS) + +.PHONY: all clean diff --git a/recipes/armhf/libbcmhost-shim/bcm_host_shim.c b/recipes/armhf/libbcmhost-shim/bcm_host_shim.c new file mode 100644 index 0000000..be4e5ce --- /dev/null +++ b/recipes/armhf/libbcmhost-shim/bcm_host_shim.c @@ -0,0 +1,162 @@ +/* + * bcm_host_shim + * (C) notaz, 2016 + * + * This work is licensed under the terms of 3-clause BSD license. + */ +#define _GNU_SOURCE +#include +#include +#include +#include + +#define SCREEN_WIDTH 800 +#define SCREEN_HEIGHT 480 + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) + +void bcm_host_init(void) +{ +} + +void bcm_host_deinit(void) +{ +} + +uint32_t vc_dispmanx_display_open(uint32_t dev) +{ + return 0xf00; +} + +uint32_t vc_dispmanx_element_add() +{ + return 0xf04; +} + +uint32_t vc_dispmanx_update_start(int32_t prio) +{ + return 0xf08; +} + +int vc_dispmanx_update_submit_sync(uint32_t upd_handle) +{ + //printf("%s\n", __func__); + return 0; +} + +int graphics_get_display_size(uint16_t dpy, uint32_t *w, uint32_t *h) +{ + *w = SCREEN_WIDTH; + *h = SCREEN_HEIGHT; + return 0; +} + +#ifndef SDL_FULLSCREEN +#define SDL_FULLSCREEN 0x80000000 +#define SDL_RESIZABLE 0x00000010 +#endif + +static void *get_real_func(const char *name) +{ + void *f; + + f = dlsym(RTLD_NEXT, name); + if (f == NULL) { + fprintf(stderr, "%s: %s\n", name, dlerror()); + _exit(1); + } + return f; +} + +/* pandora's SGX driver can only run fullscreen */ +void *SDL_SetVideoMode(int width, int height, int bpp, uint32_t flags) +{ + static void * (*f)(int, int, int, uint32_t); + + //printf("%s %d %x\n", __func__, bpp, flags); + + width = height = bpp = 0; + flags &= ~SDL_RESIZABLE; + flags |= SDL_FULLSCREEN; + + if (f == NULL) + f = get_real_func(__func__); + + return f(width, height, bpp, flags); +} + +int SDL_PollEvent(void *e) +{ + static int (*f)(void *); + int ret; + + if (f == NULL) + f = get_real_func(__func__); + + ret = f(e); + + // event, SDL_KEYDOWN, SDLK_q + if (ret != 0 && e != NULL) { + if (*(uint8_t *)e == 2 && ((uint32_t *)e)[2] == 113) + *(uint8_t *)e = 12; // SDL_QUIT + } + + return ret; +} + +/* can't use 8bits/channel on pandora, must filter out confing */ +#ifndef EGL_NONE +#define EGL_NONE 0x3038 +#define EGL_RED_SIZE 0x3024 +#define EGL_GREEN_SIZE 0x3023 +#define EGL_BLUE_SIZE 0x3022 +#define EGL_ALPHA_SIZE 0x3021 +#define EGL_SURFACE_TYPE 0x3033 +#endif + +int eglChooseConfig(void *dpy, const int32_t *attrib_list, + void *configs, int32_t config_size, int32_t *num_config) +{ + static int (*f)(void *, const int32_t *, + void *, int32_t, int32_t *); + int32_t attrib_list_c[64]; + int i, o; + + //printf("%s\n", __func__); + + if (f == NULL) + f = get_real_func(__func__); + + for (i = o = 0; o < ARRAY_SIZE(attrib_list_c) - 2; i += 2) { + if (attrib_list == NULL || attrib_list[i] == EGL_NONE) + break; + + switch (attrib_list[i]) { + case EGL_RED_SIZE: + case EGL_GREEN_SIZE: + case EGL_BLUE_SIZE: + case EGL_SURFACE_TYPE: + case EGL_ALPHA_SIZE: + continue; + } + + attrib_list_c[o++] = attrib_list[i + 0]; + attrib_list_c[o++] = attrib_list[i + 1]; + } + attrib_list_c[o++] = EGL_NONE; + + return f(dpy, attrib_list_c, configs, config_size, num_config); +} + +void *eglCreateWindowSurface(void *dpy, void *config, void *win, + const int32_t *attrib_list) +{ + static void * (*f)(void *, void *, void *, const int32_t *); + + //printf("%s\n", __func__); + + if (f == NULL) + f = get_real_func(__func__); + + return f(dpy, config, NULL, attrib_list); +} diff --git a/recipes/armhf/libbcmhost-shim_0.1.bb b/recipes/armhf/libbcmhost-shim_0.1.bb new file mode 100644 index 0000000..ea520f6 --- /dev/null +++ b/recipes/armhf/libbcmhost-shim_0.1.bb @@ -0,0 +1,37 @@ +DESCRIPTION = "Shim library for libbcm_host.so found in r-pi" +SECTION = "libs" +PRIORITY = "optional" +LICENSE = "BSD-3-Clause" +RDEPENDS = "armhflibc6" +PR = "r0" + +SRC_URI = " \ + file://bcm_host_shim.c \ + file://Makefile \ +" + +# S = "${WORKDIR}/git" + +# assumes armhf (arm-unknown-linux-gnueabihf) cross-compiler is available in PATH +# with all required deps +do_compile() { + cp ${WORKDIR}/bcm_host_shim.c ${S}/ + cp ${WORKDIR}/Makefile ${S}/ + + unset CPP + unset CC + unset LD + unset CPPFLAGS + unset CFLAGS + unset LDFLAGS + export LDFLAGS="-Wl,--hash-style=gnu" + make CROSS_COMPILE=arm-unknown-linux-gnueabihf- +} + +do_install() { + install -d ${D}/usr/lib/arm-linux-gnueabihf + install -m 0755 libbcm_host.so ${D}/usr/lib/arm-linux-gnueabihf/ +} + +FILES_${PN} = "usr/lib/arm-linux-gnueabihf/*.so" +FILES_${PN}-dbg += "usr/lib/arm-linux-gnueabihf/.debug"