LeopardBoard 368 1080p support

From RidgeRun Developer Connection

Revision as of 19:43, 8 November 2011 by Mmadrigal (Talk | contribs)
Jump to:navigation, search

Contents

Introduction

One of the great features of the DM368 processor is support for HD 1080P video resolution. As I was working on getting GStreamer configured with 1080P support, I thought I would takes notes on the issues I ran into and how I resolved them. This wiki page is a work in progress of that effort.

Hardware

I am using a leo368 with MT9P031 CMOS sensor and TFP410 digital transmitter

SDK

I am using RidgeRun's 2011Q2 DM368 SDK with TI DVSDK 4.02.00.06 that includes H.264 Baseline/Main/High Profile Encoder on DM365/DM368 with support for resolutions up to 4096x4096.

Initial configuration

I more or less used a default SDK configuration as my starting point.

Kernel configuration

Some of the key kernel configuration items are shown below.

CONFIG_VIDEO_DEV=y
CONFIG_VIDEO_V4L2_COMMON=y
CONFIG_VIDEO_MEDIA=y
CONFIG_VIDEO_V4L2=y
CONFIG_VIDEOBUF_GEN=y
CONFIG_VIDEOBUF_VMALLOC=y
CONFIG_VIDEOBUF_DMA_CONTIG=y
CONFIG_VIDEO_CAPTURE_DRIVERS=y
CONFIG_VIDEO_TVP514X=y
CONFIG_VIDEO_THS7303=y
CONFIG_VIDEO_THS7353=y
CONFIG_VIDEO_THS7353_LUMA_CHANNEL=2
CONFIG_VIDEO_DAVINCI_DISPLAY=y
CONFIG_VIDEO_VPSS_SYSTEM=y
CONFIG_VIDEO_VPFE_CAPTURE=y
CONFIG_VIDEO_DM365_ISIF=y
CONFIG_VIDEO_DM365_3A_HW=y
CONFIG_VIDEO_DM365_AF=y
CONFIG_VIDEO_DM365_AEW=y
CONFIG_VIDEO_OUTPUT_CONTROL=y

CONFIG_SOC_CAMERA_MT9P031=y

I used fgrep -i $SS $DEVDIR/bsp/mach/bspconfig | grep -v '^#' with the following search strings to obtain the above list.

SS=CONFIG_VIDEO
SS=SOC_CAMERA

Kernel command line

On the target I ran

cat /proc/cmdline 

to see the actual kernel command line parameters used by Linux

davinci_enc_mngr.ch0_output=COMPONENT davinci_enc_mngr.ch0_mode=720P-60 davinci_display.cont2_bufsize=6291456 vpfe_capture.cont_bufoffset=6291456 vpfe_capture.cont_bufsize=6291456 video=davincifb:osd1=0x0x8:osd0=1280x720x16,1800K@0,0:vid0=off:vid1=off console=ttyS0,115200n8 dm365_imp.oper_mode=0 vpfe_capture.interface=1 mem=99M root=/dev/nfs nfsroot=10.111.0.4:/local/home/tfischer/work/mot/fs/fs rw ip=dhcp mtdparts=davinci_nand.0:4096k(UBOOT),4480k(KERNEL),204800k(FS)

CMEM driver

I added set -x to the $DEVDIR/fs/fs/etc/init.d/coprocessors file so I could see exactly how the cmem driver was loaded.

modprobe cmemk phys_start=0x86f00000 phys_end=0x87e00000 allowOverlap=1 useHeapIfPoolUnavailable=1 allowOverlap=1 phys_start_1=0x00001000 phys_end_1=0x00008000 pools_1=1x28672

Getting capture path configured

Try 1 - stock SDK configuration

I was fairly use that I would have to increase some buffer sizes since the SDK was tuned for 720P. I ran a simple pipe to confirm my suspicions.

gst-launch v4l2src ! 'video/x-raw-yuv, width=1920, height=1080' ! fakesink

I removed lots of decoration (element parameter configuration), just including the capsfilter to make sure we are using 1080p. The key error output was:

vpfe-capture vpfe-capture: dma_alloc_coherent size 4149248 failed

Since I like to get caps right as soon as possible, I reran the same test with some debug and debug output filtering enabled:

gst-launch --gst-debug=v4l2:5 v4l2src ! 'video/x-raw-yuv, width=1920, height=1080' ! fakesink 2>&1 | cut -f5- -d:

Some of the helpful output was:

gst_v4l2_object_probe_caps_for_format_and_size:<v4l2src0> get frame interval for 1920x1080, UYVY
gst_v4l2_object_probe_caps_for_format_and_size:<v4l2src0> adding discrete framerate: 31/1

