Embedded Software Design

Download Report

Transcript Embedded Software Design

Embedded Software Design
Week II
Linux Intro
Linux Kernel
How an embedded system is booted?
• HDD?
• BIOS?
• RAM?
• OS?
• CPU/GPU?
Embedded System
Embedded Linux development setup
Booting kernel
• Bootloader loads and executes OS image
• Device tree is loaded - memory size, clock speeds, onboard devices,
buses, and Flash layout
• Transfer control to kernel
Bootloader
• Initializes critical hardware components, such as the SDRAM
controller, I/O controllers, and graphics controllers.
• Initializes system memory in preparation for passing control to the
operating system.
• Allocates system resources such as memory and interrupt circuits to
peripheral controllers, as necessary.
• Provides a mechanism for locating and loading your operating system
image.
• Loads and passes control to the operating system, passing any
required startup information.
Boot Overview
• Kernel Initialization - Mounting a file system
• First User Space Process: init
• Kernel context vs User space context
• Virtual memory space
• Storage Considerations
• Storage limit
• Flash memories ( block sizes, 100K write life time)
• Wear level algorithms (increase lifetime)
Boot Overview
• Memory space
• Memory Management Unit (MMU)
• Hardware engine
• Works with OS
• Access rights & memory translation
Boot Overview
• Execution Contexts
• Kernel symbols addresses : 0xC0XX…
• Context switch
• Kernel context
• User space context
• Async hw call & blocking user call
• Two kernel context modes
• Process context
• Interrupt context
Boot Overview
• Process Virtual Memory
• See sample code
• Handicaps of swapping pages
• Overhead
• Shortens life time of flash drive
• Cross-Development
•
•
•
•
gcc -Wall -o hello hello.c
Including headers (where is stdio.h)
Linking libraries (external symbol printf()! which libc-*?)
Find correct version?
Linux Commands
• Check commands at this site;
• http://www.codingbyte.com/30-most-frequently-used-linux-commands-withexamples/
• Plus this site
• http://www.tecmint.com/useful-linux-commands-for-newbies/
Raspberry Pi – OS Survey
• Moving Files Around Graphically
• Use File Manager
Raspberry Pi – OS Survey
• Starting a Terminal Session
Raspberry Pi – OS Survey
• Navigating the Filesystem Using a Terminal
•
•
•
•
•
•
•
•
$
$
$
$
$
$
$
$
cd
pwd
cd ..
cd ~
cd /
ls
ls f*
ls –a
File commands
• Copying a File or Folder
•
•
•
•
Use the cp command to copy files and directories.
echo "hello" > myfile.txt
cp myfile.txt myfile2.txt
cp -r mydirectory mydirectory2
• Renaming a File or Folder
• mv my_file.txt my_file.rtf
File operations
• Use the editor nano included with most Raspberry Pi distributions.
• If you are a Linux fan, try “vi” or “emacs”
• Use the cat or more commands to view the file.
• Creating a File Without Using an Editor
• echo "file contents here" > test.txt
• touch
Directory operations
• To create a directory, use the mkdir command
• The rm (remove) command will delete a file or directory and its
contents.
•
•
•
•
$
$
$
$
rm
rm
rm
rm
my_file.txt
my_file.*
*
-r mydir
Privileges, Access Rights
• The sudo (superuser do) command allows you to perform actions
with superuser privileges. Just prefix the command with sudo.
• $ sudo apt-get update
• To see the permissions and ownership information relating to files
and directories, use the ls command with the option -l.
“d” for
directory
Permissions
• The command chmod is used to modify file permissions.
• chmod ….
• +, -, = for add, remove, or set, respectively
• permission for currnet user(u), group (g), other users(o)
• chmod u+x file2.txt
• The command chown (change owner) is used to modify the
ownership of a file or directory.
• sudo chown root:root file2.txt
Making a Screen Capture
• Install and use the delightfully named scrot screen capture software.
• sudo apt-get install scrot
• $ scrot
• $ scrot –d 5
• $ man scrot
Installing / Removing Software with apt-get
• The most used tool for installing software from a Terminal session is
apt-get.
• $ sudo apt-get update
• $ sudo apt-cache search
• $ sudo apt-get install <name of software>
• The apt-get utility has an option (remove) that will remove a package,
but only packagesthat have been installed with apt-get install.
• $ sudo apt-get remove <name of software>
• $ sudo apt-get autoremove <name of software>
• $ sudo apt-get clean
Running a Program or Script Automatically on
Startup
1. Create an init script
2. Make the init script executable.
3. Tell the system about the new init script
•
•
•
•
$
$
$
$
sudo nano /etc/init.d/my_server
sudo chmod +x /etc/init.d/my_server
/etc/init.d/my_server start
sudo update-rc.d my_server defaults
Running a Program or Script Automatically at Regular Intervals
• Use the Linux crontab command.
• Raspberry Pi needs to know the time and date, and therefore needs a
network connection or a real-time clock.
• $ crontab –e
• If there is a * in the digit position, that means every; if there is a
number there instead, the script will only be run at that
minute/hour/day of the month
Finding Things
• Use the Linux find command.