Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions PortMaster/device_info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ for arg in "$@"; do
fi
done

export DEVICE_INFO_VERSION="0.2.6"
export DEVICE_INFO_VERSION="0.2.7"

# ------------------------------------------------------------------------------
# 0. DIRECTORY SETUP
Expand Down Expand Up @@ -341,10 +341,14 @@ export DEVICE_KERNEL_VERSION="$(uname -r 2>/dev/null | cut -d- -f1)"

# 3d. CPU SoC Discovery
detect_dynamic_cpu() {
## On mainline arm64 kernels the SMCCC soc_id driver fills machine with the board's
## device-tree model ("Anbernic RG CubeXX"), not the SoC: then the compatible below.
local dt_model="$(tr -d '\0\r\n' < /proc/device-tree/model 2>/dev/null)"
[ -z "$dt_model" ] && dt_model="$(tr -d '\0\r\n' < /sys/firmware/devicetree/base/model 2>/dev/null)"
for soc_dir in /sys/devices/soc0 /sys/bus/soc/devices/soc0; do
if [ -f "$soc_dir/machine" ]; then
local soc_mach="$(tr -d '\0\r\n' < "$soc_dir/machine" 2>/dev/null)"
if [ -n "$soc_mach" ]; then echo "$soc_mach"; return; fi
if [ -n "$soc_mach" ] && [ "$soc_mach" != "$dt_model" ]; then echo "$soc_mach"; return; fi
fi
done

Expand Down
57 changes: 57 additions & 0 deletions PortMaster/mod_nuubOS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
#
# SPDX-License-Identifier: MIT
#

## Modular - nuubOS
#
# A modular file that is sourced for specific script lines required by ports running on nuubOS.
#
# usage `[ -f "${controlfolder}/mod_${CFW_NAME}.txt" ] && source "${controlfolder}/mod_${CFW_NAME}.txt"`
#
# Ports run inside a sandbox that only sees /roms/ports, under the Wayland compositor
# (labwc): SDL2 talks Wayland, controllers are the nuubOS virtual gamepads.

export SDL_VIDEODRIVER="wayland"

# westonwrap.sh (the weston_pkg runtime of Godot 4 and other ports) sources this file
# too. nuubOS has its own Wayland compositor on Panfrost, as ROCKNIX on Panfrost: take
# westonwrap's direct path there (the program on the compositor, no Weston of its own).
if [[ "${0##*/}" == westonwrap*.sh ]]; then
CFW_NAME="ROCKNIX"
glxinfo() { echo "OpenGL version string: nuubOS Wayland compositor (Panfrost)"; }
fi

# Use for Godot 2
GODOT2_OPTS="-r ${DISPLAY_WIDTH}x${DISPLAY_HEIGHT} -f"

# Use for Godot 3+
GODOT_OPTS="--resolution ${DISPLAY_WIDTH}x${DISPLAY_HEIGHT} -f"

# The nuubOS game gamepad (buttons south, east, north, west, D-pad on hat 0), the only
# kind of controller ports see: every physical pad reaches them through it. Mapped by
# the Anbernic labels, as ports expect on these consoles: A east, B south, X north, Y west.
NUUBOS_GAMEPAD_MAPPING="060000006e7575624f532047616d6500,nuubOS Gamepad,a:b1,b:b0,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,lefttrigger:b6,righttrigger:b7,back:b8,start:b9,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,platform:Linux,"

get_controls() {
ANALOGSTICKS="${ANALOG_STICKS:-2}"
LOWRES="N"
DEVICE="060000006e7575624f532047616d6500"
param_device="nuubos"

export SDL_GAMECONTROLLERCONFIG_FILE="/tmp/gamecontrollerdb.txt"
echo "${NUUBOS_GAMEPAD_MAPPING}" > /tmp/gamecontrollerdb.txt

sdl_controllerconfig="$(< "${SDL_GAMECONTROLLERCONFIG_FILE}")"
}

pm_platform_helper() {
# Older PortMaster releases have no pm_message_close.
if declare -F pm_message_close > /dev/null; then
pm_message_close
fi

if [ -e "$PM_PIPE" ]; then
PortMasterDialogExit
fi
}
21 changes: 21 additions & 0 deletions tests/test_device_info_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,24 @@ def test_name_and_version_from_os_release(shell, os_release, expected, tmp_path)
version = text[text.index('export CFW_VERSION="Unknown"'):text.index("# 3c.")]
script = re.sub(r'(?<=[\s"])/(etc|usr|boot|userdata|opt|var|mnt|app|storage)/', lambda m: f"{tmp_path}/{m.group(1)}/", detect + version)
assert run_fragment(command, script + '\necho "$CFW_NAME|$CFW_VERSION"\n', tmp_path) == expected


@pytest.mark.parametrize("shell", SHELLS, ids=["bash", "busybox"])
@pytest.mark.parametrize("machine, expected", [
## Mainline arm64: the SMCCC soc_id driver names the board, so the SoC comes from compatible.
("Anbernic RG CubeXX", "h700"),
## A soc0 driver that names the SoC itself.
("RK3566", "RK3566"),
])
def test_cpu_from_soc0_or_compatible(shell, machine, expected, tmp_path):
command = shell_or_skip(shell)
(tmp_path / "sys" / "devices" / "soc0").mkdir(parents=True)
(tmp_path / "sys" / "devices" / "soc0" / "machine").write_text(machine + "\n")
(tmp_path / "proc" / "device-tree").mkdir(parents=True)
(tmp_path / "proc" / "device-tree" / "model").write_bytes(b"Anbernic RG CubeXX\0")
(tmp_path / "proc" / "device-tree" / "compatible").write_bytes(b"anbernic,rgcubexx\0allwinner,sun50i-h700\0")

text = (PM_DIR / "device_info.txt").read_text()
block = text[text.index("detect_dynamic_cpu() {"):text.index('export DEVICE_CPU="$(detect_dynamic_cpu)"')]
script = re.sub(r'(?<=[\s"])/(proc|sys)/', lambda m: f"{tmp_path}/{m.group(1)}/", block)
assert run_fragment(command, script + '\ndetect_dynamic_cpu\n', tmp_path) == expected