tools/: Remove the hardcode arch/chip list from all tool scripts

This commit is contained in:
Xiang Xiao 2020-01-16 09:16:14 +08:00 committed by Gregory Nutt
parent 1ff410957f
commit bc8edaf6c2
4 changed files with 85 additions and 251 deletions

View File

@ -79,14 +79,23 @@
static void show_usage(const char *progname, int exitcode); static void show_usage(const char *progname, int exitcode);
static void debug(const char *fmt, ...); static void debug(const char *fmt, ...);
static int find_archname(const char *boardname, const char *configname);
static void parse_args(int argc, char **argv); static void parse_args(int argc, char **argv);
static bool check_directory(const char *directory); static bool check_directory(const char *directory);
static void verify_directory(const char *directory); static void verify_directory(const char *directory);
static bool verify_optiondir(const char *directory); static bool verify_optiondir(const char *directory);
static bool verify_file(const char *path); static bool verify_file(const char *path);
static void find_topdir(void); static void find_topdir(void);
static void config_search(const char *boarddir); typedef void (*config_callback)(const char *boarddir, const char *archname,
const char *chipname, const char *boardname,
const char *configname, void *data);
static void config_search(const char *boarddir, config_callback callback, void *data);
static void find_archname_callback(const char *boarddir, const char *archname,
const char *chipname, const char *boardname,
const char *configname, void *data);
static void find_archname(void);
static void enumerate_callback(const char *boarddir, const char *archname,
const char *chipname, const char *boardname,
const char *configname, void *data);
static void enumerate_configs(void); static void enumerate_configs(void);
static void check_configdir(void); static void check_configdir(void);
static void check_configured(void); static void check_configured(void);
@ -148,92 +157,6 @@ static char g_buffer[BUFFER_SIZE]; /* Scratch buffer for forming full p
static struct variable_s *g_configvars = NULL; static struct variable_s *g_configvars = NULL;
static struct variable_s *g_versionvars = NULL; static struct variable_s *g_versionvars = NULL;
/* Recognized architectures */
static const char *g_archnames[] =
{
"arm",
"avr",
"hc",
"mips",
"misoc",
"or1k",
"renesas",
"risc-v",
"sim",
"x86",
"xtensa",
"z16",
"z80",
NULL
};
/* Recognized chip names */
static const char *g_chipnames[] =
{
"a1x",
"am335x",
"c5471",
"cxd56xx",
"dm320",
"efm32",
"imx6",
"imxrt",
"kinetis",
"kl",
"lc823450",
"lpc17xx_40xx",
"lpc214x",
"lpc2378",
"lpc31xx",
"lpc43xx",
"lpc54xx",
"max326xx",
"moxart",
"nrf52",
"nuc1xx",
"rx65n"
"s32k1xx",
"sam34",
"sama5",
"samd2l2",
"samd5e5",
"samv7",
"stm32",
"stm32f0l0g0",
"stm32f7",
"stm32h7",
"stm32l4",
"str71x",
"tiva",
"tms570",
"xmc4",
"at32uc3",
"at90usb",
"atmega",
"mcs92s12ne64",
"pic32mx",
"pic32mz",
"lm32",
"mor1kx",
"m32262f8",
"sh7032",
"fe310",
"gap8",
"k210",
"nr5m100",
"sim",
"qemu",
"esp32",
"z16f2811",
"ez80",
"z180",
"z8",
"z80",
NULL
};
/* Optional configuration files */ /* Optional configuration files */
static const char *g_optfiles[] = static const char *g_optfiles[] =
@ -318,49 +241,10 @@ static void debug(const char *fmt, ...)
} }
} }
static int find_archname(const char *boardname, const char *configname)
{
const char **archname;
const char **chipname;
struct stat statbuf;
int ret;
/* Try each combination of board and chip names */
for (archname = g_archnames; *archname != NULL; archname++)
{
for (chipname = g_chipnames; *chipname != NULL; chipname++)
{
/* Get the architecture directory under boards. Path format:
* board/<arch-name>/<chip-name>/<board-name>/configs/<config-name>
*/
snprintf(g_buffer, BUFFER_SIZE, "boards%c%s%c%s%c%s%cconfigs%c%s",
g_delim, *archname, g_delim, *chipname, g_delim, boardname,
g_delim, g_delim, configname);
/* Check if there is a directory at this path */
ret = stat(g_buffer, &statbuf);
if (ret == 0 && S_ISDIR(statbuf.st_mode))
{
g_archdir = *archname;
g_chipdir = *chipname;
return 0;
}
}
}
g_archdir = "unknown";
g_chipdir = "unknown";
return -1;
}
static void parse_args(int argc, char **argv) static void parse_args(int argc, char **argv)
{ {
char *ptr; char *ptr;
int ch; int ch;
int ret;
/* Parse command line options */ /* Parse command line options */
@ -477,13 +361,6 @@ static void parse_args(int argc, char **argv)
fprintf(stderr, "ERROR: Unexpected garbage at the end of the line\n"); fprintf(stderr, "ERROR: Unexpected garbage at the end of the line\n");
show_usage(argv[0], EXIT_FAILURE); show_usage(argv[0], EXIT_FAILURE);
} }
ret = find_archname(g_boarddir, g_configdir);
if (ret != 0)
{
fprintf(stderr, "ERROR: Architecture for board %s not found\n",
g_boarddir);
}
} }
static bool check_directory(const char *directory) static bool check_directory(const char *directory)
@ -633,7 +510,7 @@ static void find_topdir(void)
} }
} }
static void config_search(const char *boarddir) static void config_search(const char *boarddir, config_callback callback, void *data)
{ {
DIR *dir; DIR *dir;
struct dirent *dp; struct dirent *dp;
@ -667,7 +544,7 @@ static void config_search(const char *boarddir)
/* Visit each entry in the directory */ /* Visit each entry in the directory */
while ((dp = readdir (dir)) != NULL) while ((dp = readdir(dir)) != NULL)
{ {
/* Ignore directory entries that start with '.' */ /* Ignore directory entries that start with '.' */
@ -700,7 +577,7 @@ static void config_search(const char *boarddir)
char *tmppath; char *tmppath;
snprintf(g_buffer, BUFFER_SIZE, "%s%c%s", boarddir, g_delim, child); snprintf(g_buffer, BUFFER_SIZE, "%s%c%s", boarddir, g_delim, child);
tmppath = strdup(g_buffer); tmppath = strdup(g_buffer);
config_search(tmppath); config_search(tmppath, callback, data);
free(tmppath); free(tmppath);
} }
@ -712,10 +589,11 @@ static void config_search(const char *boarddir)
else if (S_ISREG(buf.st_mode) && strcmp("defconfig", child) == 0) else if (S_ISREG(buf.st_mode) && strcmp("defconfig", child) == 0)
{ {
char *archname;
char *chipname;
char *boardname; char *boardname;
char *configname; char *configname;
char *delim; char *delim;
char *tmp;
/* Get the board directory near the beginning of the 'boarddir' path: /* Get the board directory near the beginning of the 'boarddir' path:
* <archdir>/<chipdir>/<boarddir>/configs/<configdir> * <archdir>/<chipdir>/<boarddir>/configs/<configdir>
@ -725,7 +603,9 @@ static void config_search(const char *boarddir)
strncpy(g_buffer, boarddir, BUFFER_SIZE); strncpy(g_buffer, boarddir, BUFFER_SIZE);
/* Skip over <archdir> */ /* Save the <archdir> */
archname = g_buffer;
delim = strchr(g_buffer, g_delim); delim = strchr(g_buffer, g_delim);
if (delim == NULL) if (delim == NULL)
@ -734,13 +614,15 @@ static void config_search(const char *boarddir)
} }
else else
{ {
/* Skip over <chipdir> */ /* Save the <chipdir> */
tmp = delim + 1; *delim = '\0';
delim = strchr(tmp, g_delim); chipname = delim + 1;
delim = strchr(chipname, g_delim);
if (delim == NULL) if (delim == NULL)
{ {
debug("ERROR: delimiter not found in path: %s\n", tmp); debug("ERROR: delimiter not found in path: %s\n", chipname);
} }
else else
{ {
@ -768,7 +650,7 @@ static void config_search(const char *boarddir)
else else
{ {
configname = delim + 1; configname = delim + 1;
fprintf(stderr, " %s:%s\n", boardname, configname); callback(boarddir, archname, chipname, boardname, configname, data);
} }
} }
} }
@ -782,10 +664,39 @@ static void config_search(const char *boarddir)
closedir(dir); closedir(dir);
} }
static void find_archname_callback(const char *boarddir, const char *archname,
const char *chipname, const char *boardname,
const char *configname, void *data)
{
if (strcmp(g_boarddir, boardname) == 0 &&
strcmp(g_configdir, configname) == 0)
{
g_archdir = strdup(archname);
g_chipdir = strdup(chipname);
}
}
static void find_archname(void)
{
config_search("", find_archname_callback, NULL);
if (g_archdir == NULL || g_chipdir == NULL)
{
g_archdir = "unknown";
g_chipdir = "unknown";
}
}
static void enumerate_callback(const char *boarddir, const char *archname,
const char *chipname, const char *boardname,
const char *configname, void *data)
{
fprintf(stderr, " %s:%s\n", boardname, configname);
}
static void enumerate_configs(void) static void enumerate_configs(void)
{ {
fprintf(stderr, "Options for <board-name>:<config-name> include:\n\n"); fprintf(stderr, "Options for <board-name>:<config-name> include:\n\n");
config_search(""); config_search("", enumerate_callback, NULL);
} }
static void check_configdir(void) static void check_configdir(void)
@ -802,6 +713,8 @@ static void check_configdir(void)
* boards/<archdir>/<chipdir>/<boarddir>/configs/<configdir> * boards/<archdir>/<chipdir>/<boarddir>/configs/<configdir>
*/ */
find_archname();
snprintf(g_buffer, BUFFER_SIZE, "%s%cboards%c%s%c%s%c%s%cconfigs%c%s", snprintf(g_buffer, BUFFER_SIZE, "%s%cboards%c%s%c%s%c%s%cconfigs%c%s",
g_topdir, g_delim, g_delim, g_archdir, g_delim, g_chipdir, g_topdir, g_delim, g_delim, g_archdir, g_delim, g_chipdir,
g_delim, g_boarddir, g_delim, g_delim, g_configdir); g_delim, g_boarddir, g_delim, g_delim, g_configdir);

