Page 1 of 1
.img file not a multiple of 512 bytes
Posted: Mon Jan 03, 2022 1:37 pm
by Paletech35
I am trying to follow along with the raspberry pi barebones tutorial, and I have compiled the project as described on the wiki to generate the kernel7.img file. However, the raspberry pi imaging tool will not take it as it is not a multiple of 512 bytes, and QEMU will not load it either. The file is 41012 bytes in size and my project is stored on github
here under the master branch. I am trying to compile for a raspi 1 and am using the raspi1ap option on qemu. I am a little confused, what part of the code should ensure that the file is the right size? As far as i can tell the linker.ld file should be doing this but I am not sure. Thanks
Re: .elf file not a multiple of 512 bytes
Posted: Mon Jan 03, 2022 2:39 pm
by nullplan
Is there no option to these tools to pad the input file accordingly?
Your github repo does not contain build instructions of any sort, so I don't know how you are creating the kernel. But no, the ELF file does not have to be a multiple of 4kB in size. The last thing the linker script does is to pad the BSS section to a 4kB boundary, but BSS is not stored in the file. Perhaps the file was meant to be dumped into binary form before being used? That can be done with
Code: Select all
objcopy -O binary kernel7.elf kernel7.bin
Many kernels use this trick, in embedded development and elsewhere. I personally dislike it, but there are cases where it is needed. Such as when running without a loader capable of loading an ELF file.
Re: .img file not a multiple of 512 bytes
Posted: Mon Jan 03, 2022 5:30 pm
by Paletech35
Ah sorry, it is kernel7.img, not kernel7.elf. The elf file was generated earlier in the process. I have fixed the title and post to reflect this. I compiled the kernel exactly using the process described in the barebones tutorial, using a cross compiler with arm-none-eabi as the target. I followed the instructions as closely as possible, is there anything else I might have missed?
Re: .img file not a multiple of 512 bytes
Posted: Mon Jan 03, 2022 7:39 pm
by linuxyne
Code: Select all
$ qemu-system-arm -M raspi1ap -kernel myos.elf -serial stdio
Hello, kernel World!
From the
barebones:
With QEMU you do not need to objcopy the kernel into a plain binary; QEMU also supports ELF kernels:
$YOURINSTALLLOCATION/bin/qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel kernel.elf
Re: .img file not a multiple of 512 bytes
Posted: Tue Jan 04, 2022 8:27 am
by iansjack
You are copying the kernel to a prepared bootable SD card (rather than trying to copy it as an SD image), aren't you?