Yocto: Create a directory after mount - yocto

I have a Yocto bitbake recipe in my layer - base-files_%.bbappend. It creates mount points:
do_install_append() {
mknod -m 622 ${D}/dev/console c 5 1
install -m 0755 -d ${D}/boot/EFI
install -m 0755 -d ${D}/data
}
The /data/ directory is later mounted to the internal SD card.
I would like to create a directory ${D}/data/test. What is the best way to do it? I've added a line install -m 0755 -d ${D}/data/test to this function but it didn't do it.
Thanks so much.

You have to ship those installed files by adding to your recipe:
FILES_${PN} += "/data/test"
Another solution is to add in your image recipe:
create_dirs() {
mkdir -p ${IMAGE_ROOTFS}/data/test
}
ROOTFS_POSTPROCESS_COMMAND += "create_dirs ; "

In your do_install function
do_install(){
mkdir -d ${D}/data/test
}
-d option creates the dir in your rootfs, and if you want to copy files, use below command in do_install function.
install -m 0777 ${s}/your files ${D}/data/test
The QA packaging process verification should be informed :
FILES_${PN} += "/data/test"

Related

yocto recipe how to install file to rootfs

sorry I am a little new to syntax of yocto, this is how I have modified my recipe:
LICENSE = "LGPLv2.1"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI = "file://myscript.sh"
FILES_${PN} += "${sysconfdir}/init.d/myscript.sh"
do_install() {
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/myscript.sh ${D}${sysconfdir}/init.d/
}
The recipe is added to the build, because if I remove the LICENSE line the yocto image will not be baked.
The folder where the recipe is kept is named "customssh", inside this folder I have the recipe named customssh_0.1.bb and a subfolder named "files" where the myscript.sh is kept.
After I have baked the image, I run this command to see if the myscript.sh has been placed in the rootfs:
find . -name 'myscript*'
which will return where the file is held:
./meta-swi/common/recipes-core/customssh/files/myscript.sh
In the recipe, is this line correct?
install -m 0755 ${WORKDIR}/myscript.sh ${D}${sysconfdir}/init.d/
If this is the root recipe and not a bbappend one use do_install instead of do_install_append
Make sure that ${D}${sysconfdir}/init.d is created before copying to it
do_install(){
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/myscript.sh ${D}${sysconfdir}/init.d/
}
Now, make sure to specify the file you installed so that the do_package will not fail
FILES_${PN} += "${sysconfdir}/init.d/myscript.sh"

Bitbake not installing files from recipe to rootfs

I'm currently using yocto to build the system imx6sxsabresd (IMX6 Solo X). I have successfully built the image however I want to add a script to init.d to turn on a led. I'm appending to the linux-imx recipes within the meta-fsl-bsp-release layer.
This is my linux-imx.bbappend file:
FILESEXTRAPATHS_prepend := "${THISDIR}/linux-imx:"
SRC_URI += "file://0001-added-pad-for-heartbeat-led.patch \
file://heartbeat.sh \
file://heartbeat "
PACKAGECONFIG_append = " heartbeat"
inherit update-rc.d
INITSCRIPT_PACKAGES = "${PN}"
INITSCRIPT_PARAMS = "start"
INITSCRIPT_NAME = "heartbeat.sh"
do_install_append()
{
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/heartbeat.sh ${D}${sysconfdir}/init.d/heartbeat.sh
install -d ${D}/home/root
install -m 0755 ${WORKDIR}/heartbeat ${D}/home/root/heartbeat
}
FILES_${PN} += "${sysconfdir}/init.d/heartbeat.sh /home/root/heartbeat"
PACKAGES = "${PN}"
I'm able to create the sdcard image succesfully with the patch I've included in this bbappend file, however, the files heartbeat.sh and heartbeat are not copying to the final rootfs added to the output sdcard file. This is very odd because I'm able to see these files in their paths copied to ../tmp/work/imx6sxsabresd-poky-linux-gnueabi/linux-imx/4.14.98-r0/image/
As the comments suggests appending to the kernel recipe is the wrong way to go about this. You should instead add your own recipe and reference that recipe from the image definition (append to IMAGE_INSTALL).
Your recipe could look something like:
SUMMARY = "LED heartbeat init script"
inherit update-rc.d
SRC_URI += "\
file://heartbeat.sh \
"
do_install() {
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/heartbeat.sh ${D}${sysconfdir}/init.d/
}
FILES_${PN} = "${sysconfdir}/init.d/heartbeat.sh"
INITSCRIPT_NAME = "heartbeat.sh"
INITSCRIPT_PARAMS = "start 90 5 . stop 20 0 1 6 ."

Set new user permissions in Yocto recipe

I have a recipe to add a user called foo:
inherit useradd
USERADD_PACKAGES = "${PN}"
USERADD_PARAM_${PN} = "-P foo -u 1000 -d /home/foo -r -s /bin/bash foo;"
LICENSE = "CLOSED"
do_install () {
install -d ${D}/data/docker
install -d ${D}/home/foo
chown -R foo ${D}/home/foo
chown -R foo ${D}/data/docker
}
FILES_${PN} = " \
/home/foo \
/data \
"
For an obscure reason, data/docker is owned by foo but not /home/foo. Any idea why?
Actually, you don't need to install /home/foo(nor chown) since that task should be already accomplished by useradd, thus you can remove those commands. However, you might want to modify your recipe as follows:
do_install () {
install -d -m 755 ${D}${datadir}/foo
install -d -m 755 ${D}/data/docker
chown -R foo ${D}${datadir}/foo
chown -R foo ${D}/data/docker
}
FILES_${PN} = "${datadir}/foo/* /data/docker/*"
So the reason was that another recipe was creating a subfolder in the home directory first and was owned by root by default.
When the recipe to add the user was baked, the home folder was already created with root permissions.
My solution was to add the creation of this folder in the recipe adding the user instead.
Thanks #danior for the corrections

