cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
ChChCh
Visitor
Visitor
416 Views
Registered: ‎02-10-2021

Petalinux: How to install multiple init scripts from one recipe?

I'm using PetaLinux 2019.2 and I want to install two init.d (rcX.d) links from within one recipe.

 

I've a bb recipe that builds two C programs and installs them into the rootfs.  This is all well and good.  It's logical to keep these in the same recipe as they share source code.

Both programs need to be started when the Linux boots via init.d scripts.

I can configure my recipe to setup the init of one but I can't work out how to set-up two init scripts.

Here's a snippet of my bb recipe (without the C code files and compile etc) that configures one program to auto-start via a init.d shell script:

 

 

 

SRC_URI = "file://one.sh"

S = "${WORKDIR}"

inherit update-rc.d

INITSCRIPT_NAME = "one.sh"
INITSCRIPT_PARAMS = "start 99 4 5 ."

do_install() {
    install -d ${D}${sysconfdir}/init.d
    install -m 0755 one.sh ${D}${sysconfdir}/init.d/
}

 

 

The above sets-up one init script.  How do I set-up two in this same recipe?

I think it might be possible using something like this but I can't get it to work:

 

 

SRC_URI = "file://one.sh \
           file://two.sh \"

S = "${WORKDIR}" 

inherit update-rc.d 

INITSCRIPT_PACKAGES = "${PN}-one ${PN}-two"

INITSCRIPT_NAME_${PN}-one = "one.sh"
INITSCRIPT_PARAMS_${PN}-one = "start 50 5 ."

INITSCRIPT_NAME_${PN}-two= "two.sh"
INITSCRIPT_PARAMS_${PN}-two= "start 40 5 ."

do_install() {
    install -d ${D}${sysconfdir}/init.d
    install -m 0755 one.sh ${D}${sysconfdir}/init.d/
    install -m 0755 two.sh ${D}${sysconfdir}/init.d/
}

 

 

Both scripts get installed into /etc/init.d but neither /etc/rc5.d symbolic links get created - i.e. the update-rc.d part doesn't work.

I've messed about with things like this but I'm not sure what I actually need:

 

PACKAGES += "${PN}-one" 
PACKAGES += "${PN}-two"

FILES_${PN}-one= "{sysconfdir}/init.d/one.sh"
FILES_${PN}-two= "{sysconfdir}/init.d/two.sh"

 

 

And I've added entries into project-spec/meta-user/conf/user-rootfsconfig.

I get message from petalinux-build like the following (where parent is my bb recipe):

   No match for argument: parent-one
   No match for argument: parent-two
   Error: Unable to find a match

or

   ERROR: Nothing RPROVIDES 'parent-one'

 

Is it possible to install two init.d  (/etc/rcX.d) links from within one recipe?

4 Replies
hokim
Scholar
Scholar
330 Views
Registered: ‎10-21-2015

Hi

This is correct recipe

LICENSE = "CLOSED"

SRC_URI = "file://one.sh \
file://two.sh \
"

S = "${WORKDIR}"

inherit update-rc.d

INITSCRIPT_PACKAGES = "${PN}-one ${PN}-two"

INITSCRIPT_NAME_${PN}-one = "one.sh"
INITSCRIPT_PARAMS_${PN}-one = "start 50 5 ."

INITSCRIPT_NAME_${PN}-two= "two.sh"
INITSCRIPT_PARAMS_${PN}-two= "start 40 5 ."

do_install() {
install -d ${D}${sysconfdir}/init.d
install -m 0755 one.sh ${D}${sysconfdir}/init.d/
install -m 0755 two.sh ${D}${sysconfdir}/init.d/
}

PACKAGES =+ "${PN}-one"
PACKAGES =+ "${PN}-two"

FILES_${PN}-one= "${sysconfdir}/init.d/one.sh"
FILES_${PN}-two= "${sysconfdir}/init.d/two.sh"
ChChCh
Visitor
Visitor
275 Views
Registered: ‎02-10-2021

Thank you hokim.

Now with that recipe (as you posted) called parent.bb  I can select the recipe in:

 

petalinx-config -c rootfs
   -> apps

 

But when I run petalinux-build the two init script links are not included in the /etc/rc5.d/ directory.

 

I think I need to add the two "child" package names into project-spec/meta-user/conf/user-rootfsconfig as follows:

 

CONFIG_parent
CONFIG_parent-one
CONFIG_parent-two

 

And then I select those last two in:

petalinx-config -c rootfs
   -> user packages

 

Then I do a petalinux-build -c rootfs and I get this error:

ERROR: petalinux-user-image-1.0-r0 do_rootfs: Could not invoke dnf. Command '/home/chchch/pz7010_fmc2_2019_2/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/petalinux-user-image/1.0-r0/recipe-sysroot-native/usr/bin/dnf -v --rpmverbosity=debug -y -c /home/chchch/pz7010_fmc2_2019_2/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/petalinux-user-image/1.0-r0/rootfs/etc/dnf/dnf.conf --setopt=reposdir=/home/chchch/pz7010_fmc2_2019_2/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/petalinux-user-image/1.0-r0/rootfs/etc/yum.repos.d --repofrompath=oe-repo,/home/chchch/pz7010_fmc2_2019_2/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/petalinux-user-image/1.0-r0/oe-rootfs-repo --installroot=/home/chchch/pz7010_fmc2_2019_2/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/petalinux-user-image/1.0-r0/rootfs --setopt=logdir=/home/chchch/pz7010_fmc2_2019_2/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/petalinux-user-image/1.0-r0/temp --nogpgcheck install tcf-agent coreutils mtd-utils i2c-tools-misc i2c-tools shadow kernel-modules parent net-tools dtc parent-two netbase parent-one packagegroup-core-boot bc run-postinsts  base-passwd' returned 1:
DNF version: 2.7.5
cachedir: /home/chchch/pz7010_fmc2_2019_2/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/petalinux-user-image/1.0-r0/rootfs/var/cache/dnf
Added oe-repo repo from /home/chchch/pz7010_fmc2_2019_2/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/petalinux-user-image/1.0-r0/oe-rootfs-repo
repo: using cache for: oe-repo
not found deltainfo for: oe-repo
not found updateinfo for: oe-repo
oe-repo: using metadata from Mon 15 Feb 2021 11:21:04 AM UTC.
Last metadata expiration check: 0:00:00 ago on Mon 15 Feb 2021 11:21:05 AM UTC.
No match for argument: parent-two
No match for argument: parent-one
Error: Unable to find a match

