summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Hieber <rhi@pengutronix.de>2019-11-14 16:41:16 +0100
committerRoland Hieber <rhi@pengutronix.de>2023-05-24 22:29:59 +0200
commitcc49562a4dfee2115bffee9cbb4a923c50582999 (patch)
tree6b241a4baedce35e3c4c88a7d9f68b0d535110d8
parent8226a6575ace6f975a64068e5f32a0252c3cab14 (diff)
downloadptxdist-rhi/init-bsp-and-platform-commands.tar.gz
ptxdist-rhi/init-bsp-and-platform-commands.tar.xz
ptxdist: add 'init' commands to create new configsrhi/init-bsp-and-platform-commands
The goal here is to give users a way to create a working BSP or platform from scratch by asking only a minimal set of relevant questions and letting the user press Enter about 15 times, instead of asking every question in the whole platform and ptxconfig menu, which would require pressing Enter about 428 times. For that, we create two separate Kconfig menus, rules/Kconfig-init for the ptxconfig, and platforms/Kconfig-init for the platformconfig, which include only the relevant .in files from the full menus. Still, some options from these .in files can be set to reasonable defaults for new BSPs or platforms, which is done with two new defconfig files instead of further outsourcing the relevant config options into single .in files. With the 'init' subcommand, PTXdist first creates a standard directory structure under configs/ if necessary, then creates a minimal config file from the respective defconfig, and finally calls kconfig on the respective Kconfig-init menu, asking the user for the remaining config options. A silenced oldconfig run on the full menu file then takes care to set all other config options to their defaults. Signed-off-by: Roland Hieber <rhi@pengutronix.de> --- * v2: add IMAGE_ROOT_TGZ to platforms/init_defconfig v3: - move script to scripts/lib/ptxd_lib_bsp_init.sh and rename functions accordingly - move more code from bin/ptxdist into scripts/lib - fix trailing whitespace
-rwxr-xr-xbin/ptxdist7
-rw-r--r--doc/ref_parameter.rst5
-rw-r--r--platforms/Kconfig-init13
-rw-r--r--platforms/init_defconfig19
-rw-r--r--rules/Kconfig-init62
-rw-r--r--rules/init_defconfig21
-rw-r--r--rules/initmethod.in3
-rw-r--r--scripts/lib/ptxd_lib_bsp_init.sh140
-rw-r--r--scripts/lib/ptxd_lib_kconfig.sh10
9 files changed, 280 insertions, 0 deletions
diff --git a/bin/ptxdist b/bin/ptxdist
index 0c683e4d3..56f300b2a 100755
--- a/bin/ptxdist
+++ b/bin/ptxdist
@@ -703,6 +703,9 @@ PTXdist $(printf "%-24s" ${PTXDIST_VERSION_FULL}) Build System for Embedded Linu
Setup and Project Actions:
+ init [<platformname>] initialise a new BSP in the current directory
+ init platform [<name>] initialise a new platform in the current BSP
+
menu enter main control menu
setup setup per-user preferences
@@ -1875,6 +1878,10 @@ EOF
do_${cmd}
exit
;;
+ init)
+ ptxd_lib_bsp_init "$@"
+ exit
+ ;;
image)
PTXDIST_OPTIMIZE_IO=true
if [ ${#} -eq 0 ]; then
diff --git a/doc/ref_parameter.rst b/doc/ref_parameter.rst
index 282496e7e..30aeb5316 100644
--- a/doc/ref_parameter.rst
+++ b/doc/ref_parameter.rst
@@ -12,6 +12,11 @@ PTXdist is a command line tool, which is basically called as:
Setup and Project Actions
~~~~~~~~~~~~~~~~~~~~~~~~~
+``init <platformname>``, ``init platform <platformname>``
+ initialise a new BSP in the current directory, or add a new platform to the
+ current BSP. This action creates all required config files, and then calls
+ *menuconfig* on them, and can be used to start a new BSP from scratch.
+
``menu``
this starts a dialog based frontend for those who do not like typing
commands. It will gain us access to the most common parameters to
diff --git a/platforms/Kconfig-init b/platforms/Kconfig-init
new file mode 100644
index 000000000..9e42556d7
--- /dev/null
+++ b/platforms/Kconfig-init
@@ -0,0 +1,13 @@
+#
+# a kconfig menu structure that asks only a minimal amount of questions to
+# quickly get started with a new platform
+#
+source "generated/platform_version.in"
+source "platforms/architecture.in"
+source "platforms/toolchain.in"
+
+# dependencies for kernel rule:
+source "generated/hosttools_noprompt.in"
+source "generated/hosttools_platform.in"
+
+source "platforms/kernel.in"
diff --git a/platforms/init_defconfig b/platforms/init_defconfig
new file mode 100644
index 000000000..f8f3d4cbe
--- /dev/null
+++ b/platforms/init_defconfig
@@ -0,0 +1,19 @@
+PTXCONF_PLATFORM_VERSION="-${PTXDIST_BSP_AUTOVERSION}"
+PTXCONF_COMPILER_PREFIX_KERNEL="${PTXCONF_COMPILER_PREFIX}"
+PTXCONF_COMPILER_PREFIX_BOOTLOADER="${PTXCONF_COMPILER_PREFIX}"
+PTXCONF_LIBC_GLIBC=y
+# PTXCONF_LIBC_UCLIBC is not set
+PTXCONF_KERNEL=y
+# PTXCONF_KERNEL_MODULES is not set
+# PTXCONF_KERNEL_ZSTD is not set
+# PTXCONF_KERNEL_XZ is not set
+# PTXCONF_KERNEL_LZOP is not set
+# PTXCONF_KERNEL_LZ4 is not set
+# PTXCONF_KERNEL_OPENSSL is not set
+# PTXCONF_KERNEL_LIBELF is not set
+# PTXCONF_KERNEL_GCC_PLUGINS is not set
+# PTXCONF_KERNEL_CONFIG_BASE_VERSION is not set
+PTXCONF_KERNEL_SERIES="series"
+PTXCONF_KERNEL_CONFIG="kernelconfig-${PTXCONF_KERNEL_VERSION}"
+PTXCONF_KERNEL_EXTRA_MAKEVARS=""
+PTXCONF_IMAGE_ROOT_TGZ=y
diff --git a/rules/Kconfig-init b/rules/Kconfig-init
new file mode 100644
index 000000000..2355d070d
--- /dev/null
+++ b/rules/Kconfig-init
@@ -0,0 +1,62 @@
+#
+# a kconfig menu structure that asks only a minimal amount of questions to
+# quickly get started with a new BSP
+#
+source "rules/ptxdist-dgen.in"
+source "rules/ptxdist-version.in"
+source "generated/ptxdist_options.in"
+
+source "rules/project-name.in"
+
+#
+# stubs for options that we want to ask for or enable by default, but not ask
+# for all their suboptions
+#
+
+config BUSYBOX
+ default y
+ bool
+
+# busybox installs init, poweroff, halt etc. by default. This conflicts with
+# systemd, but since busybox brings its own kconfig menu in-tree, we cannot
+# easily influence its defaults. Therefore we first disable those options in
+# init_defconfig, and explicitely select them when needed.
+# Note: these option need to have a prompt, otherwise kconfig doesn't write them
+# to the config file if they are disabled, and busybox's default will kick in.
+config BUSYBOX_HALT
+ bool "busybox /usr/sbin/halt"
+config BUSYBOX_INIT
+ bool "busybox /usr/sbin/init"
+config BUSYBOX_POWEROFF
+ bool "busybox /usr/sbin/poweroff"
+config BUSYBOX_REBOOT
+ bool "busybox /usr/sbin/reboot"
+config BUSYBOX_RUNLEVEL
+ bool "busybox /usr/sbin/runlevel"
+
+choice
+ prompt "init method"
+ default INITMETHOD_SYSTEMD
+
+ config INITMETHOD_BBINIT
+ bool
+ prompt "busybox init "
+ select BUSYBOX_HALT
+ select BUSYBOX_INIT
+ select BUSYBOX_POWEROFF
+ select BUSYBOX_REBOOT
+ select BUSYBOX_RUNLEVEL
+
+ config INITMETHOD_SYSTEMD
+ bool
+ prompt "systemd "
+
+ config INITMETHOD_INITRAMFS
+ bool
+ prompt "initramfs init "
+ select BUSYBOX_HALT
+ select BUSYBOX_INIT
+ select BUSYBOX_POWEROFF
+ select BUSYBOX_REBOOT
+ select BUSYBOX_RUNLEVEL
+endchoice
diff --git a/rules/init_defconfig b/rules/init_defconfig
new file mode 100644
index 000000000..9fa9ab00a
--- /dev/null
+++ b/rules/init_defconfig
@@ -0,0 +1,21 @@
+# PTXCONF_ALLYES is not set
+# PTXCONF_BROKEN is not set
+PTXCONF_FIX_PERMISSIONS=y
+PTXCONF_PROJECT_VERSION="-${PTXDIST_BSP_AUTOVERSION}"
+# PTXCONF_PROJECT_CREATE_DEVPKGS is not set
+# PTXCONF_PROJECT_USE_DEVPKGS is not set
+PTXCONF_PROJECT_DEVPKGDIR=""
+PTXCONF_PROJECT_DEVMIRROR=""
+# PTXCONF_PROJECT_CHECK_LICENSES is not set
+PTXCONF_REPRODUCIBLE_TIMESTAMP_PTXDIST=y
+# PTXCONF_REPRODUCIBLE_TIMESTAMP_TOOLCHAIN is not set
+# PTXCONF_REPRODUCIBLE_TIMESTAMP_CUSTOM is not set
+# PTXCONF_REPRODUCIBLE_TIMESTAMP_STRING is not set
+PTXCONF_DEBUG_PACKAGES=y
+# initmethod will enable the following busybox tools if needed:
+# PTXCONF_BUSYBOX_HALT is not set
+# PTXCONF_BUSYBOX_INIT is not set
+# PTXCONF_BUSYBOX_POWEROFF is not set
+# PTXCONF_BUSYBOX_REBOOT is not set
+# PTXCONF_BUSYBOX_RUNLEVEL is not set
+# PTXCONF_STAGING is not set
diff --git a/rules/initmethod.in b/rules/initmethod.in
index 489fd365d..f1077e6ae 100644
--- a/rules/initmethod.in
+++ b/rules/initmethod.in
@@ -10,6 +10,9 @@ menuconfig INITMETHOD
if INITMETHOD
choice
+ #
+ # NOTE: if you add options here, also add them to rules/init_defconfig
+ #
prompt "init method"
default INITMETHOD_SYSTEMD
diff --git a/scripts/lib/ptxd_lib_bsp_init.sh b/scripts/lib/ptxd_lib_bsp_init.sh
new file mode 100644
index 000000000..9e27d2251
--- /dev/null
+++ b/scripts/lib/ptxd_lib_bsp_init.sh
@@ -0,0 +1,140 @@
+#!/bin/bash
+
+ptxd_lib_bsp_init_check() {
+ if [ -z "${PTXDIST_PTXCONFIG}" ]; then
+ echo
+ echo "${PTXDIST_LOG_PROMPT}error: cannot create empty ptxconfig file."
+ echo
+ return 1
+ fi
+
+ if [ -z "${PTXDIST_FORCE}" ] && [ -e "${PTXDIST_PTXCONFIG}" ]; then
+ echo
+ echo "${PTXDIST_LOG_PROMPT}error: the file '${PTXDIST_PTXCONFIG}' already exists,"
+ echo "${PTXDIST_LOG_PROMPT} use '--force' to overwrite it."
+ echo
+ return 1
+ fi
+
+ if [ -z "${PTXDIST_FORCE}" ] && [ -e "${PTXDIST_PTXCONFIG_DEFAULT}" ]; then
+ echo
+ echo "${PTXDIST_LOG_PROMPT}error: the file '${PTXDIST_PTXCONFIG_DEFAULT}' already exists,"
+ echo "${PTXDIST_LOG_PROMPT} use '--force' to overwrite it."
+ echo
+ return 1
+ fi
+}
+export -f ptxd_lib_bsp_init_check
+
+ptxd_lib_bsp_init_ptx() {
+ ptxd_lib_bsp_init_check &&
+
+ mkdir -p "$(dirname "${PTXDIST_PTXCONFIG}")" &&
+ cat "${PTXDIST_TOPDIR}/rules/init_defconfig" > "${PTXDIST_PTXCONFIG}" &&
+
+ PTXDIST_FORCE=true do_select ptxconfig "${PTXDIST_PTXCONFIG}" &&
+
+ # only ask the important questions first, then do silentdefconfig for
+ # all other options
+ PTXDIST_DEP_TARGET="all" ptxd_kconfig oldconfig "init-ptx" &&
+
+ # ... then do a silent defconfig for all other defaults
+ PTXDIST_DEP_TARGET="all" PTXDIST_FORCE=true \
+ yes '' | ptxd_kconfig oldconfig ptx > /dev/null
+}
+export -f ptxd_lib_bsp_init_ptx
+
+ptxd_lib_bsp_init_platform_check() {
+ if [ -z "${PTXDIST_PLATFORMCONFIG}" ]; then
+ echo
+ echo "${PTXDIST_LOG_PROMPT}error: cannot create empty platformconfig file."
+ echo
+ return 1
+ fi
+
+ if [ -z "${PTXDIST_FORCE}" ] && [ -e "${PTXDIST_PLATFORMCONFIG}" ]; then
+ echo
+ echo "${PTXDIST_LOG_PROMPT}error: the file '${PTXDIST_PLATFORMCONFIG}' already exists,"
+ echo "${PTXDIST_LOG_PROMPT} use '--force' to overwrite it."
+ echo
+ return 1
+ fi
+
+ if [ -z "${PTXDIST_FORCE}" ] && [ -e "${PTXDIST_PLATFORMCONFIG_DEFAULT}" ]; then
+ echo
+ echo "${PTXDIST_LOG_PROMPT}error: the file '${PTXDIST_PLATFORMCONFIG_DEFAULT}' already exists,"
+ echo "${PTXDIST_LOG_PROMPT} use '--force' to overwrite it."
+ echo
+ return 1
+ fi
+}
+export -f ptxd_lib_bsp_init_platform_check
+
+ptxd_lib_bsp_init_platform() {
+ local platformname="$1"
+ ptxd_lib_bsp_init_platform_check &&
+
+ mkdir -p "$(dirname "${PTXDIST_PLATFORMCONFIG}")" &&
+
+ # pre-prime with defaults
+ echo "PTXCONF_PLATFORM=\"${platformname}\"" > "${PTXDIST_PLATFORMCONFIG}" &&
+ cat "${PTXDIST_TOPDIR}/platforms/init_defconfig" >> "${PTXDIST_PLATFORMCONFIG}" &&
+
+ # pretend we have a toolchain, otherwise do_select will try to
+ # autodetect it from an incomplete platformconfig
+ PTX_toolchain_SET=true PTXDIST_FORCE=true \
+ do_select platformconfig "${PTXDIST_PLATFORMCONFIG}" &&
+
+ # only ask the important questions first...
+ PTXDIST_DEP_TARGET="all" \
+ ptxd_kconfig oldconfig init-platform &&
+
+ # ... then do a silent defconfig for all other defaults
+ PTXDIST_DEP_TARGET="all" PTXDIST_FORCE=true \
+ yes '' | ptxd_kconfig oldconfig platform > /dev/null
+}
+export -f ptxd_lib_bsp_init_platform
+
+ptxd_lib_bsp_init() {
+ local do_ptxconfig=1
+ if [ "$1" = "platform" ]; then
+ shift
+ do_ptxconfig=
+ fi
+
+ local platform="$1"
+ if [ -z "$platform" ]; then
+ echo
+ echo "${PTXDIST_LOG_PROMPT}error: Please specify a platform name."
+ echo
+ exit 1
+ fi
+
+ PTXDIST_PLATFORMCONFIG="configs/platform-${platform}/platformconfig"
+ PTXDIST_PTXCONFIG="configs/ptxconfig"
+
+ # abort early
+ ptxd_lib_bsp_init_platform_check &&
+ if [ -n "$do_ptxconfig" ]; then
+ ptxd_lib_bsp_init_check
+ fi &&
+
+ ptxd_lib_bsp_init_platform "${platform}" &&
+ if [ -n "$do_ptxconfig" ]; then
+ ptxd_lib_bsp_init_ptx
+ fi &&
+
+ if [ -n "$do_ptxconfig" ]; then
+ ptxd_dialog_msgbox \
+ "Adapt the new BSP to your needs by running:\n\n" \
+ " ptxdist menuconfig\n" \
+ " ptxdist menuconfig platform\n" \
+ " ptxdist menuconfig kernel"
+ else
+ ptxd_dialog_msgbox \
+ "Adapt the new platform to your needs by running:\n\n" \
+ " ptxdist menuconfig platform\n" \
+ " ptxdist menuconfig kernel"
+ fi
+}
+export -f ptxd_lib_bsp_init_cmd
diff --git a/scripts/lib/ptxd_lib_kconfig.sh b/scripts/lib/ptxd_lib_kconfig.sh
index 118deb421..225ef2353 100644
--- a/scripts/lib/ptxd_lib_kconfig.sh
+++ b/scripts/lib/ptxd_lib_kconfig.sh
@@ -738,10 +738,20 @@ ptxd_kconfig() {
fi
file_dotconfig="${PTXDIST_PTXCONFIG}"
;;
+ init-ptx)
+ part="ptx"
+ file_kconfig="rules/Kconfig-init"
+ file_dotconfig="${PTXDIST_PTXCONFIG}"
+ ;;
platform)
ptxd_in_path PTXDIST_PATH_LAYERS "platforms/Kconfig"
file_dotconfig="${PTXDIST_PLATFORMCONFIG}"
;;
+ init-platform)
+ part="platform"
+ file_kconfig="platforms/Kconfig-init"
+ file_dotconfig="${PTXDIST_PLATFORMCONFIG}"
+ ;;
collection)
file_dotconfig="${PTXDIST_PTXCONFIG}"
ptxd_normalize_config