Download presentation
Presentation is loading. Please wait.
Published byAugust Sutton Modified over 9 years ago
1
Linux development Lection 3 25.01.2015
2
What we gonna do today Root privileges Software packages Managing software packages Build procedures Build components Cross-compiling tool chains
3
Root privileges
4
What is root root is the user name or account that by default has access to all commands and files on a Linux or other Unix-like operating system. It is also referred to as the root account, root user and the superuser.
5
root directory The top level directory of a systems cd /
6
root data directory /root Same as /home/
7
root privileges Powers that the root has on the systems Root account has the absolute power on the system Can grant and revoke access permissions
8
rootkit Software tools inserted as an intruder Has the same privileges as root Can be used to do bad things to the OS
9
User ID (UID) Each user has UID. In order to check the UID of a user use: echo $UID
10
/etc/passwd There is information about the users Use cat /etc/passwd to open the info about all the users How many users we see ?
11
How to create new user :# adduser testuser Follow the instructions
12
User groups /etc/shadow – secure user account info /etc/passwd – user accounts info /etc/group – defines the groups that user belongs /etc/sudoers – list of users who can execute sudo Used to determine equal privileges to all users in a group
13
How to add user as sudo # adduser newSudoUser # adduser newSudoUser sudo
14
How to remove user # userdel –r newSudoUser (if newSudoUser is used you must logout)
15
How to edit user # usermod –u UID username – this will change the UID number
16
Administrator vs root Every user can become administrator The root is a user that is administrator with highest possible privileges
17
Questions ?
18
Software packages
19
Software packages are packages of source files that are unachieved and build for each unique device. That way each software on Linux/UNIX can be build for every different machine One package can run on different OS architectures
20
How to install software on Debian Dpkg APT Unachieve
21
# dpkg Debian package management system Low level Installs, remove, provide information about.deb packages
22
# dpkg use # dpkg –i - to install something # dpkg –l - to list available packages # dpkg –r - to remove
23
APT – Advanced Packaging Tool High-level user friendly interface to manage packages Automatic retrieves, configures and install software packages
24
# apt-get APT package handling utility – cmd interface # apt-get install # apt-get update – retrieve new list of packages # apt-get upgrade – performs an upgrade # apt-get remove, – removes a package # apt-get clean – Erase downloaded archive files # apt-get dist-upgrade – distribution upgrade
25
# apt-get # apt-get source – Download source archives # apt-get download - Download binary # apt-get build-dep - Finds the libraries required to build a source
26
# apt-cache Used for searching and identifying a package # apt-cache search
27
# dpkg and # apt lab – task 1 – 10 min Update / upgrade Search for openssh Download source and binary of openssh Install with# dpkg Remove openssh Clean
28
Build procedure Install build-essential (# apt-get install build-essential) # apt-get build-dep #./configure If configure successful continue else google it # make # make install
29
In case of failure in the middle of installation # apt-get –f install # dpkg –configure –a
30
# dpkg and # apt lab task 2 – 15 min Configure compile and install openssh
31
# aptitude GUI for installing packages Press + or - to change the status of application
32
Qustions ?
33
Creating build procedures
34
Before you start In order to create a build procedure you must first know the target of the build procedure You must know all the libraries and dependencies that the build needs to build
35
Target Linux/GNU is supported by almost all processors with more than 84 MHz clock frequency In most of the cases the whole core must be recompiled and then uploaded to the target using UART/SPI/JTAG The code must be optimized as possible in order to work fast and not to waste resources
36
Libraries There are different options for core libraries to be used for the different processors. For simple application developed for embedded systems it is better to use libraries like: uClibc-ng (uclibc-ng.org) – optimized for space not for speed Musl C – optimized for speed and simplicity
37
uClibc High configurability: many features can be enabled or disalbled Supports most embedded architectures Must recompile every time there is a change Low performance Size of helloworld using uClibc – 18 kB Size of helloworld using glibc – 361 kB download
38
Important note NEVER USE : sudo rm –rf /*
39
Build steps 1.Optimize for target 2.Make configure file 3.Make Makefile 4.(Optional make Makefile for install) 5.(Optional make uploading to board script)
40
Optimize for target Part of the process is reviewing the code for any unused libraries and functions, because if no code optimization is used in the compiler all the libraries and their functions will be used If used uClibc start its GUI (graphic user interface) in order to set all that you are going to need in the compilation
41
Build and release tool chain for Debian
42
Make configuration file Used to check if all the dependencies are available in the system Used to collect and add all system information into a Makefile
43
Make configuration file Install autoconf and automake Write hello wolrd.c file in a folder Then we start making the 12387168581374 lines configure file $ nano configure.ac
44
configure.ac AC_INIT([programName], [ver], [yourmain@yourdomain.com]) AM_INIT_AUTOMAKE AC_PROG_CC AC_CONFIG_FILES([Makefile]) AC_OUTPUT
45
Making configuration file We must add a Makefile.in in order to be autoset after the execution of./configure Developers are lazy and they we have an automation script that is generating this file too $ nano Makefile.am
46
Makefile.am AUTOMAKE_OPTIONS = foreign # we say to linux that this software is not following the standart layout of GNU project bin_PROGRAMS = helloworld # this is the name of the final app helloworld_SOURCES = main.c # the sources
47
Putting all together $ aclocal # set up on m4 enviroment $ autoconf # generate configuration from configure.ac $ automake –add-missing # generate makefile.in from makefile.am $./configure # generate Makefile $ make dist # use makefile to build $ make distcheck # use this to check the tarball to distribute
48
How to convert binary to.deb Make a new folder hello_world_for_debian Copy the main.c file from the first folder and paste in in the new one Make directory DEBIAN Then $ nano DEBIAN/control
49
DEBIAN/control Package: hello_world Version: 0.1 Section: custom Priority: optional Architecture: all Essential: no Installed-Size: 1024 Maintainer: yourmain@yourdomain.com Description: Print hello world to the screen
50
How to convert binary to.deb Inside the directory hello_world_for_deb make directori usr/bin/ Then move the executable file to usr/bin/ Go one level up from the directories DEBIAN/ and usr/ $ dpkg-deb --build hello_world_for_deb Then $ ls Then $ sudo dpkg –i hello_world_for_deb.deb Then $ cd /usr/bin And finally./helloworld
51
Questions ?
52
Make a tool-chain for embedded platforms
53
How to compile for ARM based CPU Two approaches: Use buildroot Create custom makefile
54
Using Buildroot Install Buildroot with $ wget https://buildroot.org/downloads/buildroot-2015.11.1.tar.gz https://buildroot.org/downloads/buildroot-2015.11.1.tar.gz Run $ make menuconfig Run $ make
55
Create custom Makefile You can write only one Makefile for all of your software and just change few lines in order to compile everything This is the most comfortable way to have full control of the code you compile
56
Makefiles – starting point all: [tab] GCC main.c hello_master.c –o outputfile
57
Makefiles – define macros CC = GCC # define compiler CFLAGS = -O –lm # define output compilation flags LIBS = “-lnurses –lm –lsdl” PINGUIN = (“)>
58
Makefiles – spacial macros $@ - the name of the file to be made $? – the names of the changed dependents $< - the name of the related file that caused the action $* - the prefix shared by target and dependent files // using $ make –p in the terminal will show you the default predefined macros
59
Makefiles – with macros CC:=gcc CFLAGS:=-O -Wall all: $(CC) main.c hello_master.c $(CFLAGS) -o outputfile
60
Makefiles - dependencies Similar to the functions in the programming languages Helps to recompile only what you need, not everything
61
Makefiles – with dependencies CC:=gcc CFLAGS:=-O -Wall –c all: compile compile: main.o hello_master.o $(CC) main.o hello_master.o -o outputfile main.o: main.c $(CC) $(CFLAGS) main.c hello_master.o: hello_master.c $(CC) $(CFLAGS) hello_master.c
62
Makefiles What if we have 500 files that we must compile ????
63
Makefiles – using macros in dependencies CC=gcc CFLAGS=-c -Wall -O LDFLAGS= SOURCES=main.c hello_master.c OBJECTS=$(SOURCES:.c=.o) EXECUTABLE=binary all: $(SOURCES) $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) $(CC) $(LDFLAGS) $(OBJECTS) -o $@.cpp.o: $(CC) $(CFLAGS) $< -o $@ clean: -rm -f *.o core *.core
64
And cross compilation for AVR Install arduino-mk Use avr-gcc instead of gcc in the Makefile
65
Qustions ?
66
Lab
67
Task 1 Write a C program that: Calculates perimeter and surface of given equilateral figure by given side and number of angles Program must have files main.c surface.c and perimeter.c Compile and run Pack to archive Pack to.deb Prepare manual Makefile
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.