+ All Categories
Home > Documents > Linux Kernel Projects

Linux Kernel Projects

Date post: 02-Jun-2018
Category:
Upload: ghfalcon7
View: 244 times
Download: 4 times
Share this document with a friend

of 40

Transcript
  • 8/10/2019 Linux Kernel Projects

    1/40

    Embedded Development ProjectBlackfin/Linux

    Walid Barreh

  • 8/10/2019 Linux Kernel Projects

    2/40

    Agenda

    2

    Introduction

    Overview of File System, Shell, Device Drivers.

    Comparing the development Environments.

    Started examples

    Advanced topics.

    Links.

  • 8/10/2019 Linux Kernel Projects

    3/40

    Introduction

  • 8/10/2019 Linux Kernel Projects

    4/40

    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 ofapplications 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 andmultimedia 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 abilitiesof the user to recognize glitches in audio and video.

    4

    http://www.linuxjournal.com/article/7814http://www.linuxjournal.com/article/7814
  • 8/10/2019 Linux Kernel Projects

    5/40

    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

  • 8/10/2019 Linux Kernel Projects

    6/40

    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.

    6

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

  • 8/10/2019 Linux Kernel Projects

    7/40

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

    files & file systems!

    7

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

  • 8/10/2019 Linux Kernel Projects

    8/40

    Device Drivers in Linux CharSerial port.

    BlockNAND Flash. NetworkEthernet.

    8

    Open() read() ioctl ()

    Close() write()

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

    http://www.analog.com/library/analogdialogue/archives/44-03/foss.htmlhttp://www.analog.com/library/analogdialogue/archives/44-03/foss.htmlhttp://www.analog.com/library/analogdialogue/archives/44-03/foss.htmlhttp://www.analog.com/library/analogdialogue/archives/44-03/foss.html
  • 8/10/2019 Linux Kernel Projects

    9/40

    Loadable Kernel Modules.

    A module is a loadable piece of code, which could be a device driver, astack, 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 aseparate independent module.

    You build it separately and attach it run-time to the Kernel.

    Modules help in easy debug & development, because you dont need tobuild the Kernel for any change in a Module.

    The same driver code used while building the Kernel can be directly usedand 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

  • 8/10/2019 Linux Kernel Projects

    10/40

    Info about Device Drivers(uC-Linux Docs).

    10

    Peripherals Documentation Source Mainlined?

    ATAPI PATA Driver src Yes

    CAN ports SocketCAN Driver src Yes

    Ethernet MAC src Yes

    General-purpose I/O

    pinsgpio src Yes

    GP Timers gptimers src Yes

    High Speed USB OTG musb src Yes

    Host DMA Port

    IRDA Docs src Yes

    Keypad Interface Docs src Yes

    LockboxTM CodeSecurity

    MXVR

    NAND Flash Controller bf5xx_nand src Yes

    Phase Lock Loops

    (PLL)

    cpufreq

    Power Management

    Support

    src Yes

    Pixel Compositor

    PPI/EPPI src No

    Real Time Clock (RTC)Real Time Clock src Yes

    SD/SDIO Controller bfin_sdh src No

    SPI ports spi src Yes

    SPORTs src No

    TWI ports i2c src Yes

    UART ports Docs src Yes

    Up / Down Counter Rotary src Yes

    USB musb src Yes

    Watchdog Timer Watchdog src Yes

    WDT1

    as NMI WatchdogTimer

    nmi_watchdog src No

    100s of drivers are available.

    This list only shows the drivers for

    Blackfin hardware.

    http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:pata_bf54xhttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:bfin_canhttp://docs.blackfin.uclinux.org/doku.php?id=gpiohttp://docs.blackfin.uclinux.org/doku.php?id=gptimershttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:musbhttp://docs.blackfin.uclinux.org/doku.php?id=irda_frameworkhttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:bf54x-keyshttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:bf5xx_nandhttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:cpufreqhttp://docs.blackfin.uclinux.org/doku.php?id=power_management_supporthttp://docs.blackfin.uclinux.org/doku.php?id=power_management_supporthttp://docs.blackfin.uclinux.org/doku.php?id=rtchttp://docs.blackfin.uclinux.org/doku.php?id=rtchttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:bfin_sdhhttp://docs.blackfin.uclinux.org/doku.php?id=spihttp://docs.blackfin.uclinux.org/doku.php?id=i2chttp://docs.blackfin.uclinux.org/doku.php?id=uclinux-dist:serial_programminghttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:bfin-rotaryhttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:musbhttp://docs.blackfin.uclinux.org/doku.php?id=watchdoghttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:nmi_watchdoghttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:nmi_watchdoghttp://docs.blackfin.uclinux.org/doku.php?id=watchdoghttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:musbhttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:bfin-rotaryhttp://docs.blackfin.uclinux.org/doku.php?id=uclinux-dist:serial_programminghttp://docs.blackfin.uclinux.org/doku.php?id=i2chttp://docs.blackfin.uclinux.org/doku.php?id=spihttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:bfin_sdhhttp://docs.blackfin.uclinux.org/doku.php?id=rtchttp://docs.blackfin.uclinux.org/doku.php?id=power_management_supporthttp://docs.blackfin.uclinux.org/doku.php?id=power_management_supporthttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:cpufreqhttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:bf5xx_nandhttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:bf54x-keyshttp://docs.blackfin.uclinux.org/doku.php?id=irda_frameworkhttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:musbhttp://docs.blackfin.uclinux.org/doku.php?id=gptimershttp://docs.blackfin.uclinux.org/doku.php?id=gpiohttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:bfin_canhttp://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:pata_bf54x
  • 8/10/2019 Linux Kernel Projects

    11/40

    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 needsto interact with widely used/known standard APIs. This helps in faster softwaredevelopment 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 eventsfor gpios, keyboard etc.

    GPIO frameworkgpios. DMA framework.

    ALSAaudio.

    V4LVideo for Linux.

    Framebuffer- dealing with images.

    11

  • 8/10/2019 Linux Kernel Projects

    12/40

    Highlighting differences between development

    environments.

    Visual DSP++

    Visual DSP Kernel.uC-Linux.

  • 8/10/2019 Linux Kernel Projects

    13/40

    VDSP environment

    13

    Application software & algorithm

    Device Drivers

    Peripheral access

    DMA access

    ISRs

    Defined Memory Space through LDF.

  • 8/10/2019 Linux Kernel Projects

    14/40

    Visual DSP Kernel environment

    14

    Thread1

    App1

    Driver1 Driver2

    ISR1 ISR2

    Defined Memory Space through LDF.

    Scheduler

    Thread

    Communication

    Thread1

    App2

  • 8/10/2019 Linux Kernel Projects

    15/40

    Linux environment

    15

    Device

    Drivers

    ISRs

    File Systems

    Process Space

    Thread

    Applicationalgorithm

    and related

    software

    Kernel

    Networking

    Thread

    Applicationalgorithm

    and related

    software

    Process Space

    Thread

    Application

    algorithm

    and related

    software

    Thread

    Application

    algorithm

    and related

    software

    Scheduler

    System calls

    Shell cmds

    Kernel decides

    where to load

    application

    Kernel decides

    where to load

    application

    Kernel Space

    Supervisor modeUser Space

    User mode

  • 8/10/2019 Linux Kernel Projects

    16/40

    VDSP development platform

    16

    JTAG

    Windows PC

    VDSP

  • 8/10/2019 Linux Kernel Projects

    17/40

    Linux development platform

    17

    Serial Port

    Linux PC Eclipse or

    Console Terminals

    Ethernet Port

  • 8/10/2019 Linux Kernel Projects

    18/40

    VDSP IDDE

    18

  • 8/10/2019 Linux Kernel Projects

    19/40

  • 8/10/2019 Linux Kernel Projects

    20/40

    Creating a project and debugging

    VisualDSP++ based

    Linux based

  • 8/10/2019 Linux Kernel Projects

    21/40

    VisualDSP++ based development

    21

    JTAG

    Windows PC VDSP

    1. Build the bare-metal applicationcode.

    2. Loading to target via JTAG is

    automatic F7 key.

    3. Start direct debugging of

    application. Access any MMR

    or Memory content.

  • 8/10/2019 Linux Kernel Projects

    22/40

    Development with Blackfin/Linux

    22

    Serial Port for

    command transfer

    Linux PC Eclipse or

    Console Terminals

    Ethernet Port

    for data transfer

    (netconsole can

    do commandtransfer also)

    ARCH-linux-gdb

    1. After power on, uboot startsrunning.

    2. Send uC-Linux Image via tftp.

    3. Load kernel.

    4. Set the network ip.

    5. Build your Module.

    6. Send Module.ko (via rcpprogram 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!

  • 8/10/2019 Linux Kernel Projects

    23/40

    Getting started examples

    1. LCD alternate image display.

    2. Push button interrupt detection using gpio-

    keys module.

  • 8/10/2019 Linux Kernel Projects

    24/40

    LCD alternate image display: Linux user.

    24

    int main(){

    strcpy(test_drv, LCD_DEV);

    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");

    imagedata();

    return 0;

    }

    void imagedata()

    {

    for(j=0;j

  • 8/10/2019 Linux Kernel Projects

    25/40

    static int __init lcd_init(void)

    {

    int ret;

    int i;

    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;

    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;

    }

    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_test();

    return 0;

    }

    lcd_test

    {

    //port muxing

    port_mux_init();

    //DMA Config

    dma_config();

    //PPI Config

    ppi_config();

    }

    LCD alternate image display: Linux driver.

    25

    LCD lt t i di l Li d i td

  • 8/10/2019 Linux Kernel Projects

    26/40

    static ssize_t lcd_write(struct file *filep, const char *buf, size_t

    count, loff_t * f_pos)

    {

    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_data);

    start_dma_ppi();

    return count;

    }

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

    unsigned int cmd , unsigned long arg ) {

    switch (cmd) {

    case SET_LCD_IMAGE1:

    stop_dma_ppi();

    dma_start_addr(LCD__Image_Data1);

    start_dma_ppi();

    return 0;

    case SET_LCD_IMAGE2:

    stop_dma_ppi();

    dma_start_addr(LCD__Image_Data1);

    start_dma_ppi();

    return 0;

    default:

    return -ENOTTY;

    }

    }

    LCD alternate image display: Linux driver contd.

    26

  • 8/10/2019 Linux Kernel Projects

    27/40

    Push Button interrupt generation

    :gpio-keys & gpio framework

    27

  • 8/10/2019 Linux Kernel Projects

    28/40

    Push Button interrupt generation

    28

  • 8/10/2019 Linux Kernel Projects

    29/40

    Advanced topics

  • 8/10/2019 Linux Kernel Projects

    30/40

    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 thecomplete system down.

    30

  • 8/10/2019 Linux Kernel Projects

    31/40

    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

  • 8/10/2019 Linux Kernel Projects

    32/40

    U-Bootboot loader

    32

  • 8/10/2019 Linux Kernel Projects

    33/40

    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

    http://docs.blackfin.uclinux.org/doku.phphttp://docs.blackfin.uclinux.org/doku.php
  • 8/10/2019 Linux Kernel Projects

    34/40

    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

  • 8/10/2019 Linux Kernel Projects

    35/40

    Make menuconfig of uC-Linux kernel build

    35

  • 8/10/2019 Linux Kernel Projects

    36/40

    Gcc optionsvisit

    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-frame-

    pointer -mno-omit-leaf-frame-pointer -mspecld-anomaly -mno-specld-anomaly -mcsync-anomaly -mno-csync-anomaly -mlow-64k -mno-low64k -mstack-check-l1 -mid-shared-library -mno-id-shared-library -mshared-library-id=n-mleaf-id-shared-library -mno-leaf-id-shared-library -msep-data -mno-sep-data -mlong-calls -mno-long-calls -mfast-fp -minline-plt -mmulticore -mcorea -mcoreb-msdram -micplb

    36

    http://gcc.gnu.org/onlinedocs/gcc/Option-Summary.htmlhttp://gcc.gnu.org/onlinedocs/gcc/Blackfin-Options.htmlhttp://gcc.gnu.org/onlinedocs/gcc/Blackfin-Options.htmlhttp://gcc.gnu.org/onlinedocs/gcc/Blackfin-Options.htmlhttp://gcc.gnu.org/onlinedocs/gcc/Blackfin-Options.htmlhttp://gcc.gnu.org/onlinedocs/gcc/Blackfin-Options.htmlhttp://gcc.gnu.org/onlinedocs/gcc/Blackfin-Options.htmlhttp://gcc.gnu.org/onlinedocs/gcc/Option-Summary.htmlhttp://gcc.gnu.org/onlinedocs/gcc/Option-Summary.htmlhttp://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html
  • 8/10/2019 Linux Kernel Projects

    37/40

    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

  • 8/10/2019 Linux Kernel Projects

    38/40

    Make: Is a utility that automatically builds executable programs and libraries from source code by reading files

    called Makefileswhich 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 Makefileprogramming!

    38

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

    http://www.codeproject.com/KB/cpp/makefiles_linux/lnxmk_01.jpghttp://www.codeproject.com/KB/cpp/makefiles_linux/lnxmk_01.jpg
  • 8/10/2019 Linux Kernel Projects

    39/40

    Links: http://blackfin.uclinux.org/gf/

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

    39

    http://tldp.org/HOWTO/HOWTO-INDEX/howtos.htmlhttp://tldp.org/HOWTO/HOWTO-INDEX/howtos.htmlhttp://tldp.org/HOWTO/HOWTO-INDEX/howtos.htmlhttp://tldp.org/HOWTO/HOWTO-INDEX/howtos.htmlhttp://tldp.org/HOWTO/HOWTO-INDEX/howtos.htmlhttp://tldp.org/HOWTO/HOWTO-INDEX/howtos.html
  • 8/10/2019 Linux Kernel Projects

    40/40

    40


Recommended