Difference between revisions of "AXIOM Alpha"

From apertus wiki
Jump to: navigation, search
Line 358: Line 358:


Or all in one command:
Or all in one command:
  convert -size 3072x3072 -depth 16 gray:image.raw16 -colors 4096 -format %c histogram:info:- | gawk -F, '(NF>3) { printf "%d\t%d\n", $2/16, $1 }'  
  convert -size 4096x3072 -depth 16 gray:image.raw16 -colors 4096 -format %c histogram:info:- | gawk -F, '(NF>3) { printf "%d\t%d\n", $2/16, $1 }' > histogram.info


Then draw it with gnuplot:
Then draw it with gnuplot:
Line 366: Line 366:
  set xrange[0:4096]
  set xrange[0:4096]
  set yrange[0:8000]
  set yrange[0:8000]
  plot 'histogram.hist' using 1:2 with lines lc rgb "#FF0000" title "dark"
  plot 'histogram.info' using 1:2 with lines lc rgb "#FF0000" title "dark"
  unset multiplot
  unset multiplot
  pause mouse any
  pause mouse any

Revision as of 20:31, 17 December 2013

1 About

Officially website: http://axiom.apertus.org/index.php?site=alpha

2 Zedboard related Notes

2.1 Zedboard Development on Ubuntu 12.04 LTS with ISE 14.5 (Currently running in Virtual Box on a Mac)

Plug in two micro USB cables (one is provided with the Zedboard) to Zedboard ports J13 and J17 (UART and PROG) respectively. Set jumpers JP7-JP11 as described in tutorial for Helloworld. Plug USB cables into computer.

Turn on Zedboard. In Virtual Box open the machine settings that Ubuntu is installed in. Select the Ports tab, and the USB tab. Add a USB Device Filter (plus sign) for 2012 Cyprus Semiconductor Cypress - USB2UART-Ver1.0G, and also Digilent USB Device. This automatically connects the USB ports for Ubuntu whenever the Zedboard is connected.

In Ubuntu:


Note, to extract files use: tar -xvf filename


1) Install libusb: sudo apt-get install libusb-dev

2) Work around for arm toolchain install: sudo dpkg-reconfigure -plow dash (Select NO when prompted)

3) Download ISE 14.5

4) Install: ./xsetup (do not install cable drivers). Select System Edition

5) Work around for arm toolchain install: sudo dpkg-reconfigure -plow dash (Select YES when prompted)

6) Download Digilent Runtime and Utilities: [1]

7) Install both using: sudo ./install.sh (note install can be for all users or the user installing, see README for instructions)

8) Download Digilent Plugin: [2]

9) Install plugin per instructions included in PDF.


Note there are several terminal emulator options. Minicom can be run in a shell. A google search will show how to use it. Alternatively in SDK you can use the terminal emulator that is included.

2.2 Getting JTAG working with the Zedboard

From http://www.digilentinc.com/Products/Detail.cfm?NavPath=2%2C66%2C828&Prod=ADEPT2 download the following packages (these are for 64bit so for x86 you will want the 32bit versions):

digilent.adept.runtime_2.13.1-x86_64.tar.gz
digilent.adept.utilities_2.1.1-x86_64.tar.gz
libCseDigilent_2.4.3-x86_64.tar.gz

then install the runtime:

tar xzf digilent.adept.runtime_2.13.1-x86_64.tar.gz; cd digilent.adept.runtime_2.13.1-x86_64; ./install.sh

and here is the important part: AND the ftdi driver

cd ftdi.drivers_1.0.4-x86_64; ./install.sh

then the utilities

same method as runtime above

at this point the following command

djtgcfg enum

should show board details:

Found 1 device(s)

Device: Zed
   Product Name:   Digilent Zed
   User Name:      Zed
   Serial Number:  XXXXXXXXXXXX

Note that you need to fix the udev rules, restart udev and unplug/replug the usb-jtag to get the driver (ftdi_sio) unloaded and the permissions for the usb device changed.

The libCseDigilent_2.4.3-x86_64.tar.gz contains two files in ISE14x/plugin:

libCseDigilent.so  
libCseDigilent.xml

which need to be copied to the ISE plugin directory.