For the fulls GStreamer caps. Now I know my caps need to be:

video/x-raw-yuv,format=(fourcc)UYVY, width=1920, height=1080, framerate=(fraction)31/1

Later in the same debug output I saw memory allocation failure details:

gst_v4l2_buffer_pool_new:<v4l2src0> STREAMING, requesting 2 MMAP buffers
gst_v4l2_buffer_pool_new:<v4l2src0>  count:  3
gst_v4l2_buffer_pool_new:<v4l2src0>  type:   1
gst_v4l2_buffer_pool_new:<v4l2src0>  memory: 1
gst_v4l2_buffer_pool_new:<v4l2src0> using 3 buffers instead
gst_v4l2_buffer_new:<v4l2src0> creating buffer 0, 0xad0e8 in pool 0x1e070
gst_v4l2_buffer_new:<v4l2src0>   index:     0
gst_v4l2_buffer_new:<v4l2src0>   type:      1
gst_v4l2_buffer_new:<v4l2src0>   bytesused: 0
gst_v4l2_buffer_new:<v4l2src0>   flags:     00000000
gst_v4l2_buffer_new:<v4l2src0>   field:     0
gst_v4l2_buffer_new:<v4l2src0>   memory:    1
gst_v4l2_buffer_new:<v4l2src0>   MMAP offset:  0
gst_v4l2_buffer_new:<v4l2src0>   length:    4147200
gst_v4l2_buffer_new:<v4l2src0>   input:     0
gst_v4l2_buffer_new:<v4l2src0> creating buffer 1, 0xad188 in pool 0x1e070
gst_v4l2_buffer_new:<v4l2src0>   index:     1
gst_v4l2_buffer_new:<v4l2src0>   type:      1
gst_v4l2_buffer_new:<v4l2src0>   bytesused: 0
gst_v4l2_buffer_new:<v4l2src0>   flags:     00000000
gst_v4l2_buffer_new:<v4l2src0>   field:     0
gst_v4l2_buffer_new:<v4l2src0>   memory:    1
gst_v4l2_buffer_new:<v4l2src0>   MMAP offset:  4149248
gst_v4l2_buffer_new:<v4l2src0>   length:    4147200
gst_v4l2_buffer_new:<v4l2src0>   input:     0
gst_v4l2_buffer_new: Failed to mmap: Cannot allocate memory
gst_v4l2_buffer_finalize:<v4l2src0> finalizing buffer 0xad188 1
gst_v4l2_buffer_finalize:<v4l2src0> the pool is shutting down
gst_v4l2_buffer_finalize:<v4l2src0> buffer 0xad188 (data (nil), len 4147200) not recovered, unmapping

It looks like v4l2src was trying to allocate 3 buffers and failed on the 3rd buffer allocation. Since mmap() is being used, I guessed the problem was the amount of buffer space reserved for v4l2 capture buffers on the kernel command line - specifically vpfe_capture.cont_bufsize=6291456.

Doing the math, 3 * 4,147,200 = 12,441,600</tt> and I was only setting aside 6,291,456, so I needed to add another 6 Mbytes (6291456), which means I need to reduce the memory available to the kernel by 6 Mbtes, from the mem=99M current setting. Remember there is some overhead with each buffer, so you have to add more that the actual usable allocation that is required.

Try 2 - increase video capture buffer pool size

In u-boot I change the bootargs:

setenv bootargs "davinci_enc_mngr.ch0_output=COMPONENT davinci_enc_mngr.ch0_mode=720P-60 davinci_display.cont2_bufsize=6291456 vpfe_capture.cont_bufoffset=12582912 vpfe_capture.cont_bufsize=12582912 video=davincifb:osd1=0x0x8:osd0=1280x720x16,1800K@0,0:vid0=off:vid1=off console=ttyS0,115200n8 dm365_imp.oper_mode=0 vpfe_capture.interface=1 mem=93M root=/dev/nfs nfsroot=10.111.0.4:/local/home/tfischer/work/mot/fs/fs rw ip=dhcp mtdparts=davinci_nand.0:4096k(UBOOT),4480k(KERNEL),204800k(FS)"
saveenv

and ran the simple script again, but from now on I will include the full GStreamer caps.

gst-launch -e v4l2src num-buffers=3 ! 'video/x-raw-yuv,format=(fourcc)UYVY, width=1920, height=1080, framerate=(fraction)31/1' ! fakesink

The above didn't produce any more memory allocation failures, next add the H.264 encoder.

For those who are working with a Professional SDK this change can be easily done by modifying the following parameter on the configuration window (make config):


 -> Architecture configurations                     
     -> Maximum Video Input Buffer Size
           -> value: 1080P

