2 # SPDX-License-Identifier: GPL-2.0+
10 Transform a pair of psu_init_gpl.c and .h files produced by the Xilinx
11 Vivado tool for ZynqMP into a smaller psu_init_gpl.c file that is almost
12 checkpatch compliant. Minor coding style might still be needed. Must be
13 run from the top-level U-Boot source directory.
15 Usage: zynqmp_psu_init_minimize.sh INPUT_DIR OUTPUT_DIR
16 Example: zynqmp_psu_init_minimize.sh \\
17 /path/to/original/psu_init_gpl_c_and_h/ \\
18 board/xilinx/zynqmp/<my_board>/
20 Notes: INPUT_DIR must contain both .c and .h files.
21 If INPUT_DIR and OUTPUT_DIR are the same directory,
22 psu_init_gpl.c will be overwritten.
27 set -o errexit -o errtrace
36 IN="${1}/psu_init_gpl.c"
37 OUT="${2}/psu_init_gpl.c"
38 TMP=$(mktemp /tmp/psu_init_gpl.XXXXXX)
41 # Step through a temp file to allow both $IN!=$OUT and $IN==$OUT
47 # preprocess to expand defines, then remove cpp lines starting with '#'
48 gcc -I${1} -E ${OUT} -o ${TMP}
49 sed '/^#/d' ${TMP} >${OUT}
51 # Remove trivial code before psu_pll_init_data()
52 sed -ni '/psu_pll_init_data/,$p' ${OUT}
54 # Functions are lowercase in U-Boot, rename them
55 sed -i 's/PSU_Mask_Write/psu_mask_write/g' ${OUT}
56 sed -i 's/mask_pollOnValue/mask_pollonvalue/g' ${OUT}
57 sed -i 's/RegValue/regvalue/g' ${OUT}
58 sed -i 's/MaskStatus/maskstatus/g' ${OUT}
60 sed -i '/&= psu_peripherals_powerdwn_data()/d' ${OUT}
62 FUNCS_TO_REMOVE="psu_protection
64 psu_init_xppu_aper_ram
70 psu_ps_pl_reset_config_data
71 psu_ps_pl_isolation_removal_data
75 psu_peripherals_powerdwn_data
76 psu_init_ddr_self_refresh
80 for i in $FUNCS_TO_REMOVE; do
81 sed -i "/$i/,/^}$/d" ${OUT}
84 scripts/Lindent ${OUT}
86 # Prepend 'static' to internal functions
87 sed -i 's/^.*data(void)$/static &/g' ${OUT}
88 sed -i 's/^.*psu_afi_config(void)$/static &/g' ${OUT}
89 sed -i 's/^void init_peripheral/static &/g' ${OUT}
90 sed -i 's/^int serdes/static &/g' ${OUT}
91 sed -i 's/^int init_serdes/static &/g' ${OUT}
92 sed -i 's/^unsigned long /static &/g' ${OUT}
94 sed -i 's/()$/(void)/g' ${OUT}
95 sed -i 's/0X/0x/g' ${OUT}
97 # return (0) -> return 0
98 sed -ri 's/return \(([0-9]+)\)/return \1/g' ${OUT}
102 // SPDX-License-Identifier: GPL-2.0+
104 * (c) Copyright 2015 Xilinx, Inc. All rights reserved.
107 #include <asm/arch/psu_init_gpl.h>
115 # Temporarily convert newlines to do some mangling across lines
116 tr "\n" "\r" <${OUT} >${TMP}
118 # Cleanup empty loops. E.g.:
120 # | | ==> |while (e)|
123 sed -i -r 's| \{\r+(\t*)\}\r\r|\n\1\t;\n|g' ${TMP}
125 # Remove empty line between variable declaration
126 sed -i -r 's|\r(\r\t(unsigned )?int )|\1|g' ${TMP}
128 # Remove empty lines at function beginning/end
129 sed -i -e 's|\r{\r\r|\r{\r|g' ${TMP}
130 sed -i -e 's|\r\r}\r|\r}\r|g' ${TMP}
132 # Remove empty lines after '{' line
133 sed -i -e 's| {\r\r| {\r|g' ${TMP}
135 # Remove braces {} around single statement blocks. E.g.:
136 # | while (e) { | | while (e) |
137 # | stg(); | => | stg();|
139 sed -i -r 's| \{(\r[^\r]*;)\r\t*\}|\1|g' ${TMP}
141 # Remove Unnecessary parentheses around 'n_code <= 0x3C' and similar. E.g.:
142 # if ((p_code >= 0x26) && ...) -> if (p_code >= 0x26 && ...)
143 sed -i -r 's|\((._code .= [x[:xdigit:]]+)\)|\1|g' ${TMP}
145 # Convert back newlines
146 tr "\r" "\n" <${TMP} >${OUT}