LibreELEC Documentation

repository·master·Indexed 25 days ago

https://github.com/libreelec/libreelec.tv

Documentation for LibreELEC, a minimal Linux distribution optimized for the Kodi media center. Includes detailed guides on creating and configuring packages via package.mk, managing build toolchains (Meson, CMake, Autotools), handling Kodi addons, and device-specific installation and debugging instructions for Amlogic, ARM, NXP, and Qualcomm Dragonboard hardware.

Tokens
24.3K
Snippets
15
Records
143
Agent score
81%

What's inside LibreELEC

  1. Overview of LibreELEC

    master
    LibreELEC is a 'Just enough OS' Linux distribution designed specifically to run the Kodi media center software on various mediacentre hardware platforms. It is a minimal, optimized operating system focused on providing a stable environment for Kodi.
  2. Use ARM project device targets for binary add-on compilation

    master

    The ARM project provides specific device targets designed for compiling a common set of binary add-ons for ARM SoC projects and devices. It also includes an "everything disabled" distro configuration, which can be used to reduce compile times when performing individual or bulk add-on compilations.

    Supported device targets:

    • ARMv7
    • ARMv8
  3. Follow coding standards within `package.mk`

    master

    When defining packages in package.mk, follow these rules for variable management and structure:

    Variable Management

    • Prefixing: Prefix package-specific variables with PKG_ (these are automatically unset before package.mk is sourced).
    • Appending: Use PKG_VAR+=" value" to append to a variable instead of PKG_VAR="${PKG_VAR} value".
    • Git Revisions: Always use the full 40-character revision string.

    Logic & Formatting

    • Indentation: When creating a directory, indent related lines:
      cd ${INSTALL}/blah
        cp -P foo ${INSTALL}/blah
    • Error Handling: While foo && bar is allowed, be careful with package functions that might exit with a non-zero code. Use foo && bar || true or a multi-line if block to prevent unintended exits:
      if foo; then
        bar
      fi
  4. Follow coding standards for build system scripts and config

    master

    When writing executable build scripts or configuration fragments for the LibreELEC build system, adhere to these shell scripting standards:

    Execution & Sourcing

    • Use #!/bin/bash for executable build scripts.
    • Sourced config fragments (e.g., config/functions, config/options, config/arch.*) must not have a shebang.
    • Use . config/blah to source files instead of source config/blah.

    Syntax & Comparisons

    • Use $() for command substitution instead of backticks.
    • String comparison: Use = (not ==).
    • Numeric comparison: Use -eq (not =).
    • Tests: Use [ expr1 -o expr2 ] or [ expr1 -a expr2 ] for simple tests. Use [[ ]] only when regex (=~) or glob/pattern matching is required.
    • Short-circuiting: If [[ ]] should be avoided but short-circuiting is needed, use command grouping: [ test1 ] && { [ test2 ] && [ test3 ]; }.

    Variables & Quoting

    • Use braces for shell variables: ${FOO} instead of $FOO.
    • Always use double-quotes (") around variables to prevent issues with special characters, e.g., cd "${PKG_DIR}/scripts".

    Best Practices

    • Use set -e or set -euo pipefail in scripts that must abort on error.
    • Avoid forking child processes (like sed or cut) if a shell built-in can be used.
    • Keep lines under 90 columns unless necessary for maintainability (e.g., LINUX_DEPENDS).
    • Validate scripts using ShellCheck.
  5. Handle late binding variable assignment in package.mk

    master

    Certain variables like PKG_BUILD and PKG_SOURCE_NAME are only initialized after the package is loaded. To use these variables, you must reference them within the configure_package() function.

    Common variables that require late binding via configure_package() include:

    • PKG_CONFIGURE_SCRIPT
    • PKG_CMAKE_SCRIPT
    • PKG_MESON_SCRIPT

    Additionally, toolchain variables (e.g., TARGET_CFLAGS, CC, LDFLAGS, PKG_CONFIG_PATH) and build-time options (e.g., TARGET_CMAKE_OPTS, HOST_CONFIGURE_OPTS) should be referenced within stage-specific functions (like pre_build_* or pre_configure_*) rather than globally to ensure they are used after being reliably initialized.

    configure_package() {
      # now we know where we're building, assign a value
      PKG_CONFIGURE_SCRIPT="${PKG_BUILD}/gettext-tools/configure"
    }
    
    post_patch() {
      # replace hardcoded stuff
      sed -i ${PKG_CONFIGURE_SCRIPT} 's|hardcoded stuff|variable stuff|'
    }
    
    pre_configure_target() {
      # add extra flag to toolchain default
      CFLAGS="$CFLAGS -DEXTRA_FLAG=yeah"
    }
    
    post_makeinstall_target() {
      # remove unused executable, install what remains
      rm $INSTALL/usr/bin/bigexecutable
    }
  6. Follow coding standards for scripts running on the device

    master

    Scripts intended to run on the LibreELEC device must be compatible with the busybox sh/ash runtime. Bash is not available on the device.

    Requirements

    • Use #!/bin/sh as the shebang.
    • Adhere strictly to the POSIX standard. The following Bash extensions are forbidden:
      • No [[ ]] extended tests (use [ ] instead).
      • No arrays.
      • No source command.
      • No =~ regex.
      • No process substitution.
      • No $'...' escape syntax.

    Validation

    • Use ShellCheck with the --shell=sh flag to ensure POSIX compliance.
  7. Build LibreELEC for RK3576 SoC

    master

    To build a LibreELEC image for the Rockchip RK3576 SoC, use the make image command with the appropriate PROJECT, DEVICE, ARCH, and UBOOT_SYSTEM parameters.

    Depending on your hardware target, use one of the following commands:

    • For roc-pc systems: PROJECT=Rockchip DEVICE=RK3576 ARCH=aarch64 UBOOT_SYSTEM=roc-pc make image

    • For rock-4d systems: PROJECT=Rockchip DEVICE=RK3576 ARCH=aarch64 UBOOT_SYSTEM=rock-4d make image