Saturday, December 31, 2016

Learning linux driver development with qemu


Linux Drivers

PCI

Based on instructions here -
http://nairobi-embedded.org/linux_pci_device_driver.html

Build yocto guest OS

$ git clone git://git.yoctoproject.org/poky
poky]$ git checkout morty
poky]$ source oe-init-build-env

#for those of us with non-US keyboards (you can also skip this step if using 'nographic' mode for qemu
build]$ echo "IMAGE_INSTALL_append = \" kbd keymaps kbd-keymaps\"" >> conf/local.conf

#this will take a while
build]$ bitbake core-image-sato-sdk

#now run it in qemu
build]$ runqemu qemux86-64 core-image-sato-sdk ext4 nographic qemuparams="-device ivshmem,shm=ivshmem,size=1"

#change keyboard layout if needed
root@qemux86-64:~# loadkeys /usr/share/keymaps/i386/qwerty/sv-latin1.map.gz 

#build guest module
#copy code to guest
[host pci]$ scp -r guest/ root@192.168.7.2:~/

ssh root@192.168.7.2
root@qemux86-64:~# cd /usr/src/kernel
root@qemux86-64:/usr/src/kernel# make modules_prepare

root@qemux86-64:/usr/src/kernel# cd ~/guest
root@qemux86-64:guest # make
root@qemux86-64:~/guest# sudo insmod ne_ivshmem_ldd_basic.ko
root@qemux86-64:~/guest# ls -l /dev/ivshmem0
root@qemux86-64:~/guest# sudo ./ne_ivshmem_shm_guest_usr -w "Dunia, vipi?"
main:169:: writing "Dunia, vipi?"

[host pci]$ hexdump -C /dev/shm/ivshmem
00000000  44 75 6e 69 61 2c 20 76  69 70 69 3f 00 00 00 00  |Dunia, vipi?....|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|


User mode
Now for user-mode, based on instructions here