View File

@ -142,33 +142,12 @@ else
boarddir=`echo ${boardconfig} | cut -d':' -f1` boarddir=`echo ${boardconfig} | cut -d':' -f1`
fi fi
# Detect the architecture of this board. configpath=${TOPDIR}/boards/*/*/${boarddir}/configs/${configdir}
if [ ! -d ${configpath} ]; then
archs="arm avr hc mips misoc or1k renesas risc-v sim x86 xtensa z16 z80"
chips="a1x am335x c5471 cxd56xx dm320 efm32 imx6 imxrt kinetis kl lc823450
lpc17xx_40xx lpc214x lpc2378 lpc31xx lpc43xx lpc54xx max326xx moxart nrf52
nuc1xx rx65n s32k1xx sam34 sama5 samd2l2 samd5e5 samv7 stm32 stm32f0l0g0 stm32f7 stm32h7
stm32l4 str71x tiva tms570 xmc4 at32uc3 at90usb atmega mcs92s12ne64 pic32mx
pic32mz lm32 mor1kx m32262f8 sh7032 fe310 k210 gap8 nr5m100 sim qemu esp32 z16f2811
ez80 z180 z8 z80"
for arc in ${archs}; do
for chip in ${chips}; do
if [ -f ${TOPDIR}/boards/${arc}/${chip}/${boarddir}/Kconfig ]; then
archdir=${arc}
chipdir=${chip}
echo " Detected ${archdir} Architecture"
echo " Detected ${chipdir} Chip"
fi
done
done
configpath=${TOPDIR}/boards/${archdir}/${chipdir}/${boarddir}/configs/${configdir}
if [ ! -d "${configpath}" ]; then
# Try direct path used with custom configurations. # Try direct path used with custom configurations.
configpath=${TOPDIR}/${boardconfig} configpath=${TOPDIR}/${boardconfig}
if [ ! -d "${configpath}" ]; then if [ ! -d ${configpath} ]; then
echo "Directory for ${boardconfig} does not exist. Options are:" echo "Directory for ${boardconfig} does not exist. Options are:"
echo "" echo ""
echo "Select one of the following options for <board-name>:" echo "Select one of the following options for <board-name>:"
@ -185,26 +164,26 @@ if [ ! -d "${configpath}" ]; then
fi fi
fi fi
src_makedefs="${TOPDIR}/boards/${archdir}/${chipdir}/${boarddir}/configs/${configdir}/Make.defs" src_makedefs=${TOPDIR}/boards/*/*/${boarddir}/configs/${configdir}/Make.defs
dest_makedefs="${TOPDIR}/Make.defs" dest_makedefs="${TOPDIR}/Make.defs"
if [ ! -r "${src_makedefs}" ]; then if [ ! -r ${src_makedefs} ]; then
src_makedefs="${TOPDIR}/boards/${archdir}/${chipdir}/${boarddir}/scripts/Make.defs" src_makedefs=${TOPDIR}/boards/*/*/${boarddir}/scripts/Make.defs
if [ ! -r "${src_makedefs}" ]; then if [ ! -r ${src_makedefs} ]; then
src_makedefs="${TOPDIR}/${boardconfig}/Make.defs" src_makedefs=${TOPDIR}/${boardconfig}/Make.defs
if [ ! -r "${src_makedefs}" ]; then if [ ! -r ${src_makedefs} ]; then
echo "File Make.defs could not be found" echo "File Make.defs could not be found"
exit 4 exit 4
fi fi
fi fi
fi fi
src_config="${configpath}/defconfig" src_config=${configpath}/defconfig
dest_config="${TOPDIR}/.config" dest_config="${TOPDIR}/.config"
if [ ! -r "${src_config}" ]; then if [ ! -r ${src_config} ]; then
echo "File \"${src_config}\" does not exist" echo "File ${src_config} does not exist"
exit 5 exit 5
fi fi
@ -223,7 +202,7 @@ fi
# If we are going to some host other then windows native or to a windows # If we are going to some host other then windows native or to a windows
# native host, then don't even check what is in the defconfig file. # native host, then don't even check what is in the defconfig file.
oldnative=`grep CONFIG_WINDOWS_NATIVE= "${src_config}" | cut -d'=' -f2` oldnative=`grep CONFIG_WINDOWS_NATIVE= ${src_config} | cut -d'=' -f2`
if [ "X$host" != "Xwindows" -o "X$wenv" != "Xnative" ]; then if [ "X$host" != "Xwindows" -o "X$wenv" != "Xnative" ]; then
unset winnative unset winnative
else else
@ -241,7 +220,7 @@ fi
defappdir=y defappdir=y
if [ -z "${appdir}" -a "X$oldnative" = "$winnative" ]; then if [ -z "${appdir}" -a "X$oldnative" = "$winnative" ]; then
quoted=`grep "^CONFIG_APPS_DIR=" "${src_config}" | cut -d'=' -f2` quoted=`grep "^CONFIG_APPS_DIR=" ${src_config} | cut -d'=' -f2`
if [ ! -z "${quoted}" ]; then if [ ! -z "${quoted}" ]; then
appdir=`echo ${quoted} | sed -e "s/\"//g"` appdir=`echo ${quoted} | sed -e "s/\"//g"`
defappdir=n defappdir=n
@ -288,15 +267,15 @@ fi
# Okay... Everything looks good. Setup the configuration # Okay... Everything looks good. Setup the configuration
echo " Copy files" echo " Copy files"
install -m 644 "${src_makedefs}" "${dest_makedefs}" || \ install -m 644 ${src_makedefs} "${dest_makedefs}" || \
{ echo "Failed to copy \"${src_makedefs}\"" ; exit 8 ; } { echo "Failed to copy ${src_makedefs}" ; exit 8 ; }
install -m 644 "${src_config}" "${dest_config}" || \ install -m 644 ${src_config} "${dest_config}" || \
{ echo "Failed to copy \"${src_config}\"" ; exit 9 ; } { echo "Failed to copy ${src_config}" ; exit 9 ; }
# Install any optional files # Install any optional files
for opt in ${OPTFILES}; do for opt in ${OPTFILES}; do
test -f "${configpath}/${opt}" && install "${configpath}/${opt}" "${TOPDIR}/" test -f ${configpath}/${opt} && install ${configpath}/${opt} "${TOPDIR}/"
done done
# If we did not use the CONFIG_APPS_DIR that was in the defconfig config file, # If we did not use the CONFIG_APPS_DIR that was in the defconfig config file,