after that, the following should work:

xmd

and should show something like:

Xilinx Microprocessor Debugger (XMD) Engine
Xilinx EDK 14.5 Build EDK_P.58f
Copyright (c) 1995-2012 Xilinx, Inc.  All rights reserved.

Then typing:

connect mb mdm -cable type xilinx_plugin modulename digilent_plugin

Should show:

XMD%
XMD% connect mb mdm -cable type xilinx_plugin modulename digilent_plugin

JTAG chain configuration
--------------------------------------------------
Device   ID Code        IR Length    Part Name
 1       4ba00477           4        Cortex-A9
 2       03727093           6        XC7Z020
ERROR: Could not detect MDM peripheral on hardware. Please check:
        1. If FPGA is configured correctly
        2. MDM Core is instantiated in the design
        3. If the correct FPGA is referred, in case of multiple FPGAs
        4. If the correct MDM is referred, in case of a multiple MDM system

Note that the default image has no mdm IP

2.3 Booting the Zedboard via JTAG

You want to get the ZedBoard_CTT_v14.3_121017.zip for some files from: http://www.zedboard.org/sites/default/files/design/ZedBoard_CTT_v14.3_121017.zip namely: ps7_init.tcl and stub.tcl

Then you also need the following from your design:

  • system.bit [PL bitstream]
  • u-boot.elf or some other elf binary [PS 2nd stage]
  • optionally (Linux Boot): zImage, ramdisk*.gz and devicetree.dtb

start xmd (the Xilinx® Microprocessor Debugger console as part of ISE), then in the xmd prompt do:

connect arm hw
fpga -f system.bit
source ps7_init.tcl
ps7_init
init_user
source stub.tcl
target 64
dow u-boot.elf
con

this will connect to the target, upload the fpga bitstream (PL), initialize memory and MIO devices (ps7_init/init_user) and load the second level bootloader (PS) the 'con' already starts the bootloader

optionally, you can also upload the Linux kernel, initramfs and the devicetree like this:

dow -data zImage 0x8000
dow -data ramdisk8M.image.gz 0x800000
dow -data devicetree.dtb 0x1000000

and boot the kernel/linux with:

con 0x8000


2.4 Booting the Zedboard via TFTP

Booting the Zedboard via TFTP is a lot faster than the JTAG boot method and doesn't have the drawbacks of SD card shuffling. It basically boots the Zedboard over the network, a DHCP server directs the Zedboard to the right place to read the required files via TFTP.

2.4.1 DHCP Server Setup Ubuntu 12.04 LTS

Connect the Zedboard via Ethernet to a PC running Ubuntu 12.04. Make sure the router in this set up does not contain DHCP records for the Zedboard otherwise the DHCP server running on the PC will have no effects on the Zedboard. The DHCP server on the router and the DHCP server on the PC even if they are on the same network do not interfere normally.

To install the required packages run:

sudo apt-get install dhcp3-server dhcpd isc-dhcp-server

If there is more than one network card(s) in your Ubuntu PC, then you have to select the network card on which your server will be listen for dhcp request. (By default, it listens on eth0):

sudo gedit /etc/default/isc-dhcp-server

Then edit the config file:

sudo gedit /etc/dhcp/dhcpd.conf

In this case the network is set up in the 192.168.10.X range and the dhcpd.conf looks like this (AAA = Ubuntu PC, BBB = Zedboard)

subnet 192.168.10.0 netmask 255.255.255.0 {
       # default gateway
       option routers 192.168.10.254;
       option subnet-mask 255.255.255.0;
         
       always-reply-rfc1048 true;
       next-server 192.168.10.AAA;

       host zedboard {
               hardware ethernet 00:0A:35:00:01:22;
               fixed-address 192.168.10.BBB;
               filename "/ZED/u-boot.scr";
       }

}

Note that all Zedboards have the same MAC address hardcoded into our bootloader currently:

00:0A:35:00:01:22

After making changes to the file restart the dhcp server with:

sudo service isc-dhcp-server restart

or start it manually if it has not been started yet:

sudo service isc-dhcp-server start

When you look at the syslog on your Ubuntu PC with:

sudo tail -f /var/log/syslog

