How to add a script (bash script) to my linux image developed in yocto? - embedded

I am developing a script to install packages in a linux image developed using yocto. Currently, I send the .sh script by scp to my device with the linux image, but I want to install this script directly in the linux image, and when for the device to have the .sh file when it boots. How can I do this in yocto? Do I need to create a recipe for this script?

You should create a recipe and a systemd services to enable it a boot time if you want to.
The architecture should be like this:
my_script/
├── files
│ ├── my_script.service
│ └── my_script.sh
└── my_recipe.bb
Your recipe should look like this,
my_recipe.bb:
LICENSE = "CLOSED"
LIC_FILES_CHKSUM = ""
SRC_URI = "file://myscript.service"
SRC_URI += "file://myscript.sh"
inherit systemd
do_install() {
install -Dm0755 ${WORKDIR}/my_script.sh ${D}/usr/bin/my_script.sh
install -Dm0644 ${WORKDIR}/my_script.service ${D}${systemd_system_unitdir}/my_script.service
}
SYSTEMD_SERVICE_${PN} = "my_script.service"
Of course, this should be in a meta-layer that is already in your conf/bblayers.conf
Otherwise create it and add it manually.

#amolina I guess you need add your shell script to /etc/init.d for the purposes of running it on OS boot.
You can inherit update-rc.d class and define INITSCRIPT_NAME/PARAMS in
your recipe.
More details can be found in this link yocto manual
Reference : add custom script to yocto

Related

Singularity Recipe: How to access executable within container?

I am a beginner with Singularity.
What I want to achieve in the long run: I have a programming project with a long lists of dependencies, and I want to be able to give the program to other people in my company without there being bugs caused by missing dependencies, or wrong versions of dependencies.
The idea was now to use Singularity in order to easily provide a working environment.
In order to test this, I wrote a Hello World application which I now want to run in a container. I have a folder HelloWorld/ which contains the source code for a C++ Qt project. Then I wrote the following recipe file:
project.recipe
Bootstrap: docker
From: ubuntu:18.04
%setup
cp -R <some_folder>/HelloWorld ${SINGULARITY_ROOTFS}/HelloWorld
%post
apt update
apt-get install -y qt5-default
apt install -y g++
apt-get install -y build-essential
cd HelloWorld
qmake
make
echo "after build:"
ls
%runscript
echo "before execution:"
ls HelloWorld/
./HelloWorld/HelloWorld
where the echos and directory listings are for my current debugging process.
I can sucessfully build an image file using sudo singularity build --writable project.img project.recipe. (My debugging output shows me that the executable was build successfully.)
The problem is now that if I try to run it using ./project.img, or singularity run project.img, it won't find the executable.
Using my debugging output, I found out that the lines in %runscript use the folders outside of the container.
Tutorials like https://sylabs.io/guides/3.1/user-guide/build_a_container.html made it seem to me as if my recipe was the way to go, but apparently it isn't?
My questions:
Is there some way for me to access my executable? Am I calling it wrong?
Is the way I do it the way it is supposed to be done? Or would one normally do something like getting the executable outside of the container and then use the container to call that outside file? Or is there a different best practice?
If the executable is to be copied outside of the container after compilation, how do I do that? How do I access outside folders when I'm within %post?
Is this the best work process for what I want to achieve? Later on, my idea is that the big project is copied likewise in the container, dependencies are either installed or copied, then the project is compiled and finally its source being deleted. I also considered using a repository, but I can't have the project being in an open repository, and I don't want to store any passwords.
Firstly, use %files, don't use %setup. %setup is run as root and can directly modify the host server. You can very easily and accidentally break things without realizing it. You can get the same effect this way:
%files
some_folder/HelloWorld /HelloWorld
You are calling it wrong. In your %setup (and hopefully now in your %files) steps, you are copying the data to /HelloWorld. In your %runscript your are calling ./HelloWorld/HelloWorld which is the equivalent of $PWD/HelloWorld/HelloWorld. Since singularity automatically mounts in $PWD (as well as $HOME and some other directories), you are not calling what you're trying to call.
You don't copy the executable outside of the container, you just need to make sure what you're executing is where you think it is.
There is no access to the host filesystem in %post, you should have everything you need copied in via %files first.
That's a reasonable workflow. Having a local private repo for the code is probably a good idea for tracking your changes, but that's your call.

YOCTO : No '/lib/modules' directory in image, modprobe fails