Try 3 - add H.264 encoder

I added the GStreamer dmaienc_h264 element. Since the H264 encoder only supports NV12 for its input, I adjusted the caps as well. Again I anticipated a memory allocation error - guessing the cmem parameters will need to be changed.

gst-launch -e v4l2src always-copy=false ! 'video/x-raw-yuv,format=(fourcc)NV12, width=1920, height=1080, framerate=(fraction)31/1' ! queue ! dmaiaccel ! dmaienc_h264 encodingpreset=2 ratecontrol=2 intraframeinterval=23 idrinterval=46 targetbitrate=3000000 ! fakesink

In order to fix this memory issue we need to change the reserved memory space and the CMEM memory amount as is show below:

 -> Proprietary software                                                                                       
    -> Reserve memory from the kernel for codec engine and friends automatically
         ->Amount of reserved memory from the kernel
               -> value: 3200000
 -> Proprietary software
   -> Amount of reserved memory for cmemk
       -> value: 1E00000

Once we change those values we have reserved enough memory to work with 1080p.

Reference information

Initial boot output

U-Boot 2010.12-rc2 (Sep 25 2011 - 11:32:58)

Cores: ARM 446 MHz
DDR:   351 MHz
I2C:   ready
DRAM:  128 MiB
NAND:  256 MiB
MMC:   davinci: 0, davinci: 1
Net:   Ethernet PHY: GENERIC @ 0x00
DaVinci-EMAC
DM368 LEOPARD # 
Skipping tty reset...
Thanks for using picocom
picocom -b 115200 -r -l /dev/ttyUSB1
tfischer@contra-lx:~$ uart b
picocom v1.4

port is        : /dev/ttyUSB1
flowcontrol    : none
baudrate is    : 115200
parity is      : none
databits are   : 8
escape is      : C-a
noinit is      : no
noreset is     : yes
nolock is      : yes
send_cmd is    : ascii_xfr -s -v -l10
receive_cmd is : rz -vv

Terminal ready
printenv
autoload=no
autostart=yes
baudrate=115200
bootargs=davinci_enc_mngr.ch0_output=COMPONENT davinci_enc_mngr.ch0_mode=720P-60 davinci_display.cont2_bufsize=6291456 vpfe_capture.cont_bufoffset=6291456 vpfe_capture.cont_bufsize=6291456 video=davincifb:osd1=0x0x8:osd0=1280x720x16,1800K@0,0:vid0=off:vid1=off console=ttyS0,115200n8 dm365_imp.oper_mode=0 vpfe_capture.interface=1 mem=99M root=/dev/nfs nfsroot=10.111.0.4:/local/home/tfischer/work/mot/fs/fs rw ip=dhcp mtdparts=davinci_nand.0:4096k(UBOOT),4480k(KERNEL),204800k(FS)
bootcmd=nboot 0x82000000 0 ${kerneloffset}
bootdelay=-1
bootfile=kernel.uImage.tfischer.mot.leopard
dnsip=10.111.0.1
ethact=DaVinci-EMAC
ethaddr="00:0C:0C:A0:02:b5"
fileaddr=82000000
filesize=3F9100
fsoffset=0xa40000
fssize=3960000
importbootenv=echo Importing environment from mmc ...; env import -t ${loadaddr} ${filesize}
ipaddr=10.111.0.199
kernelloadaddr=0x82000000
kernelmd5sum=b31b633e0cf23c3bbe1a2d38b6ae31c5
kerneloffset=0x400000
kernelsaveaddr=0x400000
ksize=0x460000
loadaddr=0x82000000
loadbootenv=fatload mmc 0 ${loadaddr} uEnv.txt
loaduimage=fatload mmc 0 ${loadaddr} uImage
serverip=10.111.0.4
stderr=serial
stdin=serial
stdout=serial
uenvcmd=echo Running Installer... ; fatload mmc 0 ${loadaddr} installer.scr ; source ${loadaddr} 
ver=U-Boot 2010.12-rc2 (Sep 25 2011 - 11:32:58)

Environment size: 1381/262140 bytes
DM368 LEOPARD # boot

Loading from nand0, offset 0x400000
   Image Name:   "RR Linux Kernel"
   Created:      2011-09-29  17:03:33 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    4165824 Bytes = 4 MiB
   Load Address: 80008000
   Entry Point:  80008000
Automatic boot of image at addr 0x82000000 ...
## Booting kernel from Legacy Image at 82000000 ...
   Image Name:   "RR Linux Kernel"
   Created:      2011-09-29  17:03:33 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    4165824 Bytes = 4 MiB
   Load Address: 80008000
   Entry Point:  80008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

