Page 1 of 1

"mcopy" command says "Disk full" when copying kernel.elf

Posted: Fri Jul 02, 2021 11:20 am
by LyricalRain
Hello! I've encountered a problem that stumps me. When creating a disk image for x86-64 UEFI, the "mcopy" command keeps saying "Disk full" whenever I try to copy the kernel.elf to its root directory. This only happened a few hours ago and it was working fine for the last few days. It started happening after I used -mcmodel=kernel, but I don't know if that is what is causing it. The ELF file is only 2 MB, and the disk is 48MB, so there shouldn't be a problem of lack of space.
Below are the commands I'm running to make the disk:

Code: Select all

dd if=/dev/zero of=$(BUILDDIR)/$(OSNAME).img bs=512 count=93750
	mformat -i $(BUILDDIR)/$(OSNAME).img -f 1440 ::
	mmd -i $(BUILDDIR)/$(OSNAME).img ::/EFI
	mmd -i $(BUILDDIR)/$(OSNAME).img ::/EFI/BOOT
	mcopy -i $(BUILDDIR)/$(OSNAME).img $(BOOTEFI) ::/EFI/BOOT
	mcopy -i $(BUILDDIR)/$(OSNAME).img startup.nsh ::
	mcopy -i $(BUILDDIR)/$(OSNAME).img $(BUILDDIR)/kernel.elf ::
I reiterate, this only started happening after I cross compiled my gcc and ld for x86_64 and used -mcmodel=kernel. Any ideas on how to fix this?

Re: "mcopy" command says "Disk full" when copying kernel.elf

Posted: Fri Jul 02, 2021 11:24 am
by bzt
What does

Code: Select all

du -hs *.elf *.img
say?

Have you tried mounting the image through a loopback device and copying kernel.elf as usual? Does that work?

Cheers,
bzt

Re: "mcopy" command says "Disk full" when copying kernel.elf

Posted: Fri Jul 02, 2021 12:13 pm
by LyricalRain
bzt wrote:What does

Code: Select all

du -hs *.elf *.img
say?
It says 8 KB for the kernel and 48 MB for the disk.
bzt wrote:Have you tried mounting the image through a loopback device and copying kernel.elf as usual? Does that work?
Yeah I did that just now, but the kernel wouldn't boot.

So the disk gets made properly with the elf generated from my native gcc, but not from my cross compiled one. So there lies the problem.
Thanks for your help!

Re: "mcopy" command says "Disk full" when copying kernel.elf

Posted: Fri Jul 02, 2021 12:43 pm
by LyricalRain
Okay I figured out the problem, I was not using the -no-red-zone flag with ld smh.

Re: "mcopy" command says "Disk full" when copying kernel.elf

Posted: Mon Jul 05, 2021 7:00 pm
by davmac314

Code: Select all

  mformat -i $(BUILDDIR)/$(OSNAME).img -f 1440 ::
You are trying to copy a 2Mb kernel to a filesystem formatted as 1.44Mb :wink: