1#!/bin/bash 2 3soc=$1 4gen=$2 5lanes=$3 6baundary=$4 7input=$9 8 9magic0=70 10magic1=63 11magic2=69 12magic3=65 13code0=00 14code1=43 15code2=00 16code3=00 17# case: vid=0x1d87 did=0x356a 18vid_l=$5 19vid_h=$6 20did_l=$7 21did_h=$8 22 23function usage() 24{ 25 echo "./pcie_idb_config.sh <soc> <gen> <lanes> <uart_baundary> <vid_l> <vid_h> <did_l> <did_h> <input>" 26 echo "like following:" 27 echo "./pcie_idb_config.sh RK3588 3 4 1500000 87 1d 6a 35 bin/rk35/rk3588_pcie_v*.bin" 28 echo "./pcie_idb_config.sh RK3588 3 2 1500000 87 1d 6a 35 bin/rk35/rk3588_pcie_v*.bin" 29 echo "./pcie_idb_config.sh RK3588 3 4 115200 87 1d 6a 35 bin/rk35/rk3568_pcie_v*.bin" 30 echo "./pcie_idb_config.sh RK3568 3 2 1500000 87 1d 6a 35 bin/rk35/rk3588_pcie_v*.bin" 31} 32 33#define PCIE_IDB_CFG_PHY_MODE_SHIFT 0 34#define PCIE_IDB_CFG_PHY_MODE_MASK 3 35#define PCIE_IDB_CFG_PHY_MODE_AGGREGATION PHY_MODE_PCIE_AGGREGATION /**< 4 PCIE3x4 */ 36#define PCIE_IDB_CFG_PHY_MODE_NANBNB PHY_MODE_PCIE_NANBNB /**< 0 P1:PCIE3x2 + P0:PCIE3x2 */ 37#define PCIE_IDB_CFG_PHY_MODE_NANBBI PHY_MODE_PCIE_NANBBI /**< 1 P1:PCIE3x2 + P0:PCIE3x1*2 */ 38#define PCIE_IDB_CFG_PHY_MODE_NABINB PHY_MODE_PCIE_NABINB /**< 2 P1:PCIE3x1*2 + P0:PCIE3x2 */ 39#define PCIE_IDB_CFG_PHY_MODE_NABIBI PHY_MODE_PCIE_NABIBI /**< 3 P1:PCIE3x1*2 + P0:PCIE3x1*2 */ 40#define PCIE_IDB_CFG_GEN_SHIFT 8 41#define PCIE_IDB_CFG_GEN_MASK 3 42#define PCIE_IDB_CFG_LANE_SHIFT 12 43#define PCIE_IDB_CFG_LANE_MASK 3 44#define PCIE_IDB_CFG_UART_ID_SHIFT 16 45#define PCIE_IDB_CFG_UART_ID_MASK 3 46#define PCIE_IDB_CFG_UART_MUX_SHIFT 20 47#define PCIE_IDB_CFG_UART_MUX_MASK 3 48#define PCIE_IDB_CFG_UART_RATE_SHIFT 24 49#define PCIE_IDB_CFG_UART_RATE_MASK 2 50#define PCIE_IDB_CFG_UART_RATE_DEFAULT 0 51#define PCIE_IDB_CFG_UART_RATE_15000000 1 52#define PCIE_IDB_CFG_UART_RATE_1152000 2 53 54if [[ $soc != RK3588 && $soc != RK3568 ]]; then 55 echo "input param soc=$soc invalid, support RK3588/RK3568" 56 usage 57 exit 58fi 59 60if [[ $soc == RK3588 ]]; then 61 if [[ $gen != 3 ]]; then 62 echo "input param gen=$gen invalid, support 3" 63 usage 64 exit 65 fi 66 67 if [[ $lanes != 4 && $lanes != 2 && $lanes != 1 ]]; then 68 echo "input param lanes=$lanes invalid, support 4/2/1" 69 usage 70 exit 71 fi 72 73 if [[ $baundary != 1500000 && $baundary != 115200 ]]; then 74 echo "input param baundary=$baundary invalid, support 1500000/115200" 75 usage 76 exit 77 fi 78fi 79 80if [[ $soc == RK3568 ]]; then 81 if [[ $gen != 3 ]]; then 82 echo "input param gen=$gen invalid, support 3" 83 usage 84 exit 85 fi 86 87 if [[ $lanes != 2 ]]; then 88 echo "input param lanes=$lanes invalid, support 2" 89 usage 90 exit 91 fi 92 93 if [[ $baundary != 1500000 ]]; then 94 echo "input param baundary=$baundary invalid, support 1500000" 95 usage 96 exit 97 fi 98fi 99 100if [ -f "$input" ]; then 101 echo "input param file=$input" 102else 103 echo "input param file=$input invalid" 104 exit 105fi 106 107if [[ $lanes == 4 ]]; then 108 code1=43 109 if [[ $soc == RK3588 ]]; then 110 code0=04 111 fi 112elif [[ $lanes == 2 ]]; then 113 code1=23 114 if [[ $soc == RK3588 ]]; then 115 code0=01 116 fi 117elif [[ $lanes == 1 ]]; then 118 code1=13 119 if [[ $soc == RK3588 ]]; then 120 code0=03 121 fi 122fi 123 124if [[ $baundary == 1500000 ]]; then 125 code3=01 126fi 127 128if [[ $baundary == 115200 ]]; then 129 code3=02 130 131fi 132 133if [[ $baundary == 115200 ]]; then 134 code3=02 135 136fi 137 138echo "code0=$code0" 139echo "code1=$code1" 140echo "code2=$code2" 141echo "code3=$code3" 142echo "vid=0x${vid_h}${vid_l} did=0x${did_h}${did_l}" 143 144echo -e -n "\x${magic0}\x${magic1}\x${magic2}\x${magic3}" > .pcie_idb_cfg.bak 145echo -e -n "\x${code0}\x${code1}\x${code2}\x${code3}\x${vid_l}\x${vid_h}\x${did_l}\x${did_h}" >> .pcie_idb_cfg.bak 146dd if=$input of=.temp bs=1 count=4 > /dev/null 147dd if=.pcie_idb_cfg.bak of=$input bs=1 seek=4 conv=notrunc > /dev/null 148 149