Starting kernel ...

Linux version 2.6.32-17-ridgerun (tfischer@contra-lx) (gcc version 4.3.3 (Sourcery G++ Lite 2009q1-203) ) #3 PREEMPT Thu Sep 29 11:02:50 MDT 2011
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177
CPU: VIVT data cache, VIVT instruction cache
Machine: DM368 Leopard
Memory policy: ECC disabled, Data cache writeback
DaVinci dm36x_rev1.2 variant 0x8
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 25146
Kernel command line: davinci_enc_mngr.ch0_output=COMPONENT davinci_enc_mngr.ch0_mode=720P-60 davinci_display.cont2_bufsize=6291456 vpfe_capture.cont_bufoffset=6291456 vpfe_capture.cont_bufsize=6291456 video=davincifb:osd1=0x0x8:osd0=1280x720x16,1800K@0,0:vid0=off:vid1=off console=ttyS0,115200n8 dm365_imp.oper_mode=0 vpfe_capture.interface=1 mem=99M root=/dev/nfs nfsroot=10.111.0.4:/local/home/tfischer/work/mot/fs/fs rw ip=dhcp mtdparts=davinci_nand.0:4096k(UBOOT),4480k(KERNEL),204800k(FS)
PID hash table entries: 512 (order: -1, 2048 bytes)
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory: 99MB = 99MB total
Memory: 96028KB available (3736K code, 291K data, 140K init, 0K highmem)
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:245
Console: colour dummy device 80x30
Calibrating delay loop... 222.00 BogoMIPS (lpj=1110016)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
DaVinci: 8 gpio irqs
NET: Registered protocol family 16
davinci_serial_init:97: failed to get UART2 clock
bio: create slab <bio-0> at 0
DM365 IPIPE initialized in Continuous mode
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
vpss vpss: dm365_vpss vpss probed
vpss vpss: dm365_vpss vpss probe success
dm365_afew_hw_init
ch0 default output "COMPONENT", mode "720P-60"
VPBE Encoder Initialized
LogicPD encoder initialized
Switching to clocksource timer0_1
musb_hdrc: version 6.0, cppi-dma, host, debug=0
musb_hdrc: USB Host mode controller at fec64000 using DMA, IRQ 12
musb_hdrc musb_hdrc: MUSB HDRC host driver
musb_hdrc musb_hdrc: new USB bus registered, assigned bus number 1
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
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: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP reno registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
msgmni has been set to 187
alg: No test for stdrng (krng)
io scheduler noop registered
io scheduler anticipatory registered (default)
davincifb davincifb.0: dm_osd0_fb: 1280x720x16@0,0 with framebuffer size 1800KB
davincifb davincifb.0: dm_osd1_fb: 0x0x8@0,0 with framebuffer size 1800KB
DM365 IPIPEIF probed
imp serializer initialized
davinci_previewer initialized
davinci_resizer initialized
Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled
serial8250.0: ttyS0 at MMIO 0x1c20000 (irq = 40) is a 16550A
console [ttyS0] enabled
brd: module loaded
loop: module loaded
NAND device: Manufacturer ID: 0x2c, Chip ID: 0xda (Micron NAND 256MiB 3,3V 8-bit)
3 cmdlinepart partitions found on MTD device davinci_nand.0
Creating 3 MTD partitions on "davinci_nand.0":
0x000000000000-0x000000400000 : "UBOOT"
0x000000400000-0x000000860000 : "KERNEL"
0x000000860000-0x00000d060000 : "FS"
davinci_nand davinci_nand.0: controller rev. 2.3
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usbcore: registered new interface driver usbtest
i2c /dev entries driver
Linux video capture interface: v2.00
ths7303 1-002c: chip found @ 0x58 (DaVinci I2C adapter)
vpfe_init
vpfe-capture: vpss clock vpss_master enabled
vpfe-capture vpfe-capture: v4l2 device registered
vpfe-capture vpfe-capture: video device registered
mt9p031 1-0048: Detected a MT9P031 chip ID 1801
mt9p031 1-0048: mt9p031 1-0048 decoder driver registered !!
vpfe-capture vpfe-capture: v4l2 sub device mt9p031 registered
vpfe_register_ccdc_device: DM365 ISIF
DM365 ISIF is registered with vpfe.
af major#: 252, minor# 0
AF Driver initialized
aew major#: 251, minor# 0
AEW Driver initialized
Trying to register davinci display video device.
layer=c509c800,layer->video_dev=c509c964
Trying to register davinci display video device.
layer=c509cc00,layer->video_dev=c509cd64
davinci_init:DaVinci V4L2 Display Driver V1.0 loaded
watchdog watchdog: heartbeat 60 sec
davinci_mmc davinci_mmc.0: Using DMA, 4-bit mode
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.21.
No device for DAI tlv320aic3x
No device for DAI davinci-i2s
asoc: tlv320aic3x <-> davinci-i2s mapping ok
ALSA device list:
  #0: DaVinci DM365 EVM (tlv320aic3x)
