world leader in high performance signal processing
Trace: » xip

Execute In Place (XIP)

Execute in place (XIP) is a method for executing code straight out of flash. Normally when you run code (both the kernel and userspace applications), the code is loaded out of flash and into external memory, and then executed from there. By executing straight out of flash, you can significantly cut down on memory usage as there is no copy step, and no memory taken up by read-only sections. It can also be used to decrease your boot time if the kernel itself is executed out of flash.

Overview

There are different pieces which may be executed out of flash. You can choose to execute only some pieces out of flash; in other words, it is not an “all or nothing” scenario.

The major choices are:

  • Linux kernel
  • Userspace
    • all applications in root file system
    • applications found only in additional file systems

For userspace, XIP is controlled on a per-filesystem basis. So if you wanted, you could create one MTD device and store most programs there and then create another MTD device and store a select few.

Also keep in mind that you have to use an executable file format in the file system that supports separation of sections. That means the FLAT file format cannot be used. Choose Shared FLAT or FDPIC ELF. This of course only affects user space applications and has no bearing on having the Linux kernel itself be used for XIP.

Status

Currently only the following works:

  • Linux kernel ROM in RAM
  • File system executing out of uClinux MTD
  • File system executing out of parallel flash MTD

These file systems have been tested:

  • ROMFS

Configuration

Kernel XIP

If you want the Linux kernel itself to be XIP, then select:

Blackfin Processor Options  --->
  Kernel executes from (ROM)
Device Drivers  --->
  Memory Technology Device (MTD) support  --->
    RAM/ROM/Flash chip drivers  --->
        Support for ROM chips in bus mapping

Don't select “Detect flash chips by Common Flash Interface (CFI) probe” and “Detect non-CFI AMD/JEDEC-compatible flash chips”. They will set flash into query mode, then destroy the instruction fetching of kernel codes.

You need write vmImage to the kernel partition of flash, then run bootm from the base address of this partition. Here is an example for that:

U-Boot 2008.10-svn2133 (ADI-2009R1.1-rc1) (Dec  4 2009 - 00:02:38)

CPU:   ADSP bf537-0.2 (Detected Rev: 0.2) (bypass boot)
Board: ADI BF537 stamp board
       Support: http://blackfin.uclinux.org/
Clock: VCO: 500 MHz, Core: 500 MHz, System: 125 MHz
RAM:   64 MB
Flash:  4 MB
In:    serial
Out:   serial
Err:   serial
Net:   Blackfin EMAC
MAC:   00:E0:FE:DB:2B:29
Hit any key to stop autoboot:  0
bfin> protect off 0x20040000 0x201BFFFF
........................ done
Un-Protected 24 sectors
bfin> erase 0x20040000 0x201BFFFF

........................ done
Erased 24 sectors
bfin> tftp 0x1000000 vmImage
Using Blackfin EMAC device
TFTP from server 10.99.29.104; our IP address is 10.99.29.108
Filename 'vmImage'.
Load address: 0x1000000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #############################################
done
Bytes transferred = 1560184 (17ce78 hex)
bfin> cp.b 0x1000000 0x20040000 0x17ce78
Copy to Flash... done
bfin> set bootargs root=/dev/mtdblock2 clkin_hz=25000000 earlyprintk=serial,uart0,57600 console=ttyBF0,57600
bfin> bootm 0x20040000
## Booting kernel from Legacy Image at 20040000 ...
   Image Name:   bf537-2.6.32.3-ADI-2010R1-pre-sv
   Created:      2010-01-07   3:51:57 UTC
   Image Type:   Blackfin Linux Kernel Image (uncompressed)
   Data Size:    1560120 Bytes =  1.5 MB
   Load Address: 20040000
   Entry Point:  20040040
   Verifying Checksum ... OK
   XIP Kernel Image ... OK
