Guest User

rpi4

a guest
Jun 29th, 2019
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 13.82 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # This file is part of The RetroPie Project
  4. #
  5. # The RetroPie Project is the legal property of its developers, whose names are
  6. # too numerous to list here. Please refer to the COPYRIGHT.md file distributed with this source.
  7. #
  8. # See the LICENSE.md file at the top-level directory of this distribution and
  9. # at https://raw.githubusercontent.com/RetroPie/RetroPie-Setup/master/LICENSE.md
  10. #
  11.  
  12. function setup_env() {
  13.  
  14.     __ERRMSGS=()
  15.     __INFMSGS=()
  16.  
  17.     # if no apt-get we need to fail
  18.     [[ -z "$(which apt-get)" ]] && fatalError "Unsupported OS - No apt-get command found"
  19.  
  20.     __memory_phys=$(free -m | awk '/^Mem:/{print $2}')
  21.     __memory_total=$(free -m -t | awk '/^Total:/{print $2}')
  22.  
  23.     __has_binaries=0
  24.  
  25.     get_platform
  26.     get_os_version
  27.     get_retropie_depends
  28.  
  29.     __gcc_version=$(gcc -dumpversion)
  30.  
  31.     # workaround for GCC ABI incompatibility with threaded armv7+ C++ apps built
  32.     # on Raspbian's armv6 userland https://github.com/raspberrypi/firmware/issues/491
  33.     if [[ "$__os_id" == "Raspbian" ]] && compareVersions $__gcc_version lt 5.0.0; then
  34.         __default_cxxflags+=" -U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2"
  35.     fi
  36.  
  37.     # set location of binary downloads
  38.     __binary_host="files.retropie.org.uk"
  39.     [[ "$__has_binaries" -eq 1 ]] && __binary_url="https://$__binary_host/binaries/$__os_codename/$__platform"
  40.  
  41.     __archive_url="https://files.retropie.org.uk/archives"
  42.  
  43.     # -pipe is faster but will use more memory - so let's only add it if we have more thans 256M free ram.
  44.     [[ $__memory_phys -ge 512 ]] && __default_cflags+=" -pipe"
  45.  
  46.     [[ -z "${CFLAGS}" ]] && export CFLAGS="${__default_cflags}"
  47.     [[ -z "${CXXFLAGS}" ]] && export CXXFLAGS="${__default_cxxflags}"
  48.     [[ -z "${ASFLAGS}" ]] && export ASFLAGS="${__default_asflags}"
  49.     [[ -z "${MAKEFLAGS}" ]] && export MAKEFLAGS="${__default_makeflags}"
  50.  
  51.     # test if we are in a chroot
  52.     if [[ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]]; then
  53.         [[ -z "$QEMU_CPU" && -n "$__qemu_cpu" ]] && export QEMU_CPU=$__qemu_cpu
  54.         __chroot=1
  55.     else
  56.         __chroot=0
  57.     fi
  58.  
  59.     if [[ -z "$__nodialog" ]]; then
  60.         __nodialog=0
  61.     fi
  62. }
  63.  
  64. function get_os_version() {
  65.     # make sure lsb_release is installed
  66.     getDepends lsb-release
  67.  
  68.     # get os distributor id, description, release number and codename
  69.     local os
  70.     mapfile -t os < <(lsb_release -sidrc)
  71.     __os_id="${os[0]}"
  72.     __os_desc="${os[1]}"
  73.     __os_release="${os[2]}"
  74.     __os_codename="${os[3]}"
  75.    
  76.     local error=""
  77.     case "$__os_id" in
  78.         Raspbian|Debian)
  79.             # get major version (8 instead of 8.0 etc)
  80.             __os_debian_ver="${__os_release%%.*}"
  81.  
  82.             # Debian unstable is not officially supported though
  83.             if [[ "$__os_release" == "unstable" ]]; then
  84.                 __os_debian_ver=11
  85.             fi
  86.  
  87.             if compareVersions "$__os_debian_ver" lt 8; then
  88.                 error="You need Raspbian/Debian Stretch or newer"
  89.             fi
  90.  
  91.             # set a platform flag for osmc
  92.             if grep -q "ID=osmc" /etc/os-release; then
  93.                 __platform_flags+=" osmc"
  94.             fi
  95.  
  96.             # and for xbian
  97.             if grep -q "NAME=XBian" /etc/os-release; then
  98.                 __platform_flags+=" xbian"
  99.             fi
  100.  
  101.             # we provide binaries for RPI on Raspbian 9 only
  102.             if isPlatform "rpi" && compareVersions "$__os_debian_ver" gt 8 && compareVersions "$__os_debian_ver" lt 10; then
  103.                 __has_binaries=1
  104.             fi
  105.             ;;
  106.         Devuan)
  107.             if isPlatform "rpi"; then
  108.                 error="We do not support Devuan on the Raspberry Pi. We recommend you use Raspbian to run RetroPie."
  109.             fi
  110.             # devuan lsb-release version numbers don't match jessie
  111.             case "$__os_codename" in
  112.                 jessie)
  113.                     __os_debian_ver="8"
  114.                     ;;
  115.                 ascii)
  116.                     __os_debian_ver="9"
  117.                     ;;
  118.                 beowolf)
  119.                     __os_debian_ver="10"
  120.                     ;;
  121.                 ceres)
  122.                     __os_debian_ver="11"
  123.                     ;;
  124.             esac
  125.             ;;
  126.         LinuxMint)
  127.             if [[ "$__os_desc" != LMDE* ]]; then
  128.                 if compareVersions "$__os_release" lt 18; then
  129.                     error="You need Linux Mint 18 or newer"
  130.                 elif compareVersions "$__os_release" lt 19; then
  131.                     __os_ubuntu_ver="16.04"
  132.                     __os_debian_ver="8"
  133.                 else
  134.                     __os_ubuntu_ver="18.04"
  135.                     __os_debian_ver="9"
  136.                 fi
  137.             fi
  138.             ;;
  139.         Ubuntu)
  140.             if compareVersions "$__os_release" lt 16.04; then
  141.                 error="You need Ubuntu 16.04 or newer"
  142.             elif compareVersions "$__os_release" lt 16.10; then
  143.                 __os_debian_ver="8"
  144.             else
  145.                 __os_debian_ver="9"
  146.             fi
  147.             __os_ubuntu_ver="$__os_release"
  148.             ;;
  149.         Deepin)
  150.             if compareVersions "$__os_release" lt 15.5; then
  151.                 error="You need Deepin OS 15.5 or newer"
  152.             fi
  153.             __os_debian_ver="9"
  154.             ;;
  155.         elementary)
  156.             if compareVersions "$__os_release" lt 0.4; then
  157.                 error="You need Elementary OS 0.4 or newer"
  158.             elif compareVersions "$__os_release" eq 0.4; then
  159.                 __os_ubuntu_ver="16.04"
  160.                 __os_debian_ver="8"
  161.             else
  162.                 __os_ubuntu_ver="18.04"
  163.                 __os_debian_ver="9"
  164.             fi
  165.             ;;
  166.         neon)
  167.             __os_ubuntu_ver="$__os_release"
  168.             if compareVersions "$__os_release" lt 16.10; then
  169.                 __os_debian_ver="8"
  170.             else
  171.                 __os_debian_ver="9"
  172.             fi
  173.             ;;
  174.         *)
  175.             error="Unsupported OS"
  176.             ;;
  177.     esac
  178.    
  179.     [[ -n "$error" ]] && fatalError "$error\n\n$(lsb_release -idrc)"
  180.  
  181.     # add 32bit/64bit to platform flags
  182.     __platform_flags+=" $(getconf LONG_BIT)bit"
  183.  
  184.     # configure Raspberry Pi graphics stack
  185.     isPlatform "rpi" && get_rpi_video
  186. }
  187.  
  188. function get_retropie_depends() {
  189.     local depends=(git dialog wget gcc g++ build-essential unzip xmlstarlet python-pyudev ca-certificates)
  190.  
  191.     if ! getDepends "${depends[@]}"; then
  192.         fatalError "Unable to install packages required by $0 - ${md_ret_errors[@]}"
  193.     fi
  194.  
  195.     # make sure we don't have xserver-xorg-legacy installed as it breaks launching x11 apps from ES
  196.     if ! isPlatform "x11" && hasPackage "xserver-xorg-legacy"; then
  197.         aptRemove xserver-xorg-legacy
  198.     fi
  199. }
  200.  
  201. function get_rpi_video() {
  202.     local pkgconfig="/opt/vc/lib/pkgconfig"
  203.  
  204.     # detect driver via inserted module / platform driver setup
  205.     if [[ -d "/sys/module/vc4" ]]; then
  206.         __platform_flags+=" mesa kms"
  207.         [[ "$(ls -A /sys/bus/platform/drivers/vc4_firmware_kms/*.firmwarekms 2>/dev/null)" ]] && __platform_flags+=" dispmanx"
  208.     else
  209.         __platform_flags+=" videocore dispmanx"
  210.     fi
  211.  
  212.     # use our supplied fallback pkgconfig if necessary
  213.     [[ ! -d "$pkgconfig" ]] && pkgconfig="$scriptdir/pkgconfig"
  214.  
  215.     # set pkgconfig path for vendor libraries
  216.     export PKG_CONFIG_PATH="$pkgconfig"
  217. }
  218.  
  219. function get_platform() {
  220.     local architecture="$(uname --machine)"
  221.     if [[ -z "$__platform" ]]; then
  222.         case "$(sed -n '/^Hardware/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo)" in
  223.             BCM*)
  224.                 # calculated based on information from https://github.com/AndrewFromMelbourne/raspberry_pi_revision
  225.                 local rev="0x$(sed -n '/^Revision/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo)"
  226.                 # if bit 23 is not set, we are on a rpi1 (bit 23 means the revision is a bitfield)
  227.                 if [[ $((($rev >> 23) & 1)) -eq 0 ]]; then
  228.                     __platform="rpi1"
  229.                 else
  230.                     # if bit 23 is set, get the cpu from bits 12-15
  231.                     local cpu=$((($rev >> 12) & 15))
  232.                     case $cpu in
  233.                         0)
  234.                             __platform="rpi1"
  235.                             ;;
  236.                         1)
  237.                             __platform="rpi2"
  238.                             ;;
  239.                         2)
  240.                             __platform="rpi3"
  241.                             ;;
  242.                         3)
  243.                             __platform="rpi4"
  244.                             ;;
  245.                     esac
  246.                 fi
  247.                 ;;
  248.             ODROIDC)
  249.                 __platform="odroid-c1"
  250.                 ;;
  251.             ODROID-C2)
  252.                 __platform="odroid-c2"
  253.                 ;;
  254.             "Freescale i.MX6 Quad/DualLite (Device Tree)")
  255.                 __platform="imx6"
  256.                 ;;
  257.             ODROID-XU[34])
  258.                 __platform="odroid-xu"
  259.                 ;;
  260.             "Rockchip (Device Tree)")
  261.                 __platform="tinker"
  262.                 ;;
  263.             Vero4K)
  264.                 __platform="vero4k"
  265.                 ;;
  266.             "Allwinner sun8i Family")
  267.                 __platform="armv7-mali"
  268.                 ;;
  269.             *)
  270.                 case $architecture in
  271.                     i686|x86_64|amd64)
  272.                         __platform="x86"
  273.                         ;;
  274.                 esac
  275.                 ;;
  276.         esac
  277.     fi
  278.  
  279.     if ! fnExists "platform_${__platform}"; then
  280.         fatalError "Unknown platform - please manually set the __platform variable to one of the following: $(compgen -A function platform_ | cut -b10- | paste -s -d' ')"
  281.     fi
  282.  
  283.     platform_${__platform}
  284.     [[ -z "$__default_cxxflags" ]] && __default_cxxflags="$__default_cflags"
  285. }
  286.  
  287. function platform_rpi1() {
  288.     # values to be used for configure/make
  289.     __default_cflags="-O2 -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard"
  290.     __default_asflags=""
  291.     __default_makeflags=""
  292.     __platform_flags="arm armv6 rpi gles"
  293.     # if building in a chroot, what cpu should be set by qemu
  294.     # make chroot identify as arm6l
  295.     __qemu_cpu=arm1176
  296. }
  297.  
  298. function platform_rpi2() {
  299.     __default_cflags="-O2 -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
  300.     __default_asflags=""
  301.     __default_makeflags="-j2"
  302.     __platform_flags="arm armv7 neon rpi gles"
  303.     __qemu_cpu=cortex-a7
  304. }
  305.  
  306. # note the rpi3 currently uses the rpi2 binaries - for ease of maintenance - rebuilding from source
  307. # could improve performance with the compiler options below but needs further testing
  308. function platform_rpi3() {
  309.     __default_cflags="-O2 -march=armv8-a+crc -mtune=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
  310.     __default_asflags=""
  311.     __default_makeflags="-j2"
  312.     __platform_flags="arm armv8 neon rpi gles"
  313. }
  314.  
  315. function platform_rpi4() {
  316.     __default_cflags="-O2 -march=armv8-a+crc -mtune=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
  317.     __default_asflags=""
  318.     __default_makeflags="-j2"
  319.     __platform_flags="arm armv8 neon rpi gles"
  320. }
  321.  
  322. function platform_odroid-c1() {
  323.     __default_cflags="-O2 -mcpu=cortex-a5 -mfpu=neon-vfpv4 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
  324.     __default_asflags=""
  325.     __default_makeflags="-j2"
  326.     __platform_flags="arm armv7 neon mali gles"
  327.     __qemu_cpu=cortex-a9
  328. }
  329.  
  330. function platform_odroid-c2() {
  331.     if [[ "$(getconf LONG_BIT)" -eq 32 ]]; then
  332.         __default_cflags="-O2 -march=armv8-a+crc -mtune=cortex-a53 -mfpu=neon-fp-armv8"
  333.         __platform_flags="arm armv8 neon mali gles"
  334.     else
  335.         __default_cflags="-O2 -march=native"
  336.         __platform_flags="aarch64 mali gles"
  337.     fi
  338.     __default_cflags+=" -ftree-vectorize -funsafe-math-optimizations"
  339.     __default_asflags=""
  340.     __default_makeflags="-j2"
  341. }
  342.  
  343. function platform_odroid-xu() {
  344.     __default_cflags="-O2 -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
  345.     # required for mali-fbdev headers to define GL functions
  346.     __default_cflags+=" -DGL_GLEXT_PROTOTYPES"
  347.     __default_asflags=""
  348.     __default_makeflags="-j2"
  349.     __platform_flags="arm armv7 neon mali gles"
  350. }
  351.  
  352. function platform_tinker() {
  353.     __default_cflags="-O2 -marm -march=armv7-a -mtune=cortex-a17 -mfpu=neon-vfpv4 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
  354.     # required for mali headers to define GL functions
  355.     __default_cflags+=" -DGL_GLEXT_PROTOTYPES"
  356.     __default_asflags=""
  357.     __default_makeflags="-j2"
  358.     __platform_flags="arm armv7 neon kms gles"
  359. }
  360.  
  361. function platform_x86() {
  362.     __default_cflags="-O2 -march=native"
  363.     __default_asflags=""
  364.     __default_makeflags="-j$(nproc)"
  365.     __platform_flags="x11 gl"
  366. }
  367.  
  368. function platform_generic-x11() {
  369.     __default_cflags="-O2"
  370.     __default_asflags=""
  371.     __default_makeflags="-j$(nproc)"
  372.     __platform_flags="x11 gl"
  373. }
  374.  
  375. function platform_armv7-mali() {
  376.     __default_cflags="-O2 -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
  377.     __default_asflags=""
  378.     __default_makeflags="-j$(nproc)"
  379.     __platform_flags="arm armv7 neon mali gles"
  380. }
  381.  
  382. function platform_imx6() {
  383.     __default_cflags="-O2 -march=armv7-a -mfpu=neon -mtune=cortex-a9 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
  384.     __default_asflags=""
  385.     __default_makeflags="-j2"
  386.     __platform_flags="arm armv7 neon"
  387. }
  388.  
  389. function platform_vero4k() {
  390.     __default_cflags="-I/opt/vero3/include -L/opt/vero3/lib -O2 -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -ftree-vectorize -funsafe-math-optimizations"
  391.     __default_asflags=""
  392.     __default_makeflags="-j4"
  393.     __platform_flags="arm armv7 neon vero4k gles"
  394. }
Advertisement
Add Comment
Please, Sign In to add comment