# HG changeset patch # User Paul Boddie # Date 1527451738 -7200 # Node ID 86ad5faff7f2195c71e0c9507be1ced7f79b17fd # Parent 83c29a35353013ab5b42a5bc9bf4935936caf6a8 Added a test of dlopen usage. diff -r 83c29a353530 -r 86ad5faff7f2 conf/landfall-examples/mips-qi_lb60-dl-example.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/landfall-examples/mips-qi_lb60-dl-example.cfg Sun May 27 22:08:58 2018 +0200 @@ -0,0 +1,165 @@ +-- vim: ft=lua ts=2 et sw=2 + +-- Start Mag to multiplex the framebuffer showing only a single program. +-- This example shows a framebuffer terminal showing the dl_test example's output. +-- The target platform is the Ben NanoNote. + +local L4 = require("L4"); + +local l = L4.default_loader; + +-- Define general access to peripherals. + +local io_buses = { + cpm = l:new_channel(); + gpio = l:new_channel(); + lcd = l:new_channel(); + }; + +l:start({ + caps = { + cpm = io_buses.cpm:svr(), + gpio = io_buses.gpio:svr(), + lcd = io_buses.lcd:svr(), + + icu = L4.Env.icu, + sigma0 = L4.cast(L4.Proto.Factory, L4.Env.sigma0):create(L4.Proto.Sigma0), + }, + }, + "rom/io rom/hw_devices.io rom/mips-qi_lb60-common.io"); + +-- Expose a SPI peripheral as a device. + +local spi = l:new_channel(); + +l:startv({ + caps = { + vbus = io_buses.gpio, + spi = spi:svr(), + }, + }, + "rom/dev_spi_jz4740", "C23", "C22", "C21"); -- specifying clock, data, enable pin details + +-- Expose a SPI backlight device for the Ben. + +local backlight = l:new_channel(); -- exposes backlight device + +l:start({ + caps = { + spi = spi, + backlight = backlight:svr(), + }, + }, + "rom/dev_backlight_spi_ili8960"); + +-- Expose a display device for the Ben. + +local display = l:new_channel(); -- exposes display device + +l:start({ + caps = { + backlight = backlight, + display = display:svr(), + vbus = io_buses.gpio, + }, + }, + "rom/dev_display_qi_lb60"); + +-- Expose a panel definition for the Ben. + +local panel = l:new_channel(); -- exposes panel + +l:start({ + caps = { + panel = panel:svr(), + }, + }, + "rom/dev_panel_qi_lb60"); + +-- Expose the CPM peripheral. + +local cpm = l:new_channel(); + +l:start({ + caps = { + vbus = io_buses.cpm, + cpm = cpm:svr(), + }, + }, + "rom/dev_cpm_jz4740"); + +-- Expose a framebuffer device. + +local fbdrv_fb = l:new_channel(); + +l:start({ + caps = { + vbus = io_buses.lcd, + fb = fbdrv_fb:svr(), + cpm = cpm, + display = display, -- needed by LCD driver + panel = panel, + }, + }, + "rom/fb-drv"); + +-- Expose the keypad matrix. + +local keypad = l:new_channel(); + +l:start({ + caps = { + vbus = io_buses.gpio, + keypad = keypad:svr(), + }, + }, + "rom/dev_keypad_qi_lb60"); + +-- Expose the keypad events. + +local ev = l:new_channel(); + +l:start({ + caps = { + keypad = keypad, + ev = ev:svr(), + }, + }, + "rom/dev_input_keypad_qi_lb60"); + +-- Multiplex the framebuffer. + +local mag_caps = { + mag = l:new_channel(), + svc = l:new_channel(), + }; + +l:start({ + caps = { + vbus = io_buses.gpio, -- needed by input driver + fb = fbdrv_fb, + mag = mag_caps.mag:svr(), + svc = mag_caps.svc:svr(), + ev = ev, + }, + }, + "rom/mag"); + +-- Show the terminal. + +local term = l:new_channel(); + +l:start({ + caps = { + fb = mag_caps.svc:create(L4.Proto.Goos, "g=320x230+0+0", "barheight=10"), + term = term:svr(), + }, + }, + "rom/fbterminal"); + +-- Show the hello example. + +l:start({ + log_cap = term, + }, + "rom/ex_dl_test"); diff -r 83c29a353530 -r 86ad5faff7f2 conf/landfall-examples/mips-qi_lb60-dl-example.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/landfall-examples/mips-qi_lb60-dl-example.list Sun May 27 22:08:58 2018 +0200 @@ -0,0 +1,25 @@ + +modaddr 0x1100000 + +entry mips-qi_lb60-dl-example +bootstrap bootstrap -serial +kernel fiasco -serial_esc +roottask moe rom/mips-qi_lb60-dl-example.cfg +module mips-qi_lb60-dl-example.cfg +module mips-qi_lb60-common.io +module plat-qi_lb60/hw_devices.io +module l4re +module io +module ned +module fb-drv +module mag +module dev_spi_jz4740 +module dev_backlight_spi_ili8960 +module dev_display_qi_lb60 +module dev_panel_qi_lb60 +module dev_cpm_jz4740 +module dev_keypad_qi_lb60 +module dev_input_keypad_qi_lb60 +module fbterminal +module ex_dl_test +module libdl_test_data.so diff -r 83c29a353530 -r 86ad5faff7f2 pkg/landfall-examples/dl_test/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/landfall-examples/dl_test/Makefile Sun May 27 22:08:58 2018 +0200 @@ -0,0 +1,8 @@ +PKGDIR ?= .. +L4DIR ?= $(PKGDIR)/../.. + +TARGET = ex_dl_test +SRC_C = dl_test.c +REQUIRES_LIBS = l4re_c-util libdl + +include $(L4DIR)/mk/prog.mk diff -r 83c29a353530 -r 86ad5faff7f2 pkg/landfall-examples/dl_test/dl_test.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/landfall-examples/dl_test/dl_test.c Sun May 27 22:08:58 2018 +0200 @@ -0,0 +1,52 @@ +/* + * Test dynamic loading. + * + * (c) 2018 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include +#include +#include + +static const char *libname = "rom/libdl_test_data.so"; + +int main(void) +{ + const char *buffer; + + /* Obtain the linked data. */ + + void *handle = dlopen(libname, RTLD_NOW); + const char *(*get_data)(void); + + if (handle == NULL) + { + printf("Could not open %s\n", libname); + return 1; + } + + get_data = dlsym(handle, "get_data"); + + /* Load and show the data. */ + + buffer = get_data(); + puts(buffer); + + l4_sleep_forever(); + return 0; +} diff -r 83c29a353530 -r 86ad5faff7f2 pkg/landfall-examples/dl_test_data/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/landfall-examples/dl_test_data/Makefile Sun May 27 22:08:58 2018 +0200 @@ -0,0 +1,7 @@ +PKGDIR ?= .. +L4DIR ?= $(PKGDIR)/../.. + +TARGET = libdl_test_data.so +SRC_C = dl_test_data.c + +include $(L4DIR)/mk/lib.mk diff -r 83c29a353530 -r 86ad5faff7f2 pkg/landfall-examples/dl_test_data/dl_test_data.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/landfall-examples/dl_test_data/dl_test_data.c Sun May 27 22:08:58 2018 +0200 @@ -0,0 +1,29 @@ +/* + * Test dynamic loading. + * + * (c) 2018 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +static const char *buffer = "Hello shared!"; + +const char *get_data(void); + +const char *get_data(void) +{ + return buffer; +}