To rebuild the PetaLinux SD card image for this project, follow the steps below. 

NOTE: Before starting Petalinux build ensure that downloaded package
(fmchc_hls_{version}.zip) is unzipped in Linux.

$ unzip fmchc_hls_{version}.zip

Extract the components.zip archive in the target's petalinux directory

$ cd fmchc_hls/pzfmc2/software/petalinux
$ unzip components.zip

Commands to run in a terminal window are prefaced with the $ symbol. 
This project is built using PetaLinux 2015.4, which corresponds to 
Linux kernel version 4.0 (kernel tag xilinx-v2015.4.01). 

1. Configure the Petalinux BSP with hardware export
$ petalinux-config --get-hw-description=./hw-description --oldconfig

2. Set the devicetree 
$ cd subsystems/linux/configs/device-tree
$ ln -sf fmc-hdmi-cam-top-pzfmc2.dts system-top.dts
$ cd -

3.  Patch the ps7_init.c file used inside the FSBL to override the default DDR Memory Controller QoS settings. 
This will affect the transaction state arbitration stage by increasing the value of the WR_min_non_critical field. 
Refer Zynq-7000 AP SoC Technical Reference Manual Ch 10.4 DDRC Arbitration for details.

$ patch ./components/bootloader/zynq_fsbl/ps7_init.c < ./hw-description/ps7_init.patch

4. Copy linux kernel source and update driver code
We need to make some modifications to the Linux kernel. PetaLinux does not provide for applying
patches at build time, so we need to copy the kernel sources into the project locally. From the root
directory of the PetaLinux project, run the following commands:

$ mkdir components/linux-kernel
$ cp -r build/linux/kernel/download/linux-xlnx components/linux-kernel/xlnx-4.0-python

Re-run petalinux-config and choose the local kernel source
$ petalinux-config
   -> linux Components Selection
      -> kernel (xlnx-4.0-python)

5. Apply kernel patch for PYTHON camera receiver core

$ cd components/linux-kernel/xlnx-4.0-python
$ patch -p1 < ../../../patches/embv-python-2015.4.01-v2.2a.patch
$ cd -

Re-run petalinux-config to configure the kernel
$ petalinux-config -c kernel
   -> Device Drivers
      -> SPI Support
         -> Python SPI controller
      -> Multimedia support
         *** Media ancillary drivers (SPI) ***
         -> Encoders, decoders, sensors and other helper chips		 
            -> Onsemi Python sensor support
      -> Multimedia support
         -> V4L platform devices
            -> Xilinx Receive Interface for Python1300
      -> Common Clock Framework
	     -> AXI clkgen driver

6. Apply kernel patch for ADV7611 driver

$ patch ./components/linux-kernel/xlnx-4.0-python/drivers/media/i2c/adv7604.c < patches/adv7604_maxdrive_llc0.patch

7. Build PetaLinux image
$ petalinux-build

8. Wrap the generated kernel and rootfs with a u-boot header
$ petalinux-package --image -c kernel --format uImage

9. Rename devicetree blob and ramdisk for final image
$ mv images/linux/system.dtb images/linux/devicetree.dtb
$ mv images/linux/urootfs.cpio.gz images/linux/uramdisk.image.gz

10. The final output products are located under ./images/linux and are ready to
   be copied to an SD card.   