You should see lines like the following when the DHCP server is started and Zedboard is making requests to the DHCP server (AAA = Ubuntu PC, BBB = Zedboard):

Oct  3 20:23:40 Ubuntu-PC dhcpd: Internet Systems Consortium DHCP Server 4.1-ESV-R4
Oct  3 20:23:40 Ubuntu-PC dhcpd: Copyright 2004-2011 Internet Systems Consortium.
Oct  3 20:23:40 Ubuntu-PC dhcpd: All rights reserved.
Oct  3 20:23:40 Ubuntu-PC dhcpd: For info, please visit https://www.isc.org/software/dhcp/
Oct  3 20:23:40 Ubuntu-PC dhcpd: Wrote 0 deleted host decls to leases file.
Oct  3 20:23:40 Ubuntu-PC dhcpd: Wrote 0 new dynamic host decls to leases file.
Oct  3 20:23:40 Ubuntu-PC dhcpd: Wrote 0 leases to leases file.
Oct  3 20:23:54 Ubuntu-PC dhcpd: BOOTREQUEST from 00:0a:35:00:01:22 via eth0
Oct  3 20:23:54 Ubuntu-PC dhcpd: BOOTREPLY for 192.168.10.BBB to zedboard (00:0a:35:00:01:22) via eth0

On the Zedboards UART you should see something like this (AAA = Ubuntu PC, BBB = Zedboard):

U-Boot 2012.04.01-dirty (Jun 23 2013 - 19:36:00)
DRAM:  512 MiB
WARNING: Caches not enabled
MMC:   SDHCI: 0
Using default environment
In:    serial
Out:   serial
Err:   serial
Net:   zynq_gem
Hit any key to stop autoboot:  3 ��� 2 ��� 1 ��� 0 
Scripted Boot via TFTP...
Xilinx Device
Descriptor @ 0x1ffb8a64
Family:        	Zynq PL
Interface type:	Device configuration interface (Zynq)
Device Size:   	4045564 bytes
Cookie:        	0x0 (0)
No Device Function Table.
Requesting Boot Script via TFTP...
Trying to set up GEM link...
Phy ID: 01410DD1
Resetting PHY... 
PHY reset complete.
Waiting for PHY to complete auto-negotiation...
Link is now at 1000Mbps!
BOOTP broadcast 1
Using zynq_gem device
TFTP from server 192.168.10.AAA; our IP address is 192.168.10.BBB
Filename '/ZED/u-boot.scr'.
Load address: 0xf00000
Loading: *�#
done
Bytes transferred = 303 (12f hex)
Executing Boot Script...
## Executing script at 00f00000
Using zynq_gem device
TFTP from server 192.168.10.AAA; our IP address is 192.168.10.BBB
Filename 'ZED/system.bin'.
Load address: 0x1000000
Loading: *�############################

2.4.2 TFTP Server Setup Ubuntu 12.04 LTS

Install required packages:

apt-get install tftpd-hpa tftp-hpa xinetd

Create a text file if it does not exist yet called tftp under /etc/xinetd.d/

sudo gedit /etc/xinetd.d/tftp

The tftp file should look like this:

service tftp
{
protocol        = udp
port            = 69
socket_type     = dgram
wait            = yes
user            = root
server          = /usr/sbin/in.tftpd
server_args     = -c -s /var/lib/tftpboot --verbose
disable         = no
}

The files that are served via tftp are located in

/var/lib/tftpboot

Download the 'ZED' folder to your /var/lib/tftpboot folder by typing:

wget -m -nv -np -c -nH --cut-dirs=3 -R 'index.html*' http://vserver.13thfloor.at/Stuff/AXIOM/TFTP/ZED/

Download the

boot.bin

from http://vserver.13thfloor.at/Stuff/AXIOM/TFTP/ to your /var/lib/tftpboot/ directory

Then create some symlinks inside the ZED folder in the root TFTP folder (/var/lib/tftpboot/ZED/)

cd /var/lib/tftpboot/ZED/
ln -s BERTL.xilinx/zImage zImage
ln -s BERTL.PL/cmv_io.bin system.bin
ln -s ZedBoard_OOB_Design/ramdisk8M.image.gz ramdisk.image.gz
ln -s BERTL.xilinx/devicetree_ramdisk.dtb devicetree_ramdisk.dtb

