.img file not a multiple of 512 bytes
-
- Posts: 8
- Joined: Sun Mar 28, 2021 6:30 pm
.img file not a multiple of 512 bytes
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
Last edited by Paletech35 on Mon Jan 03, 2022 5:27 pm, edited 1 time in total.
Re: .elf file not a multiple of 512 bytes
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
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.
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
Carpe diem!
-
- Posts: 8
- Joined: Sun Mar 28, 2021 6:30 pm
Re: .img file not a multiple of 512 bytes
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
Code: Select all
$ qemu-system-arm -M raspi1ap -kernel myos.elf -serial stdio
Hello, kernel World!
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
You are copying the kernel to a prepared bootable SD card (rather than trying to copy it as an SD image), aren't you?