forked from projectara/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refresh_defconfigs.sh
executable file
·152 lines (122 loc) · 4.42 KB
/
refresh_defconfigs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
# refresh_defconfigs.sh
# define exit error codes
ARA_BUILD_CONFIG_ERR_BAD_PARAMS=1
ARA_BUILD_CONFIG_ERR_NO_NUTTX_TOPDIR=2
ARA_BUILD_CONFIG_ERR_CONFIG_NOT_FOUND=3
ARA_BUILD_CONFIG_ERR_CONFIG_COPY_FAILED=4
# Other build configuration.
ARA_BUILD_PARALLEL=1 # controls make's -j flag
echo "Project Ara firmware defconfig refresh"
ARA_BUILD_PARALLEL="-j 6"
# determine NuttX top level folder absolute path
TOPDIR="`dirname \"$0\"`" # relative
TOPDIR="`( cd \"$TOPDIR/nuttx\" && pwd )`" # absolutized and normalized
if [ -z "$TOPDIR" ] ; then
# error; for some reason, the path is not accessible
# to the script (e.g. permissions)
echo "Can't determine NuttX top level folder, fatal."
exit $ARA_BUILD_CONFIG_ERR_NO_NUTTX_TOPDIR
fi
rebuild_defconfig() {
# configpath, defconfigFile, buildname, buildbase
# must be defined on entry
# define paths used during build process
ARA_BUILD_CONFIG_PATH="$buildbase/$buildname/config"
ARA_BUILD_TOPDIR="$buildbase/$buildname"
# delete build tree if it already exists
if [ -d $ARA_BUILD_TOPDIR ] ; then
rm -rf $ARA_BUILD_TOPDIR
fi
# create folder structure in build output tree
mkdir -p "$ARA_BUILD_CONFIG_PATH"
mkdir -p "$ARA_BUILD_TOPDIR"
# Copy nuttx tree to build tree
cp -r $TOPDIR/../nuttx $ARA_BUILD_TOPDIR/nuttx
cp -r $TOPDIR/../apps $ARA_BUILD_TOPDIR/apps
cp -r $TOPDIR/../misc $ARA_BUILD_TOPDIR/misc
# copy Make.defs to build output tree
if ! install -m 644 -p ${configpath}/Make.defs ${ARA_BUILD_TOPDIR}/nuttx/Make.defs >/dev/null 2>&1; then
echo "Warning: Failed to copy Make.defs"
fi
# copy setenv.sh to build output tree
if install -p ${configpath}/setenv.sh ${ARA_BUILD_TOPDIR}/nuttx/setenv.sh >/dev/null 2>&1; then
chmod 755 "${ARA_BUILD_TOPDIR}/nuttx/setenv.sh"
fi
# copy defconfig to build output tree
if ! install -m 644 -p ${defconfigFile} ${ARA_BUILD_TOPDIR}/nuttx/.config ; then
echo "ERROR: Failed to copy defconfig"
exit $ARA_BUILD_CONFIG_ERR_CONFIG_COPY_FAILED
fi
# save config files
cp ${ARA_BUILD_TOPDIR}/nuttx/.config ${ARA_BUILD_CONFIG_PATH}/.config > /dev/null 2>&1
cp ${ARA_BUILD_TOPDIR}/nuttx/Make.defs ${ARA_BUILD_CONFIG_PATH}/Make.defs > /dev/null 2>&1
cp ${ARA_BUILD_TOPDIR}/nuttx/setenv.sh ${ARA_BUILD_CONFIG_PATH}/setenv.sh > /dev/null 2>&1
echo "Building config for '$buildname'"
export ARA_BUILD_NAME=$buildname
pushd $ARA_BUILD_TOPDIR/nuttx > /dev/null
make -j ${ARA_BUILD_PARALLEL} -r -f Makefile.unix olddefconfig > /dev/null 2>&1
MAKE_RESULT=${PIPESTATUS[0]}
popd > /dev/null
}
copy_defconfig_file() {
# uses configpath
if ! diff -q $ARA_BUILD_TOPDIR/nuttx/.config $configpath/defconfig > /dev/null ; then
echo "Updating defconfig"
cp $ARA_BUILD_TOPDIR/nuttx/.config $configpath/defconfig
fi
}
remove_build() {
# uses buildbase and buildname
rm -rf "$buildbase/$buildname"
}
canonicalize() {
TARGET_FILE=$1
cd `dirname $TARGET_FILE`
TARGET_FILE=`basename $TARGET_FILE`
# Iterate down a (possible) chain of symlinks
while [ -L "$TARGET_FILE" ]
do
TARGET_FILE=`readlink $TARGET_FILE`
cd `dirname $TARGET_FILE`
TARGET_FILE=`basename $TARGET_FILE`
done
# Compute the canonicalized name by finding the physical path
# for the directory we're in and appending the target file.
PHYS_DIR=`pwd -P`
RESULT=$PHYS_DIR/$TARGET_FILE
echo $RESULT
}
# set build output path
buildbase="`( cd \"$TOPDIR/..\" && pwd )`/build"
# build list of defconfigs
defconfig_list=$(find $TOPDIR/configs/ara -iname defconfig)
# build the kconfig tools if we haven't already. Only need to do this once.
echo "prebuilding kconfig tools"
pushd "${TOPDIR}" > /dev/null
make -f Makefile.unix buildconfig > /dev/null 2>&1
popd > /dev/null
# process list of defconfigs
for cfg in $defconfig_list; do
# save full path to defconfig
defconfigFile=${cfg}
# get abs path to defconfig
configpath=$(canonicalize $(dirname "$cfg"))
#create build name
buildname=$(canonicalize $(dirname "$cfg"))
#strip abs path
buildname=$(echo "$buildname" | sed -e "s:^$TOPDIR/configs/::")
# repl slash with dash
buildname=$(echo "$buildname" | sed -e "s#/#-#g")
# rebuild the defconfig
rebuild_defconfig
# check build result
if [ $MAKE_RESULT -ne 0 ] ; then
echo "Rebuild defconfig for '$buildname' failed"
exit 1
fi
copy_defconfig_file
remove_build
done
echo "Refresh defconfigs completed"
exit 0