TCP cubic registered
NET: Registered protocol family 17
Clocks: disable unused mmcsd1
Clocks: disable unused spi0
Clocks: disable unused spi1
Clocks: disable unused spi2
Clocks: disable unused spi3
Clocks: disable unused spi4
Clocks: disable unused pwm0
Clocks: disable unused pwm1
Clocks: disable unused pwm2
Clocks: disable unused pwm3
Clocks: disable unused timer1
Clocks: disable unused timer3
Clocks: disable unused emac
Clocks: disable unused voice_codec
Clocks: disable unused rto
Clocks: disable unused mjcp
davinci_emac_probe: using random MAC addr: be:91:a5:85:b5:0a
emac-mii: probed
mmc0: host does not support reading read-only switch. assuming write-enable.
mmc0: new high speed SD card at address b368
mmcblk0: mmc0:b368 SD    1.88 GiB 
 mmcblk0: p1
Sending DHCP requests .., OK
IP-Config: Got DHCP answer from 10.111.0.1, my address is 10.111.0.183
IP-Config: Complete:
     device=eth0, addr=10.111.0.183, mask=255.255.255.0, gw=10.111.0.1,
     host=10.111.0.183, domain=fischerfamily.org, nis-domain=fischerfamily.org,
     bootserver=10.111.0.1, rootserver=10.111.0.4, rootpath=
Looking up port of RPC 100003/2 on 10.111.0.4
Looking up port of RPC 100005/1 on 10.111.0.4
VFS: Mounted root (nfs filesystem) on device 0:13.
Freeing init memory: 140K
init started: BusyBox v1.18.2 (2011-09-07 16:07:18 MDT)
starting pid 986, tty '': '/etc/rcS'
Starting System
done.
Welcome to
__________ .__     .___               __________                
\______   \|__|  __| _/  ____    ____ \______   \ __ __   ____  
 |       _/|  | / __ |  / ___\ _/ __ \ |       _/|  |  \ /    \ 
 |    |   \|  |/ /_/ | / /_/  >\  ___/ |    |   \|  |  /|   |  \
 |____|_  /|__|\____ | \___  /  \___  >|____|_  /|____/ |___|  /
        \/          \//_____/       \/        \/             \/ 
	   
    Embedded Linux Solutions
 
For further information see:
http://www.ridgerun.com
Build host: contra-lx
Built by: admin
Build date: Thu, 29 Sep 2011 11:03:32 -0600
Build tag: leopard
Configuring network interfaces
Starting D-Bus message bus system
Loading coprocessors modules...
  Loading cmem from 0x86f00000 to 0x87e00000
CMEMK module: built on Sep 25 2011 at 11:28:31
  Reference Linux version 2.6.32
  File /local/home/tfischer/work/mot/proprietary/dvsdk-4_02_00_06/dvsdk/linuxutils_2_26_01_02/packages/ti/sdo/linuxutils/cmem/src/module/cmemk.c
allocated heap buffer 0xcb000000 of size 0xf00000
heap fallback enabled - will try heap if pool buffer is not available
CMEM Range Overlaps Kernel Physical - allowing overlap
CMEM phys_start (0x1000) overlaps kernel (0x80000000 -> 0x86300000)
cmemk initialized
EDMAK module: built on Sep 25 2011 at 11:28:36
  Reference Linux version 2.6.32
  File /local/home/tfischer/work/mot/proprietary/dvsdk-4_02_00_06/dvsdk/linuxutils_2_26_01_02/packages/ti/sdo/linuxutils/edma/src/module/edmak.c
IRQK module: built on Sep 25 2011 at 11:28:35
  Reference Linux version 2.6.32
  File /local/home/tfischer/work/mot/proprietary/dvsdk-4_02_00_06/dvsdk/linuxutils_2_26_01_02/packages/ti/sdo/linuxutils/irq/src/module/irqk.c
irqk initialized
Starting GStreamer Daemon

Please press Enter to activate this console. 
starting pid 1120, tty '/dev/ttyS0': '-/bin/sh'


BusyBox v1.18.2 (2011-09-07 16:07:18 MDT) built-in shell (ash)
Enter 'help' for a list of built-in commands.

/ # 
Navigation
Toolbox