]> git.ipfire.org Git - people/ms/u-boot.git/blob - mkconfig
Licenses: introduce SPDX Unique Lincense Identifiers
[people/ms/u-boot.git] / mkconfig
1 #!/bin/sh -e
2
3 # Script to create header files and links to configure
4 # U-Boot for a specific board.
5 #
6 # Parameters: Target Architecture CPU Board [VENDOR] [SOC]
7 #
8 # (C) 2002-2013 DENX Software Engineering, Wolfgang Denk <wd@denx.de>
9 #
10 # SPDX-License-Identifier: GPL-2.0+
11 #
12
13 APPEND=no # Default: Create new config file
14 BOARD_NAME="" # Name to print in make output
15 TARGETS=""
16
17 arch=""
18 cpu=""
19 board=""
20 vendor=""
21 soc=""
22 options=""
23
24 if [ \( $# -eq 2 \) -a \( "$1" = "-A" \) ] ; then
25 # Automatic mode
26 line=`egrep -i "^[[:space:]]*${2}[[:space:]]" boards.cfg` || {
27 echo "make: *** No rule to make target \`$2_config'. Stop." >&2
28 exit 1
29 }
30
31 set ${line}
32 # add default board name if needed
33 [ $# = 3 ] && set ${line} ${1}
34 fi
35
36 while [ $# -gt 0 ] ; do
37 case "$1" in
38 --) shift ; break ;;
39 -a) shift ; APPEND=yes ;;
40 -n) shift ; BOARD_NAME="${1%_config}" ; shift ;;
41 -t) shift ; TARGETS="`echo $1 | sed 's:_: :g'` ${TARGETS}" ; shift ;;
42 *) break ;;
43 esac
44 done
45
46 [ $# -lt 4 ] && exit 1
47 [ $# -gt 7 ] && exit 1
48
49 # Strip all options and/or _config suffixes
50 CONFIG_NAME="${1%_config}"
51
52 [ "${BOARD_NAME}" ] || BOARD_NAME="${1%_config}"
53
54 arch="$2"
55 cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $1}'`
56 spl_cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $2}'`
57 if [ "$4" = "-" ] ; then
58 board=${BOARD_NAME}
59 else
60 board="$4"
61 fi
62 [ $# -gt 4 ] && [ "$5" != "-" ] && vendor="$5"
63 [ $# -gt 5 ] && [ "$6" != "-" ] && soc="$6"
64 [ $# -gt 6 ] && [ "$7" != "-" ] && {
65 # check if we have a board config name in the options field
66 # the options field mave have a board config name and a list
67 # of options, both separated by a colon (':'); the options are
68 # separated by commas (',').
69 #
70 # Check for board name
71 tmp="${7%:*}"
72 if [ "$tmp" ] ; then
73 CONFIG_NAME="$tmp"
74 fi
75 # Check if we only have a colon...
76 if [ "${tmp}" != "$7" ] ; then
77 options=${7#*:}
78 TARGETS="`echo ${options} | sed 's:,: :g'` ${TARGETS}"
79 fi
80 }
81
82 if [ "${ARCH}" -a "${ARCH}" != "${arch}" ]; then
83 echo "Failed: \$ARCH=${ARCH}, should be '${arch}' for ${BOARD_NAME}" 1>&2
84 exit 1
85 fi
86
87 if [ "$options" ] ; then
88 echo "Configuring for ${BOARD_NAME} - Board: ${CONFIG_NAME}, Options: ${options}"
89 else
90 echo "Configuring for ${BOARD_NAME} board..."
91 fi
92
93 #
94 # Create link to architecture specific headers
95 #
96 if [ "$SRCTREE" != "$OBJTREE" ] ; then
97 mkdir -p ${OBJTREE}/include
98 mkdir -p ${OBJTREE}/include2
99 cd ${OBJTREE}/include2
100 rm -f asm
101 ln -s ${SRCTREE}/arch/${arch}/include/asm asm
102 LNPREFIX=${SRCTREE}/arch/${arch}/include/asm/
103 cd ../include
104 mkdir -p asm
105 else
106 cd ./include
107 rm -f asm
108 ln -s ../arch/${arch}/include/asm asm
109 fi
110
111 rm -f asm/arch
112
113 if [ -z "${soc}" ] ; then
114 ln -s ${LNPREFIX}arch-${cpu} asm/arch
115 else
116 ln -s ${LNPREFIX}arch-${soc} asm/arch
117 fi
118
119 if [ "${arch}" = "arm" ] ; then
120 rm -f asm/proc
121 ln -s ${LNPREFIX}proc-armv asm/proc
122 fi
123
124 #
125 # Create include file for Make
126 #
127 ( echo "ARCH = ${arch}"
128 if [ ! -z "$spl_cpu" ] ; then
129 echo 'ifeq ($(CONFIG_SPL_BUILD),y)'
130 echo "CPU = ${spl_cpu}"
131 echo "else"
132 echo "CPU = ${cpu}"
133 echo "endif"
134 else
135 echo "CPU = ${cpu}"
136 fi
137 echo "BOARD = ${board}"
138
139 [ "${vendor}" ] && echo "VENDOR = ${vendor}"
140 [ "${soc}" ] && echo "SOC = ${soc}"
141 exit 0 ) > config.mk
142
143 # Assign board directory to BOARDIR variable
144 if [ -z "${vendor}" ] ; then
145 BOARDDIR=${board}
146 else
147 BOARDDIR=${vendor}/${board}
148 fi
149
150 #
151 # Create board specific header file
152 #
153 if [ "$APPEND" = "yes" ] # Append to existing config file
154 then
155 echo >> config.h
156 else
157 > config.h # Create new config file
158 fi
159 echo "/* Automatically generated - do not edit */" >>config.h
160
161 for i in ${TARGETS} ; do
162 i="`echo ${i} | sed '/=/ {s/=/ /;q; } ; { s/$/ 1/; }'`"
163 echo "#define CONFIG_${i}" >>config.h ;
164 done
165
166 echo "#define CONFIG_SYS_ARCH \"${arch}\"" >> config.h
167 echo "#define CONFIG_SYS_CPU \"${cpu}\"" >> config.h
168 echo "#define CONFIG_SYS_BOARD \"${board}\"" >> config.h
169
170 [ "${vendor}" ] && echo "#define CONFIG_SYS_VENDOR \"${vendor}\"" >> config.h
171
172 [ "${soc}" ] && echo "#define CONFIG_SYS_SOC \"${soc}\"" >> config.h
173
174 cat << EOF >> config.h
175 #define CONFIG_BOARDDIR board/$BOARDDIR
176 #include <config_cmd_defaults.h>
177 #include <config_defaults.h>
178 #include <configs/${CONFIG_NAME}.h>
179 #include <asm/config.h>
180 #include <config_fallbacks.h>
181 #include <config_uncmd_spl.h>
182 EOF
183
184 exit 0