* [U-Boot] [PATCH] [x86] Fix how the location of the realmode and bios blobs are calculated
@ 2011-11-08 6:49 Gabe Black
2011-11-08 10:28 ` Graeme Russ
2011-11-08 22:19 ` [U-Boot] [PATCH v2] x86: " Gabe Black
0 siblings, 2 replies; 7+ messages in thread
From: Gabe Black @ 2011-11-08 6:49 UTC (permalink / raw)
To: u-boot
There are two blobs embedded into the u-boot image which are linked to run
at an address which is different from where they actually end up in the
ROM, one called "realmode" and one called "bios". There are realmode_setup
and bios_setup functions which prepare those blobs by copying them into the
location they're supposed to run from, among other things.
During u-boot relocation from ROM to RAM, the text and a few data segments
are copied over. The realmode and bios sections are not copied, and so the
only place they can be read from is their original location in the ROM.
Looking specifically at the bios blob, there are symbols defined in the
linker script called __bios_start and __bios_size which are defined to be
the start and size of the blob in the ROM.
In the bios_setup function, there seem to be two mistakes happening. First,
the offset from ROM to RAM is being added to __bios_start which implies that
this code expects to use the copy moved to RAM. No such copy is made, so
that's wrong. More subtly, when u-boot relocates itself, it goes through
all of the relocations stored in .rel.dyn and fixes them up. This has the
effect of transforming the __bios_start reference in bios_setup so that it
refers to the version in RAM (if one existed) instead of the one in ROM. To
correct for that, the offset actually needs to be subtracted out again to
translate the address back into the ROM.
The net effect is that for both blobs, a + needs to be changed to a -.
Signed-off-by: Gabe Black <gabeblack@chromium.org>
---
arch/x86/lib/bios_setup.c | 6 +++++-
arch/x86/lib/realmode.c | 6 +++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/arch/x86/lib/bios_setup.c b/arch/x86/lib/bios_setup.c
index 9bf7e58..6c6b0fe 100644
--- a/arch/x86/lib/bios_setup.c
+++ b/arch/x86/lib/bios_setup.c
@@ -140,7 +140,11 @@ static void setvector(int vector, u16 segment, void *handler)
int bios_setup(void)
{
- ulong bios_start = (ulong)&__bios_start + gd->reloc_off;
+ /*
+ * The BIOS section is not relocated and still in the ROM. The
+ * __bios_start symbol was adjusted, though, so adjust it back.
+ */
+ ulong bios_start = (ulong)&__bios_start - gd->reloc_off;
ulong bios_size = (ulong)&__bios_size;
static int done=0;
diff --git a/arch/x86/lib/realmode.c b/arch/x86/lib/realmode.c
index 6aa0f23..f8f2251 100644
--- a/arch/x86/lib/realmode.c
+++ b/arch/x86/lib/realmode.c
@@ -34,7 +34,11 @@ extern char realmode_enter;
int realmode_setup(void)
{
- ulong realmode_start = (ulong)&__realmode_start + gd->reloc_off;
+ /*
+ * The realmode section is not relocated and still in the ROM. The
+ * __realmode_start symbol was adjusted, though, so adjust it back.
+ */
+ ulong realmode_start = (ulong)&__realmode_start - gd->reloc_off;
ulong realmode_size = (ulong)&__realmode_size;
/* copy the realmode switch code */
--
1.7.3.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [U-Boot] [PATCH] [x86] Fix how the location of the realmode and bios blobs are calculated
2011-11-08 6:49 [U-Boot] [PATCH] [x86] Fix how the location of the realmode and bios blobs are calculated Gabe Black
@ 2011-11-08 10:28 ` Graeme Russ
2011-11-08 22:19 ` [U-Boot] [PATCH v2] x86: " Gabe Black
1 sibling, 0 replies; 7+ messages in thread
From: Graeme Russ @ 2011-11-08 10:28 UTC (permalink / raw)
To: u-boot
Gabe,
Can you please change your prefix from '[x86]' to 'x86:'
Thanks,
Graeme
^ permalink raw reply [flat|nested] 7+ messages in thread
* [U-Boot] [PATCH v2] x86: Fix how the location of the realmode and bios blobs are calculated
2011-11-08 6:49 [U-Boot] [PATCH] [x86] Fix how the location of the realmode and bios blobs are calculated Gabe Black
2011-11-08 10:28 ` Graeme Russ
@ 2011-11-08 22:19 ` Gabe Black
2011-11-09 9:58 ` Graeme Russ
2011-11-12 10:21 ` Graeme Russ
1 sibling, 2 replies; 7+ messages in thread
From: Gabe Black @ 2011-11-08 22:19 UTC (permalink / raw)
To: u-boot
There are two blobs embedded into the u-boot image which are linked to run
at an address which is different from where they actually end up in the
ROM, one called "realmode" and one called "bios". There are realmode_setup
and bios_setup functions which prepare those blobs by copying them into the
location they're supposed to run from, among other things.
During u-boot relocation from ROM to RAM, the text and a few data segments
are copied over. The realmode and bios sections are not copied, and so the
only place they can be read from is their original location in the ROM.
Looking specifically at the bios blob, there are symbols defined in the
linker script called __bios_start and __bios_size which are defined to be
the start and size of the blob in the ROM.
In the bios_setup function, there seem to be two mistakes happening. First,
the offset from ROM to RAM is being added to __bios_start which implies that
this code expects to use the copy moved to RAM. No such copy is made, so
that's wrong. More subtly, when u-boot relocates itself, it goes through
all of the relocations stored in .rel.dyn and fixes them up. This has the
effect of transforming the __bios_start reference in bios_setup so that it
refers to the version in RAM (if one existed) instead of the one in ROM. To
correct for that, the offset actually needs to be subtracted out again to
translate the address back into the ROM.
The net effect is that for both blobs, a + needs to be changed to a -.
Signed-off-by: Gabe Black <gabeblack@chromium.org>
---
Changes in v2:
Update x86 tag.
arch/x86/lib/bios_setup.c | 6 +++++-
arch/x86/lib/realmode.c | 6 +++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/arch/x86/lib/bios_setup.c b/arch/x86/lib/bios_setup.c
index 9bf7e58..6c6b0fe 100644
--- a/arch/x86/lib/bios_setup.c
+++ b/arch/x86/lib/bios_setup.c
@@ -140,7 +140,11 @@ static void setvector(int vector, u16 segment, void *handler)
int bios_setup(void)
{
- ulong bios_start = (ulong)&__bios_start + gd->reloc_off;
+ /*
+ * The BIOS section is not relocated and still in the ROM. The
+ * __bios_start symbol was adjusted, though, so adjust it back.
+ */
+ ulong bios_start = (ulong)&__bios_start - gd->reloc_off;
ulong bios_size = (ulong)&__bios_size;
static int done=0;
diff --git a/arch/x86/lib/realmode.c b/arch/x86/lib/realmode.c
index 6aa0f23..f8f2251 100644
--- a/arch/x86/lib/realmode.c
+++ b/arch/x86/lib/realmode.c
@@ -34,7 +34,11 @@ extern char realmode_enter;
int realmode_setup(void)
{
- ulong realmode_start = (ulong)&__realmode_start + gd->reloc_off;
+ /*
+ * The realmode section is not relocated and still in the ROM. The
+ * __realmode_start symbol was adjusted, though, so adjust it back.
+ */
+ ulong realmode_start = (ulong)&__realmode_start - gd->reloc_off;
ulong realmode_size = (ulong)&__realmode_size;
/* copy the realmode switch code */
--
1.7.3.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [U-Boot] [PATCH v2] x86: Fix how the location of the realmode and bios blobs are calculated
2011-11-08 22:19 ` [U-Boot] [PATCH v2] x86: " Gabe Black
@ 2011-11-09 9:58 ` Graeme Russ
2011-11-12 10:21 ` Graeme Russ
1 sibling, 0 replies; 7+ messages in thread
From: Graeme Russ @ 2011-11-09 9:58 UTC (permalink / raw)
To: u-boot
On 09/11/11 09:19, Gabe Black wrote:
> There are two blobs embedded into the u-boot image which are linked to run
> at an address which is different from where they actually end up in the
> ROM, one called "realmode" and one called "bios". There are realmode_setup
> and bios_setup functions which prepare those blobs by copying them into the
> location they're supposed to run from, among other things.
>
> During u-boot relocation from ROM to RAM, the text and a few data segments
> are copied over. The realmode and bios sections are not copied, and so the
> only place they can be read from is their original location in the ROM.
> Looking specifically at the bios blob, there are symbols defined in the
> linker script called __bios_start and __bios_size which are defined to be
> the start and size of the blob in the ROM.
>
> In the bios_setup function, there seem to be two mistakes happening. First,
> the offset from ROM to RAM is being added to __bios_start which implies that
> this code expects to use the copy moved to RAM. No such copy is made, so
> that's wrong. More subtly, when u-boot relocates itself, it goes through
> all of the relocations stored in .rel.dyn and fixes them up. This has the
> effect of transforming the __bios_start reference in bios_setup so that it
> refers to the version in RAM (if one existed) instead of the one in ROM. To
> correct for that, the offset actually needs to be subtracted out again to
> translate the address back into the ROM.
>
> The net effect is that for both blobs, a + needs to be changed to a -.
>
> Signed-off-by: Gabe Black <gabeblack@chromium.org>
Fixes breakage introduced by commit 5fed8211... 'x86: Fix incorrect usage
of relocation offset'
Acked-by: Graeme Russ <graeme.russ@gmail.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [U-Boot] [PATCH v2] x86: Fix how the location of the realmode and bios blobs are calculated
2011-11-08 22:19 ` [U-Boot] [PATCH v2] x86: " Gabe Black
2011-11-09 9:58 ` Graeme Russ
@ 2011-11-12 10:21 ` Graeme Russ
2011-11-13 2:31 ` [U-Boot] [PATCH v3] " Gabe Black
1 sibling, 1 reply; 7+ messages in thread
From: Graeme Russ @ 2011-11-12 10:21 UTC (permalink / raw)
To: u-boot
Hi Gabe,
On 09/11/11 09:19, Gabe Black wrote:
> There are two blobs embedded into the u-boot image which are linked to run
> at an address which is different from where they actually end up in the
> ROM, one called "realmode" and one called "bios". There are realmode_setup
> and bios_setup functions which prepare those blobs by copying them into the
> location they're supposed to run from, among other things.
>
> During u-boot relocation from ROM to RAM, the text and a few data segments
> are copied over. The realmode and bios sections are not copied, and so the
> only place they can be read from is their original location in the ROM.
> Looking specifically at the bios blob, there are symbols defined in the
> linker script called __bios_start and __bios_size which are defined to be
> the start and size of the blob in the ROM.
>
> In the bios_setup function, there seem to be two mistakes happening. First,
> the offset from ROM to RAM is being added to __bios_start which implies that
> this code expects to use the copy moved to RAM. No such copy is made, so
> that's wrong. More subtly, when u-boot relocates itself, it goes through
> all of the relocations stored in .rel.dyn and fixes them up. This has the
> effect of transforming the __bios_start reference in bios_setup so that it
> refers to the version in RAM (if one existed) instead of the one in ROM. To
> correct for that, the offset actually needs to be subtracted out again to
> translate the address back into the ROM.
>
> The net effect is that for both blobs, a + needs to be changed to a -.
>
> Signed-off-by: Gabe Black <gabeblack@chromium.org>
> ---
> Changes in v2:
> Update x86 tag.
>
> arch/x86/lib/bios_setup.c | 6 +++++-
> arch/x86/lib/realmode.c | 6 +++++-
> 2 files changed, 10 insertions(+), 2 deletions(-)
Can you please rebase against u-boot-x86/master and re-submit
Thanks,
Graeme
^ permalink raw reply [flat|nested] 7+ messages in thread
* [U-Boot] [PATCH v3] x86: Fix how the location of the realmode and bios blobs are calculated
2011-11-12 10:21 ` Graeme Russ
@ 2011-11-13 2:31 ` Gabe Black
2011-11-13 11:43 ` Graeme Russ
0 siblings, 1 reply; 7+ messages in thread
From: Gabe Black @ 2011-11-13 2:31 UTC (permalink / raw)
To: u-boot
From: Gabe Black <gabeblack@google.com>
There are two blobs embedded into the u-boot image which are linked to run
at an address which is different from where they actually end up in the
ROM, one called "realmode" and one called "bios". There are realmode_setup
and bios_setup functions which prepare those blobs by copying them into the
location they're supposed to run from, among other things.
During u-boot relocation from ROM to RAM, the text and a few data segments
are copied over. The realmode and bios sections are not copied, and so the
only place they can be read from is their original location in the ROM.
Looking specifically at the bios blob, there are symbols defined in the
linker script called __bios_start and __bios_size which are defined to be
the start and size of the blob in the ROM.
In the bios_setup function, there seem to be two mistakes happening. First,
the offset from ROM to RAM is being added to __bios_start which implies that
this code expects to use the copy moved to RAM. No such copy is made, so
that's wrong. More subtly, when u-boot relocates itself, it goes through
all of the relocations stored in .rel.dyn and fixes them up. This has the
effect of transforming the __bios_start reference in bios_setup so that it
refers to the version in RAM (if one existed) instead of the one in ROM. To
correct for that, the offset actually needs to be subtracted out again to
translate the address back into the ROM.
The net effect is that for both blobs, a + needs to be changed to a -.
Signed-off-by: Gabe Black <gabeblack@chromium.org>
---
Changes in v2:
Update x86 tag.
Changes in v3:
Rebase onto the x86 repository.
arch/x86/lib/bios_setup.c | 6 +++++-
arch/x86/lib/realmode.c | 6 +++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/arch/x86/lib/bios_setup.c b/arch/x86/lib/bios_setup.c
index 053280b..0dfe4a1 100644
--- a/arch/x86/lib/bios_setup.c
+++ b/arch/x86/lib/bios_setup.c
@@ -78,7 +78,11 @@ static void setvector(int vector, u16 segment, void *handler)
int bios_setup(void)
{
- ulong bios_start = (ulong)&__bios_start + gd->reloc_off;
+ /*
+ * The BIOS section is not relocated and still in the ROM. The
+ * __bios_start symbol was adjusted, though, so adjust it back.
+ */
+ ulong bios_start = (ulong)&__bios_start - gd->reloc_off;
ulong bios_size = (ulong)&__bios_size;
static int done;
diff --git a/arch/x86/lib/realmode.c b/arch/x86/lib/realmode.c
index 5a525ee..bf0d0aa 100644
--- a/arch/x86/lib/realmode.c
+++ b/arch/x86/lib/realmode.c
@@ -30,7 +30,11 @@
int realmode_setup(void)
{
- ulong realmode_start = (ulong)&__realmode_start + gd->reloc_off;
+ /*
+ * The realmode section is not relocated and still in the ROM. The
+ * __realmode_start symbol was adjusted, though, so adjust it back.
+ */
+ ulong realmode_start = (ulong)&__realmode_start - gd->reloc_off;
ulong realmode_size = (ulong)&__realmode_size;
/* copy the realmode switch code */
--
1.7.3.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [U-Boot] [PATCH v3] x86: Fix how the location of the realmode and bios blobs are calculated
2011-11-13 2:31 ` [U-Boot] [PATCH v3] " Gabe Black
@ 2011-11-13 11:43 ` Graeme Russ
0 siblings, 0 replies; 7+ messages in thread
From: Graeme Russ @ 2011-11-13 11:43 UTC (permalink / raw)
To: u-boot
On 13/11/11 13:31, Gabe Black wrote:
> From: Gabe Black <gabeblack@google.com>
>
> There are two blobs embedded into the u-boot image which are linked to run
> at an address which is different from where they actually end up in the
> ROM, one called "realmode" and one called "bios". There are realmode_setup
> and bios_setup functions which prepare those blobs by copying them into the
> location they're supposed to run from, among other things.
>
> During u-boot relocation from ROM to RAM, the text and a few data segments
> are copied over. The realmode and bios sections are not copied, and so the
> only place they can be read from is their original location in the ROM.
> Looking specifically at the bios blob, there are symbols defined in the
> linker script called __bios_start and __bios_size which are defined to be
> the start and size of the blob in the ROM.
>
> In the bios_setup function, there seem to be two mistakes happening. First,
> the offset from ROM to RAM is being added to __bios_start which implies that
> this code expects to use the copy moved to RAM. No such copy is made, so
> that's wrong. More subtly, when u-boot relocates itself, it goes through
> all of the relocations stored in .rel.dyn and fixes them up. This has the
> effect of transforming the __bios_start reference in bios_setup so that it
> refers to the version in RAM (if one existed) instead of the one in ROM. To
> correct for that, the offset actually needs to be subtracted out again to
> translate the address back into the ROM.
>
> The net effect is that for both blobs, a + needs to be changed to a -.
>
> Signed-off-by: Gabe Black <gabeblack@chromium.org>
> ---
Applied to u-boot-x86/master
Thanks,
Graeme
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-11-13 11:43 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-08 6:49 [U-Boot] [PATCH] [x86] Fix how the location of the realmode and bios blobs are calculated Gabe Black
2011-11-08 10:28 ` Graeme Russ
2011-11-08 22:19 ` [U-Boot] [PATCH v2] x86: " Gabe Black
2011-11-09 9:58 ` Graeme Russ
2011-11-12 10:21 ` Graeme Russ
2011-11-13 2:31 ` [U-Boot] [PATCH v3] " Gabe Black
2011-11-13 11:43 ` Graeme Russ
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox