OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:59 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: .img file not a multiple of 512 bytes
PostPosted: Mon Jan 03, 2022 1:37 pm 
Offline

Joined: Sun Mar 28, 2021 6:30 pm
Posts: 8
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.

Top
 Profile  
 
 Post subject: Re: .elf file not a multiple of 512 bytes
PostPosted: Mon Jan 03, 2022 2:39 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
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:
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.

_________________
Carpe diem!


Top
 Profile  
 
 Post subject: Re: .img file not a multiple of 512 bytes
PostPosted: Mon Jan 03, 2022 5:30 pm 
Offline

Joined: Sun Mar 28, 2021 6:30 pm
Posts: 8
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?


Top
 Profile  
 
 Post subject: Re: .img file not a multiple of 512 bytes
PostPosted: Mon Jan 03, 2022 7:39 pm 
Offline
Member
Member

Joined: Sat Jul 02, 2016 7:02 am
Posts: 207
Code:
$ qemu-system-arm -M raspi1ap -kernel myos.elf -serial stdio
Hello, kernel World!


From the barebones:
Quote:
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


Top
 Profile  
 
 Post subject: Re: .img file not a multiple of 512 bytes
PostPosted: Tue Jan 04, 2022 8:27 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
You are copying the kernel to a prepared bootable SD card (rather than trying to copy it as an SD image), aren't you?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 63 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group