View File

@ -33,7 +33,6 @@
# #
WD=`test -d ${0%/*} && cd ${0%/*}; pwd` WD=`test -d ${0%/*} && cd ${0%/*}; pwd`
TOPDIR="${WD}/.."
USAGE="USAGE: $0 [options] <board>:<config>" USAGE="USAGE: $0 [options] <board>:<config>"
ADVICE="Try '$0 --help' for more information" ADVICE="Try '$0 --help' for more information"
@ -115,39 +114,6 @@ else
BOARDSUBDIR=`echo ${CONFIG} | cut -d':' -f1` BOARDSUBDIR=`echo ${CONFIG} | cut -d':' -f1`
fi fi
# Detect the architecture of this board.
ARCHLIST="arm avr hc mips misoc or1k renesas risc-v sim x86 xtensa z16 z80"
ARCHLIST="arm avr hc mips misoc or1k renesas risc-v sim x86 xtensa z16 z80"
CHIPLIST="a1x am335x c5471 cxd56xx dm320 efm32 imx6 imxrt kinetis kl lc823450
lpc17xx_40xx lpc214x lpc2378 lpc31xx lpc43xx lpc54xx max326xx moxart nrf52
nuc1xx rx65n s32k1xx sam34 sama5 samd2l2 samd5e5 samv7 stm32 stm32f0l0g0 stm32f7 stm32h7
stm32l4 str71x tiva tms570 xmc4 at32uc3 at90usb atmega mcs92s12ne64 pic32mx
pic32mz lm32 mor1kx m32262f8 sh7032 fe310 k210 gap8 nr5m100 sim qemu esp32 z16f2811
ez80 z180 z8 z80"
for ARCH in ${ARCHLIST}; do
for CHIP in ${CHIPLIST}; do
if [ -f ${TOPDIR}/boards/${ARCH}/${CHIP}/${BOARDSUBDIR}/Kconfig ]; then
ARCHSUBDIR=${ARCH}
CHIPSUBDIR=${CHIP}
echo " Detected ${ARCHSUBDIR} Architecture"
echo " Detected ${CHIPSUBDIR} Chip"
fi
done
done
for ARCH in ${ARCHLIST}; do
if [ -f boards/${ARCH}/${BOARDSUBDIR}/Kconfig ]; then
ARCHSUBDIR=${ARCH}
fi
done
if [ -z "${ARCHSUBDIR}" ]; then
echo "ERROR: Architecture of ${BOARDSUBDIR} not found"
exit 1
fi
# Where are we # Where are we
MYNAME=`basename $0` MYNAME=`basename $0`
@ -163,7 +129,7 @@ fi
# Set up the environment # Set up the environment
BOARDDIR=boards/$ARCHSUBDIR/$CHIPSUBDIR/$BOARDSUBDIR BOARDDIR=boards/*/*/$BOARDSUBDIR
SCRIPTSDIR=$BOARDDIR/scripts SCRIPTSDIR=$BOARDDIR/scripts
MAKEDEFS1=$SCRIPTSDIR/Make.defs MAKEDEFS1=$SCRIPTSDIR/Make.defs
@ -179,25 +145,25 @@ CMPCONFIGMAKEDIR=tools
# Check the board configuration directory # Check the board configuration directory
if [ ! -d "$BOARDDIR" ]; then if [ ! -d $BOARDDIR ]; then
echo "No board directory found at $BOARDDIR" echo "No board directory found at $BOARDDIR"
exit 1 exit 1
fi fi
if [ ! -d "$CONFIGDIR" ]; then if [ ! -d $CONFIGDIR ]; then
echo "No configuration directory found at $CONFIGDIR" echo "No configuration directory found at $CONFIGDIR"
exit 1 exit 1
fi fi
if [ ! -r "$DEFCONFIG" ]; then if [ ! -r $DEFCONFIG ]; then
echo "No readable defconfig file at $DEFCONFIG" echo "No readable defconfig file at $DEFCONFIG"
exit 1 exit 1
fi fi
if [ -r "$MAKEDEFS1" ]; then if [ -r $MAKEDEFS1 ]; then
MAKEDEFS=$MAKEDEFS1 MAKEDEFS=$MAKEDEFS1
else else
if [ -r "$MAKEDEFS2" ]; then if [ -r $MAKEDEFS2 ]; then
MAKEDEFS=$MAKEDEFS2 MAKEDEFS=$MAKEDEFS2
else else
echo "No readable Make.defs file at $MAKEDEFS1 or $MAKEDEFS2" echo "No readable Make.defs file at $MAKEDEFS1 or $MAKEDEFS2"

