Вы находитесь на странице: 1из 40

Embedded Development Project

Blackfin/Linux
Walid Barreh

Agenda

Introduction
Overview of File System, Shell, Device Drivers.
Comparing the development Environments.
Started examples
Advanced topics.
Links.

Introduction

Many things to explore (http://www.linuxjournal.com/article/7814)

The advantage of Embedded Linux is that it is a royalty-free, open source,


compact solution that provides a strong foundation for an ever growing base of
applications to run on.

Why Linux on embedded hardware?

Originally not designed for embedded systems.


Large number of drivers.
No run-time royalties.

But why would anyone use Linux on a DSP?

Powerful processor that will meet the intensive demands of a wide range of communication and
multimedia applications.
Combined with the capabilities and the power of an operating system like Linux, there are endless
possibilities.

Real time?

It has no hard real-time capabilities, though there are patches for Real Time.
Particularly for multimedia applications, in which the time constraints are dictated by the abilities
of the user to recognize glitches in audio and video.
4

Linux Kernel advantages and


downsides
Advantages
-

Rapid Application Development


Debugged Control Structures
Code Reuse
Hardware Abstraction
Partitioning an Application

Disadvantages
-

Memory consumption.
Boot Time.
Interrupt Latency.
Robustness.
5

Linux Shell

Shell is an interactive way of connecting user world to Kernel world.


100s of commands.
Do not learn commands at one shot; no use and you will never remember.
Store output of tested commands so you know what it brings out.
Web search gives you answers for almost all questions on Commands.

Img src: http://files.opensuse.org/opensuse/en/e/e2/Flow1.jpg


6

File System. In Linux or Unix world, everything you deal is about


files & file systems!

Image src: http://www.pinoytux.com/wp-content/uploads/2008/08/linux-dir-tree.jpg


7

Device Drivers in Linux

Char Serial port.


Block NAND Flash.
Network Ethernet.

Open() read() ioctl ()


Close() write()

Img src: http://www.analog.com/library/analogdialogue/archives/44-03/foss.html


8

Loadable Kernel Modules.


A module is a loadable piece of code, which could be a device driver, a
stack, or even a file system.
The best case of an example is a Device Driver module.
Device Drivers could be built along with the Kernel or can be loaded as a
separate independent module.
You build it separately and attach it run-time to the Kernel.
Modules help in easy debug & development, because you dont need to
build the Kernel for any change in a Module.
The same driver code used while building the Kernel can be directly used
and built as a loadable mode.
Built as *.ko files.
Easy loading with insmod and unloading with rmmod.
In case of dependencies, `modprobe` can be used to automatically resolve
& load dependent modules.
9

Info about Device Drivers (uC-Linux Docs).


Peripherals
ATAPI
CAN ports
Ethernet MAC
General-purpose I/O
pins
GP Timers

Documentation
PATA Driver
SocketCAN Driver

Source
src
src
src

Mainlined?
Yes
Yes
Yes

gpio

src

Yes

gptimers

src

Yes

src

Yes

src
src

Yes
Yes

src

Yes

src

Yes

src
src
src
src
src
src
src
src
src
src

No
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Yes

High Speed USB OTG musb


Host DMA Port
IRDA
Docs
Keypad Interface
Docs
LockboxTM Code
Security
MXVR
NAND Flash Controller bf5xx_nand
cpufreq
Phase Lock Loops
Power Management
(PLL)
Support
Pixel Compositor
PPI/EPPI
Real Time Clock (RTC) Real Time Clock
SD/SDIO Controller
bfin_sdh
SPI ports
spi
SPORTs
TWI ports
i2c
UART ports
Docs
Up / Down Counter
Rotary
USB
musb
Watchdog Timer
Watchdog
WDT1
as NMI Watchdog
nmi_watchdog
Timer

src

No

10

100s of drivers are available.


This list only shows the drivers for
Blackfin hardware.

Frameworks..

The main idea of using frameworks is that, it allows user to focus on the lowest level -the actual hardware. All higher level pieces are taken care of and the user only needs
to interact with widely used/known standard APIs. This helps in faster software
development and portability.

Using frameworks are recommended in your products.


Frameworks are tested thoroughly.
Easy to port.
More people use it, so more help.
If you dont use frameworks, you are left on your own.

Input events for gpios, keyboard etc.


GPIO framework gpios.
DMA framework.
ALSA audio.
V4L Video for Linux.
Framebuffer- dealing with images.
11

Highlighting differences between development


environments.

Visual DSP++
Visual DSP Kernel.
uC-Linux.

VDSP environment
Application software & algorithm

Defined Memory Space through LDF.

Device Drivers
Peripheral access
DMA access

ISRs

13

Visual DSP Kernel environment


Thread1
App1

Scheduler

Thread1
App2

Thread
Communication

Driver1

Driver2

ISR1

ISR2

Defined Memory Space through LDF.

14

Linux environment
Kernel Space
Supervisor mode

User Space
User mode

Device
Drivers

Process Space
Scheduler

ISRs
System calls

Thread

Thread

Application
algorithm
and related
software

Application
algorithm
and related
software

Kernel decides
where to load
application

Kernel

Shell cmds
File Systems

Networking

Process Space
Thread

Thread

Application
algorithm
and related
software

Application
algorithm
and related
software

15

Kernel decides
where to load
application

VDSP development platform


Windows PC
VDSP

JTAG

16

Linux development platform


Linux PC Eclipse or
Console Terminals

Serial Port
Ethernet Port

17

VDSP IDDE

18

Eclipse IDDE

19

Creating a project and debugging


VisualDSP++ based
Linux based

VisualDSP++ based development


1. Build the bare-metal application
code.
2. Loading to target via JTAG is
automatic F7 key.
3. Start direct debugging of
application. Access any MMR
or Memory content.

Windows PC VDSP

JTAG

21

Development with Blackfin/Linux


Linux PC Eclipse or
Console Terminals

Serial Port for


command transfer

Ethernet Port
for data transfer
(netconsole can
do command
transfer also)

ARCH-linux-gdb
22

1. After power on, uboot starts


running.
2. Send uC-Linux Image via tftp.
3. Load kernel.
4. Set the network ip.
5. Build your Module.
6. Send Module.ko (via rcp
program to any directory).
7. Send application Image (via rcp
to any directory).
8. Run gdbserver for the
application image.
9. Debug and enjoy from eclipse!

Getting started examples


1. LCD alternate image display.
2. Push button interrupt detection using gpiokeys module.

LCD alternate image display: Linux user.


#define LCD_DEV "/dev/lcd_bf548_driver"

int main()
{

void imagedata()
{
for(j=0;j<10;j++)
{
#ifdef USE_WRITE
delay_func();

strcpy(test_drv, LCD_DEV);

ret = write(test_fd,&LCD__Image_Data1[0],N);
(ret < 0) errp("error writing to driver test_drv '%s'", test_drv);

test_fd = open(test_drv, O_RDWR);


if (test_fd < 0) errp("unable to open '%s'", test_drv);
printf("\n Driver has been opened \n\n");

delay_func();

imagedata();

ret = write(test_fd,&LCD__Image_Data2[0],N);
if (ret < 0) errp("error writing to driver test_drv '%s'", test_drv);

return 0;

#endif

#ifdef USE_IOCTL
delay_func();
ret = ioctl(test_fd,SET_LCD_IMAGE1,&lcd_data);
if ( ret < 0 ) errp("unable to send io ctrl '%s'", test_drv);
delay_func();
ret = ioctl(test_fd,SET_LCD_IMAGE2,&lcd_data);
if ( ret < 0 ) errp("unable to send io ctrl '%s'", test_drv);
#endif
}
}

24

LCD alternate image display: Linux driver.


static int __init lcd_init(void)
{
int ret;
int i;

static int lcd_open(struct inode *inode, struct file *file)


{
int ret = 0;
printk(KERN_DEBUG " Driver lcd_basic opened .. ret %d
\n",ret);
// allow only one user
if(test_and_set_bit(0, &lcd_is_open))
return -EBUSY;

lcd_driver_fops.read
= lcd_read;
lcd_driver_fops.write = lcd_write;
lcd_driver_fops.open = lcd_open;
lcd_driver_fops.release = lcd_release;
lcd_driver_fops.ioctl
= lcd_ioctl;

lcd_test();
return 0;

ret = register_chrdev(lcd_major, LCD_DEV, &lcd_driver_fops);


printk(KERN_INFO " Driver lcd_basic registered .. ret %d \n",ret);
if ( ret > 0 ) {
lcd_major = ret;
ret = 0;
}
return ret;
}

lcd_test
{
//port muxing
port_mux_init();
//DMA Config
dma_config();
//PPI Config
ppi_config();
}

25

LCD alternate image display: Linux driver contd.


static ssize_t lcd_write(struct file *filep, const char *buf, size_t
count, loff_t * f_pos)
{

int lcd_ioctl(struct inode* inode , struct file* filp ,


unsigned int cmd , unsigned long arg ) {

switch (cmd) {
case SET_LCD_IMAGE1:

stop_dma_ppi();

stop_dma_ppi();

/* copy count from a user space buffer to the kernel buffer */


/* copy_from_user returns 0 on success */
if (copy_from_user(&lcd_data[pos],buf,count))
return -EFAULT;

dma_start_addr(LCD__Image_Data1);
start_dma_ppi();

dma_start_addr(lcd_data);

return 0;

start_dma_ppi();

case SET_LCD_IMAGE2:

return count;

stop_dma_ppi();

dma_start_addr(LCD__Image_Data1);
start_dma_ppi();
return 0;
default:
return -ENOTTY;
}
}

26

Push Button interrupt generation


:gpio-keys & gpio framework

27

Push Button interrupt generation

28

Advanced topics

Linux vs uC-Linux : MMU vs No MMU

The UNIX security model, from which Linux is designed, protects every process in its own
environment with its own address space. Every process is also protected from processes
being invoked by different users.

You will find an MMU in x86 architectures, including the Pentium machines.

Some devices, like the Blackfin Processor, do not provide a full-fledged MMU.

MMU-less processors such as the Blackfin are more power efficient and are often
significantly cheaper than the alternatives.

In uCLinux, Memory allocation is done in chunks. Also, a faulty process can bring the
complete system down.

30

Boot-loader concept.

The boot-loader is a piece of code responsible for:

Basic hardware initialization.


Loading of an application binary, usually an operating system kernel, from flash
storage, from the network, or from another type of nonvolatile storage.
Possibly de compression of the application binary.
Execution of the application

Besides these basic functions, most boot loaders provide a shell with various
commands implementing different operations:

Loading of data from storage or network, memory inspection.


Hardware diagnostics and testing, etc.

31

U-Boot boot loader

32

Jtag?

http://docs.blackfin.uclinux.org/doku.php

Traditional non-Linux or non-OS embedded software development often requires


hardware debuggers connected through a JTAG interface. This is necessary for
development of drivers, and possibly applications, because theyre linked into the
same memory space as the kernel. If a driver or application crashes, the kernel and
system may crash as a result.

All Linux applications run in their own address space which is different than the
link time or compile time addresses.

You use the hardware debugger to debug the Bootloader, kernel start, and drivers
and gdb to debug applications once the kernel is running.

JTAG is not used for developing Linux applications.

33

Executable file formats

Files can be in two basic formats in the Blackfin Linux world:

FLAT Binary Flat files commonly known as BFLT, are a relatively simple and
lightweight executable format based on the original a.out format. BFLT files are the
default file format in embedded Linux.

FDPIC ELF The executable and linking format (ELF) was originally developed by
Unix System Laboratories and has become the standard in file formats. The ELF
standard has greater power and more flexibility than the BFLT format. However,
they are more heavyweight, requiring more disk space and having a small run-time
penalty.

34

Make menuconfig of uC-Linux kernel build

35

Gcc options visit


http://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html &
http://gcc.gnu.org/onlinedocs/gcc/Blackfin-Options.html#Blackfin-Options

Blackfin Options
-mcpu=cpu[-sirevision] -msim -momit-leaf-framepointer -mno-omit-leaf-frame-pointer -mspecldanomaly -mno-specld-anomaly -mcsync-anomaly mno-csync-anomaly -mlow-64k -mno-low64k mstack-check-l1 -mid-shared-library -mno-idshared-library -mshared-library-id=n -mleaf-idshared-library -mno-leaf-id-shared-library -msepdata -mno-sep-data -mlong-calls -mno-long-calls mfast-fp -minline-plt -mmulticore -mcorea -mcoreb
-msdram -micplb
36

System parameters to explore.

Code and Data mostly runs in SDRAM.


Cache is enabled.
Look inside the /proc /sys file systems from the
Linux Image you have.

37

Make:

Is a utility that automatically builds executable programs and libraries from source code by reading files
called Makefiles which specify how to derive the target program.
You may ignore Makefiles, as long as you are developing your own simple codes & you can manage the build
yourself.
If you want to port open source software (any!) or if your project build process is getting complex, then better
learn Makefile programming!

Img src: http://www.codeproject.com/KB/cpp/makefiles_linux/lnxmk_01.jpg


38

Links:

http://blackfin.uclinux.org/gf/
http://docs.blackfin.uclinux.org/doku.php?id=main

39

40