ERROR: petalinux-user-image-1.0-r0 do_rootfs: Function failed: do_rootfs
ERROR: Logfile of failure stored in: /home/chchch/pz7010_fmc2_2019_2/build/tmp/work/plnx_zynq7-xilinx-linux-gnueabi/petalinux-user-image/1.0-r0/temp/log.do_rootfs.17276
ERROR: Task (/home/chchch/pz7010_fmc2_2019_2/project-spec/meta-plnx-generated/recipes-core/images/petalinux-user-image.bb:do_rootfs) failed with exit code '1'

 

Having written the recipe (as described in hokim's post) how do I "enable" the action of the two INITSCRIPT sections?

 

0 Kudos
hokim
Scholar
Scholar
260 Views
Registered: ‎10-21-2015

Hi

After doing 'petalinux-build -c parent' , could you check whether the following rpms are generated under build/tmp/deploy/rpm/arm?

parent-one-1.0-r0.arm.rpm, parent-two-1.0-r0.arm.rpm

If there is no such rpms, check again your recipe.

It is important to change

 

 

PACKAGES += "${PN}-one"
PACKAGES += "${PN}-two"

 

 

to

 

 

PACKAGES =+ "${PN}-one"
PACKAGES =+ "${PN}-two"

 

 

 

The above fix  places  parent-one, parent-two before parent in PACKAGES variable

Because of FILES_parent = " ...  /etc  ... " , parent  can also include  one.sh, two.sh

The do_package task processes the list from  the left to the right, creating the leftmost package first and the rightmost last.

The order in PACKAGES is important, since a package consume the files that are associated with it

These show scripts of rpms

$ rpm -q -scripts parent-one-1.0-r0.arm.rpm

postinstall scriptlet (using /bin/sh):
# parent-one - postinst
#!/bin/sh
set -e
if true && type update-rc.d >/dev/null 2>/dev/null; then
	if [ -n "$D" ]; then
		OPT="-r $D"
	else
		OPT="-s"
	fi
	update-rc.d $OPT one.sh start 50 5 .
fi
preuninstall scriptlet (using /bin/sh):
# parent-one - prerm
#!/bin/sh
if [ "$1" = "0" ] ; then
set -e
if true && [ -z "$D" -a -x "/etc/init.d/one.sh" ]; then
	/etc/init.d/one.sh stop || :
fi
fi
postuninstall scriptlet (using /bin/sh):
# parent-one - postrm
#!/bin/sh
if [ "$1" = "0" ] ; then
set -e
if true && type update-rc.d >/dev/null 2>/dev/null; then
	if [ -n "$D" ]; then
		OPT="-f -r $D"
	else
		OPT="-f"
	fi
	update-rc.d $OPT one.sh remove
fi
fi

 $ rpm -q -scripts parent-two-1.0-r0.arm.rpm

postinstall scriptlet (using /bin/sh):
# parent-two - postinst
#!/bin/sh
set -e
if true && type update-rc.d >/dev/null 2>/dev/null; then
	if [ -n "$D" ]; then
		OPT="-r $D"
	else
		OPT="-s"
	fi
	update-rc.d $OPT two.sh start 40 5 .
fi
preuninstall scriptlet (using /bin/sh):
# parent-two - prerm
#!/bin/sh
if [ "$1" = "0" ] ; then
set -e
if true && [ -z "$D" -a -x "/etc/init.d/two.sh" ]; then
	/etc/init.d/two.sh stop || :
fi
fi
postuninstall scriptlet (using /bin/sh):
# parent-two - postrm
#!/bin/sh
if [ "$1" = "0" ] ; then
set -e
if true && type update-rc.d >/dev/null 2>/dev/null; then
	if [ -n "$D" ]; then
		OPT="-f -r $D"
	else
		OPT="-f"
	fi
	update-rc.d $OPT two.sh remove
fi
fi
ChChCh
Visitor
Visitor
233 Views
Registered: ‎02-10-2021

Thank you again hokim for your help on this.  You've provided some really useful tips and information in your last post.  Sadly I've given up.  I just can't get my recipe to setup the /etc/rc5.d symbolic links.

I don't get the  parent-one-1.0-r0.arm.rpm and parent-two-1.0-r0.arm.rpm packages created in the deploy directory.  I do get the parent package though.

I can't see any silly mistakes in my recipe. 

Incidentally, for anyone else using this post in the future, for me, the rpm files are placed in: build/tmp/deploy/rpm/cortexa9t2hf_neon/ .

I'm not sure what's wrong but I've spent long enough on this so I've resorted to creating two additional recipes: one-init and two-init that each handle the installation of a their individual startup script into /etc/init.d and the creation of the symbolic link from /etc/rc5.d.   Some people might feel this is a better approach anyway.

 

0 Kudos