OK
Starting Kernel at = 20040040
Linux version 2.6.32.3-ADI-2010R1-pre-svn8126 (root@roc-desktop) (gcc version 4.1.2 (ADI svn)) #3070 Thu Jan 7 11:51:53 CST 2010
register early platform devices
bootconsole [early_shadow0] enabled
bootconsole [early_BFuart0] enabled
early printk enabled on early_BFuart0
Limiting kernel memory to 56MB due to anomaly 05000263
Board Memory: 64MB
Kernel Managed Memory: 64MB
Memory map:
  fixedcode = 0x00000400-0x00000490
  text      = 0x20040000-0x20149ad0
  rodata    = 0x20149ad0-0x2019afb8
  bss       = 0x00001000-0x0000fa28
  data      = 0x0000fa28-0x0001e000
    stack   = 0x0001c000-0x0001e000
  init      = 0x0001e000-0x00022000
  available = 0x00022000-0x03800000
  DMA Zone  = 0x03e00000-0x04000000
Hardware Trace Active and Enabled
Boot Mode: 0
Blackfin support (C) 2004-2009 Analog Devices, Inc.
Compiled for ADSP-BF537 Rev 0.2
Blackfin Linux support by http://blackfin.uclinux.org/
Processor Speed: 500 MHz core clock and 125 MHz System Clock
NOMPU: setting up cplb tables
Instruction Cache Enabled for CPU0
  External memory: cacheable in instruction cache
Data Cache Enabled for CPU0
  External memory: cacheable (write-back) in data cache
Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 14224
Kernel command line: root=/dev/mtdblock2 clkin_hz=25000000 earlyprintk=serial,uart0,57600 console=ttyBF0,57600
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory available: 56640k/65536k RAM, (16k init code, 1062k kernel code, 4294966350k data, 2048k dma, 6716k reserved)
Hierarchical RCU implementation.
NR_IRQS:98
Configuring Blackfin Priority Driven Interrupts
console [ttyBF0] enabled, bootconsole disabled
console [ttyBF0] enabled, bootconsole disabled
Calibrating delay loop... 985.08 BogoMIPS (lpj=1970176)
Security Framework initialized
Mount-cache hash table entries: 512
Blackfin Scratchpad data SRAM: 4 KB
Blackfin L1 Data A SRAM: 16 KB (9 KB free)
Blackfin L1 Data B SRAM: 16 KB (16 KB free)
Blackfin L1 Instruction SRAM: 48 KB (48 KB free)
NET: Registered protocol family 16
Blackfin DMA Controller
stamp_init(): registering device resources
bio: create slab <bio-0> at 0
Switching to clocksource bfin_cs_cycles
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 110
io scheduler noop registered
io scheduler anticipatory registered (default)
bfin-uart: Blackfin serial driver
bfin-uart.0: ttyBF0 at MMIO 0xffc00400 (irq = 18) is a BFIN-UART
physmap platform flash device: 00400000 at 20000000
cmdlinepart partition parsing not available
RedBoot partition parsing not available
Using physmap partition information
Creating 4 MTD partitions on "physmap-flash.0":
0x000000000000-0x000000040000 : "bootloader(nor)"
0x000000040000-0x0000001c0000 : "linux kernel(nor)"
0x0000001c0000-0x0000003f0000 : "file system(nor)"
0x0000003f0000-0x000000400000 : "MAC Address(nor)"
bfin_mii_bus: probed
bfin_mac: attached PHY driver [Generic PHY] (mii_bus:phy_addr=0:01, irq=-1, mdc_clk=2500000Hz(mdc_div=24)@sclk=125MHz)
bfin_mac bfin_mac.0: Blackfin on-chip Ethernet MAC driver, Version 1.1
TCP cubic registered
NET: Registered protocol family 17
VFS: Mounted root (romfs filesystem) readonly on device 31:2.
                           _____________________________________
        a8888b.           / Welcome to the uClinux distribution \
       d888888b.         /       _     _                         \
       8P"YP"Y88        /       | |   |_|            __  __ (TM)  |
       8|o||o|88  _____/        | |    _ ____  _   _ \ \/ /       |
       8'    .88       \        | |   | |  _ \| | | | \  /        |
       8`._.' Y8.       \       | |__ | | | | | |_| | /  \        |
      d/      `8b.       \      \____||_|_| |_|\____|/_/\_\       |
     dP   .    Y8b.       \   For embedded processors including   |
    d8:'  "  `::88b        \    the Analog Devices Blackfin      /
   d8"         'Y88b        \___________________________________/
  :8P    '      :888
   8a.   :     _a88P         For further information, check out:
 ._/"Yaa_:   .| 88P|            - http://blackfin.uclinux.org/
 \    YP"    `| 8P  `.          - http://docs.blackfin.uclinux.org/
 /     \.___.d|    .'           - http://www.uclinux.org/
 `--..__)8888P`._.'  jgs/a:f    - http://www.analog.com/blackfin