I'm trying to load and unload modules using modprobe but I'm having problems. The command fails with "modprobe:
can't change directory to '/lib/modules': no such file or directory"
There is actually no /lib/modules directory on the image at all.
PS : I used yocto project to build Linux os image and I'm using the 3.14 kernel.
Any help would be appreciated!
Probably you just don't have any modules installed. Add
IMAGE_INSTALL += "kernel-modules"
to your image recipe.
Update:
If this does not add the modules to the image, your next steps to check are:
Check if there actually any modules built. Not all kernel configurations actually do this. An easy way is to look into the tmp/deploy/... directory that holds your generated packages.
Check if the setting actually gets propagated to the iamge. bitbake -e on your image will tell, grep for IMAGE_INSTALL.
Update 2:
For 1) All built kernel-modules are automatically packaged in packages starting with "kernel-module-". So if there is no package bearing that prefix and the module name you expect, then its not a problem of installing, but a problem of your kernel or kernel config not building the module at all.
For 2) "I can't read it all": Thats why I explicitly said "grep for IMAGE_INSTALL" - you shall not read it all, just see if that variable actually includes "kernel-modules".
Well I found the solution:
In fact
IMAGE_INSTALL += "kernel-modules"
Does not add modules folder under /lib . It does not work wiTh YOCTO PROJECT SUMO release. I added this
CORE_IMAGE_EXTRA_INSTALL += " kernel-modules"
to my local.conf and now the /lib/modules is found and kernel-modules are packaged

How do I use my own modules in a JuliaBox notebook?

I've recently started using JuliaBox for programming in Julia, and I want to use my own modules that I've previously written using the Juno-Atom IDE. I've uploaded the relevant modules to JuliaBox, but I am unable to call them from a JuliaBox notebook. The error message I get is as follows:
using MyModule
ArgumentError: Module MyModule not found in current path.
Run `Pkg.add("MyModule")` to install the MyModule package.
Stacktrace:
[1] _require(::Symbol) at ./loading.jl:435
[2] require(::Symbol) at ./loading.jl:405
[3] include_string(::String, ::String) at ./loading.jl:522
I originally had the module in a separate folder called 'modules', but even after moving it to the main folder (same location as the notebook), I still get the same error message.
I have ascertained the working directory:
pwd()
"/mnt/juliabox"
..and that seems to be the folder where my module is currently stored. At least, that's the directory which is displayed when I try to move the module file on the main JuliaBox screen.
I did try installing the module as an unregistered package under Package Builder (I was getting desperate!), but that didn't work either.
So I'm wondering whether I need to add something to the JULIA_LOAD_PATH in Environment Variables; however, that would seem to rather defeat the purpose of using an online version of Jupyter notebooks, which presumably is to allow easy access anywhere.
Anyway, I've run out of ideas, so if anyone could give me a clue as to where I am going wrong it would be very much appreciated.
If your module file is in the main folder, add it to the LOAD_PATH (it is not added by default). Customize the path if you put your file somewhere else.
#everywhere push!(LOAD_PATH, homedir())
import MyModule
or
include("MyModule.jl") # if it is already in pwd()
import MyModule
The issue is not related to JuliaBox or IJulia. That is how you import a Module. You either put the folder in LOAD_PATH or include the file containing the module.
https://docs.julialang.org/en/stable/manual/modules/#Relative-and-absolute-module-paths-1
I believe this issue on Github addressing the problem you are facing: https://github.com/JuliaLang/julia/issues/4600
I did try installing the module as an unregistered package under Package Builder (I was getting desperate!), but that didn't work either.
I think the package builder functionality is working properly. Just try creating a dummy module with the following structure and the contents:
~/MyModule.jl> tree
.
├── REQUIRE
└── src
├── functions
│   └── myfunc.jl
└── MyModule.jl
2 directories, 3 files
~/MyModule.jl> cat REQUIRE
julia 0.6
~/MyModule.jl> cat src/functions/myfunc.jl
myfunc(x) = 2x
~/MyModule.jl> cat src/MyModule.jl
module MyModule
export myfunc
include(joinpath("functions", "myfunc.jl"))
end
Then, git init a repository inside the directory, git add and git commit all the files, add a remote repository (like on GitHub or GitLab) with git remote add, and git push your local repository to the newly added remote repository. You should see that the unregistered package option is working as intended.
All that remains is to call
julia> using MyModule
julia> myfunc(10)
20
EDIT. You can try adding https://github.com/aytekinar/MyModule.jl as an unregistered package to your JuliaBox. That repository hosts the above-mentioned dummy module.

Why are `__init__.py` and `BUILD` needed inside TensorFlow's `models/tutorials/rnn/translate`?

