From: Frank Date: Tue, 21 Nov 2006 20:10:34 -0800 (PST) Subject: [U-Boot-Users] Reading out version_string from a binary In-Reply-To: <20061121130236.GC3803@igloo.df.lth.se> Message-ID: <20061122041034.43367.qmail@web32207.mail.mud.yahoo.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de --- Fredrik Roubert wrote: > Hi! > > I use U-Boot (1.1.4) on a custom PowerPC (MPC8347) based > board, and from > my application I need to read out the value of version_string > from the > U-Boot binary, for logging. I've written some code that does > this (see > attached sample program), but would like some comments if > someone has > suggestions on how to do it more robust. > > On MPC83XX, version_string is stored at the beginning of > .rodata, so if > only the offset for .rodata is found, reading out > version_string is > quite straightforward. > > The offset of .rodata changes, however, when code is added or > removed > from U-Boot. I've found that an offset is being written at the > end of > start.o, from which it is possible to calculate the offset of > .rodata, > and even though this works for my current needs, it's hardly > what one > would call a robust solutions. > > Does anyone have ideas about a better way to do this? Look at the way objdump finds the offset of the sections for an elf file and do it the same way. The source to objdump is readily available or you could pipe the output of objdump to your application program, parse the output, open u-boot, seek to the offset of the .rodata section and extract the information. You could also use the same technique and extarct the symbol itself from the elf binary. I've done this in the past.... ____________________________________________________________________________________ Sponsored Link Compare mortgage rates for today. Get up to 5 free quotes. www2.nextag.com