Layer's post-scripts execution
After the creation of the build environment is completed, the configurator can execute scripts belonging to:
- Seco flavours layers (such as
meta-seco-clea-os-things) - Seco hardware layers (such as
meta-seco-rk)
The configurator looks into the layers for executable scripts matching the naming pattern *-seco-<flavour>-post-script.sh for flavours layers and *-seco-<arch>-post-script.sh for hardware layers. The values of <flavour> and <arch> are retrieve from the configuration file. For seco-build-configurator v1.2.1 the clusters are:
CONFIG_FLAVOURfor flavour layer (CONFIG_FLAVOUR_CLEAOS_clea-os-things=y)CONFIG_ARCHfor the architecture layer (i.e.CONFIG_ARCH_ARCHITECTURE_rk=y)
Firstly, the post-scripts belonging to the flavour layer are executed. Then, the hardware-related post-scripts are executed. If a layer has more scripts, those are executed in alphabetical order.
The scripts are looked into these layers only if they have been included in the bblayers.conf to ensure that the scripts are not executed if the layer is not deployed. The configurator executes the script in source mode so it's also possible to export variables to the main environment. The function that executes the scripts redirects stdout to python so that it can processed by the configurator. Differently, the stderr is not redirected so it's possible to exploit it to print messages to the user from the post-scripts.
Basic example
For example, assume that a Rockchip board needs to be built and that meta-seco-rk requires some scripts to be executed before letting the user build the project. The layer tree should look like:
$ tree -a -L 2 layers/meta-seco/meta-seco-rk
layers/meta-seco/meta-seco-rk
├── conf
│ ├── 0001-seco-rk-post-script.sh
│ ├── bblayers.conf
│ ├── layer.conf
│ ├── machine
│ ├── SRCREV.conf
│ └── Yconfig
├── docs
│ └── assets
├── .git -> ../../../.repo/projects/layers/meta-seco/meta-seco-rk.git
├── .gitlab-ci
│ ├── build-pipeline-ci-test.yml
......
│ └── .yamllint.yml
├── .gitlab-ci.yml
├── .gitmodules
├── LICENSE.txt
├── README.md
├── recipes-bsp
│ └── u-boot
├── recipes-kernel
│ └── linux
└── wic
└── mmc-image-rockchip.wks.in
15 directories, 30 files
where in the conf folder there is an executable script called 0001-seco-rk-post-script.sh. This script matches the naming pattern so it's suitable to be executed by the configurator.
NOTE: the configurator searches the scripts in the whole layer directory. It is anyway suggested to place them in the
confdirectory.
For example, the content of 0001-seco-rk-post-script.sh is:
#!/bin/sh
# Add variable to environment
export RK_TEST_ENV_VAR="SECO_RK_TEST_VAR"
# Ask for EULA acceptance
eula_text="END-USER LICENSE AGREEMENT (EULA)
Last Updated: $(date)
IMPORTANT: PLEASE READ THIS END-USER LICENSE AGREEMENT ('EULA') CAREFULLY BEFORE INSTALLING, USING, OR OTHERWISE ACCESSING THE SOFTWARE ('SOFTWARE').
BY INSTALLING, COPYING, OR OTHERWISE USING THE SOFTWARE, YOU AGREE TO BE BOUND BY THE TERMS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO THESE TERMS, DO NOT INSTALL OR USE THE SOFTWARE.
1. DEFINITIONS
1.1. 'Software' refers to the computer programs, code, files, and documentation provided by the company or entity granting this license.
1.2. 'User' refers to the individual or organization using the Software.
1.3. 'Licensor' refers to the owner of the Software.
2. LICENSE GRANT
2.1. Subject to the terms and conditions of this Agreement, Licensor grants the User a non-exclusive, non-transferable, revocable license to install and use the Software.
2.2. The Software is licensed, not sold, and no ownership rights are transferred under this Agreement.
3. RESTRICTIONS
3.1. The User may not reverse engineer, decompile, disassemble, or otherwise attempt to discover the source code of the Software.
3.2. The User may not sublicense, rent, lease, or distribute the Software without explicit written permission from the Licensor.
3.3. The Software may only be used on the hardware or system specified by the Licensor in the documentation.
.......
By clicking 'Accept' or by using the Software, you agree to be bound by the terms and conditions of this Agreement.
End of EULA
"
echo "$eula_text" | less >&2
read -p "Do you accept the terms of the EULA? (yes/no) [yes]: " choice
choice=${choice:-yes}
if [[ "$choice" == "yes" ]]; then
echo "Thank you for accepting the EULA." >&2
else
echo "You did not accept the EULA. Exiting..." >&2
fi
This script does the following:
- exports the variable
RK_TEST_ENV_VARto the environment. - asks to the user to accept the EULA agreement.
NOTE: to print text to the console always redirect it to
stderr.
The post-scripts are executed after the build environment is ready. The procedure is the same as shown in Basics. For example, starting from scratch, creating the environment for Seco E09 (Rockchip) with clea-os flavour:
yoctouser@8960ff9e65dc:~/workdir$ . ./seco-setup.sh -d seco_sbc_e09_clea-os
***
USE defconfig configuration file: seco_sbc_e09_clea-os
SBC RK3568 E09 for Clea OS Wayland and default settings
***
yoctouser@8960ff9e65dc:~/workdir$ . ./seco-setup.sh -c
WARNING: no CONFIG_CLOUD_ASTARTE-URL found in the configuration.
WARNING: no CONFIG_CLOUD_ASTARTE-REALM found in the configuration.
WARNING: no CONFIG_CLOUD_ASTARTE-PAIRING-TOKEN found in the configuration.
WARNING: no RAUC found in the configuration.
Welcome to SECO BSP
The Yocto Project has extensive documentation about OE including a
reference manual which can be found at:
http://yoctoproject.org/documentation
For more information about OpenEmbedded see their website:
http://www.openembedded.org/
Your build environment has been configured with:
MACHINE=seco-rk3568-e09
SDKMACHINE=i686
DISTRO=clea-os-fb
EULA=
No post-script has been found in the layer meta-seco-clea-os.
Executing post-script 0001-seco-rk-post-script.sh found in the layer meta-seco-rk
The flavour layer has no scripts matching the naming pattern. In the hardware-related layer a script is found and is then executed.
When the script is executed the EULA is shown with less so that the user can interactively read the document:
END-USER LICENSE AGREEMENT (EULA)
Last Updated: Thu 19 Dec 2024 02:42:22 PM UTC
IMPORTANT: PLEASE READ THIS END-USER LICENSE AGREEMENT ('EULA') CAREFULLY BEFORE INSTALLING, USING, OR OTHERWISE ACCESSING THE SOFTWARE ('SOFTWARE').
BY INSTALLING, COPYING, OR OTHERWISE USING THE SOFTWARE, YOU AGREE TO BE BOUND BY THE TERMS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO THESE TERMS, DO NOT INSTALL OR USE THE SOFTWARE.
1. DEFINITIONS
1.1. 'Software' refers to the computer programs, code, files, and documentation provided by the company or entity granting this license.
1.2. 'User' refers to the individual or organization using the Software.
1.3. 'Licensor' refers to the owner of the Software.
1. LICENSE GRANT
2.1. Subject to the terms and conditions of this Agreement, Licensor grants the User a non-exclusive, non-transferable, revocable license to install and use the Software.
2.2. The Software is licensed, not sold, and no ownership rights are transferred under this Agreement.
1. RESTRICTIONS
3.1. The User may not reverse engineer, decompile, disassemble, or otherwise attempt to discover the source code of the Software.
3.2. The User may not sublicense, rent, lease, or distribute the Software without explicit written permission from the Licensor.
3.3. The Software may only be used on the hardware or system specified by the Licensor in the documentation.
.......
By clicking 'Accept' or by using the Software, you agree to be bound by the terms and conditions of this Agreement.
End of EULA
(END)
Then the terminal asks for user input:
Do you accept the terms of the EULA? (yes/no) [yes]: yes
Thank you for accepting the EULA.
yoctouser@8960ff9e65dc:~/workdir/build_e09$
and the post-script is completed.
If another script is added to Rockchip's layer called 0002-seco-rk-post-script.sh so that:
yoctouser@8960ff9e65dc:~/workdir$ ll layers/meta-seco/meta-seco-rk/conf/
total 36
drwxrwxr-x 4 yoctouser yoctouser 4096 Dec 17 11:04 ./
drwxrwxr-x 8 yoctouser yoctouser 4096 Dec 11 10:30 ../
-rwxrwxr-x 1 yoctouser yoctouser 1881 Dec 19 13:52 0001-seco-rk-post-script.sh*
-rwxrwxr-x 1 yoctouser yoctouser 80 Dec 19 14:39 0002-seco-rk-post-script.sh*
-rw-rw-r-- 1 yoctouser yoctouser 119 Dec 11 10:30 bblayers.conf
-rw-rw-r-- 1 yoctouser yoctouser 579 Dec 11 10:30 layer.conf
drwxrwxr-x 3 yoctouser yoctouser 4096 Dec 11 10:30 machine/
-rw-rw-r-- 1 yoctouser yoctouser 162 Dec 11 10:30 SRCREV.conf
drwxrwxr-x 2 yoctouser yoctouser 4096 Dec 11 10:30 Yconfig/
and with the content:
#!/bin/sh
echo "This is a test post-script executed for Rockchip boards." >&2
After the execution of 0001-seco-rk-post-script.sh, 0002-seco-rk-post-script.sh is executed resulting in more messages in the terminal:
Executing post-script 0002-seco-rk-post-script.sh found in the layer meta-seco-rk
This is a test post-script executed for Rockchip boards.
To verify that the variable has been exported:
yoctouser@8960ff9e65dc:~/workdir$ env | grep ^RK
RK_TEST_ENV_VAR=SECO_RK_TEST_VAR
The configurator handles the variables to export incrementally: for each script executed the needed changes to the environment is collected. The changes are collected into a dictionary as the configurator outputs the command to export the variables only at the very end of the post-scripts execution, once that all the scripts have been processed. If a variable to export is already in the dictionary, the value is substituted so the last script has the priority.
NXP EULA example
NXP build require to accept the EULA located in layers/meta-freescale/EULA. The EULA acceptance is confirmed writing in the local.conf the string ACCEPT_FSL_EULA = "1". Thus, a post-script has been developed to do this interactively. The script is:
#!/bin/sh
LICENSE_COMMENT="# Accepted NXP EULA"
LICENSE_VARIABLE="ACCEPT_FSL_EULA"
LICENSE_VARIABLE_LINE="${LICENSE_VARIABLE} = \"1\""
# The post-scripts are executed from the build dir
BUILD_DIR=${PWD}
FSL_EULA_FILE=${BUILD_DIR}/../layers/meta-freescale/EULA
LOCAL_CONF_PATH="${BUILD_DIR}/conf/local.conf"
# Check for the existence of EULA file in meta-freescale
if [ ! -e $FSL_EULA_FILE ]; then
echo -e "ERROR: NXP EULA not found at $FSL_EULA_FILE." >&2
echo -e "Building the project will not be possible." >&2
return 1
fi
# Ask user to accept the FSL EULA:
echo "
Some BSPs depend on libraries and packages which are covered by NXP's
End User License Agreement (EULA). To have the right to use these binaries in
your images, you need to read and accept the following...
" >&2
# Open NXP EULA
echo "Opening NXP EULA..." >&2
sleep 4
more -d $FSL_EULA_FILE >&2
# Ask the user to accept EULA
echo >&2
read -p "Do you accept NXP's EULA? (yes/no) [default: yes]: " choice
choice=${choice:-yes}
# Remove all non-alphanumeric characters (sanitizing input)
choice=$(echo "$choice" | tr -cd '[:alnum:]' | tr '[:upper:]' '[:lower:]')
# Validate input. Write to local.conf if the license has been accepted
case "$choice" in
yes|y)
echo >&2
echo "The NXP EULA has been accepted." >&2
if grep -q "${LICENSE_VARIABLE}" "${LOCAL_CONF_PATH}"; then
echo "The NXP EULA flag ${LICENSE_VARIABLE} is already present. Updating it with the new value." >&2
sed -i "/${LICENSE_COMMENT}/d" "${LOCAL_CONF_PATH}"
sed -i "/${LICENSE_VARIABLE}/d" "${LOCAL_CONF_PATH}"
else
echo "Adding NXP EULA flag ${LICENSE_VARIABLE} to local.conf." >&2
fi
echo -e "\n${LICENSE_COMMENT}\n${LICENSE_VARIABLE_LINE}\n" >> "${LOCAL_CONF_PATH}"
;;
no|n)
echo "WARNING: the NXP EULA has not been accepted. Building the project will not be possible." >&2
;;
*)
echo "Invalid input. Please respond with 'yes', 'y', 'no' or 'n'." >&2
;;
esac
This is the process when creating a NXP build (i.e. NXP i.MX8M Plus EVK board):
yoctouser@15455813a79f:~/workdir$ . ./seco-setup.sh -d nxp_imx8mpevk_clea-os
***
USE defconfig configuration file: nxp_imx8mpevk_clea-os
NXP i.MX8M Plus EVK board for Clea OS Wayland and default settings
***
yoctouser@15455813a79f:~/workdir$ . ./seco-setup.sh -c
WARNING: no CONFIG_CLOUD_ASTARTE-URL found in the configuration.
WARNING: no CONFIG_CLOUD_ASTARTE-REALM found in the configuration.
WARNING: no CONFIG_CLOUD_ASTARTE-PAIRING-TOKEN found in the configuration.
WARNING: no RAUC found in the configuration.
WARNING: No SRCREV.conf found in meta-seco-imx for machine nxp-imx8mpevk.
WARNING: no SRCREV.conf files found. Not creating build_imx8mpevk/conf/SRCREV.conf.
Welcome to SECO BSP
The Yocto Project has extensive documentation about OE including a
reference manual which can be found at:
http://yoctoproject.org/documentation
For more information about OpenEmbedded see their website:
http://www.openembedded.org/
Your build environment has been configured with:
MACHINE=nxp-imx8mpevk
SDKMACHINE=i686
DISTRO=clea-os-fb
EULA=
No post-script has been found in the layer meta-seco-clea-os.
Executing post-script 0001-nxp-eula-seco-imx-post-script.sh found in the layer meta-seco-imx
Some BSPs depend on libraries and packages which are covered by NXP's
End User License Agreement (EULA). To have the right to use these binaries in
your images, you need to read and accept the following...
Opening NXP EULA...
LA_OPT_NXP_Software_License v56 April 2024
IMPORTANT. Read the following NXP Software License Agreement ("Agreement")
completely. By selecting the "I Accept" button at the end of this page, or by
downloading, installing, or using the Licensed Software, you indicate that you
accept the terms of the Agreement, and you acknowledge that you have the
authority, for yourself or on behalf of your company, to bind your company to
these terms. You may then download or install the file. In the event of a
conflict between the terms of this Agreement and any license terms and
conditions for NXP’s proprietary software embedded anywhere in the Licensed
Software file, the terms of this Agreement shall control. If a separate
license agreement for the Licensed Software has been signed by you and NXP,
then that agreement shall govern your use of the Licensed Software and shall
supersede this Agreement.
NXP SOFTWARE LICENSE AGREEMENT
This is a legal agreement between your employer, of which you are an authorized
representative, or, if you have no employer, you as an individual ("you" or
"Licensee"), and and NXP USA, Inc., if Licensee is located within the United
States or NXP Semiconductors Netherlands B.V., if Licensee if located outside
of the United States (“NXP”). It concerns your rights to use the software
Do you accept NXP's EULA? (yes/no) [default: yes]: y
The NXP EULA has been accepted.
Adding NXP EULA flag ACCEPT_FSL_EULA to local.conf.
yoctouser@15455813a79f:~/workdir/build_imx8mpevk$ cat conf/local.conf | grep ^ACCEPT
ACCEPT_FSL_EULA = "1"
Raspberry Pi license example
Building a Yocto OS for Raspberry Pi boards requires the license for synaptics-killswitch to be accepted in order to complete the build process. The implemented post-script asks for the acceptance and if the user accepts the post-script writes to local.conf the string LICENSE_FLAGS_ACCEPTED = "synaptics-killswitch". Here is the script:
#!/bin/sh
LICENSE_COMMENT="# Accepted synaptics-killswitch license"
LICENSE_VARIABLE="LICENSE_FLAGS_ACCEPTED"
LICENSE_VARIABLE_LINE="${LICENSE_VARIABLE} += \"synaptics-killswitch\""
# The post-scripts are executed from the build dir
BUILD_DIR=${PWD}
LOCAL_CONF_PATH="${BUILD_DIR}/conf/local.conf"
# Ask the user to accept synaptics-killswitch licence
echo >&2
read -p "Do you accept synaptics-killswitch license? (yes/no) [default: yes]: " choice
choice=${choice:-yes}
# Remove all non-alphanumeric characters (sanitizing input)
choice=$(echo "$choice" | tr -cd '[:alnum:]' | tr '[:upper:]' '[:lower:]')
# Validate input. Write to local.conf if the license has been accepted
case "$choice" in
yes|y)
echo >&2
echo "The synaptics-killswitch license has been accepted." >&2
if grep -q "${LICENSE_VARIABLE}" "${LOCAL_CONF_PATH}"; then
echo "The license flag ${LICENSE_VARIABLE} is already present. Updating it with the new value." >&2
sed -i "/${LICENSE_COMMENT}/d" "${LOCAL_CONF_PATH}"
sed -i "/${LICENSE_VARIABLE}/d" "${LOCAL_CONF_PATH}"
else
echo "Adding the license flag ${LICENSE_VARIABLE} to local.conf." >&2
fi
echo -e "\n${LICENSE_COMMENT}\n${LICENSE_VARIABLE_LINE}\n" >> "${LOCAL_CONF_PATH}"
;;
no|n)
echo "WARNING: the synaptics-killswitch license has not been accepted. Building the project will not be possible." >&2
;;
*)
echo "Invalid input. Please respond with 'yes', 'y', 'no' or 'n'." >&2
;;
esac
This is the output of the configurator during the creation of the build environment for Raspberry Pi 4 boards:
yoctouser@15455813a79f:~/workdir$ . ./seco-setup.sh -d raspberrypi4_64_clea-os
***
USE defconfig configuration file: raspberrypi4_64_clea-os
Raspberry Pi 4 for Clea OS FB and default settings
***
yoctouser@15455813a79f:~/workdir$ . ./seco-setup.sh -c
WARNING: no CONFIG_CLOUD_ASTARTE-URL found in the configuration.
WARNING: no CONFIG_CLOUD_ASTARTE-REALM found in the configuration.
WARNING: no CONFIG_CLOUD_ASTARTE-PAIRING-TOKEN found in the configuration.
WARNING: no RAUC found in the configuration.
WARNING: using non-Seco raspberrypi4-64. No SRCREV.conf will be created unless custom layer is used.
WARNING: no SRCREV.conf files found. Not creating build_rpi4_64/conf/SRCREV.conf.
Welcome to SECO BSP
The Yocto Project has extensive documentation about OE including a
reference manual which can be found at:
http://yoctoproject.org/documentation
For more information about OpenEmbedded see their website:
http://www.openembedded.org/
Your build environment has been configured with:
MACHINE=raspberrypi4-64
SDKMACHINE=i686
DISTRO=clea-os-fb
EULA=
No post-script has been found in the layer meta-seco-clea-os.
Executing post-script 0001-licenses-seco-rpi-post-script.sh found in the layer meta-seco-rpi
Do you accept synaptics-killswitch license? (yes/no) [default: yes]: y
The synaptics-killswitch license has been accepted.
Adding the license flag LICENSE_FLAGS_ACCEPTED to local.conf.
yoctouser@15455813a79f:~/workdir/build_rpi4_64$ cat conf/local.conf | grep ^LICENSE
LICENSE_FLAGS_ACCEPTED += "synaptics-killswitch"
Flavour post-scripts example
An example for the flavour layer post-scripts is not provided as the working principle is the same as the previous examples.