Ca't install my own syslog's syslog-startup.conf via Yocto - yocto

I was trying to create a new syslog-startup.conf by creating a busy-box%.bbappend having the following in it:
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI += "\
file://syslog-startup.conf \
"
do_install_append() {
install -m 0644 ${WORKDIR}/syslog-startup.conf ${D}${sysconfdir}/syslog-startup.conf
}
FILE_${PN} += "\
${sysconfdir}/syslog-startup.conf \
"
My syslog-startup.conf is the same as the default one except i have it logging to a file instead of a buffer on system startup instead of my having to go in and change it manually. I never have this work. I always have the default .conf file installed on system startup. I should mention that I'm also having the same issue when i try to update another of my system files: /etc/fstab which also doesn't work and i end up with default file installed.
Why am I not able to change/append to system files?
Is there a better way to do this?
Is there a way to find out if my .bbappend file got executed at all?

I had to alter the syslog-startup.conf for a different reason. How I managed to do it was by adding the below line in my busybox_%.bbappend
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
I added the modified syslog-startup.conf inside a folder called files. Where you place the file is upto you. Yocto will replace the default file with the file provided by the .bbapend file. So all you will have to do is point to the file in your busybox_%.bbapend file

Related

Stale file is located outside of the allowed root path when using Cuckoo

I wanted to mock some of my files, so I used Cuckoo framework. I am using Swift Package Manager, so I did every step that is shown in README of framework.
I tried to use this script
# Define output file. Change "${PROJECT_DIR}/${PROJECT_NAME}Tests" to your test's
root source folder, if it's not the default name.
OUTPUT_FILE="${PROJECT_DIR}/${PROJECT_NAME}Tests/GeneratedMocks.swift"
echo "Generated Mocks File = ${OUTPUT_FILE}"
# Define input directory. Change "${PROJECT_DIR}/${PROJECT_NAME}" to your project's root source folder, if it's not the default name.
INPUT_DIR="${PROJECT_DIR}/${PROJECT_NAME}"
echo "Mocks Input Directory = ${INPUT_DIR}"
# Generate mock files, include as many input files as you'd like to create mocks for.
"${PROJECT_DIR}/run" --download generate --testable "${PROJECT_NAME}" \
--output "${OUTPUT_FILE}" \
"${INPUT_DIR}/Common/Repository/LatestNewsRepository/LatestNewsRepositoryImpl.swift" \
# ... and so forth, the last line should never end with a backslash
# After running once, locate `GeneratedMocks.swift` and drag it into your Xcode test target group.
I also downloaded the latest run script and I had to check For install builds only.
When app is launched I am getting this error -
Stale file '.../LibraryTests/GeneratedMocks.swift' is located outside of the allowed root paths.
Things I tried -
Clean Xcode derived data
Clean build folder
Reset Xcode
Reset Packages Cache
and I am still not getting output file. Is there anything else I should try?

Yocto: add a statement in the default service file within a recipe

I'd need to add a Restart statement within a default .service file, and was looking to an alternate solution to replacing the .service file with a custom one (which works).
The idea would be just adding the following "delta" requirement in a, e.g., ${systemd_system_unitdir}/my_service.d/override.conf file:
[Service]
Restart=always
and then adding that file in a dedicated .bbappend recipe file.
Tests so far were not successful in adding the above statements in the deployed service file (despite the "delta" conf file being correctly deployed). Is this even a possible solution?
You should be able to do that simply by echoing that entry in a do_install:append() section in you .bbappend file. Something like:
do_install:append() {
echo "[Service]\nRestart=always" >> ${D}${sysconfdir}/wpa_supplicant/...
}
You can equally use sed to find and replace that section if there is already a file inplace.
${sysconfdir} will expanded to /etc. Check this file for more defined path variables: https://git.yoctoproject.org/poky/plain/meta/conf/bitbake.conf?h=blinky

accessing variables exported in a shell in the recepe file

I have a yocto recipe file.
However I want to set a value to the variable, by exporting a variable.
For example
I modified I added a variable in oe-init-build-env, (which calls 'svn_util')
export REPO_BRANCH_ROOT=${REPO_BRANCH_ROOT}
The REPO_BRANCH_ROOT variable is set by running a utility 'svn_util', by looking at by current branch.
Now in my recepie.bb file
SRC_URI = "\
svn://${REPO_ROOT_NO_URI}/${REPO_BRANCH_ROOT}/sample module=mymodule;protocol=protocol=http;rev=HEAD \
"
However do_fetch: fails as follows.
Fetcher failure for URL: 'svn://${REPO_ROOT_NO_URI}/${REPO_BRANCH_ROOT}/sample;module=mymodule;protocol=http;rev=HEAD'. Unable to fetch URL from any source.
How do I make .bb file to be aware of my current branch and repository uri? I do not want to hard code it in the .bb file, or local.conf file Because if the .bb file is checked in to a different branch it should work correctly across all branch.
Or to rephrase the question, How a shell exported variable be accessed in the recipe file?
Got my answer, from another post.
https://www.yoctoproject.org/docs/3.1/bitbake-user-manual/bitbake-user-manual.html#var-bb-BB_ENV_EXTRAWHITE
In this case i have to add
export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE REPO_SVNREV REPO_ROOT_NO_URI REPO_BRANCH_ROOT"
In the oe-init-build-env