Have a lot of fun...


BusyBox v1.15.3 (2009-12-24 11:58:56 CST) hush - the humble shell

root:/>

From the memory map information printed, you can find text and read-only data section are in flash, data section is in normal memory.

Userspace XIP

Assuming you've selected an appropriate executable file format, here are the relevant common kernel configuration options:

File systems  --->
  <*> MTD-based ROM file system support
Device Drivers  --->
  <*> Memory Technology Device (MTD) support  --->
    RAM/ROM/Flash chip drivers  --->
      <*> Support for ROM chips in bus mapping

You should also enable the appropriate MTD driver.

Then you need to enable a file system format that supports XIP. See the status section for more info. Obviously only the file system formats you will be using needs to be selected. If doing XIP for the root file system, you also of course need to build support into the kernel and not as a module.

File systems  --->
  Miscellaneous filesystems  --->
    <*> ROM file system support

Example Boot

You need to set correct bootargs in u-boot before boot up kernel.

For BF548-EZKIT and BF526-EZBRD:
    set bootargs root=mtd3 rootfstype=romfs ro console=ttyBF0,57600
For other boards:
    set bootargs root=mtd0 rootfstype=romfs ro console=ttyBF0,57600

Review the image files produced by the distribution. Here is an example booting with the ROMFS in parallel flash on a BF548-EZKIT:

U-Boot 2008.10-svn1872 (ADI-2009R1-rc1) (May 20 2009 - 17:37:34)

CPU:   ADSP bf548-0.2 (Detected Rev: 0.2) (parallel flash boot)
Board: ADI BF548 EZ-Kit board
       Support: http://blackfin.uclinux.org/
Clock: VCO: 525 MHz, Core: 525 MHz, System: 131.250 MHz
RAM:   64 MB
Flash: 16 MB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   MAC:   00:E0:22:FE:BF:4E
Hit any key to stop autoboot:  0
bfin> set bootargs root=mtd3 rootfstype=romfs ro console=ttyBF0,57600
bfin> tftpboot 0x1000000 uImage.romfs
smc911x: initializing
smc911x: detected LAN9218 controller
smc911x: phy initialized
smc911x: MAC 00:e0:22:fe:bf:4e
TFTP from server 10.100.4.174; our IP address is 10.100.4.50
Filename 'uImage.romfs'.
Load address: 0x1000000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         ##########################################
done
Bytes transferred = 4419923 (437153 hex)
bfin> bootm
## Booting kernel from Legacy Image at 01000000 ...
   Image Name:   Linux Kernel and romfs
   Created:      2009-06-30  18:01:00 UTC
   Image Type:   Blackfin Linux Kernel Image (gzip compressed)
   Data Size:    4419859 Bytes =  4.2 MB
   Load Address: 00001000
   Entry Point:  00267904
   Verifying Checksum ... OK
   Uncompressing Kernel Image ... OK
Starting Kernel at = 00267904
Linux version 2.6.28.10-ADI-2009R1-svn6864 (test@uclinux61-bf548-std) (gcc version 4.1.2 (ADI svn)) #4 Tue Jun 30 17:54:21 GMT 29
Board Memory: 64MB
Kernel Managed Memory: 64MB
Memory map:
  fixedcode = 0x00000400-0x00000490
  text      = 0x00001000-0x00198120
  rodata    = 0x00198120-0x00223c7c
  bss       = 0x00224000-0x00238158
  data      = 0x00238158-0x00252000
    stack   = 0x00250000-0x00252000
  init      = 0x00252000-0x0027e000
  available = 0x0027e000-0x037e9000
  rootfs    = 0x037e9000-0x03e00000
  DMA Zone  = 0x03e00000-0x04000000
