UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor pjsym2014
Visitor
17,565 Views
Registered: ‎03-23-2016

Petalinux: Runnning a script file at startup

Hi,

 

I have a Microzed 7020 module and Linux machine running Ubuntu 14.04 LTS, with the Vivado/XSDK 2015.2 and Petalinux 2015.2.1 development tools installed. I have compiled a Petalinux version for a given hdf file and tested the kernel build using Qemu. Works perfectly.

 

What I wish to do is run a simple script, mzstartup.sh, at boot time, to set some basic features, such as adding colour to the command line using alias ls='ls --color=auto'.

 

This topic has been dealt with in:

1. AR # 55998 Petalinux – How do I add a script to my Petalinux root file system that runs at startup? Web page: http://www.xilinx.com/support/answers/55998.html, and

2. UG1144 (v2015.2.1), Petalinux Tools Documentation: Reference Guide, page 76 (Application Auto Run at Startup). 

 

In the appropriate Petalinux project director, I have created an app, called mzstartup, created mzstartup.sh and modified the Makefile ensuring that all:, build: and clean: are empty (as required) and that install has been appropriately modified so that the script file is copied to /etc/init.d with a symbolic link to /etc/rc5.d. All good and well, the only problem is that when I do the petalinux build/install I do not get the script file being copied to /etc/init.d and of course no link is generated.

 

I will be the first to admit that I am not a Linux guru and as such would really appreciate feedback from anyone who has got this to work, as I am sure that I am missing a step in the overall process. Having spent a couple of evenings on this problem I am keen to resolve it asap, so that I can move forward.

 

Thanks in advance,

Paul

0 Kudos
11 Replies
Adventurer
Adventurer
17,335 Views
Registered: ‎12-03-2015

Re: Petalinux: Runnning a script file at startup

Hi Paul,

 

I have it working. You should make sure that the paths in your makefile are correct. Here is my makefile that works. Check that your file is in <PETALINUX_PROJ_DIR>/build/linux/rootfs/targetroot/etc/init.d/ after a petalinux-build. In my case the file iiod.sh is in <PETALINUX_PROJ_DIR>/build/linux/rootfs/targetroot/etc/init.d/ after the build. This then becomes part of the the image file.

 

include libs.common.mk

all: build install

build:

clean:

.PHONY: install image

install:
	$(TARGETINST) -d -p 0755 ./usr/sbin/iiod /usr/sbin/iiod
	$(TARGETINST) -d -p 0755 ./usr/sbin/iiod.init /etc/init.d/iiod.sh
	$(TARGETINST) -s /etc/init.d/iiod.sh /etc/rc5.d/S89iiod.sh

help:

Ron

0 Kudos
Visitor pjsym2014
Visitor
17,263 Views
Registered: ‎03-23-2016

Re: Petalinux: Runnning a script file at startup

Hi Ron,

 

Many thanks for your response to my question - much appreciated. Looking at your working makefile I am confident, on checking mine again, that it is correctly setup. I did not, however, have the inlude libs.common.mk, which I have now added. I cleaned my previous Petalinux build using the distclean option and then did a clean rebuild. I still do not get the script file being copied to <PETALINUX_PROJ_DIR>/build/linux/rootfs/targetroot/etc/init.d/.

 

I have this sneaking suspicion that the makefile is not being run and need to look into how I can go about debugging the makefile in the overall build process.

 

When I created the application, I did not use the --enable option. From my understanding of the documentation that I managed to find, this is not necessary as one is not wanting to build anything, but rather just copy a (script) file to the appropriate location, with the appropriate link, hence the install: target must be correct. To confirm that the application was created correctly, I ran the config. menu for rootfs and checked that it was registered but not enabled. Since your setup is working, please could you clarify that this is indeed correct - the application is not enabled in the rootfs config menu.

 

Out of curiosity, I enabled the application and did a clean build. This time I got a build error, which terminated the build process. I need to figure out whether the error is due to the fact that the makefile is not found or because the build: target is empty.

 

Paul

 

 

0 Kudos
Adventurer
Adventurer
17,233 Views
Registered: ‎12-03-2015

Re: Petalinux: Runnning a script file at startup

Hi Paul,

 

Yes you do need to enable the app by running petalinux-config -c rootfs. Go to Apps and select you application. Petalinux-build will only run the Makefile if the app is enabled. Once you enable it, run petalinux-build -x distclean then petalinux-build. It should be in the targetroot directory.

 

Ron 

0 Kudos
Visitor pjsym2014
Visitor
17,208 Views
Registered: ‎03-23-2016

Re: Petalinux: Runnning a script file at startup

Hi Ron,

 

Happy to report that all is now working and up and running on my microzed. Many thanks for your help.

 

With my initial attempt I did a couple of things wrong in the overall process - firstly I did not enable the app. on creation and secondly once I had created the mzstartup.sh script I then made it executable, which I don't believe is correct based on the discussion below. For whatever reason, when I did enable the app via the rootfs config. menu and perform a clean build I got a build error that stopped the process. This threw me a bit as I couldn't understand why and jumped to the conclusion that the Makefile wasn't found and run. After thinking about the problem I decided to try again from scratch, as I had a little more info at hand and a better understanding of the process.

 

