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
69 psu_ps_pl_reset_config_data
70 psu_ps_pl_isolation_removal_data
74 psu_peripherals_powerdwn_data
75 psu_init_ddr_self_refresh
79 for i in $FUNCS_TO_REMOVE; do
80 sed -i "/$i/,/^}$/d" ${OUT}
83 scripts/Lindent ${OUT}
85 # Prepend 'static' to internal functions
86 sed -i 's/^.*data(void)$/static &/g' ${OUT}
87 sed -i 's/^.*psu_afi_config(void)$/static &/g' ${OUT}
88 sed -i 's/^void init_peripheral/static &/g' ${OUT}
89 sed -i 's/^int serdes/static &/g' ${OUT}
90 sed -i 's/^int init_serdes/static &/g' ${OUT}
91 sed -i 's/^unsigned long /static &/g' ${OUT}
93 sed -i 's/()$/(void)/g' ${OUT}
94 sed -i 's/0X/0x/g' ${OUT}
96 # return (0) -> return 0
97 sed -ri 's/return \(([0-9]+)\)/return \1/g' ${OUT}
101 // SPDX-License-Identifier: GPL-2.0+
103 * (c) Copyright 2015 Xilinx, Inc. All rights reserved.
106 #include <asm/arch/psu_init_gpl.h>
114 # Temporarily convert newlines to do some mangling across lines
115 tr "\n" "\r" <${OUT} >${TMP}
117 # Cleanup empty loops. E.g.:
119 # | | ==> |while (e)|
122 sed -i -r 's| \{\r+(\t*)\}\r\r|\n\1\t;\n|g' ${TMP}
124 # Remove empty line between variable declaration
125 sed -i -r 's|\r(\r\t(unsigned )?int )|\1|g' ${TMP}
127 # Remove empty lines at function beginning/end
128 sed -i -e 's|\r{\r\r|\r{\r|g' ${TMP}
129 sed -i -e 's|\r\r}\r|\r}\r|g' ${TMP}
131 # Remove empty lines after '{' line
132 sed -i -e 's| {\r\r| {\r|g' ${TMP}
134 # Remove braces {} around single statement blocks. E.g.:
135 # | while (e) { | | while (e) |
136 # | stg(); | => | stg();|
138 sed -i -r 's| \{(\r[^\r]*;)\r\t*\}|\1|g' ${TMP}
140 # Remove Unnecessary parentheses around 'n_code <= 0x3C' and similar. E.g.:
141 # if ((p_code >= 0x26) && ...) -> if (p_code >= 0x26 && ...)
142 sed -i -r 's|\((._code .= [x[:xdigit:]]+)\)|\1|g' ${TMP}
144 # Convert back newlines
145 tr "\r" "\n" <${TMP} >${OUT}