Files
build/packages/bsp/rk322x/rk322x-config
Paolo 23604e8a0d Introducing Rockchip RK322X SoC support (#2032)
* Introducing Rockchip rk322x SoC support

Main features:

- Legacy kernel flavour based upon stable v2.x rk3288 Rockchip branch (https://github.com/rockchip-linux/kernel/tree/stable-4.4-rk3288-linux-v2.x)
- Current kernel flavour based on mainline 5.6.y kernel
- Mainline u-boot (v2020.04)
- Single generic tv box target (rk322x-box) which boots on all the known tv boxes
- Hardware devices (eMMC/NAND, led wiring configuration, SoC variant selection) modulation done by user at runtime via device tree overlays - a script (rk322x-config) is provided for autodetection and simple configuration by inexperienced users;
- Bits added to armbian-hardware-optimization to set affinity for irq handlers
- rk322x-box targets already added to targets.conf for automatic image creation

* Removed disabled patches
* Restored mysteriously removed comment character
2020-06-19 17:27:27 +02:00

406 lines
9.2 KiB
Bash
Executable File

#!/bin/bash
DEVICE_TREE_PATH="/boot/dtb"
DEVICE_TREE_GLOB="rk322*-box*.dtb"
ARMBIAN_ENV_TXT="/boot/armbianEnv.txt"
BLACKLIST_MODPROBE_CONF="/etc/modprobe.d/blacklist-rk322x-box.conf"
BACKTITLE="Armbian RK322x device tree board selection | Paolo Sabatino"
TITLE="Board configuration"
MENU_TITLE="Please choose your board"
CONFIRM_FLASH_MISMATCH="\nYour board has a type of internal memory but you \
selected a board without support for that.\n\nYou will not be able to detect \
the internal memory and your system may not boot anymore\n\nAre you sure?"
COLOR_RED="\Z1"
COLOR_BLACK="\Z0"
EFUSE_PATH="/sys/bus/nvmem/devices/rockchip-efuse0/nvmem"
SDIO_WIFI_PATH="/sys/bus/sdio/devices/mmc1:0001:1"
EMMC_DEVICE_PATH="/sys/bus/mmc/devices/mmc2:0001"
NAND_DEVICE_PATH="/sys/block/rknand0/device"
declare -A CHIP_IDS
declare -A WIFI_NAMES
declare -A WIFI_CHIPS
declare -A DT_FLASH_OVERLAYS
declare -A DT_LED_OVERLAYS
declare -A DT_CPU_OVERLAYS
# Declarations for the various SoCs IDs
CHIP_IDS+=(["524b2382"]="RK3228A/B")
CHIP_IDS+=(["524b2392"]="RK3229")
# Declarations for the various Wifi IDs
WIFI_NAMES+=(["3030:3030"]="South Silicon Valley 6051p/6256p")
WIFI_NAMES+=(["024c:b703"]="Realtek RTL8703bs")
WIFI_NAMES+=(["024c:8179"]="Realtek RTL8189ES/ETV")
# Declarations for the various wifi IDs -> kernel modules
WIFI_CHIPS+=(["3030:3030"]=ssv6051)
WIFI_CHIPS+=(["024c:b703"]=8723cs)
WIFI_CHIPS+=(["024c:8179"]=8189es)
# Declarations for device tree overlays
DT_FLASH_OVERLAYS+=(["emmc"]="eMMC only flash memory")
DT_FLASH_OVERLAYS+=(["nand"]="NAND only flash memory")
DT_FLASH_OVERLAYS+=(["emmc-nand"]="eMMC or NAND flash memory")
DT_LED_OVERLAYS+=(["led-conf1"]="LED configuration #1 (Chiptrip)")
DT_LED_OVERLAYS+=(["led-conf2"]="LED configuration #2 (R329q)")
DT_CPU_OVERLAYS+=(["cpu-hs"]="RK3228B or RK3229")
KERNEL_VERSION=$(uname -r | cut -d "-" -f 1)
if [[ "$KERNEL_VERSION" < "4.5.0" ]]; then
LEGACY_KERNEL=1
else
LEGACY_KERNEL=0
fi
DT_OVERLAY_PREFIX="$(grep overlay_prefix /boot/armbianEnv.txt | cut -d "=" -f 2)-"
# Query the efuse to get the chip type.
# Not always reliable, but often.
function get_chip_type() {
CHIP_ID=$(od -A none -N 4 -tx1 $EFUSE_PATH | tr -d " ")
CHIP_TYPE=${CHIP_IDS[$CHIP_ID]}
CHIP_TYPE=${CHIP_TYPE:-"unknown"}
echo $CHIP_TYPE
return 0
}
# Get the chip serial, from bytes 7 to 22 of the efuse
function get_chip_serial() {
ASCII_PART=$(od -A none -j 7 -N 9 -tc $EFUSE_PATH | tr -d " ")
BIN_PART=$(od -A none -j 16 -N 7 -tx1 $EFUSE_PATH | tr -d " ")
echo "$ASCII_PART $BIN_PART"
return 0
}
# Get the cpu leakage, byte 23 of the efuse
function get_cpu_leakage() {
LEAKAGE=$(od -A none -j 23 -N 1 -tx1 $EFUSE_PATH | tr -d " ")
echo $LEAKAGE
return 0
}
# Get the logic leakage, byte 25 of the efuse
function get_logic_leakage() {
LEAKAGE=$(od -A none -j 25 -N 1 -tx1 $EFUSE_PATH | tr -d " ")
echo $LEAKAGE
return 0
}
# Get the vendor and device ids of the wifi chip
function get_wifi_chip_id() {
if [ -d "$SDIO_WIFI_PATH" ]; then
VENDOR=$(cut -c 3- "$SDIO_WIFI_PATH/vendor")
DEVICE=$(cut -c 3- "$SDIO_WIFI_PATH/device")
echo "$VENDOR:$DEVICE"
return 0
fi
return 1
}
function get_internal_flash_type() {
if [ -d "$EMMC_DEVICE_PATH" ]; then
echo "eMMC"
elif [ -d "$NAND_DEVICE_PATH" ]; then
echo "NAND"
fi
return 0
}
# Blacklists all the modules buth whitelist only that one
# that has been detected
function apply_wifi_blacklist() {
WIFI_ID=$1
# Detect wifi chip on legacy kernel and unblacklist it
WIFI_MODULE=""
if [ -n "$WIFI_ID" ]; then
# blacklist all the modules and unblacklist only the one which is matching
WIFI_MODULE="${WIFI_CHIPS[$WIFI_ID]}"
if [ ! -f $BLACKLIST_MODPROBE_CONF ]; then
touch $BLACKLIST_MODPROBE_CONF
fi
if [ -n "$WIFI_MODULE" ]; then
for MODULE in "${WIFI_CHIPS[@]}"; do
sed -i "/blacklist $MODULE/d" $BLACKLIST_MODPROBE_CONF
done
declare -A BLACKLIST_MODULES
for VALUE in "${WIFI_CHIPS[@]}"; do
if [ "$VALUE" != "$WIFI_MODULE" ]; then
BLACKLIST_MODULES+=([$VALUE]=1)
fi
done
for MODULE in "${!BLACKLIST_MODULES[@]}"; do
echo "blacklist $MODULE" >> $BLACKLIST_MODPROBE_CONF
done
echo "#blacklist $WIFI_MODULE" >> $BLACKLIST_MODPROBE_CONF
fi
fi
# unsupported wifi_chip_type: blacklist all known wifi
# modules if the blacklist file exists. If the blacklist file does not exist just skip over
if [ -z $WIFI_MODULE ]; then
if [ -f $BLACKLIST_MODPROBE_CONF ]; then
for MODULE in "${WIFI_CHIPS[@]}"; do
sed -i "s/#blacklist $MODULE/blacklist $MODULE/g" $BLACKLIST_MODPROBE_CONF
done
fi
fi
echo $WIFI_MODULE
return 0
}
function select_soc() {
declare -a DIALOG_ENTRIES
# SoC section
SELECTION="0"
[[ "$CHIP_TYPE" = "RK3229" ]] && SELECTION="2"
DIALOG_ENTRIES=("0" "RK3228A (max 1.2Ghz)")
DIALOG_ENTRIES+=("1" "RK3228B (max 1.4Ghz)")
DIALOG_ENTRIES+=("2" "RK3229 (max 1.4Ghz)")
MENU_TITLE="${BOARD_INFO}Select the SoC type\n"
MENU_CMD=(dialog --colors --backtitle "$BACKTITLE" --title "$TITLE" --default-item "$SELECTION" --menu "$MENU_TITLE" 24 0 20)
SELECTION=$("${MENU_CMD[@]}" "${DIALOG_ENTRIES[@]}" 2>&1 >/dev/tty)
RET=$?
if [ "$RET" -eq 1 ]; then
echo "Cancelled"
return 1
fi
if [ "$RET" -ne 0 ]; then
echo "dialog utility returned an unexpected error code: $RET"
return 1
fi
[[ "$SELECTION" -eq 0 ]] && SELECTION=""
[[ "$SELECTION" -eq 1 ]] && SELECTION="cpu-hs"
[[ "$SELECTION" -eq 2 ]] && SELECTION="cpu-hs"
echo $SELECTION
return 0
}
function select_flash() {
declare -a DIALOG_ENTRIES
SELECTION="emmc-nand"
[[ "$FLASH_TYPE" = "eMMC" ]] && SELECTION="emmc"
[[ "$FLASH_TYPE" = "NAND" ]] && SELECTION="nand"
for KEY in "${!DT_FLASH_OVERLAYS[@]}"; do
DIALOG_ENTRIES+=($KEY "${DT_FLASH_OVERLAYS[$KEY]}")
done
MENU_TITLE="${BOARD_INFO}Select the internal flash type\n"
MENU_CMD=(dialog --colors --backtitle "$BACKTITLE" --title "$TITLE" --default-item "$SELECTION" --menu "$MENU_TITLE" 24 0 20)
SELECTION=$("${MENU_CMD[@]}" "${DIALOG_ENTRIES[@]}" 2>&1 >/dev/tty)
RET=$?
if [ "$RET" -eq 1 ]; then
echo "Cancelled"
return 1
fi
if [ "$RET" -ne 0 ]; then
echo "dialog utility returned an unexpected error code: $RET"
return 1
fi
echo $SELECTION
return 0
}
function select_led_configuration() {
declare -a DIALOG_ENTRIES
for KEY in "${!DT_LED_OVERLAYS[@]}"; do
DIALOG_ENTRIES+=($KEY "${DT_LED_OVERLAYS[$KEY]}")
done
MENU_TITLE="${BOARD_INFO}Select the led wiring configuation\n"
MENU_CMD=(dialog --colors --backtitle "$BACKTITLE" --title "$TITLE" --default-item "$SELECTION" --menu "$MENU_TITLE" 24 0 20)
SELECTION=$("${MENU_CMD[@]}" "${DIALOG_ENTRIES[@]}" 2>&1 >/dev/tty)
RET=$?
if [ "$RET" -eq 1 ]; then
echo "Cancelled"
return 1
fi
if [ "$RET" -ne 0 ]; then
echo "dialog utility returned an unexpected error code: $RET"
return 1
fi
echo $SELECTION
return 0
}
# ----- Entry point -----
USER_ID=$(id -u)
if [ $USER_ID -ne 0 ]; then
echo "Please run this script with administrative privileges"
exit 2
fi
declare -a DT_OVERLAYS_TO_APPLY
CHIP_TYPE=$(get_chip_type)
CHIP_SERIAL=$(get_chip_serial)
CPU_LEAKAGE=$(get_cpu_leakage)
LOGIC_LEAKAGE=$(get_logic_leakage)
WIFI_ID=$(get_wifi_chip_id)
FLASH_TYPE=$(get_internal_flash_type)
if [ -z "$WIFI_ID" ]; then
WIFI_NAME="not available"
else
WIFI_NAME="${WIFI_NAMES[$WIFI_ID]:-"unknown"} - Device ID: ${WIFI_ID}"
fi
if [ -z "$FLASH_TYPE" ]; then
FLASH_NAME="not detected"
else
FLASH_NAME="$FLASH_TYPE"
fi
BOARD_INFO="\nDetected board features:\n\
Chip type: ${COLOR_RED}\Zb${CHIP_TYPE}\Zn${COLOR_BLACK} - \
Serial: $CHIP_SERIAL\n\
CPU Leakage: 0x$CPU_LEAKAGE - Logic Leakage: 0x$LOGIC_LEAKAGE\n\
Internal flash: ${COLOR_RED}\Zb${FLASH_NAME}\Zn${COLOR_BLACK}\n\
Wifi device: $WIFI_NAME\n\n"
### --- SOC selection ---
SELECTION=$(select_soc) || exit 1
DT_OVERLAYS_TO_APPLY+=($SELECTION)
SELECTION=$(select_flash) || exit 1
DT_OVERLAYS_TO_APPLY+=($SELECTION)
SELECTION=$(select_led_configuration) || exit 1
DT_OVERLAYS_TO_APPLY+=($SELECTION)
sed -i '/^overlays=/d' $ARMBIAN_ENV_TXT
if [ $? -ne 0 ]; then
echo "An error occurred while removing existing fdtfile entry from $ARMBIAN_ENV_TXT"
exit 1
fi
echo "overlays=${DT_OVERLAYS_TO_APPLY[@]}" >> $ARMBIAN_ENV_TXT
if [ $? -ne 0 ]; then
echo "An error occurred while adding overlays entry in $ARMBIAN_ENV_TXT"
exit 1
fi
# Apply the wifi blacklist only with legacy kernel
if [[ $LEGACY_KERNEL -eq 1 ]]; then
WIFI_MODULE=$(apply_wifi_blacklist "$WIFI_ID")
fi
echo ""
echo ""
echo "Device tree overlays enabled: ${DT_OVERLAYS_TO_APPLY[@]}"
# Print the outcome of wifi chip selection only with legacy kernel
# Mainline kernel is supposed to work ok by itself with hardware recognition
if [[ $LEGACY_KERNEL -eq 1 ]]; then
if [ -n "$WIFI_MODULE" ]; then
echo "Enabled wifi module $WIFI_MODULE"
fi
if [ -n "$WIFI_ID" ] && [ -z "$WIFI_MODULE" ]; then
echo "Wifi chip $WIFI_ID has been detected, but currently it is unsupported"
echo "Please report to: https://forum.armbian.com/topic/12656-wip-armbian-for-rk322x-devices/"
fi
fi
echo "Reboot the device to make changes effective!"
echo ""