Skip to content

Kernel with Networking

Cupertino Miranda edited this page Nov 18, 2020 · 1 revision
  1. Obtain buildroot and build it

    git clone git://git.buildroot.net/buildroot
    cd buildroot
    make snps_archs38_hsdk_defconfig
    make menuconfig
     #Target options --> Target Architecture --> ARC (little endian)
     #                   Target CPU          --> ARC HS38
     #Filesystem images --> cpio the root filesystem
     #Save
    make BR2_JLEVEL=4
    

    Note: You will need cpio package installed.

  2. Grab the latest kernel for qemu-arc and build

    git clone --single-branch --branch qemu-5.0 --depth 1 https://github.com/abrodkin/linux.git
    cd linux
    export ARCH=arc
    export CROSS_COMPILE=arc-elf32-             # make sure you have arc-elf32-gcc in PATH
    make hsdk_defconfig           
    make menuconfig
     # Ensure CONFIG_VIRTIO=y, CONFIG_VIRTIO_NET=y, CONFIG_VIRTIO_MENU=y, CONFIG_VIRTIO_MMIO=y
     # General setup --> Init ramfs source file(s) -->
     #  /path/to/buildroot/output/images/rootfs.cpio
    cat .config
     #CONFIG_INITRAMFS_SOURCE="/path/to/buildroot/output/images/rootfs.cpio"
    make -j4
    
  3. Run the kernel with the following QEMU command

    qemu-system-arc -M virt                                                        \
                    -nographic                                                      \
                    -no-reboot                                                      \
                    -serial stdio                                                   \
                    -monitor none                                                   \
                    -cpu archs                                                      \
                    -netdev user,id=net,hostfwd=tcp::5555-:23,hostfwd=tcp::5556-:21 \
                    -device virtio-net-device,netdev=net0                           \
                    -device virtio-rng-pci                                          \
                    -kernel vmlinux
    

See QEMU's VirtIORNG for -device virtio-rng-pci.

  1. Once booted
    ifconfig eth0 up
    udhcpc
    

Shared folder

If you need shared folder access, add the following arguments to QEMU's command line:

... -drive format=vvfat,id=hd0,file=fat:rw:FOLDER -device virtio-blk-device,drive=hd0 ...

and then in the guest:

# mount /dev/vda1
# mount /dev/vda1 /mnt
# touch /mnt/test.txt

Note:

  1. Target will see contents on your __FOLDER__ as if it's a FAT partition on some drive so I guess no symlinks, no special attributes etc.
  2. Target may do changes to the contents of this folder (with rw permissions above)
  3. Host MUST NOT do any changes to the folder while target is using this share, otherwise things will go seriously wrong (QEMU creates FAT table on start and then it's target which manipulates it but not host).
Clone this wiki locally