View File

@ -296,32 +296,8 @@ for line in $testlist; do
boarddir=`echo $config | cut -d':' -f1` boarddir=`echo $config | cut -d':' -f1`
fi fi
# Detect the architecture of this board. path=$nuttx/boards/*/*/$boarddir/configs/$configdir
if [ ! -r $path/defconfig ]; then
ARCHLIST="arm avr hc mips misoc or1k renesas risc-v sim x86 xtensa z16 z80"
CHIPLIST="a1x am335x c5471 cxd56xx dm320 efm32 imx6 imxrt kinetis kl lc823450
lpc17xx_40xx lpc214x lpc2378 lpc31xx lpc43xx lpc54xx max326xx moxart nrf52
nuc1xx rx65n s32k1xx sam34 sama5 samd2l2 samd5e5 samv7 stm32 stm32f0l0g0 stm32f7 stm32h7
stm32l4 str71x tiva tms570 xmc4 at32uc3 at90usb atmega mcs92s12ne64 pic32mx
pic32mz lm32 mor1kx m32262f8 sh7032 fe310 k210 gap8 nr5m100 sim qemu esp32 z16f2811
ez80 z180 z8 z80"
for arch in ${ARCHLIST}; do
for chip in ${CHIPLIST}; do
if [ -f ${nuttx}/boards/${arch}/${chip}/${boarddir}/Kconfig ]; then
archdir=${arch}
chipdir=${chip}
fi
done
done
if [ -z "${archdir}" ]; then
echo "ERROR: Architecture of ${boarddir} not found"
exit 1
fi
path=$nuttx/boards/$archdir/$chipdir/$boarddir/configs/$configdir
if [ ! -r "$path/defconfig" ]; then
echo "ERROR: no configuration found at $path" echo "ERROR: no configuration found at $path"
showusage showusage
fi fi