1 #!/bin/bash
2 # Tool mainly for U-Boot Quality Assurance: build one or more board
3 # configurations with minimal verbosity, showing only warnings and
4 # errors.
6 usage()
7 {
8 # if exiting with 0, write to stdout, else write to stderr
9 local ret=${1:-0}
10 [ "${ret}" -eq 1 ] && exec 1>&2
11 cat <<-EOF
12 Usage: MAKEALL [options] [--] [boards-to-build]
14 Options:
15 -a ARCH, --arch ARCH Build all boards with arch ARCH
16 -c CPU, --cpu CPU Build all boards with cpu CPU
17 -v VENDOR, --vendor VENDOR Build all boards with vendor VENDOR
18 -s SOC, --soc SOC Build all boards with soc SOC
19 -l, --list List all targets to be built
20 -m, --maintainers List all targets and maintainer email
21 -M, --mails List all targets and all affilated emails
22 -h, --help This help output
24 Selections by these options are logically ANDed; if the same option
25 is used repeatedly, such selections are ORed. So "-v FOO -v BAR"
26 will select all configurations where the vendor is either FOO or
27 BAR. Any additional arguments specified on the command line are
28 always build additionally. See the boards.cfg file for more info.
30 If no boards are specified, then the default is "powerpc".
32 Environment variables:
33 BUILD_NCPUS number of parallel make jobs (default: auto)
34 CROSS_COMPILE cross-compiler toolchain prefix (default: "")
35 MAKEALL_LOGDIR output all logs to here (default: ./LOG/)
36 BUILD_DIR output build directory (default: ./)
37 BUILD_NBUILDS number of parallel targets (default: 1)
39 Examples:
40 - build all Power Architecture boards:
41 MAKEALL -a powerpc
42 MAKEALL --arch powerpc
43 MAKEALL powerpc
44 - build all PowerPC boards manufactured by vendor "esd":
45 MAKEALL -a powerpc -v esd
46 - build all PowerPC boards manufactured either by "keymile" or "siemens":
47 MAKEALL -a powerpc -v keymile -v siemens
48 - build all Freescale boards with MPC83xx CPUs, plus all 4xx boards:
49 MAKEALL -c mpc83xx -v freescale 4xx
50 EOF
51 exit ${ret}
52 }
54 SHORT_OPTS="ha:c:v:s:lmM"
55 LONG_OPTS="help,arch:,cpu:,vendor:,soc:,list,maintainers,mails"
57 # Option processing based on util-linux-2.13/getopt-parse.bash
59 # Note that we use `"$@"' to let each command-line parameter expand to a
60 # separate word. The quotes around `$@' are essential!
61 # We need TEMP as the `eval set --' would nuke the return value of
62 # getopt.
63 TEMP=`getopt -o ${SHORT_OPTS} --long ${LONG_OPTS} \
64 -n 'MAKEALL' -- "$@"`
66 [ $? != 0 ] && usage 1
68 # Note the quotes around `$TEMP': they are essential!
69 eval set -- "$TEMP"
71 SELECTED=''
72 ONLY_LIST=''
73 PRINT_MAINTS=''
74 MAINTAINERS_ONLY=''
76 while true ; do
77 case "$1" in
78 -a|--arch)
79 # echo "Option ARCH: argument \`$2'"
80 if [ "$opt_a" ] ; then
81 opt_a="${opt_a%)} || \$2 == \"$2\")"
82 else
83 opt_a="(\$2 == \"$2\")"
84 fi
85 SELECTED='y'
86 shift 2 ;;
87 -c|--cpu)
88 # echo "Option CPU: argument \`$2'"
89 if [ "$opt_c" ] ; then
90 opt_c="${opt_c%)} || \$3 == \"$2\")"
91 else
92 opt_c="(\$3 == \"$2\")"
93 fi
94 SELECTED='y'
95 shift 2 ;;
96 -s|--soc)
97 # echo "Option SoC: argument \`$2'"
98 if [ "$opt_s" ] ; then
99 opt_s="${opt_s%)} || \$6 == \"$2\")"
100 else
101 opt_s="(\$6 == \"$2\")"
102 fi
103 SELECTED='y'
104 shift 2 ;;
105 -v|--vendor)
106 # echo "Option VENDOR: argument \`$2'"
107 if [ "$opt_v" ] ; then
108 opt_v="${opt_v%)} || \$5 == \"$2\")"
109 else
110 opt_v="(\$5 == \"$2\")"
111 fi
112 SELECTED='y'
113 shift 2 ;;
114 -l|--list)
115 ONLY_LIST='y'
116 shift ;;
117 -m|--maintainers)
118 ONLY_LIST='y'
119 PRINT_MAINTS='y'
120 MAINTAINERS_ONLY='y'
121 shift ;;
122 -M|--mails)
123 ONLY_LIST='y'
124 PRINT_MAINTS='y'
125 shift ;;
126 -h|--help)
127 usage ;;
128 --)
129 shift ; break ;;
130 *)
131 echo "Internal error!" >&2 ; exit 1 ;;
132 esac
133 done
134 # echo "Remaining arguments:"
135 # for arg do echo '--> '"\`$arg'" ; done
137 FILTER="\$1 !~ /^#/"
138 [ "$opt_a" ] && FILTER="${FILTER} && $opt_a"
139 [ "$opt_c" ] && FILTER="${FILTER} && $opt_c"
140 [ "$opt_s" ] && FILTER="${FILTER} && $opt_s"
141 [ "$opt_v" ] && FILTER="${FILTER} && $opt_v"
143 if [ "$SELECTED" ] ; then
144 SELECTED=$(awk '('"$FILTER"') { print $1 }' boards.cfg)
146 # Make sure some boards from boards.cfg are actually found
147 if [ -z "$SELECTED" ] ; then
148 echo "Error: No boards selected, invalid arguments"
149 exit 1
150 fi
151 fi
153 #########################################################################
155 # Print statistics when we exit
156 trap exit 1 2 3 15
157 trap print_stats 0
159 # Determine number of CPU cores if no default was set
160 : ${BUILD_NCPUS:="`getconf _NPROCESSORS_ONLN`"}
162 if [ "$BUILD_NCPUS" -gt 1 ]
163 then
164 JOBS="-j $((BUILD_NCPUS + 1))"
165 else
166 JOBS=""
167 fi
170 if [ "${CROSS_COMPILE}" ] ; then
171 MAKE="make CROSS_COMPILE=${CROSS_COMPILE}"
172 else
173 MAKE=make
174 fi
176 if [ "${MAKEALL_LOGDIR}" ] ; then
177 LOG_DIR=${MAKEALL_LOGDIR}
178 else
179 LOG_DIR="LOG"
180 fi
182 : ${BUILD_NBUILDS:=1}
183 BUILD_MANY=0
185 if [ "${BUILD_NBUILDS}" -gt 1 ] ; then
186 BUILD_MANY=1
187 : ${BUILD_DIR:=./build}
188 mkdir -p "${BUILD_DIR}/ERR"
189 find "${BUILD_DIR}/ERR/" -type f -exec rm -f {} +
190 fi
192 : ${BUILD_DIR:=.}
194 OUTPUT_PREFIX="${BUILD_DIR}"
196 [ -d ${LOG_DIR} ] || mkdir "${LOG_DIR}" || exit 1
197 find "${LOG_DIR}/" -type f -exec rm -f {} +
199 LIST=""
201 # Keep track of the number of builds and errors
202 ERR_CNT=0
203 ERR_LIST=""
204 TOTAL_CNT=0
205 CURRENT_CNT=0
206 OLDEST_IDX=1
207 RC=0
209 # Helper funcs for parsing boards.cfg
210 boards_by_field()
211 {
212 awk \
213 -v field="$1" \
214 -v select="$2" \
215 '($1 !~ /^#/ && $field == select) { print $1 }' \
216 boards.cfg
217 }
218 boards_by_arch() { boards_by_field 2 "$@" ; }
219 boards_by_cpu() { boards_by_field 3 "$@" ; }
220 boards_by_soc() { boards_by_field 6 "$@" ; }
222 #########################################################################
223 ## MPC5xx Systems
224 #########################################################################
226 LIST_5xx="$(boards_by_cpu mpc5xx)"
228 #########################################################################
229 ## MPC5xxx Systems
230 #########################################################################
232 LIST_5xxx="$(boards_by_cpu mpc5xxx)"
234 #########################################################################
235 ## MPC512x Systems
236 #########################################################################
238 LIST_512x="$(boards_by_cpu mpc512x)"
240 #########################################################################
241 ## MPC8xx Systems
242 #########################################################################
244 LIST_8xx="$(boards_by_cpu mpc8xx)"
246 #########################################################################
247 ## PPC4xx Systems
248 #########################################################################
250 LIST_4xx="$(boards_by_cpu ppc4xx)"
252 #########################################################################
253 ## MPC8220 Systems
254 #########################################################################
256 LIST_8220="$(boards_by_cpu mpc8220)"
258 #########################################################################
259 ## MPC824x Systems
260 #########################################################################
262 LIST_824x="$(boards_by_cpu mpc824x)"
264 #########################################################################
265 ## MPC8260 Systems (includes 8250, 8255 etc.)
266 #########################################################################
268 LIST_8260="$(boards_by_cpu mpc8260)"
270 #########################################################################
271 ## MPC83xx Systems (includes 8349, etc.)
272 #########################################################################
274 LIST_83xx="$(boards_by_cpu mpc83xx)"
276 #########################################################################
277 ## MPC85xx Systems (includes 8540, 8560 etc.)
278 #########################################################################
280 LIST_85xx="$(boards_by_cpu mpc85xx)"
282 #########################################################################
283 ## MPC86xx Systems
284 #########################################################################
286 LIST_86xx="$(boards_by_cpu mpc86xx)"
288 #########################################################################
289 ## 74xx/7xx Systems
290 #########################################################################
292 LIST_74xx_7xx="$(boards_by_cpu 74xx_7xx)"
294 #########################################################################
295 ## PowerPC groups
296 #########################################################################
298 LIST_TSEC=" \
299 ${LIST_83xx} \
300 ${LIST_85xx} \
301 ${LIST_86xx} \
302 "
304 LIST_powerpc=" \
305 ${LIST_5xx} \
306 ${LIST_512x} \
307 ${LIST_5xxx} \
308 ${LIST_8xx} \
309 ${LIST_8220} \
310 ${LIST_824x} \
311 ${LIST_8260} \
312 ${LIST_83xx} \
313 ${LIST_85xx} \
314 ${LIST_86xx} \
315 ${LIST_4xx} \
316 ${LIST_74xx_7xx}\
317 "
319 # Alias "ppc" -> "powerpc" to not break compatibility with older scripts
320 # still using "ppc" instead of "powerpc"
321 LIST_ppc=" \
322 ${LIST_powerpc} \
323 "
325 #########################################################################
326 ## StrongARM Systems
327 #########################################################################
329 LIST_SA="$(boards_by_cpu sa1100)"
331 #########################################################################
332 ## ARM9 Systems
333 #########################################################################
335 LIST_ARM9="$(boards_by_cpu arm920t) \
336 $(boards_by_cpu arm926ejs) \
337 $(boards_by_cpu arm925t) \
338 "
340 #########################################################################
341 ## ARM11 Systems
342 #########################################################################
343 LIST_ARM11="$(boards_by_cpu arm1136)"
345 #########################################################################
346 ## ARMV7 Systems
347 #########################################################################
349 LIST_ARMV7="$(boards_by_cpu armv7)"
351 #########################################################################
352 ## AT91 Systems
353 #########################################################################
355 LIST_at91="$(boards_by_soc at91)"
357 #########################################################################
358 ## Xscale Systems
359 #########################################################################
361 LIST_pxa="$(boards_by_cpu pxa)"
363 LIST_ixp="$(boards_by_cpu ixp)"
365 #########################################################################
366 ## ARM groups
367 #########################################################################
369 LIST_arm=" \
370 ${LIST_SA} \
371 ${LIST_ARM9} \
372 ${LIST_ARM10} \
373 ${LIST_ARM11} \
374 ${LIST_ARMV7} \
375 ${LIST_at91} \
376 ${LIST_pxa} \
377 ${LIST_ixp} \
378 "
380 #########################################################################
381 ## MIPS Systems (default = big endian)
382 #########################################################################
384 LIST_mips4kc=" \
385 incaip \
386 qemu_mips \
387 vct_platinum \
388 vct_platinum_small \
389 vct_platinum_onenand \
390 vct_platinum_onenand_small \
391 vct_platinumavc \
392 vct_platinumavc_small \
393 vct_platinumavc_onenand \
394 vct_platinumavc_onenand_small \
395 vct_premium \
396 vct_premium_small \
397 vct_premium_onenand \
398 vct_premium_onenand_small \
399 "
401 LIST_au1xx0=" \
402 dbau1000 \
403 dbau1100 \
404 dbau1500 \
405 dbau1550 \
406 gth2 \
407 "
409 LIST_mips=" \
410 ${LIST_mips4kc} \
411 ${LIST_mips5kc} \
412 ${LIST_au1xx0} \
413 "
415 #########################################################################
416 ## MIPS Systems (little endian)
417 #########################################################################
419 LIST_xburst_el=" \
420 qi_lb60 \
421 "
423 LIST_au1xx0_el=" \
424 dbau1550_el \
425 pb1000 \
426 "
427 LIST_mips_el=" \
428 ${LIST_xburst_el} \
429 ${LIST_au1xx0_el} \
430 "
431 #########################################################################
432 ## OpenRISC Systems
433 #########################################################################
435 LIST_openrisc="$(boards_by_arch openrisc)"
437 #########################################################################
438 ## x86 Systems
439 #########################################################################
441 LIST_x86="$(boards_by_arch x86)"
443 #########################################################################
444 ## Nios-II Systems
445 #########################################################################
447 LIST_nios2="$(boards_by_arch nios2)"
449 #########################################################################
450 ## MicroBlaze Systems
451 #########################################################################
453 LIST_microblaze="$(boards_by_arch microblaze)"
455 #########################################################################
456 ## ColdFire Systems
457 #########################################################################
459 LIST_m68k="$(boards_by_arch m68k)
460 EB+MCF-EV123 \
461 EB+MCF-EV123_internal \
462 M52277EVB \
463 M5235EVB \
464 M54451EVB \
465 M54455EVB \
466 "
467 LIST_coldfire=${LIST_m68k}
469 #########################################################################
470 ## AVR32 Systems
471 #########################################################################
473 LIST_avr32="$(boards_by_arch avr32)"
475 #########################################################################
476 ## Blackfin Systems
477 #########################################################################
479 LIST_blackfin="$(boards_by_arch blackfin)"
481 #########################################################################
482 ## SH Systems
483 #########################################################################
485 LIST_sh2="$(boards_by_cpu sh2)"
486 LIST_sh3="$(boards_by_cpu sh3)"
487 LIST_sh4="$(boards_by_cpu sh4)"
489 LIST_sh="$(boards_by_arch sh)"
491 #########################################################################
492 ## SPARC Systems
493 #########################################################################
495 LIST_sparc="$(boards_by_arch sparc)"
497 #########################################################################
498 ## NDS32 Systems
499 #########################################################################
501 LIST_nds32="$(boards_by_arch nds32)"
503 #-----------------------------------------------------------------------
505 get_target_location() {
506 local target=$1
507 local BOARD_NAME=""
508 local CONFIG_NAME=""
509 local board=""
510 local vendor=""
512 # Automatic mode
513 local line=`egrep -i "^[[:space:]]*${target}[[:space:]]" boards.cfg`
515 if [ -z "${line}" ] ; then echo "" ; return ; fi
517 set ${line}
519 # add default board name if needed
520 [ $# = 3 ] && set ${line} ${1}
522 CONFIG_NAME="${1%_config}"
524 [ "${BOARD_NAME}" ] || BOARD_NAME="${1%_config}"
526 if [ "$4" = "-" ] ; then
527 board=${BOARD_NAME}
528 else
529 board="$4"
530 fi
532 [ $# -gt 4 ] && [ "$5" != "-" ] && vendor="$5"
533 [ $# -gt 6 ] && [ "$7" != "-" ] && {
534 tmp="${7%:*}"
535 if [ "$tmp" ] ; then
536 CONFIG_NAME="$tmp"
537 fi
538 }
540 # Assign board directory to BOARDIR variable
541 if [ -z "${vendor}" ] ; then
542 BOARDDIR=${board}
543 else
544 BOARDDIR=${vendor}/${board}
545 fi
547 echo "${CONFIG_NAME}:${BOARDDIR}"
548 }
550 get_target_maintainers() {
551 local name=`echo $1 | cut -d : -f 1`
553 if ! grep -qsi "[[:blank:]]${name}[[:blank:]]" MAINTAINERS ; then
554 echo ""
555 return ;
556 fi
558 local line=`tac MAINTAINERS | grep -ni "[[:blank:]]${name}[[:blank:]]" | cut -d : -f 1`
559 local mail=`tac MAINTAINERS | tail -n +${line} | \
560 sed -n ":start /.*@.*/ { b mail } ; n ; b start ; :mail /.*@.*/ { p ; n ; b mail } ; q" | \
561 sed "s/^.*<//;s/>.*$//"`
562 echo "$mail"
563 }
565 list_target() {
566 if [ "$PRINT_MAINTS" != 'y' ] ; then
567 echo "$1"
568 return
569 fi
571 echo -n "$1:"
573 local loc=`get_target_location $1`
575 if [ -z "${loc}" ] ; then echo "ERROR" ; return ; fi
577 local maintainers_result=`get_target_maintainers ${loc} | tr " " "\n"`
579 if [ "$MAINTAINERS_ONLY" != 'y' ] ; then
581 local dir=`echo ${loc} | cut -d ":" -f 2`
582 local cfg=`echo ${loc} | cut -d ":" -f 1`
583 local git_result=`git log --format=%aE board/${dir} \
584 include/configs/${cfg}.h | grep "@"`
585 local git_result_recent=`echo ${git_result} | tr " " "\n" | \
586 head -n 3`
587 local git_result_top=`echo ${git_result} | tr " " "\n" | \
588 sort | uniq -c | sort -nr | head -n 3 | \
589 sed "s/^ \+[0-9]\+ \+//"`
591 echo -e "$git_result_recent\n$git_result_top\n$maintainers_result" | \
592 sort -u | tr "\n" " " | sed "s/ $//" ;
593 else
594 echo -e "$maintainers_result" | sort -u | tr "\n" " " | \
595 sed "s/ $//" ;
596 fi
598 echo ""
599 }
601 # Each finished build will have a file called ${donep}${n},
602 # where n is the index of the build. Each build
603 # we've already noted as finished will have ${skipp}${n}.
604 # The code managing the build process will use this information
605 # to ensure that only BUILD_NBUILDS builds are in flight at once
606 donep="${LOG_DIR}/._done_"
607 skipp="${LOG_DIR}/._skip_"
609 build_target() {
610 target=$1
611 build_idx=$2
613 if [ "$ONLY_LIST" == 'y' ] ; then
614 list_target ${target}
615 return
616 fi
618 if [ $BUILD_MANY == 1 ] ; then
619 output_dir="${OUTPUT_PREFIX}/${target}"
620 mkdir -p "${output_dir}"
621 else
622 output_dir="${OUTPUT_PREFIX}"
623 fi
625 export BUILD_DIR="${output_dir}"
627 ${MAKE} distclean >/dev/null
628 ${MAKE} -s ${target}_config
630 ${MAKE} ${JOBS} all \
631 >${LOG_DIR}/$target.MAKELOG 2> ${LOG_DIR}/$target.ERR
633 # Check for 'make' errors
634 if [ ${PIPESTATUS[0]} -ne 0 ] ; then
635 RC=1
636 fi
638 if [ $BUILD_MANY == 1 ] ; then
639 ${MAKE} tidy
641 if [ -s ${LOG_DIR}/${target}.ERR ] ; then
642 touch ${OUTPUT_PREFIX}/ERR/${target}
643 else
644 rm ${LOG_DIR}/${target}.ERR
645 fi
646 else
647 if [ -s ${LOG_DIR}/${target}.ERR ] ; then
648 : $(( ERR_CNT += 1 ))
649 ERR_LIST="${ERR_LIST} $target"
650 else
651 rm ${LOG_DIR}/${target}.ERR
652 fi
653 fi
655 OBJS=${output_dir}/u-boot
656 if [ -e ${output_dir}/spl/u-boot-spl ]; then
657 OBJS="${OBJS} ${output_dir}/spl/u-boot-spl"
658 fi
660 ${CROSS_COMPILE}size ${OBJS} | tee -a ${LOG_DIR}/$target.MAKELOG
662 [ -e "${LOG_DIR}/${target}.ERR" ] && cat "${LOG_DIR}/${target}.ERR"
664 touch "${donep}${build_idx}"
665 }
667 manage_builds() {
668 search_idx=${OLDEST_IDX}
669 if [ "$ONLY_LIST" == 'y' ] ; then return ; fi
671 while true; do
672 if [ -e "${donep}${search_idx}" ] ; then
673 : $(( CURRENT_CNT-- ))
674 [ ${OLDEST_IDX} -eq ${search_idx} ] &&
675 : $(( OLDEST_IDX++ ))
677 # Only want to count it once
678 rm -f "${donep}${search_idx}"
679 touch "${skipp}${search_idx}"
680 elif [ -e "${skipp}${search_idx}" ] ; then
681 [ ${OLDEST_IDX} -eq ${search_idx} ] &&
682 : $(( OLDEST_IDX++ ))
683 fi
684 : $(( search_idx++ ))
685 if [ ${search_idx} -gt ${TOTAL_CNT} ] ; then
686 if [ ${CURRENT_CNT} -ge ${BUILD_NBUILDS} ] ; then
687 search_idx=${OLDEST_IDX}
688 sleep 1
689 else
690 break
691 fi
692 fi
693 done
694 }
696 build_targets() {
697 for t in "$@" ; do
698 # If a LIST_xxx var exists, use it. But avoid variable
699 # expansion in the eval when a board name contains certain
700 # characters that the shell interprets.
701 case ${t} in
702 *[-+=]*) list= ;;
703 *) list=$(eval echo '${LIST_'$t'}') ;;
704 esac
705 if [ -n "${list}" ] ; then
706 build_targets ${list}
707 else
708 : $((TOTAL_CNT += 1))
709 : $((CURRENT_CNT += 1))
710 rm -f "${donep}${TOTAL_CNT}"
711 rm -f "${skipp}${TOTAL_CNT}"
712 if [ $BUILD_MANY == 1 ] ; then
713 build_target ${t} ${TOTAL_CNT} &
714 else
715 build_target ${t} ${TOTAL_CNT}
716 fi
717 fi
719 # We maintain a running count of all the builds we have done.
720 # Each finished build will have a file called ${donep}${n},
721 # where n is the index of the build. Each build
722 # we've already noted as finished will have ${skipp}${n}.
723 # We track the current index via TOTAL_CNT, and the oldest
724 # index. When we exceed the maximum number of parallel builds,
725 # We look from oldest to current for builds that have completed,
726 # and update the current count and oldest index as appropriate.
727 # If we've gone through the entire list, wait a second, and
728 # reprocess the entire list until we find a build that has
729 # completed
730 if [ ${CURRENT_CNT} -ge ${BUILD_NBUILDS} ] ; then
731 manage_builds
732 fi
733 done
734 }
736 #-----------------------------------------------------------------------
738 kill_children() {
739 kill -- "-$1"
741 exit
742 }
744 print_stats() {
745 if [ "$ONLY_LIST" == 'y' ] ; then return ; fi
747 rm -f ${donep}* ${skipp}*
749 if [ $BUILD_MANY == 1 ] && [ -e "${OUTPUT_PREFIX}/ERR" ] ; then
750 ERR_LIST=$(ls ${OUTPUT_PREFIX}/ERR/)
751 ERR_CNT=`ls -1 ${OUTPUT_PREFIX}/ERR/ | wc | awk '{print $1}'`
752 fi
754 echo ""
755 echo "--------------------- SUMMARY ----------------------------"
756 echo "Boards compiled: ${TOTAL_CNT}"
757 if [ ${ERR_CNT} -gt 0 ] ; then
758 echo "Boards with warnings or errors: ${ERR_CNT} (${ERR_LIST} )"
759 fi
760 echo "----------------------------------------------------------"
762 if [ $BUILD_MANY == 1 ] ; then
763 kill_children $$ &
764 fi
766 exit $RC
767 }
769 #-----------------------------------------------------------------------
771 # Build target groups selected by options, plus any command line args
772 set -- ${SELECTED} "$@"
773 # run PowerPC by default
774 [ $# = 0 ] && set -- powerpc
775 build_targets "$@"
776 wait