Hence I deleted the app. and then ran the rootfs config to check that it was no longer registered. Next I created the app again, this time enabling it with the --enable parameter. I then ran petalinux-build without the -v option, to check that the mzstartup.c module was compiled. Without the verbose option, sufficient, intelligible information was dumped to the screen to confirm that the module pre-build, build, post-build and install all happened.

 

I deleted the mzstartup.c module, then created and edited mzstartup.sh, without changing its mode to executable. Next I edited the Makefile, then cleaned the distribution and did a rebuild. On completion the mzstartup.sh was in etc/init.d and the S99mzstartup.sh link in etc/rc5.d. During the install process, when the script is copied over, the install: target macro changes the files' mode to executable. A little fact that I had failed to appreciate.

0 Kudos
Newbie msdk
Newbie
9,636 Views
Registered: ‎10-22-2017

Re: Petalinux: Runnning a script file at startup

Hi,I'm using Petalinux 2017.2,when I has seen the latest document of Xilinx,it told me that I shoud modify the the file with  suffix named .bb.

2017-10-23 00-22-44屏幕截图.png

But it doesn't work. And I find that it doesn't create of a link in rc5.d.

Can you tell me how to solve the problem?

Thank you! 

0 Kudos
9,351 Views
Registered: ‎04-20-2017

Re: Petalinux: Runnning a script file at startup

excatly stuck at the same
there must be some mistake in the manual, as I followed it too

 

what fixed it for me so far  is to manually add (as it seems the script just does not get added to the rcS.d directory)

 

         install -d ${D}${sysconfdir}/rcS.d

         install -m 0755 ${S}/GetIP-init ${D}${sysconfdir}/rcS.d/S99GetIP-init

 

to the .bb file of the myapp-init (myapp is GetIP in my case). Aside from that I left everything as in the manual.

0 Kudos
Highlighted
Visitor kpr29806
Visitor
7,180 Views
Registered: ‎04-17-2018

Re: Petalinux: Runnning a script file at startup

In case anyone is still stuck attempting to create aliases automatically at boot, you'll need to do that by adding your custom script to /etc/profile.d/ and allowing /etc/profile to source that script.

 

Putting aliases in the rc*.d scripts won't work because those scripts are all called from sub-shells of the initial boot process, not from the login shell where your prompt exists (i.e. where you want to use your aliases). That means the aliases become defined for the duration of the script and are lost after that.

 

 

The solution is to use your bitbake recipe to create a directory at /etc/profile.d and put the init script that defines your aliases in that directory (e.g. /etc/profile.d/app-init.sh). Remember to use the .sh extension for your init script, even if it has a shebang, or /etc/profile won't pick it up.

 

Your app-init.bb recipe should look something like this:

 

 

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

Then your shell will source your init script every time you log in, even over SSH.

 

0 Kudos
Moderator
Moderator
4,277 Views
Registered: ‎02-07-2018

Re: Petalinux: Runnning a script file at startup

Hi @pjsym2014 

 

I just followed the procedure mentioned in ug1144 guide 2018.2.(Page No :69), it is working properly.

Below are the steps you need to follow.

 

1. petalinux-create -t apps --template install -n myapp-init --enable

2. vim project-spec/meta-user/recipes-apps/myapp-init/myapp-init.bb 

 

#thiss file is the myapp-init recipe.

#

SUMMARY = "Simple myapp-init application"

SECTION = "PETALINUX/apps"

LICENSE = "MIT"

 

LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://myapp-init \

"

S = "${WORKDIR}"

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

inherit update-rc.d

INITSCRIPT_NAME = "myapp-init"

INITSCRIPT_PARAMS = "start 99 S ."

do_install() {

install -d ${D}${sysconfdir}/init.d

install -m 0755 ${S}/myapp-init ${D}${sysconfdir}/init.d/myapp-init

}

FILES_${PN} += "${sysconfdir}/*"

 

3. Modify your script (project-spec/meta-user/recipes-apps/myapp-init/files/myapp-init)according to your requirements and build it.

By default this script only print "Hello PetaLinux World"

 

Thanks & regards

Aravind

0 Kudos
Observer oska874
Observer
3,798 Views
Registered: ‎10-17-2012

Re: Petalinux: Runnning a script file at startup

I did the same ,but the script doesnot run at startup. And I can see the script int /etc/init.d/.

I run the linux as image.ub(ramdisk mode)

0 Kudos
Adventurer
Adventurer
2,919 Views
Registered: ‎08-01-2018

Re: Petalinux: Runnning a script file at startup

Hello,

 

    Does anybody know how to make the script to run in background so I can still open a ssh for example?

   Putting & in INITSCRIPT_PARAMS gives me a build error.

 

Thanks,

       Mihaita

0 Kudos
Observer russellsnow
Observer
2,710 Views
Registered: ‎09-17-2018

Re: Petalinux: Runnning a script file at startup

Me either. Did you figure it out?

0 Kudos