From 0039f93de67aca5e3a870a49b19d5d6c8d55c17f Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Sun, 21 Mar 2021 14:58:10 +0100 Subject: [PATCH 1/4] busybox: add create-edid-cpio script This script simply creates /flash/edid.cpio with the contents from .config/firmware/edid Compared to the x86 specific getedid script this works on all platforms as it doesn't contain any platform specific code. Eventually getedid should be refactored make use of this helper script, too. Signed-off-by: Matthias Reichl --- packages/sysutils/busybox/package.mk | 1 + .../sysutils/busybox/scripts/create-edid-cpio | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100755 packages/sysutils/busybox/scripts/create-edid-cpio diff --git a/packages/sysutils/busybox/package.mk b/packages/sysutils/busybox/package.mk index 9556a1c488..272aa4dc2f 100644 --- a/packages/sysutils/busybox/package.mk +++ b/packages/sysutils/busybox/package.mk @@ -123,6 +123,7 @@ makeinstall_host() { makeinstall_target() { mkdir -p ${INSTALL}/usr/bin [ ${TARGET_ARCH} = x86_64 ] && cp ${PKG_DIR}/scripts/getedid ${INSTALL}/usr/bin + cp ${PKG_DIR}/scripts/create-edid-cpio ${INSTALL}/usr/bin/ cp ${PKG_DIR}/scripts/createlog ${INSTALL}/usr/bin/ cp ${PKG_DIR}/scripts/dthelper ${INSTALL}/usr/bin ln -sf dthelper ${INSTALL}/usr/bin/dtfile diff --git a/packages/sysutils/busybox/scripts/create-edid-cpio b/packages/sysutils/busybox/scripts/create-edid-cpio new file mode 100755 index 0000000000..d98362886e --- /dev/null +++ b/packages/sysutils/busybox/scripts/create-edid-cpio @@ -0,0 +1,36 @@ +#!/bin/sh + +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021-present Team LibreELEC (https://libreelec.tv) + +EDID_DIR="/storage/.config/firmware/edid" +EDID_CPIO="/flash/edid.cpio" +TMPDIR="/tmp/edid-cpio" + +if [ "$1" = "-q" ]; then + VERBOSE=0 +else + VERBOSE=1 +fi + +if [ ! -d "${EDID_DIR}" ]; then + echo "error: ${EDID_DIR} does not exist" + exit 1 +fi + +set -e + +rm -rf "${TMPDIR}" +mkdir -p "${TMPDIR}/usr/lib/firmware" +cp -r "${EDID_DIR}" "${TMPDIR}/usr/lib/firmware" +cd "${TMPDIR}" +mount -o remount,rw /flash +find usr -print | cpio -ov -H newc > "${EDID_CPIO}" +sync +mount -o remount,ro /flash +cd /storage +rm -rf "${TMPDIR}" + +if [ "${VERBOSE}" = "1" ]; then + echo "successfully created ${EDID_CPIO}" +fi From a02a2e8b51255f9b0e8d255c3eb78ecc017c8783 Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Tue, 23 Mar 2021 16:05:39 +0100 Subject: [PATCH 2/4] busybox: add script to dump edids of active DRM connectors The script dumps all edids of currently active connectors to .config/firmware/edid as edid-CONNECTORNAME.bin When run with the "-q" option informative messages are disabled and only the active connectors are returned so the output can be easily used by other scripts. Signed-off-by: Matthias Reichl --- packages/sysutils/busybox/package.mk | 6 ++- .../busybox/scripts/dump-active-edids-drm | 42 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100755 packages/sysutils/busybox/scripts/dump-active-edids-drm diff --git a/packages/sysutils/busybox/package.mk b/packages/sysutils/busybox/package.mk index 272aa4dc2f..59c1034f07 100644 --- a/packages/sysutils/busybox/package.mk +++ b/packages/sysutils/busybox/package.mk @@ -122,7 +122,11 @@ makeinstall_host() { makeinstall_target() { mkdir -p ${INSTALL}/usr/bin - [ ${TARGET_ARCH} = x86_64 ] && cp ${PKG_DIR}/scripts/getedid ${INSTALL}/usr/bin + if [ ${TARGET_ARCH} = x86_64 ]; then + cp ${PKG_DIR}/scripts/getedid ${INSTALL}/usr/bin + else + cp ${PKG_DIR}/scripts/dump-active-edids-drm ${INSTALL}/usr/bin/dump-active-edids + fi cp ${PKG_DIR}/scripts/create-edid-cpio ${INSTALL}/usr/bin/ cp ${PKG_DIR}/scripts/createlog ${INSTALL}/usr/bin/ cp ${PKG_DIR}/scripts/dthelper ${INSTALL}/usr/bin diff --git a/packages/sysutils/busybox/scripts/dump-active-edids-drm b/packages/sysutils/busybox/scripts/dump-active-edids-drm new file mode 100755 index 0000000000..2dd4af57c1 --- /dev/null +++ b/packages/sysutils/busybox/scripts/dump-active-edids-drm @@ -0,0 +1,42 @@ +#!/bin/sh + +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021-present Team LibreELEC (https://libreelec.tv) + +EDID_DIR="/storage/.config/firmware/edid" +CONNECTORS="" + +if [ "$1" = "-q" ]; then + VERBOSE=0 +else + VERBOSE=1 +fi + +info() { + [ "${VERBOSE}" = "1" ] && echo "$@" +} + +mkdir -p "${EDID_DIR}" + +for c in /sys/class/drm/card?-* ; do + [ ! -d "$c" ] && continue + [ ! -e "$c/status" ] && continue + + if [ $(cat $c/status 2>/dev/null) = "connected" ]; then + CONNECTOR=$(basename $c | cut -c 7-) + EDID_NAME="edid-${CONNECTOR}.bin" + cat $c/edid > "${EDID_DIR}/${EDID_NAME}" 2>/dev/null + if [ $? -eq 0 ]; then + [ -n "${CONNECTORS}" ] && CONNECTORS="${CONNECTORS} " + CONNECTORS="${CONNECTORS}${CONNECTOR}" + fi + fi +done + +if [ -z "${CONNECTORS}" ]; then + info "error: no active connectors found" + exit 1 +else + info "found active connector(s) ${CONNECTORS}" + [ "${VERBOSE}" = "0" ] && echo "${CONNECTORS}" +fi From f962a4b2b6df0990ebd15ca1879f6a34af3f1a29 Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Tue, 23 Mar 2021 16:20:22 +0100 Subject: [PATCH 3/4] busybox: add script to modify edid override with RPi bootloader The script supports two operations: "set" enables initramfs cpio in config.txt and adds edid and video override kernel options for the specified connectors to cmdline.txt "delete" removes edid.cpio initramfs loading in config.txt and removes all edid override and video options from cmdline.txt Signed-off-by: Matthias Reichl --- packages/sysutils/busybox/package.mk | 3 + .../scripts/update-bootloader-edid-rpi | 95 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100755 packages/sysutils/busybox/scripts/update-bootloader-edid-rpi diff --git a/packages/sysutils/busybox/package.mk b/packages/sysutils/busybox/package.mk index 59c1034f07..a84111a2b6 100644 --- a/packages/sysutils/busybox/package.mk +++ b/packages/sysutils/busybox/package.mk @@ -128,6 +128,9 @@ makeinstall_target() { cp ${PKG_DIR}/scripts/dump-active-edids-drm ${INSTALL}/usr/bin/dump-active-edids fi cp ${PKG_DIR}/scripts/create-edid-cpio ${INSTALL}/usr/bin/ + if [ "${PROJECT}" = "RPi" ]; then + cp ${PKG_DIR}/scripts/update-bootloader-edid-rpi ${INSTALL}/usr/bin/update-bootloader-edid + fi cp ${PKG_DIR}/scripts/createlog ${INSTALL}/usr/bin/ cp ${PKG_DIR}/scripts/dthelper ${INSTALL}/usr/bin ln -sf dthelper ${INSTALL}/usr/bin/dtfile diff --git a/packages/sysutils/busybox/scripts/update-bootloader-edid-rpi b/packages/sysutils/busybox/scripts/update-bootloader-edid-rpi new file mode 100755 index 0000000000..1516f3e9d1 --- /dev/null +++ b/packages/sysutils/busybox/scripts/update-bootloader-edid-rpi @@ -0,0 +1,95 @@ +#!/bin/sh + +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021-present Team LibreELEC (https://libreelec.tv) + +EDID_DIR="/storage/.config/firmware/edid" +EDID_CPIO="/flash/edid.cpio" +CONFIG_TXT="/flash/config.txt" +CMDLINE_TXT="/flash/cmdline.txt" + +usage() { + echo "$0 set CONNECTOR... | delete | help" +} + +check_args() { + if [ $# -eq 0 ]; then + echo "error: no connector(s) specified!" + exit 1 + fi + if [ ! -f "${EDID_CPIO}" ]; then + echo "error: ${EDID_CPIO} not present" + exit 1 + fi + for conn in "$@"; do + if [ ! -f "${EDID_DIR}/edid-${conn}.bin" ]; then + echo "error: ${EDID_DIR}/edid-${conn}.bin not present" + exit 1 + fi + done +} + +cleanup_config_txt() { + sed -i "/^initramfs edid\.cpio/d" ${CONFIG_TXT} +} + +get_cleaned_cmdline_txt() { + sed \ + -e 's| drm\.edid_firmware=[^ ]*||g' \ + -e 's| video=[^ ]*||g' \ + ${CMDLINE_TXT} +} + +add_initramfs() { + # make sure config.txt ends with a newline + if [ "$(tail -c 1 ${CONFIG_TXT} | tr -c -d '\n' | tr '\n' 'X')" != "X" ]; then + echo "" >> ${CONFIG_TXT} + fi + echo "initramfs edid.cpio" >> ${CONFIG_TXT} +} + +add_cmdline() { + CMDLINE=$(get_cleaned_cmdline_txt) + FIRMWARE="" + VIDEO="" + for conn in "$@"; do + VIDEO="${VIDEO} video=${conn}:D" + [ -n "${FIRMWARE}" ] && FIRMWARE="${FIRMWARE}," + FIRMWARE="${FIRMWARE}${conn}:edid/edid-${conn}.bin" + done + echo "${CMDLINE} drm.edid_firmware=${FIRMWARE}${VIDEO}" > ${CMDLINE_TXT} +} + +set_edids() { + check_args "$@" + mount -o remount,rw /flash + cleanup_config_txt + add_initramfs + add_cmdline "$@" + mount -o remount,ro /flash +} + +delete_edids() { + mount -o remount,rw /flash + cleanup_config_txt + CMDLINE=$(get_cleaned_cmdline_txt) + echo "${CMDLINE}" > ${CMDLINE_TXT} + mount -o remount,ro /flash +} + +case $1 in + set) + shift + set_edids "$@" + ;; + delete) + delete_edids + ;; + help) + usage + ;; + *) + usage + exit 1 + ;; +esac From 76fd023bb049537a27473c1749277dc83d5f283f Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Tue, 23 Mar 2021 16:25:27 +0100 Subject: [PATCH 4/4] busybox: add getedid script for RPi The getedid script supports the "create" and "delete" options like the x86 version. It makes use of the "dump-active-edids", "create-edid-cpio" and "update-bootloader-edid" scripts and can be used as is on other DRM platforms as well as it doesn't contain any RPi specific code. Signed-off-by: Matthias Reichl --- packages/sysutils/busybox/package.mk | 1 + packages/sysutils/busybox/scripts/getedid-drm | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100755 packages/sysutils/busybox/scripts/getedid-drm diff --git a/packages/sysutils/busybox/package.mk b/packages/sysutils/busybox/package.mk index a84111a2b6..ae002922f0 100644 --- a/packages/sysutils/busybox/package.mk +++ b/packages/sysutils/busybox/package.mk @@ -130,6 +130,7 @@ makeinstall_target() { cp ${PKG_DIR}/scripts/create-edid-cpio ${INSTALL}/usr/bin/ if [ "${PROJECT}" = "RPi" ]; then cp ${PKG_DIR}/scripts/update-bootloader-edid-rpi ${INSTALL}/usr/bin/update-bootloader-edid + cp ${PKG_DIR}/scripts/getedid-drm ${INSTALL}/usr/bin/getedid fi cp ${PKG_DIR}/scripts/createlog ${INSTALL}/usr/bin/ cp ${PKG_DIR}/scripts/dthelper ${INSTALL}/usr/bin diff --git a/packages/sysutils/busybox/scripts/getedid-drm b/packages/sysutils/busybox/scripts/getedid-drm new file mode 100755 index 0000000000..2b8d7d3627 --- /dev/null +++ b/packages/sysutils/busybox/scripts/getedid-drm @@ -0,0 +1,55 @@ +#!/bin/sh + +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021-present Team LibreELEC (https://libreelec.tv) + +usage() { + echo "$0 create|delete|help" +} + +delete_edid() { + update-bootloader-edid delete + if [ $? -eq 0 ]; then + echo "successfully removed edid override" + else + echo "error removing bootloader edid-override options" + exit 1 + fi +} + +create_edid() { + CONNECTORS=$(dump-active-edids -q) + if [ $? -ne 0 -o -z "${CONNECTORS}" ]; then + echo "error: cannot detemine active connectors" + exit 1 + fi + create-edid-cpio -q + if [ $? -ne 0 ]; then + echo "error creating edid.cpio" + exit 1 + fi + update-bootloader-edid set ${CONNECTORS} + if [ $? -eq 0 ]; then + echo "successfully installed edid override for ${CONNECTORS}" + else + echo "error setting bootloader edid-override options" + exit 1 + fi +} + +case $1 in + create) + shift + create_edid "$@" + ;; + delete) + delete_edid + ;; + help) + usage + ;; + *) + usage + exit 1 + ;; +esac