Inside the tensorflow/models/tutorials/rnn/translate folder, we have a few files including __init__.py and BUILD.
Without __init__.py and BUILD files, the translate script can still manage to run.
What is the purpose of __init__.py and BUILD here? Are we supposed to install or build it using these two files?
The BUILD file supports using Bazel for hermetic building and testing of the model code. In particular a BUILD file is present in that directory to define the integration test translate_test.py and its dependencies, so that we can run it on continuous integration system (e.g. Jenkins).
The __init__.py file causes Python to treat that directory as a package. See this question for a discussion of why __init__.py is often present in a Python source directory. While this file is not strictly necessary to invoke translate.py directly from that directory, it is necessary if we want to import the code from translate.py into a different module.
(Note that when you run a Python binary through Bazel, the build system will automatically generate __init__.py files if they are missing. However, TensorFlow's repositories often have explicit __init__.py files in Python source directories so that you can run the code without invoking Bazel.)

GO in IntelliJ IDEA. Multiple File and Error Undefined: Data

I want use IntelliJ IDE Community Edition to write code in GO (GoLang). I instaled right plugin, and instaled all need tools to build application.
My application consists with two below file. Each is in direcytory ../EventServer.
Main.go
Data.go
If I want to run project from IntelliJ using function Run (Ctlr+Shift+F10) and I get below error
/usr/lib/go/bin/go build -o "/tmp/Build Main.go and run0go" -gcflags "-N -l" /my/home/blah/EventServer/Main.go
# command-line-arguments
./Main.go:11: undefined: Data
I can without any problem compiled code from terminal come in to direcytory with project and execution command
:~/Pulpit/EventServer$ go build
./EventServer
Hello
dane w strukturze someone
tree direcytory and files looks like
EventServer$ tree -a
.
├── Data.go
├── EventServer
├── EventServer.iml
├── .idea
│   ├── compiler.xml
│   ├── copyright
│   │   └── profiles_settings.xml
│   ├── libraries
│   │   └── GOPATH__EventServer_.xml
│   ├── misc.xml
│   ├── modules.xml
│   ├── .name
│   ├── vcs.xml
│   └── workspace.xml
└── Main.go
I suppose that command to run is bad, because compiler trying build program with only one file Main.go but not with all files. Right command should be
$ go run *.go
But I do not know where Can I set this.
I also set GOPATH to:
export GOPATH=$HOME/Pulpit/EventServer
This also hasn't help
CODE
Main.go
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello")
abcd := Data{"someone" , "1234567"}
fmt.Printf("dane w strukturze %s ", abcd.Name)
}
And Data.go
package main
type Data struct {
Name string
Phone string
}
SYSTEM: LINUX
----------------------SOLVED-------------------------------------------SOLVED---------------------
Steps
Project must be found in directory for/example/MyProject/src/HERE_DIRECTORY_WITH_YOUR_SOURCE_GO_FILE
sub direcytory src is important
Go to Run --> Edit Configurations
Find below position
Change Run Kind to Package
In Position Package write Your folder with Your code (Shold be Highlight it is correct)
Click On PLUS icon in left top corner, and Add Go Application
Apply changes
In the right top corner main window IDE You see small icon Play
Chose early defined Go Application my is Unamed
Click Play
An Joy :D
Let say you are having a project with src/ sub directory and two .go files inside: hello.go and typetest.go and both defines the same package "main". One of them (hello.go) also implements func main().
To make it compile as whole you need to make sure two things are configured properly: GOPATH and Run/Debug configuration.
Open the Project Libraries/GOPATH settings:
For Gogland
File -> Settings -> Go
For Intellij IDEA
File -> Settings -> Languages & Frameworks -> Go -> Go Libraries
Makes sure the GOPATH for the project looks something like that:
GOPATH settings
Next, open Run -> Edit Configurations and make sure your configuration looks similar to this:
Run/Debug configuration
You can add second file (in your case Data.go) as Go tool arguments field in Run/Debug Configurations. I read about this here: https://github.com/go-lang-plugin-org/go-lang-idea-plugin/issues/2013 near the end of discussion. Example below (I used 2 files HelGo.go and aaa.go) worked for me:
Go Run Configuration with 2 files
Intellij objected in these 2 files were in different folders, and so both of them has to be same package (main).
On the other side I couldn't make any advises on this page work at all.
I solved the same problem with a complete list of checking. Usually, there are multiple problems combined with each other.
First of all, check your GOPATH settings, there are two ways:
use the command line to check your go environment:
$ go env
you will get a global environment setting, make sure your GO folders are correct. If you are using some local packages, be aware of them too.
check your Build tool setting, whether you have added all your resources files into your dependencies. This is another way to set up your project GOPATH, and do not affects the global settings.
Secondly, check your Run/Debug configuration, and make sure your settings have located the main package or main file. No matter which kind of configuration you use, this is always the start.
Sarp Kaya, just follow Mbded steps. Additional step is, ensure that your additional GOPATH should be there.
For example, this is our ~/.profile GOPATH
export GOPATH=$HOME/lib/Go:$HOME/Development/Go
The first path used by go get processes etc, while your active go development directory goes to the next path.
According to our config, the RightApp exact path should be $HOME/Development/Go/src/RightApp.