# Requirements:
- LinuxMint 18.1 or Ubuntu ??.?
# Build Xilinx QEMU
```
#!/bin/bash
#TODO: Create "update" version of the script, package retrieving and cloning should be done one time only
prerequisites="build-essential libglib2.0-dev libgcrypt20-dev zlib1g-dev autoconf automake libtool bison flex git"
if [[ $EUID != 0 ]];
then
echo "Please run as sudo";
exit;
fi
apt-get update
apt-get install $prerequisites
git clone git://github.com/Xilinx/qemu.git
cd qemu
git submodule update --init pixman dtc
./configure --target-list="aarch64-softmmu,microblazeel-softmmu" --enable-fdt --disable-kvm --disable-xen
make -j4
```
# TODO
~~- Needs investigation, if kernel/device tree etc. have to be supplied separately~~
~~- Maybe mounting ting first partition to the loop device is also fine, to get access to the files, but then QEMU has to be started with sudo~~
- Mounted first partition from extracted image (from 3GB to 16GB) directly, but the script has to be adjusted to do it automatically
**Steps**
- Get partitions of the disk image
```
andi@LMdev ~/Development/images/mymod $ sudo sfdisk -l beta_20170109.dd
Disk beta_20170109.dd: 14,9 GiB, 16021192704 bytes, 31291392 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x076fe881
Device Boot Start End Sectors Size Id Type
beta_20170109.dd1 8192 110591 102400 50M c W95 FAT32 (LBA)
beta_20170109.dd2 110592 7626751 7516160 3,6G 83 Linux
beta_20170109.dd3 7626752 24403967 16777216 8G 83 Linux
```
- Create directory to hold the partition data
```
mkdir boot
```
- Mount
```
sudo mount -o loop,offset=4194304,sizelimit=52428800 beta_20170109.dd boot/
```
- QEMU start script
```
target_dir="./images/mymod"
image="beta_20170109.dd"
dtb="boot/devicetree.dtb"
kernel="boot/zImage"
# Create and mount boot partition to get kernel, bootloader etc.
if [ ! -d "$target_dir/boot" ];
then
{
mkdir $target_dir/boot
}
fi
sudo mount -o loop,offset=4194304,sizelimit=52428800 $target_dir/$image $target_dir/boot
# Start QEMU
./qemu/aarch64-softmmu/qemu-system-aarch64 \
-M arm-generic-fdt-7series -machine linux=on -m 256M \
-serial /dev/null -serial mon:stdio -display none \
-dtb $target_dir/$dtb \
-kernel $target_dir/$kernel \
-drive file=$target_dir/$image,format=raw,index=0,media=disk -append "bootargs=console=ttyPS0,115200 root=//dev/mmcblk0p2 rw rootwait earlyprintk nosmp"
# Unmount after emulator exits
sudo umount $target_dir/boot
```
# Current state
It seems to boot (output: AXIOM Beta MicroZed), but panic still occurs. Possibly that QEMU needs some pointers to the partitions inside the image. Investigation ongoing.
```
Warning: Orphaned drive without device: id=ide0-hd0,file=./images/mymod/beta_20170109.dd,if=ide,bus=0,unit=0
rom: requested regions overlap (rom ./images/mymod/zImage. free=0x00000000fffffff8, addr=0x0000000000010000)
Uncompressing Linux... done, booting the kernel.
Booting Linux on physical CPU 0x0
Linux version 4.6.0-xilinx-00016-gb49271f (root@newhost) (gcc version 5.1.1 20150618 (Red Hat Cross 5.1.1-3) (GCC) ) #53 SMP PREEMPT Mon Jan 9 01:07:28 CET 2017
CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
Machine model: AXIOM Beta MicroZed
bootconsole [earlycon0] enabled
INITRD: 0x00800000+0x01000000 overlaps in-use memory region - disabling initrd
Memory policy: Data cache writealloc
percpu: Embedded 12 pages/cpu @ef7d3000 s19904 r8192 d21056 u49152
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 260096
Kernel command line: console=ttyPS0,115200n8 root=/dev/ram rw initrd=0x00800000,16M earlyprintk mtdparts=physmap-flash.0:512K(nor-fsbl),512K(nor-u-boot),5M(nor-linux),9M(nor-user),1M(nor-scratch),-(nor-rootfs)
log_buf_len individual max cpu contribution: 262144 bytes
log_buf_len total cpu_extra contributions: 262144 bytes
log_buf_len min size: 16384 bytes
log_buf_len: 524288 bytes
early log buf free: 14728(89%)
PID hash table entries: 4096 (order: 2, 16384 bytes)
Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)
Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)
Memory: 1031344K/1048576K available (4234K kernel code, 148K rwdata, 1484K rodata, 1024K init, 175K bss, 17232K reserved, 0K cma-reserved)
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xffc00000 - 0xfff00000 (3072 kB)
vmalloc : 0xf0800000 - 0xff800000 ( 240 MB)
lowmem : 0xb0000000 - 0xf0000000 (1024 MB)
modules : 0xaf000000 - 0xb0000000 ( 16 MB)
.text : 0xb0008000 - 0xb0695850 (6711 kB)
.init : 0xb0700000 - 0xb0800000 (1024 kB)
.data : 0xb0800000 - 0xb0825100 ( 149 kB)
.bss : 0xb0825100 - 0xb08510fc ( 176 kB)
Preemptible hierarchical RCU implementation.
Build-time adjustment of leaf fanout to 32.
NR_IRQS:16 nr_irqs:16 16
efuse mapped to f0802000
slcr mapped to f0804000
L2C: platform modifies aux control register: 0x00000000 -> 0x30400000
L2C: DT/platform modifies aux control register: 0x00000000 -> 0x30400000
L2C-310 errata 588369 769419 enabled
L2C-310 full line of zeros enabled for Cortex-A9
L2C-310 cache controller enabled, 8 ways, 64 kB
L2C-310: CACHE_ID 0x00000000, AUX_CTRL 0x00000000
zynq_clock_init: clkc starts at f0804100
Zynq clock init
clocksource: ttc_clocksource: mask: 0xffff max_cycles: 0xffff, max_idle_ns: 826992825 ns
sched_clock: 16 bits at 35kHz, resolution 28357ns, wraps every 929205421ns
timer #0 at f080c000, irq=16
global-timer: non support for this cpu version.
Console: colour dummy device 80x30
Calibrating delay loop... 1856.30 BogoMIPS (lpj=9281536)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 2048 (order: 1, 8192 bytes)
Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes)
CPU: Testing write buffer coherency: ok
CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
Setting up static identity map for 0x100000 - 0x100058
CPU1: thread -1, cpu 1, socket 0, mpidr 80000001
Brought up 2 CPUs
SMP: Total of 2 processors activated (3516.00 BogoMIPS).
CPU: WARNING: CPU(s) started in wrong/inconsistent modes (primary CPU mode 0x13)
CPU: This may indicate a broken bootloader or firmware.
devtmpfs: initialized
VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 0
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
pinctrl core: initialized pinctrl subsystem
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
cpuidle: using governor ladder
cpuidle: using governor menu
hw-breakpoint: debug architecture 0x4 unsupported.
zynq-ocm f800c000.ocmc: can't request region for resource [mem 0x0000000c-0x0003ffff]
zynq-ocm: probe of f800c000.ocmc failed with error -16
zynq-pinctrl 700.pinctrl: zynq pinctrl initialized
SCSI subsystem initialized
i2c-gpio zed_i2c_gpio: using pins 915 (SDA) and 906 (SCL)
media: Linux media interface: v0.10
Linux video capture interface: v2.00
pps_core: LinuxPPS API ver. 1 registered
pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
PTP clock support registered
EDAC MC: Ver: 3.0.0
Advanced Linux Sound Architecture Driver Initialized.
clocksource: Switched to clocksource ttc_clocksource
NET: Registered protocol family 2
TCP established hash table entries: 8192 (order: 3, 32768 bytes)
TCP bind hash table entries: 8192 (order: 4, 65536 bytes)
TCP: Hash tables configured (established 8192 bind 8192)
UDP hash table entries: 512 (order: 2, 16384 bytes)
UDP-Lite hash table entries: 512 (order: 2, 16384 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
hw perfevents: enabled with armv7_cortex_a9 PMU driver, 1 counters available
futex hash table entries: 512 (order: 3, 32768 bytes)
workingset: timestamp_bits=29 max_order=18 bucket_order=0
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
dma-pl330 f8003000.dmac: Loaded driver for PL330 DMAC-241330
dma-pl330 f8003000.dmac: DBUFF-256x8bytes Num_Chans-8 Num_Peri-4 Num_Events-16
e0000000.serial: ttyPS1 at MMIO 0xe0000000 (irq = 20, base_baud = 859788) is a xuartps
e0001000.serial: ttyPS0 at MMIO 0xe0001000 (irq = 21, base_baud = 859788) is a xuartps
console [ttyPS0] enabled
console [ttyPS0] enabled
bootconsole [earlycon0] disabled
bootconsole [earlycon0] disabled
xdevcfg f8007000.devcfg: ioremap 0xf8007000 to f0862000
gpiod_set_value: invalid GPIO
libphy: MACB_mii_bus: probed
macb e000b000.ethernet eth0: Cadence GEM rev 0x00020118 at 0xe000b000 irq 144 (52:54:00:12:34:56)
Generic PHY e000b000.etherne:00: attached PHY driver [Generic PHY] (mii_bus:phy_addr=e000b000.etherne:00, irq=-1)
mousedev: PS/2 mouse device common for all mice
i2c /dev entries driver
cdns-i2c e0004000.i2c: 100 kHz mmio e0004000 irq 23
cdns-i2c e0005000.i2c: 100 kHz mmio e0005000 irq 24
Xilinx Zynq CpuIdle Driver started
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
sdhci-pltfm: SDHCI platform and OF driver helper
mmc0: SDHCI controller on e0100000.sdhci [e0100000.sdhci] using DMA
mmc1: SDHCI controller on e0101000.sdhci [e0101000.sdhci] using DMA
ledtrig-cpu: registered to indicate activity on CPUs
NET: Registered protocol family 17
zynq_pm_remap_ocm: OCM pool is not available
zynq_pm_suspend_init: Unable to map OCM.
Registering SWP/SWPB emulation handler
input: gpio-keys as /devices/soc0/gpio-keys/input/input0
ALSA device list:
No soundcards found.
VFS: Cannot open root device "ram" or unknown-block(1,0): error -6
Please append a correct "root=" boot option; here are the available partitions:
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(1,0)
CPU1: stopping
CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.6.0-xilinx-00016-gb49271f #53
Hardware name: Xilinx Zynq Platform
[<b010e424>] (unwind_backtrace) from [<b010a678>] (show_stack+0x10/0x14)
[<b010a678>] (show_stack) from [<b02c3198>] (dump_stack+0x80/0xa0)
[<b02c3198>] (dump_stack) from [<b010cb64>] (ipi_cpu_stop+0x3c/0x70)
[<b010cb64>] (ipi_cpu_stop) from [<b010d3dc>] (handle_IPI+0x64/0x84)
[<b010d3dc>] (handle_IPI) from [<b01013e4>] (gic_handle_irq+0x74/0x90)
[<b01013e4>] (gic_handle_irq) from [<b010b054>] (__irq_svc+0x54/0x90)
SMP: failed to stop secondary CPUs
Exception stack(0xef071f68 to 0xef071fb0)
1f60: 00000000 00000002 3f0aa000 ef7e3280 00000000 ef7e2580
1f80: 971f83d5 00000002 952ec607 00000002 00000000 00000000 0000000f ef071fb8
---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(1,0)
1fa0: b03e1e58 b03e1e7c 60000013 ffffffff
[<b010b054>] (__irq_svc) from [<b03e1e7c>] (cpuidle_enter_state+0xe0/0x1b4)
[<b03e1e7c>] (cpuidle_enter_state) from [<b014b634>] (cpu_startup_entry+0x184/0x1d0)
[<b014b634>] (cpu_startup_entry) from [<0010148c>] (0x10148c)
```
- zImage (kernel) and .dtb (device tree) have to be supplied seprately, as boot bin has problems to start in QEMU, neds investigation
- QEMU start script
```
#!/bin/bash
target_dir="./images/mymod"
image="./beta_20170109.dd"
dtb="devicetree.dtb"
kernel="zImage"
# Start QEMU
./qemu/aarch64-softmmu/qemu-system-aarch64 \
-M arm-generic-fdt-7series -machine linux=on -m 1024 \
-serial null -serial mon:stdio -nographic -boot mode=3 \
-dtb $target_dir/$dtb \
-kernel $target_dir/$kernel -append "console=ttyPS0,115200n8 root=/dev/mmcblk0p2 rw rootwait rootfstype=ext4 systemd.log_level=warning systemd.log_target=console kernel.sysrq=1 init=/usr/lib/systemd/systemd" \
-drive file=$target_dir/$image,if=sd,format=raw,index=0
```
# Current state
Boot works, needs some time. But further inspection is needed to verify that it works to the level where one can develop through remote debug for example.