Then make sure that all the files can be acessed by TFTP:

sudo chmod -R 777 /var/lib/tftpboot/*

Start the TFTP server with:

sudo service xinetd start

Monitor your Ubuntu-PC's syslog by typing:

sudo tail -f /var/log/syslog

When the Zedboard is correctly booting via TFTP you should see something like the following in syslog (AAA = Ubuntu PC, BBB = Zedboard):

Oct  3 20:24:52 Ubuntu-PC in.tftpd[2859]: RRQ from 192.168.10.BBB filename /ZED/u-boot.scr
Oct  3 20:24:52 Ubuntu-PC in.tftpd[2860]: RRQ from 192.168.10.BBB filename ZED/system.bin
Oct  3 20:24:54 Ubuntu-PC in.tftpd[2861]: RRQ from 192.168.10.BBB filename ZED/zImage
Oct  3 20:24:55 Ubuntu-PC in.tftpd[2862]: RRQ from 192.168.10.BBB filename ZED/devicetree_ramdisk.dtb
Oct  3 20:24:55 Ubuntu-PC in.tftpd[2863]: RRQ from 192.168.10.BBB filename ZED/ramdisk.image.gz

2.4.3 SD Card Preparations

Download boot.bin (as BOOT.BIN) and copy it the to the SD card that is plugged into the Zedboard:


The boot.bin will request an IP via DHCP and then start loading the advertised boot file, which is an u-boot script that is then executed, and can be used to customize the setup steps. An example script is provided to boot into the demo ZedBoard_OOB design.

2.4.4 Boot Process

Boot time from power on till Linux prompt is 29 seconds

5 seconds till boot.bin is booted, 3 seconds wait to interrupt the bootloader, 3 seconds kernel boot, rest is bootp/tftp and stuff

  1. Autoboot (from boot.bin) will first request an IP via BOOTP
  2. Then request the file ZED/u-boot.scr (the script)
  3. Then execute that script, which contains:
  4. tftp 0x1000000 ZED/system.bin
  5. fpga load 0 0x${fileaddr} 0x${filesize}
  6. tftp 0x8000 ZED/zImage
  7. tftp 0x1000000 ZED/devicetree_ramdisk.dtb
  8. tftp 0x800000 ZED/ramdisk.image.gz
  9. bootz 0x8000 0x${fileaddr}:0x${filesize} 0x1000000
  10. go 0x8000 so it first fetches the PL code and uploads it to the FPGA
  11. then it requests the kernel, devicetree and initrd
  12. then it tries to boot the new style

2.5 Capturing an Image

Preparations:

ssh root@*alpha-IP* "./cmv_init.sh
ssh root@*alpha-IP* "./cmv_train
ssh root@*alpha-IP* "./cmv_snap -r -e 0x200" | tee snap.raw16 | display -size 4096x3072 -depth 16 gray:-

2.6 cmv_snap

cmv_snap -h
This is ./cmv_snap V1.1
options are:
-h        print this help message
-8        output 8 bit per pixel
-b        enable black columns
-r        dump sensor registers
-e <exp>  exposure values
-s <num>  shift values by <num>
-B <val>  register mapping base
-S <val>  register mapping size
-A <val>  register mapping address
-M <val>  buffer memory base
-Z <val>  buffer memory size
-P <pat>  mark pattern

2.7 Post Processing images

2.7.1 Create RGGB separated color images from raw file:

convert -size 4096x3072 -depth 16 -crop +0+0 -sample 2048x1536 gray:colors_500ms.raw16 gray:colors_500ms_ch0.raw
convert -size 4096x3072 -depth 16 -crop -1+0 -sample 2048x1536 gray:colors_500ms.raw16 gray:colors_500ms_ch1.raw
convert -size 4096x3072 -depth 16 -crop +0-1 -sample 2048x1536 gray:colors_500ms.raw16 gray:colors_500ms_ch2.raw
convert -size 4096x3072 -depth 16 -crop -1-1 -sample 2048x1536 gray:colors_500ms.raw16 gray:colors_500ms_ch3.raw

2.7.2 Simple debayer with ImageMagick:

For flipped images:

convert \( -size 4096x3072 -depth 16 gray:colors_500ms.raw16 \) \
\( -clone 0 -crop -1-1 \) \( -clone 0 -crop -1+0 \) \( -clone 0 -crop +0-1 \) \
-sample 2048x1536 \( -clone 2,3 -average \) -delete 2,3 -swap 0,1 +swap -combine colors_500ms.png

For unflipped images:

convert \( -size 4096x3072 -depth 16 gray:IT8_incand.raw16 \) \
\( -clone 0 -crop -1-1 \) \( -clone 0 -crop -1+0 \) \( -clone 0 -crop +0-1 \) \
-sample 2048x1536 \( -clone 0,1 -average \) -delete 0,1 +swap -combine IT8_incand.png

2.7.3 Plot Histogram of Raw Image

Create histogram values file with imagemagick:

convert -size 4096x3072 -depth 16 gray:image.raw16 -format "%c" histogram:info: > histogram.hist

Reformat the file:

gawk -F, '(NF>3) { printf "%d\t%d\n", $2/16, $1 }' 

Or all in one command:

convert -size 4096x3072 -depth 16 gray:image.raw16 -colors 4096 -format %c histogram:info:- | gawk -F, '(NF>3) { printf "%d\t%d\n", $2/16, $1 }' > histogram.info

Then draw it with gnuplot:

set notitle
set term svg size 1024, 512
set multiplot
set xrange[0:4096]
set yrange[0:8000]
plot 	'histogram.info' using 1:2	with lines lc rgb "#FF0000"	title "dark"
unset multiplot
pause mouse any

3 Sensor Front End

3.1 Parts

3.1.1 Image Sensor

CMV12000 from Cmosis

http://www.cmosis.com/products/standard_products/cmv12000

Price: 1265.00 €

3.1.2 FMC connector

Samtec Vita 57

http://www.samtec.com/standards/vita.aspx

Part Number: ASP-134604-01

Price: $19.70

3.1.3 HDR Cable

300mm FMC extension cable (HDR⁃169473⁃01)

http://www.samtec.com/standards/vita.aspx

Price: $180.54

3.1.4 Image Sensor Socket

Socket for CMV12000 from Andon:

Partnumber | Prices: 10-30-07-237-414T4-R27-L14 - 87.00 €

10-30-07-237-400T4-R27-L14 - 88.15 €

10-30-07-237-RB501T4-R27-L14 - 102.30 €


3.2 Reading and Writing Sensor Register

This example script:

#!/bin/sh
cmv_reg() {
   addr=$(( 0x60000000 + ($1 * 4) ))
   [ $# -gt 1 ] && devmem $addr 32 $2
   devmem $addr 32
}
#change the registers 69/98/102/107/108/112 and 124                 
cmv_reg  69      2
cmv_reg  98  39705
cmv_reg 102   8312
cmv_reg 107   9814
cmv_reg 108  12381
cmv_reg 112      5
cmv_reg 124     15
#read the register 127
cmv_reg 127

basically the registers get mapped to 32bit spaces starting at a specific memory address (0x60000000 in this case), reading from that memory will show the register, writing to that memory will change it

so register '0' is at 0x60000000, register '1' at 0x60000004 ...


This example script reads the current bitdepth the sensor is running with:

get_bitdepth () {
	depth=$(( `cmv_reg 118` + 0 ))
	[ $depth -eq 0 ] && echo "12 bit mode"
	[ $depth -eq 1 ] && echo "10 bit mode"
	[ $depth -eq 2 ] && echo "8 bit mode"
}

3.2.1 statically linked busybox

http://vserver.13thfloor.at/Stuff/AXIOM/FAKE/

builtin fake devmem

all you need to get it to work is the following:

dd if=/dev/zero of=/tmp/mem bs=1k seek=4M count=1

this will create a sparse 4GB file /tmp/mem, which will be used by the fake devmem values written can be read back, non existing values return 0

/bin/sh and /sbin/devmem both link to busybox on the axiom alpha filesystem so both can be tested with this executeable