From: Jerry Van Baren <gerald.vanbaren@smiths-aerospace.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] Reading out version_string from a binary
Date: Tue, 21 Nov 2006 13:33:23 -0500 [thread overview]
Message-ID: <45634673.2060800@smiths-aerospace.com> (raw)
In-Reply-To: <20061121130236.GC3803@igloo.df.lth.se>
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?
>
> Cheers // Fredrik Roubert
Looking in cpu/mpc83xx/start.S I find:
/*
* Version string - must be in data segment because MPC83xx uses the
* first 256 bytes for the Hard Reset Configuration Word table (see
* below). Similarly, can't have the U-Boot Magic Number as the first
* thing in the image - don't know how this will affect the image tools,
* but I guess I'll find out soon.
*/
.data
.globl version_string
version_string:
.ascii U_BOOT_VERSION
.ascii " (", __DATE__, " - ", __TIME__, ")"
.ascii " ", CONFIG_IDENT_STRING, "\0"
so your statement that it is in .rodata is only part of the story - it
actually is in .data but is initialized so a copy is in .rodata.
I see several ways to accomplish what you want.
1) (Easiest) Duplicate the above stuff at a fixed location. The best
fixed location would be in the gap between the HRCW and the 0x100 trap
offset. Big hole, mostly unused, fixed location. Problem solved, at
least for the 83xx CPU and potentially could be applied to most or all
of the PowerPC family.
2) Put the above string in a new section and use the linker control file
(lds) to put it in a fixed location, at least for your board. Lots of
work with no obvious benefit and more hassle (unnecessary fixed
locations are Evil).
3) Variant of #1: the string _should be_ constant, and having someone
scribbling on it (which .data implies is permissible) would be a Bad
Thing[tm] in my book. The variant on #1 would be to _move_ the string
(rather than replicate it) after the HRCW in the .text section in
start.S and fix up the users of the string so that they can find it OK
after relocation. You could make an argument that this is a Better Way[tm].
gvb
next prev parent reply other threads:[~2006-11-21 18:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-21 13:02 [U-Boot-Users] Reading out version_string from a binary Fredrik Roubert
2006-11-21 14:11 ` Markus Klotzbücher
2006-11-21 14:47 ` Wolfgang Denk
2006-11-21 16:18 ` Fredrik Roubert
2006-11-21 17:58 ` Wolfgang Denk
2006-11-21 18:33 ` Jerry Van Baren [this message]
2006-11-22 4:10 ` Frank
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45634673.2060800@smiths-aerospace.com \
--to=gerald.vanbaren@smiths-aerospace.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.