2 # SPDX-License-Identifier: GPL-2.0+
5 # Copyright (C) 2022 Weidmüller Interface GmbH & Co. KG
12 Transform a pair of psu_init_gpl.c and .h files produced by the Xilinx
13 Vivado tool for ZynqMP into a smaller psu_init_gpl.c file that is almost
14 checkpatch compliant. Minor coding style might still be needed. Must be
15 run from the top-level U-Boot source directory.
17 Usage: zynqmp_psu_init_minimize.sh INPUT_DIR OUTPUT_DIR
18 Example: zynqmp_psu_init_minimize.sh \\
19 /path/to/original/psu_init_gpl_c_and_h/ \\
20 board/xilinx/zynqmp/<my_board>/
22 Notes: INPUT_DIR must contain both .c and .h files.
23 If INPUT_DIR and OUTPUT_DIR are the same directory,
24 psu_init_gpl.c will be overwritten.
29 set -o errexit -o errtrace
38 IN="${1}/psu_init_gpl.c"
39 OUT="${2}/psu_init_gpl.c"
40 TMP=$(mktemp /tmp/psu_init_gpl.XXXXXX)
43 # Step through a temp file to allow both $IN!=$OUT and $IN==$OUT
49 # preprocess to expand defines, then remove cpp lines starting with '#'
50 gcc -I${1} -E ${OUT} -o ${TMP}
51 sed '/^#/d' ${TMP} >${OUT}
53 # Remove trivial code before psu_pll_init_data()
54 sed -ni '/psu_pll_init_data/,$p' ${OUT}
56 # Functions are lowercase in U-Boot, rename them
57 sed -i 's/PSU_Mask_Write/psu_mask_write/g' ${OUT}
58 sed -i 's/mask_pollOnValue/mask_pollonvalue/g' ${OUT}
59 sed -i 's/RegValue/regvalue/g' ${OUT}
60 sed -i 's/MaskStatus/maskstatus/g' ${OUT}
62 sed -i '/&= psu_peripherals_powerdwn_data()/d' ${OUT}
64 FUNCS_TO_REMOVE="psu_protection
66 psu_init_xppu_aper_ram
71 psu_ps_pl_reset_config_data
72 psu_ps_pl_isolation_removal_data
76 psu_peripherals_powerdwn_data
77 psu_init_ddr_self_refresh
81 for i in $FUNCS_TO_REMOVE; do
82 sed -i "/$i/,/^}$/d" ${OUT}
85 scripts/Lindent ${OUT}
87 # Prepend 'static' to internal functions
88 sed -i 's/^.*data(void)$/static &/g' ${OUT}
89 sed -i 's/^.*psu_afi_config(void)$/static &/g' ${OUT}
90 sed -i 's/^void init_peripheral/static &/g' ${OUT}
91 sed -i 's/^int serdes/static &/g' ${OUT}
92 sed -i 's/^int init_serdes/static &/g' ${OUT}
93 sed -i 's/^unsigned long /static &/g' ${OUT}
95 sed -i 's/()$/(void)/g' ${OUT}
96 sed -i 's/0X/0x/g' ${OUT}
98 # return (0) -> return 0
99 sed -ri 's/return \(([0-9]+)\)/return \1/g' ${OUT}
103 // SPDX-License-Identifier: GPL-2.0+
105 * (c) Copyright 2015 Xilinx, Inc. All rights reserved.
108 #include <asm/arch/psu_init_gpl.h>
116 # Temporarily convert newlines to do some mangling across lines
117 tr "\n" "\r" <${OUT} >${TMP}
119 # Cleanup empty loops. E.g.:
121 # | | ==> |while (e)|
124 sed -i -r 's| \{\r+(\t*)\}\r\r|\r\1\t;\r|g' ${TMP}
126 # Remove empty line between variable declaration
127 sed -i -r 's|\r(\r\t(unsigned )?int )|\1|g' ${TMP}
129 # Remove empty lines at function beginning/end
130 sed -i -e 's|\r{\r\r|\r{\r|g' ${TMP}
131 sed -i -e 's|\r\r}\r|\r}\r|g' ${TMP}
133 # Remove empty lines after '{' line
134 sed -i -e 's| {\r\r| {\r|g' ${TMP}
136 # Remove braces {} around single statement blocks. E.g.:
137 # | while (e) { | | while (e) |
138 # | stg(); | => | stg();|
140 sed -i -r 's| \{(\r[^\r]*;)\r\t*\}|\1|g' ${TMP}
142 # Remove Unnecessary parentheses around 'n_code <= 0x3C' and similar. E.g.:
143 # if ((p_code >= 0x26) && ...) -> if (p_code >= 0x26 && ...)
144 sed -i -r 's|\((._code .= [x[:xdigit:]]+)\)|\1|g' ${TMP}
146 # Move helper functions below header includes
147 TARGET="#include <xil_io.h>"
148 START="static int serdes_rst_seq"
149 END="static int serdes_enb_coarse_saturation"
151 sed -i -e "s|\(${TARGET}\r\r\)\(.*\)\(${START}(.*\)\(${END}(\)|\1\3\2\4|g" \
154 # Convert back newlines
155 tr "\r" "\n" <${TMP} >${OUT}
157 # Remove unnecessary settings
159 SETTINGS_TO_REMOVE="0xFF000000
168 for i in $SETTINGS_TO_REMOVE; do
169 sed -i "/^\tpsu_mask_write($i,.*$/d" ${OUT}