Skip to content

Commit

Permalink
rm2fb: start socket on install, add xochitl env file, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timower committed Nov 27, 2023
1 parent 2ee3051 commit 93c8b98
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 12 deletions.
6 changes: 4 additions & 2 deletions cmake/CPackOptions.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ set(CPACK_DEBIAN_ARCHIVE_TYPE "gnutar")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "rmall")

# rm2fb stuff
# TODO: Xochitl fails to install on 3.5 :(
# set(CPACK_DEBIAN_RM2DISPLAY_PACKAGE_DEPENDS "xochitl")
set(CPACK_DEBIAN_RM2DISPLAY_PACKAGE_DEPENDS "xochitl")
set(CPACK_DEBIAN_RM2DISPLAY_PACKAGE_PROVIDES "display, rm2fb-client")
set(CPACK_DEBIAN_RM2DISPLAY_PACKAGE_CONFLICTS "display, rm2fb-client, rm2fb")
set(CPACK_DEBIAN_RM2DISPLAY_PACKAGE_REPLACES "display, rm2fb-client, rm2fb")
set(CPACK_DEBIAN_RM2DISPLAY_PACKAGE_CONTROL_EXTRA
"@CMAKE_SOURCE_DIR@/libs/rm2fb/opkg/postinst;@CMAKE_SOURCE_DIR@/libs/rm2fb/opkg/prerm")


# yaft2 and yaft term files conflict.
set(CPACK_DEBIAN_YAFT2_PACKAGE_REPLACES "yaft")
Expand Down
4 changes: 4 additions & 0 deletions libs/rm2fb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,9 @@ install(FILES rm2fb.service rm2fb.socket
COMPONENT rm2display
DESTINATION lib/systemd/system)

install(FILES opkg/rm2fb-preload.env
COMPONENT rm2display
DESTINATION opt/etc/xochitl.env.d)

add_deploy(rm2fb_client)
add_deploy(rm2fb_server)
10 changes: 10 additions & 0 deletions libs/rm2fb/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,17 @@ serverMain(int argc, char* argv[], char** envp) { // NOLINT
// Call the get or create Instance function.
if (!inQemu) {
std::cerr << "SWTCON calling init\n";

// NOLINTNEXTLINE
auto copyBuffer = std::make_unique<uint16_t[]>(fb_width * fb_height);

// The init threads does a memset to 0xff. But if we're activated by a
// systemd socket the shared memory already has some content. So make a
// backup and preserve it.
memcpy(copyBuffer.get(), fb.mem, fb_size);
addrs->initThreads();
memcpy(fb.mem, copyBuffer.get(), fb_size);

std::cout << "SWTCON initalized!\n";
} else {
std::cout << "In QEMU, not starting SWTCON\n";
Expand Down
15 changes: 12 additions & 3 deletions libs/rm2fb/SharedBuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#include "SharedBuffer.h"

#include <cerrno>
#include <cstdio>
#include <errno.h>
#include <cstring>
#include <fcntl.h> /* For O_* constants */
#include <sys/mman.h>
#include <sys/stat.h> /* For mode constants */
#include <unistd.h>

SharedFB::SharedFB(const char* path)
: fd(shm_open(path, O_RDWR | O_CREAT, 0755)) {
SharedFB::SharedFB(const char* path) : fd(shm_open(path, O_RDWR, 0755)) {

bool clear = false;
if (fd == -1 && errno == ENOENT) {
fd = shm_open(path, O_RDWR | O_CREAT, 0755);
clear = true;
}

if (fd == -1 && errno == EACCES) {
fd = shm_open(path, O_RDWR | O_CREAT, 0755);
Expand All @@ -21,6 +27,9 @@ SharedFB::SharedFB(const char* path)

ftruncate(fd, fb_size);
mem = (uint16_t*)mmap(nullptr, fb_size, PROT_WRITE, MAP_SHARED, fd, 0);
if (clear) {
memset(mem, UINT8_MAX, fb_size);
}
}

SharedFB::~SharedFB() {
Expand Down
6 changes: 6 additions & 0 deletions libs/rm2fb/opkg/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -eu

# Enable the rm2fb socket
systemctl daemon-reload
systemctl enable --now rm2fb.socket
5 changes: 5 additions & 0 deletions libs/rm2fb/opkg/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -eu

# Disable the rm2fb socket
systemctl disable --now rm2fb.socket
3 changes: 3 additions & 0 deletions libs/rm2fb/opkg/rm2fb-preload.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Part of the rm2-stuff rm2display package. Don't edit unless you know what
# you're doing.
export LD_PRELOAD=/opt/lib/librm2fb_client.so
9 changes: 2 additions & 7 deletions test/integration/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,9 @@ scp -P 2222 "$IPKS_PATH"/*.ipk root@localhost:
do_ssh systemctl restart systemd-timesyncd
do_ssh opkg update

do_ssh opkg install ./*.ipk
do_ssh opkg install ./*.ipk || true # TODO: xochitl doesn't configure for 3.5+

do_ssh opkg install xochitl || true # TODO: xochitl doesn't configure for 3.5+

do_ssh systemctl daemon-reload

do_ssh systemctl start rm2fb
sleep 1
# Start rocket, which should trigger the rm2fb socket and start the service.
do_ssh systemctl start rocket

# rocket
Expand Down

0 comments on commit 93c8b98

Please sign in to comment.