Why does the yocto bblayers.conf file use absolute paths?

The yocto project allows the use of relative path in most of its configuration files but not within the ./build/conf/bblayers.conf file. What is the reason for blocking the use of anything but absolute paths for the BBLAYERS and BBLAYERS_NON_REMOVABLE variables?
I have looked at the BitBake user manual for yocto version 2.0 (current release) but that does not explain the reasoning. I also checked some of the older manual versions but they do not seem to mention the reasoning when talking of the bblayers.conf file or the BBLAYERS variable. The same file also contains BBPATH = "${TOPDIR}" which is at least dynamically assigned and not that far away from the root yotco directory.
My best guess is that the bblayers.conf file is specific to the system it is being run on. That would make it unsuitable for sharing between developers via source control and the absolute paths would force people to edit the file whenever they received a copy. That did not seem like a very good reason though, hence the question.
I found a way to use relative paths.
You can use inline python to traverse the file system. The following script uses the provided TOPDIR variable and then navigates to its parent via python's os.path api.
# LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
LCONF_VERSION = "6"
BBPATH = "${TOPDIR}"
BBFILES ?= ""
YOCTOROOT = "${#os.path.abspath(os.path.join("${TOPDIR}", os.pardir))}"
BBLAYERS ?= " \
${YOCTOROOT}/poky/meta \
${YOCTOROOT}/poky/meta-yocto \
${YOCTOROOT}/poky/meta-yocto-bsp \
"
BBLAYERS_NON_REMOVABLE ?= " \
${YOCTOROOT}/poky/meta \
${YOCTOROOT}/poky/meta-yocto \
"
References
OpenEmbedded's bitbake.conf
Advanced functionality with python
How do I get the parent directory in Python?
I have managed to get "relative paths" in bblayers.conf files working by replacing
BBLAYERS ?= " \
/home/username/poky/meta \
...
with
BBLAYERS ?= " \
${TOPDIR}/../meta \
...
I guess one caveat with this approach is that I'm relying on the meta-XXX layer directories always being in the parent folder of TOPDIR. This seems to be the case with the default way of using yocto, but might not be so for more customized build setups.
All the existing answers are answering "how to use relative paths" but the question is "why are absolute paths used". As far as I know the "why" is simple, it is done that way so that the build directory can be moved anywhere on the filesystem. Think about it: you can source poky/oe-init-build-env from anywhere on the filesystem and the build directory will be created there, so relying on paths relative to the build directory is very fragile.
Edit:
maybe this is clearer, I think you are assuming that the file bblayers.conf is always in poky/build/conf/bblayers.conf and that you can therefore use a path like ../../meta-layer-foo to refer so some layer which would be in poky/meta-layer-foo, but the layer will not be found if I instantiate "build" in another path poky/foo/bar:
etienne#ubuntu:~/repos/poky-tx2$ mkdir -p foo/bar
etienne#ubuntu:~/repos/poky-tx2$ cd foo/bar/
etienne#ubuntu:~/repos/poky-tx2/foo/bar$ ls
etienne#ubuntu:~/repos/poky-tx2/foo/bar$ source ../../oe-init-build-env
You had no conf/local.conf file. This configuration file has therefore been
created for you with some default values. You may wish to edit it to, for
example, select a different MACHINE (target hardware). See conf/local.conf
for more information as common configuration options are commented.
You had no conf/bblayers.conf file. This configuration file has therefore been
created for you with some default values. To add additional metadata layers
into your configuration please add entries to conf/bblayers.conf.
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/
### Shell environment set up for builds. ###
You can now run 'bitbake <target>'
Common targets are:
core-image-minimal
core-image-sato
meta-toolchain
meta-ide-support
You can also run generated qemu images with a command like 'runqemu qemux86'
etienne#ubuntu:~/repos/poky-tx2/foo/bar/build$ ls
conf
You can use relative paths in bblayers.conf.
There is probably this line in your bblayers.conf:
BBPATH = "${TOPDIR}"
When you want to find out this variable's content, you will probably find the top-level directory of your build directory:
bitbake -e | grep ^TOPDIR
# searches for bitbake variables
Inside this directory you could create a layer meta-test and add it in bblayers.conf with a relative path:
BBLAYERS ?= " \
meta-test \
[...]
"
So the answer on your question why there are absolute paths in bblayers.conf is that you can place your build directory anywhere on the system and not dependant from Yocto.
Relative Paths to Layers must always be relative to the build directory.
I am working with Rocko version
and my bblayers.conf file also doesn't support relative paths
I tried to change the bblayers.conf file by using TEMPLATECONF variable.
TEMPLATECONF variable points to the directory containing bblayers.conf.sample, layer.conf, and local.conf.sample.
I exported the TEMPLATECONF variable to get the desired bblayers.conf and local.conf files in the build directory but in my bblayers.conf.sample the BBLAYERS variable was set by a relative path as shown below:
BBLAYERS ?= " \
##OEROOT##/meta \
##OEROOT##/../meta-xilinx \
##OEROOT##/../meta-xilinx-tools \
##OEROOT##/../meta-openembedded/meta-oe \
##OEROOT##/../meta-openembedded/meta-perl \
##OEROOT##/../meta-openembedded/meta-python \
##OEROOT##/../meta-openembedded/meta-multimedia \
##OEROOT##/../meta-openembedded/meta-networking \
##OEROOT##/../meta-openembedded/meta-filesystems \
##OEROOT##/../meta-openembedded/meta-webserver"
but it doesn't seem to work.OEROOT variable was not able to set the correct paths.
One reason could be that as oe-init-build-env script ends it unset the OEROOT variable.
Although if you manually export OEROOT variable to your required value it may help.
However, when I changed from OEROOT to TOPDIR variable it worked like a charm as shown below:
BBLAYERS ?= " \
${TOPDIR}/../meta \
${TOPDIR}/../meta-poky \
${TOPDIR}/../meta-skeleton \
${TOPDIR}/../meta-selftest \
${TOPDIR}/../meta-yocto-bsp \
${TOPDIR}/../../meta-xilinx/meta-xilinx-bsp \
${TOPDIR}/../../meta-xilinx/meta-xilinx-contrib \
${TOPDIR}/../../meta-xilinx-tools \
${TOPDIR}/../../meta-openembedded/meta-oe \
${TOPDIR}/../../meta-openembedded/meta-perl \
${TOPDIR}/../../meta-openembedded/meta-python \
${TOPDIR}/../../meta-openembedded/meta-multimedia \
${TOPDIR}/../../meta-openembedded/meta-networking \
${TOPDIR}/../../meta-openembedded/meta-filesystems \
${TOPDIR}/../../meta-openembedded/meta-webserver"
Which probably make me think that unsetting of OEROOT variable by the oe-root-init-env script caused the problem.
Also if somebody finds a better solution please respond.
As you already mentioned in your self-comment, bblayers.conf is
intended to be specific to a user on a machine and only temporary.
IMHO, the idea is that bblayers.conf should never be distributed amongst developers. Nevertheless, if the absolute path of layers is something specific to each developers' system installation, it seems sound to keep the actual layer list as part of the project.
Inspired by Kamal Pandey's answer, I came up with a solution leveraging template file engine behind the oe-init-build-env script.
By changing the content of conf/templateconf.cfg to conf (instead of meta-poky/conf by default), you instruct oe-init-build-env to add any missing files in your configuration directory from its .sample counterpart (now located in your conf directory).
This way, renaming your bblayers.conf to bblayers.conf.sample lets you use the OEROOT variable (which is unfortunately no longer available after oe-init-build-env invocation).
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"
BBPATH = "${TOPDIR}"
BBFILES ?= ""
BBLAYERS ?= " \
##OEROOT##/meta \
##OEROOT##/meta-poky \
##OEROOT##/meta-yocto-bsp \
${TOPDIR}/meta-tensorflow-lite \
"
With this bblayers.conf.sample file, you can now use the ##OEROOT## substitution variable to refer to file relative to your poky installation directory. By removing bblayers.conf (or not versioning/ditributing it), you ensure that sourcing oe-init-build-env will regenerate bblayers.conf with correct absolute values.

How to make a file executable using Makefile

I want to copy a particular file using Makefile and then make this file executable. How can this be done?
The file I want to copy is a .pl file.
For copying I am using the general cp -rp command. This is done successfully. But now I want to make this file executable using Makefile
Its a bad practice to use cp and chmod, instead use install command.
all:
install -m 0777 hello ../hello
You can use -m option with install to set the permission mode, and even note that by using the install you will preserve not only the permission but also the owner of the file.
You can still use chmod accordingly but it would be a bad practice
all:
cp hello ../hello
chmod +x ../hello
Update: install vs cp
cp would simply copy files with current permissions, install not only copies, but also can change perms/ownership as arg flags. (This is what your requirement was)
One significant difference is that cp truncates the destination file and starts copying data from the source into the destination file. install, on the other hand, removes the destination file first.
This is significant because if the destination file is already in use, bad things could happen to whomever is using that file in case you cp a new file on top of it. e.g. overwriting an executable that is running might fail. Truncating a data file that an existing process is busy reading/writing to could cause pretty weird behavior. If you just remove the destination file first, as install does, things continue much like normal - the removed file isn't actually removed until all processes close that file.[source]
For more details check these,
install vs. cp; and mmap
How is install -c different from cp