busybear-linux icon indicating copy to clipboard operation
busybear-linux copied to clipboard

File transfer between riscv-qemu and host.

Open lewiz-sunny opened this issue 5 years ago • 5 comments

hello I am following steps provided on

https://www.cnx-software.com/2018/03/16/how-to-run-linux-on-risc-v-with-qemu-emulator/.

i was able to boot the qemu successfully, but now I want to run my own hello world program on qemu.

I have cross compiled my hello world program but, I am not able to find the directory to where i should place my executable file, so that I can access it from qemu after booting it up.

Any help is appreciated. thank you

lewiz-sunny avatar Jun 10 '19 23:06 lewiz-sunny

Take a look at the filesystem build script: scripts/image.sh. Notice it copies etc at line 17.

It should suffice to put your program in the etc/ directory and it will be copied into the image, or you could add another rsync command to copy another directory into the image.

$ nl scripts/image.sh 
     1	#!/bin/bash
     2	set -e
     3	. conf/busybear.config
     4	#
     5	# create root filesystem
     6	#
     7	rm -f ${IMAGE_FILE}
     8	dd if=/dev/zero of=${IMAGE_FILE} bs=1M count=${IMAGE_SIZE}
     9	/sbin/mkfs.ext4 -j -F ${IMAGE_FILE}
    10	test -d mnt || mkdir mnt
    11	mount -o loop ${IMAGE_FILE} mnt
    12	( cd mnt && mkdir -p root bin dev lib lib64 lib/modules proc sbin sys tmp usr usr/bin usr/sbin var/run var/log var/tmp etc/dropbear etc/network/if-pre-up.d etc/network/if-up.d etc/network/if-down.d etc/network/if-post-down.d )
    13	cp build/busybox-${BUSYBOX_VERSION}/busybox mnt/bin/
    14	cp build/dropbear-${DROPBEAR_VERSION}/dropbear mnt/sbin/
    15	rsync -a --exclude ldscripts --exclude '*.la' --exclude '*.a' ${RISCV}/sysroot/lib/ mnt/lib/
    16	rsync -a --exclude ldscripts --exclude '*.la' --exclude '*.a' ${RISCV}/sysroot/lib64/ mnt/lib64/
    17	rsync -a etc/ mnt/etc/
    18	hash=$(openssl passwd -1 -salt xyzzy ${ROOT_PASSWORD})
    19	sed -i'' "s:\*:${hash}:" mnt/etc/shadow
    20	chmod 600 mnt/etc/shadow
    21	touch mnt/var/log/lastlog
    22	touch mnt/var/log/wtmp
    23	ln -s ../bin/busybox mnt/sbin/init
    24	ln -s busybox mnt/bin/sh
    25	cp bin/ldd mnt/bin/ldd
    26	mknod mnt/dev/console c 5 1
    27	mknod mnt/dev/ttyS0 c 4 64
    28	mknod mnt/dev/null c 1 3
    29	umount mnt
    30	rmdir mnt

michaeljclark avatar Jun 10 '19 23:06 michaeljclark

@michaeljclark thank you for your response. It worked for me.

lewiz-sunny avatar Jun 11 '19 17:06 lewiz-sunny

@michaeljclark Can I also share a text file from qemu-linux after booting it up to host linux??

if yes, can you please say how?

thank you.

lewiz-sunny avatar Jun 11 '19 21:06 lewiz-sunny

@jim-wilson @michaeljclark i mounted my qemu.bin image file and was able to save the cross compiled user C code on the qemu. My user C code program creates a text file and writes a string into the file. I want to copy this file from Qemu to host while qemu is still logged in.

I was able to copy a file once I log out of Qemu, mount my image file again and then copy the file to my host process. but, I am looking for some solution through which I can copy file from qemu to host just by mounting it once and be logged in as root in Qemu.

lewiz-sunny avatar Jun 13 '19 17:06 lewiz-sunny

It isn't safe to mount a file system twice.

To have access to the live system, you have to get ssh/scp working. There are various ways to do this. The busybear README.md file explains one way to do this in the linux bridged networking section.

jim-wilson avatar Jun 13 '19 17:06 jim-wilson