Bitbake recipes - Simple file copy

I know there is already an answer for my problem here : bitbake recipe - doing a simple copy of the image
I also want to copy files but I have this error when trying to compile my recipe :
gcc: error: none: No such file or directory
Removing the line :
inherit allarch
Won't cause me any problem, but apparently I need it to copy my files...
Here is my recipe :
DESCRIPTION = "My description"
#To prevent the LICENSE field not set
LICENSE = "CLOSED"
PR = "r1"
SRC_URI = "file://main.c \
file://foo_update.sh \
file://foo.service \
"
S = "${WORKDIR}/"
FILES_${PN} += "/script"
inherit allarch
do_compile() {
${CC} ${WORKDIR}/main.c -o fooupdate
}
do_install() {
install -m 0755 -d ${D}${bindir} ${D}/script
install -m 0755 ${S}/fooupdate ${D}${bindir}
install -m 0755 ${S}/foo_update.sh ${D}/script
install -m 0755 ${S}/foo.service ${D}/script
}
What am I doing wrong ?
Thank you for your help !
Find the solution thanks to this question :
bitbake recipe for copying folder, subfolders for yocto
Remove inherit allarch and instead of using install -m 0755 for the files you want to copy:
install -m 0755 ${S}/foo_update.sh ${D}/script
install -m 0755 ${S}/foo.service ${D}/script
Use cp:
cp ${S}/foo_update.sh ${D}/script
cp ${S}/foo.service ${D}/script
Complete recipe :
DESCRIPTION = "My description"
#To prevent the LICENSE field not set
LICENSE = "CLOSED"
PR = "r1"
SRC_URI = "file://main.c \
file://foo_update.sh \
file://foo.service \
"
S = "${WORKDIR}/"
FILES_${PN} += "/script"
inherit allarch
do_compile() {
${CC} ${WORKDIR}/main.c -o fooupdate
}
do_install() {
install -m 0755 -d ${D}${bindir} ${D}/script
install -m 0755 ${S}/fooupdate ${D}${bindir}
cp ${S}/foo_update.sh ${D}/script
cp ${S}/foo.service ${D}/script
}

Yocto build not including files in sdcard image

I am trying to build an SDK into my sysroot on my yocto build. However when i compile my build i get no errors and everything appears to have worked fine.
When i flash my SD card and run it on my board and go to look for my files, they arent there.
here is my .bb file which is used to install the SDK i want to use.
giffgaff-connectDESCRIPTION = "azure"
HOMEPAGE = "https://github.com/Azure/azure-iot-sdk-c"
LICENSE = "MIT"
SECTION = "applications"
PRIORITY = "optional"
DEPENDS = "mono"
LIC_FILES_CHKSUM = "file://${WORKDIR}/git/LICENSE;md5=4283671594edec4c13aeb073c219237a"
SRCREV = "${AUTOREV}"
SRC_URI = "git://git#bitbucket.org/condecosoftware/azure-iot-sdk-c;protocol=ssh;branch=master"
COMPATIBLE_MACHINE = "imx6qsabresd"
S = "${WORKDIR}"
ALLOW_EMPTY_${PN} = "1"
do_compile() {
echo libdir: ${libdir}
echo Files : FILES_${PN}
echo "compiler: ${CC}"
echo "sysroot: ${STAGING_DIR_TARGET}"
export SYSROOT=${STAGING_DIR_TARGET}
cd ${WORKDIR}/git/build_all/linux/
./build.sh --toolchain-file toolchain-yocto.cmake -cl --sysroot=${STAGING_DIR_TARGET} --install-path-prefix ${STAGING_DIR_TARGET}
cd ../..
cmake -P cmake/iotsdk_linux/cmake_install.cmake
}
do_install() {
cd git
pwd
echo ${D}
echo ${libdir}
install -d 0755 ${D}${libdir}
install -m 0755 ./cmake/iotsdk_linux/umqtt/libumqtt.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/uamqp/libuamqp.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/c-utility/libaziotsharedutil.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_client/libiothub_client_http_transport.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_client/libiothub_client.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_client/libiothub_client_amqp_ws_transport.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_client/libiothub_client_amqp_transport.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_client/libiothub_client_mqtt_transport.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_client/libiothub_client_mqtt_ws_transport.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/serializer/libserializer.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_service_client/libiothub_service_client.a ${D}${libdir}/
}
do_fetch_extra(){
cd ${WORKDIR}/git/
git submodule update --init --recursive
}
addtask fetch_extra after do_unpack before do_patch
Any help would be great appreciated. Thanks
Have you tried ${WORKDIR} variable? This variable holds the pathname of the work directory of recipe being build. So every file fetched from git can be accessed from there, I presume. For example:
install -m 0755 ${WORKDIR}/cmake/iotsdk_linux/umqtt/libumqtt.a ${D}${libdir}/
Please let me know if it works.
You will probably need to add
PACKAGES =+ "${PN}-staticdev"
FILES_${PN}-staticdev += "${libdir}/*.a"
to ship every files you installed into your image.
You can also add every files one by one instead of wildcard.
Some remarks:
For git submodules, you can use gitsm:// url, it will initialize every submodules.
You can also put the following instruction to avoid doing some change dir in recipe.
S = "${WORKDIR}/git"
By the way, you can look this OE recipe for Azure from Intel meta-iot-cloud layer. It is python recipe, but it depends on C iot sdk, it can be inspiring:
https://github.com/intel-iot-devkit/meta-iot-cloud/blob/master/recipes-azure/azure-iot-sdk/azure-iot-sdk_1.1.23.bb