Hardware Trace Active and Enabled
Boot Mode: 1
Blackfin support (C) 2004-2009 Analog Devices, Inc.
Compiled for ADSP-BF548 Rev 0.2
Blackfin Linux support by http://blackfin.uclinux.org/
Processor Speed: 525 MHz core clock and 131 MHz System Clock
NOMPU: setting up cplb tables
Instruction Cache Enabled for CPU0
Data Cache Enabled for CPU0 (write-back)
Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 14201
Kernel command line: root=mtd3 rootfstype=romfs ro console=ttyBF0,57600
Configuring Blackfin Priority Driven Interrupts
PID hash table entries: 256 (order: 8, 1024 bytes)
console [ttyBF0] enabled
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory available: 54132k/65536k RAM, (176k init code, 1628k kernel code, 744k data, 2048k dma, 572k reserved)
Calibrating delay loop... 1046.52 BogoMIPS (lpj=2093056)
Security Framework initialized
Mount-cache hash table entries: 512
Blackfin Scratchpad data SRAM: 4 KB
Blackfin L1 Data A SRAM: 16 KB (15 KB free)
Blackfin L1 Data B SRAM: 16 KB (16 KB free)
Blackfin L1 Instruction SRAM: 48 KB (42 KB free)
Blackfin L2 SRAM: 128 KB (128 KB free)
net_namespace: 288 bytes
NET: Registered protocol family 16
Blackfin DMA Controller
ezkit_init(): registering device resources
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
musb_hdrc: version 6.0, musb-dma, host, debug=0
musb_hdrc: USB Host mode controller at ffc03c00 using DMA, IRQ 82
musb_hdrc musb_hdrc.0: MUSB HDRC host driver
musb_hdrc musb_hdrc.0: new USB bus registered, assigned bus number 1
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
dma_alloc_init: dma_page @ 0x037a5000 - 512 pages at 0x03e00000
hub 1-0:1.0: 1 port detected
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
ROMFS MTD (C) 2006 Red Hat, Inc.
msgmni has been set to 105
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler cfq registered
bf54x-lq043: FrameBuffer initializing...
bfin-otp: initialized
Serial: Blackfin serial driver
bfin-uart.1: ttyBF0 at MMIO 0xffc02000 (irq = 48) is a BFIN-UART
brd: module loaded
smsc911x: Driver version 2007-07-13.
eth0: SMSC911x MAC Address: 00:e0:22:fe:bf:4e
Driver 'sd' needs updating - please use bus_type methods
register bfin atapi driver
scsi0 : pata-bf54x
ata1: PATA max UDMA/66 irq 68
ata1.00: ATA-6: TOSHIBA MK4032GAX, AD101A, max UDMA/100
ata1.00: 78140160 sectors, multi 16: LBA48
ata1.00: configured for UDMA/66
blk_queue_max_hw_segments: set to minimum 1
scsi 0:0:0:0: Direct-Access     ATA      TOSHIBA MK4032GA AD10 PQ: 0 ANSI: 5
sd 0:0:0:0: [sda] 78140160 512-byte hardware sectors: (40.0 GB/37.2 GiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
sd 0:0:0:0: [sda] 78140160 512-byte hardware sectors: (40.0 GB/37.2 GiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
 sda: sda1 sda2
sd 0:0:0:0: [sda] Attached SCSI disk
physmap platform flash device: 02000000 at 20000000
physmap-flash.0: Found 1 x16 devices at 0x0 in 16-bit bank
 Intel/Sharp Extended Query Table at 0x010A
 Intel/Sharp Extended Query Table at 0x010A
 Intel/Sharp Extended Query Table at 0x010A
 Intel/Sharp Extended Query Table at 0x010A
 Intel/Sharp Extended Query Table at 0x010A
Using buffer write method
Using auto-unlock on power-up/resume
cfi_cmdset_0001: Erase suspend on write enabled
RedBoot partition parsing not available
Using physmap partition information
Creating 3 MTD partitions on "physmap-flash.0":
0x00000000-0x00040000 : "bootloader(nor)"
0x00040000-0x00440000 : "linux kernel(nor)"
0x00440000-0x01000000 : "file system(nor)"
uclinux[mtd]: RAM probe address=0x37e9000 size=0x616180
Creating 1 MTD partitions on "RAM":
0x00000000-0x00616180 : "ROMfs"
BF5xx on-chip NAND FLash Controller Driver, Version 1.2 (c) 2007 Analog Devices, Inc.
bf5xx-nand bf5xx-nand.0: page_size=256, data_width=8, wr_dly=3, rd_dly=3
NAND device: Manufacturer ID: 0x20, Chip ID: 0xda (ST Micro NAND 256MiB 3,3V 8-bit)
Creating 2 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x00000000-0x00400000 : "linux kernel(nand)"
0x00400000-0x10000000 : "file system(nand)"
m25p80 spi0.1: m25p16 (2048 Kbytes)
Creating 2 MTD partitions on "m25p80":
0x00000000-0x00040000 : "bootloader(spi)"
0x00040000-0x00200000 : "linux kernel(spi)"
bfin-spi bfin-spi.0: Blackfin on-chip SPI Controller Driver, Version 1.0, regs_base@ffc00500, dma channel@4
bfin-spi bfin-spi.1: Blackfin on-chip SPI Controller Driver, Version 1.0, regs_base@ffc02300, dma channel@5
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
input: bf54x-keys as /devices/platform/bf54x-keys/input/input0
bf54x-keys: Blackfin BF54x Keypad registered IRQ 76
rtc-bfin rtc-bfin: rtc core: registered rtc-bfin as rtc0
i2c /dev entries driver
i2c-bfin-twi i2c-bfin-twi.0: Blackfin BF5xx on-chip I2C TWI Contoller, regs_base@ffc00700
i2c-bfin-twi i2c-bfin-twi.1: Blackfin BF5xx on-chip I2C TWI Contoller, regs_base@ffc02200
bfin-wdt: initialized: timeout=20 sec (nowayout=0)
bfin-sdh bfin-sdh.0: unable to request DMA channel
bfin-sdh: probe of bfin-sdh.0 failed with error -16
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.18rc3.
ASoC version 0.13.2
dma rx:0 tx:1, err irq:10, regs:ffc00800
AD1980 SoC Audio Codec
asoc: AC97 <-> bf5xx-ac97 mapping ok
ALSA device list:
  #0: bf5xx-board (AD1980)
TCP cubic registered
NET: Registered protocol family 17
rtc-bfin rtc-bfin: setting system clock to 2004-05-31 10:52:03 UTC (1086000723)
ROMFS: Mounting image 'rom 4a4a52ce'
VFS: Mounted root (romfs filesystem) readonly.
Freeing unused kernel memory: 176k freed
                           _____________________________________
        a8888b.           / Welcome to the uClinux distribution \
       d888888b.         /       _     _                         \
       8P"YP"Y88        /       | |   |_|            __  __ (TM)  |
       8|o||o|88  _____/        | |    _ ____  _   _ \ \/ /       |
       8'    .88       \        | |   | |  _ \| | | | \  /        |
       8`._.' Y8.       \       | |__ | | | | | |_| | /  \        |
      d/      `8b.       \      \____||_|_| |_|\____|/_/\_\       |
     dP   .    Y8b.       \   For embedded processors including   |
    d8:'  "  `::88b        \    the Analog Devices Blackfin      /
   d8"         'Y88b        \___________________________________/
  :8P    '      :888
   8a.   :     _a88P         For further information, check out:
 ._/"Yaa_:   .| 88P|            - http://blackfin.uclinux.org/
 \    YP"    `| 8P  `.          - http://docs.blackfin.uclinux.org/
 /     \.___.d|    .'           - http://www.uclinux.org/
 `--..__)8888P`._.'  jgs/a:f    - http://www.analog.com/blackfin

Have a lot of fun...


BusyBox v1.13.4 (2009-06-30 17:58:08 GMT) built-in shell (msh)
Enter 'help' for a list of built-in commands.

root:/> cat /proc/cpuinfo
processor       : 0
vendor_id       : Analog Devices
cpu family      : 0x27de
model name      : ADSP-BF548 525(MHz CCLK) 131(MHz SCLK) (mpu off)
stepping        : 2
cpu MHz         : 525.000/131.250000
bogomips        : 1046.52
Calibration     : 523264000 loops
cache size      : 16 KB(L1 icache) 32 KB(L1 dcache-wb) 0 KB(L2 cache)
dbank-A/B       : cache/cache
icache setup    : 4 Sub-banks/4 Ways, 32 Lines/Way
dcache setup    : 2 Super-banks/4 Sub-banks/2 Ways, 64 Lines/Way
L2 SRAM         : 128KB
board name      : ADI BF548-EZKIT
board memory    : 65536 kB (0x00000000 -> 0x04000000)
kernel memory   : 57248 kB (0x00001000 -> 0x037e9000)

root:/>