Skip to contentSkip to conversation

docs/firmware: Update FW_JUMP documentation

PATCH Superseded Nylon Chen 6 participants 7 messages Sep 13, 2022 – Sep 14, 2022

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Nylon Chen

author
#0 lore raw

PATCH 1/1 docs/firmware: Update FW_JUMP documentation

From: "Nylon.Chen" <[email protected]>

Add a tip for OpenSBI's Jump mode.

help user avoids the kernel overwritten.

---
 docs/firmware/fw_jump.md | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
docs/firmware/fw_jump.md +18 -0
index 35a4301..c20d722 100644
@@ -40,6 +40,24 @@ follows:
   the booting stage following the OpenSBI firmware. If this option is not
   provided, then the OpenSBI firmware will pass the FDT address passed by the
   previous booting stage to the next booting stage.
+  
+  If your *PLATFORM=generic* and your *FW_JUMP_FDT_ADDR* is default, you must check
+  your Linux size because Linux will be overwritten in OpneSBI's FDT copy loop.
+  You can use the following method.
+
+  ```
+  LAST_SECTION=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" | awk '{print $5,$3}'\
+  | sort -rfu | head -n 1 | awk '{split($0,addr," ");print addr[1]}'` \
+  && LAST_SECTION_SIZE=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" |awk '{print $5,$3}'\
+  | sort -rfu | head -n 1 | awk '{split($0,addr,"")}'` \
+  && OFFSET_ADDR=$(( 16#$LAST_SECTION_SIZE + 16#$LAST_SECTION)) \
+  && printf "The LMA of the last section of the Kernel is 0x%X\n" ${OFFSET_ADDR}
+  ```
+  
+  If the result is bigger than the default of FW_JUMP_FDT_ADDR(0x2200000), 
+  you must change it to avoid the problem of being overwritten.
+
+
 
 *FW_JUMP* Example
 -----------------
Signature · 1 line
2.36.1
#1 lore raw

PATCH 1/1 docs/firmware: Update FW_JUMP documentation

Quoted 6 lines · Nylon Chen

From: "Nylon.Chen" <[email protected]>

Add a tip for OpenSBI's Jump mode.

help user avoids the kernel overwritten.

Minor grammer error.

This can be:

"Add a tip for OpenSBI's FW_JUMP which helps users avoid overwriting the kernel."

Quoted 3 lines

Otherwise, it looks good to me.

Regards,
Anup

Quoted 41 lines
---
 docs/firmware/fw_jump.md | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
docs/firmware/fw_jump.md +18 -1
index 35a4301..c20d722 100644
@@ -40,6 +40,24 @@ follows:
   the booting stage following the OpenSBI firmware. If this option is not
   provided, then the OpenSBI firmware will pass the FDT address passed by the
   previous booting stage to the next booting stage.
+
+  If your *PLATFORM=generic* and your *FW_JUMP_FDT_ADDR* is default, you must check
+  your Linux size because Linux will be overwritten in OpneSBI's FDT copy loop.
+  You can use the following method.
+
+  ```
+  LAST_SECTION=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" | awk '{print $5,$3}'\
+  | sort -rfu | head -n 1 | awk '{split($0,addr," ");print addr[1]}'` \
+  && LAST_SECTION_SIZE=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" |awk '{print $5,$3}'\
+  | sort -rfu | head -n 1 | awk '{split($0,addr,"")}'` \
+  && OFFSET_ADDR=$(( 16#$LAST_SECTION_SIZE + 16#$LAST_SECTION)) \
+  && printf "The LMA of the last section of the Kernel is 0x%X\n" ${OFFSET_ADDR}
+  ```
+
+  If the result is bigger than the default of FW_JUMP_FDT_ADDR(0x2200000),
+  you must change it to avoid the problem of being overwritten.
+
+
 
 *FW_JUMP* Example
 -----------------
--

2.36.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#2 lore raw

PATCH 1/1 docs/firmware: Update FW_JUMP documentation

In reply to Nylon Chen
Quoted 9 lines · Nylon Chen

From: "Nylon.Chen" <[email protected]>

Add a tip for OpenSBI's Jump mode.

help user avoids the kernel overwritten.

One more thing, you don't need two Signed-off-by for yourself. Just keep one.

Regards,
Anup

Quoted 41 lines
---
 docs/firmware/fw_jump.md | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
docs/firmware/fw_jump.md +18 -1
index 35a4301..c20d722 100644
@@ -40,6 +40,24 @@ follows:
   the booting stage following the OpenSBI firmware. If this option is not
   provided, then the OpenSBI firmware will pass the FDT address passed by the
   previous booting stage to the next booting stage.
+
+  If your *PLATFORM=generic* and your *FW_JUMP_FDT_ADDR* is default, you must check
+  your Linux size because Linux will be overwritten in OpneSBI's FDT copy loop.
+  You can use the following method.
+
+  ```
+  LAST_SECTION=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" | awk '{print $5,$3}'\
+  | sort -rfu | head -n 1 | awk '{split($0,addr," ");print addr[1]}'` \
+  && LAST_SECTION_SIZE=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" |awk '{print $5,$3}'\
+  | sort -rfu | head -n 1 | awk '{split($0,addr,"")}'` \
+  && OFFSET_ADDR=$(( 16#$LAST_SECTION_SIZE + 16#$LAST_SECTION)) \
+  && printf "The LMA of the last section of the Kernel is 0x%X\n" ${OFFSET_ADDR}
+  ```
+
+  If the result is bigger than the default of FW_JUMP_FDT_ADDR(0x2200000),
+  you must change it to avoid the problem of being overwritten.
+
+
 
 *FW_JUMP* Example
 -----------------
--

2.36.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#3 lore raw

PATCH 1/1 docs/firmware: Update FW_JUMP documentation

In reply to Nylon Chen

(Resent to avoid mailing list error wrt HTML messages. Sorry.)

Quoted 17 lines · Nylon Chen

From: "Nylon.Chen" <[email protected]>

Add a tip for OpenSBI's Jump mode.

help user avoids the kernel overwritten.

---
 docs/firmware/fw_jump.md | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
docs/firmware/fw_jump.md +0 -0
index 35a4301..c20d722 100644

docs/firmware/fw_jump.md follows: · line 45

Quoted 6 lines
docs/firmware/fw_jump.md +3 -0
@@ -40,6 +40,24 @@ follows:
   the booting stage following the OpenSBI firmware. If this option is not
   provided, then the OpenSBI firmware will pass the FDT address passed by the
   previous booting stage to the next booting stage.
+  
+  If your *PLATFORM=generic* and your *FW_JUMP_FDT_ADDR* is default, you must check
+  your Linux size because Linux will be overwritten in OpneSBI's FDT copy loop.

Typo: OpneSBI -> OpenSBI

docs/firmware/fw_jump.md follows: · line 55

Quoted 10 lines
docs/firmware/fw_jump.md +10 -0
+  You can use the following method.
+
+  ```
+  LAST_SECTION=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" | awk '{print $5,$3}'\
+  | sort -rfu | head -n 1 | awk '{split($0,addr," ");print addr[1]}'` \
+  && LAST_SECTION_SIZE=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" |awk '{print $5,$3}'\
+  | sort -rfu | head -n 1 | awk '{split($0,addr,"")}'` \
+  && OFFSET_ADDR=$(( 16#$LAST_SECTION_SIZE + 16#$LAST_SECTION)) \
+  && printf "The LMA of the last section of the Kernel is 0x%X\n" ${OFFSET_ADDR}
+  ```

I couldn't get this particular shell command/script to work on a random kernel I've built. LAST_SECTION_SIZE seems to be the empty string, which gives the following error:

bash: 16#: invalid integer constant (error token is "16#")

I'm not sure how this command works, so I have pasted the output of objdump at the bottom of this message. Hopefully it should help with fixing it.

Also, It seems that the intention is to parse the output of 'objdump -h vmlinux' and find the maximum value of LMA + Size among the sections, which in my case corresponds to the .bss section. It would be helpful if there's an explanation for this code, so that those reading the documentation know what they are doing.

Thanks,
dram

docs/firmware/fw_jump.md follows: · line 63

Quoted 7 lines
docs/firmware/fw_jump.md +4 -0
+  If the result is bigger than the default of FW_JUMP_FDT_ADDR(0x2200000), 
+  you must change it to avoid the problem of being overwritten.
+
+
 
 *FW_JUMP* Example
 -----------------

Output of 'riscv64-unknown-linux-gnu-objdump -h vmlinux':

vmlinux: file format elf64-littleriscv

Sections:

Idx Name          Size      VMA               LMA               File off  Algn
  0 .head.text    0000019a  ffffffff80000000  0000000000000000  00001000  2**3

CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .text 005bca24 ffffffff80001000 0000000000001000 00002000 2**3
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .init.text 0002a3e6 ffffffff80600000 0000000000600000 00600000 2**21
CONTENTS, ALLOC, LOAD, READONLY, CODE
3 .exit.text 00001402 ffffffff8062a3e8 000000000062a3e8 0062a3e8 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
4 .init.data 00013da0 ffffffff80800000 0000000000800000 0062c000 2**12
CONTENTS, ALLOC, LOAD, DATA
5 .data..percpu 00008178 ffffffff80814000 0000000000814000 00640000 2**6
CONTENTS, ALLOC, LOAD, DATA
6 .alternative 00000750 ffffffff8081c178 000000000081c178 00648178 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
7 .rodata 0015cbb8 ffffffff80a00000 0000000000a00000 00649000 2**6
CONTENTS, ALLOC, LOAD, DATA
8 .pci_fixup 00003ba0 ffffffff80b5cbb8 0000000000b5cbb8 007a5bb8 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
9 __ksymtab 00016650 ffffffff80b60758 0000000000b60758 007a9758 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
10 __ksymtab_gpl 000166e0 ffffffff80b76da8 0000000000b76da8 007bfda8 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
11 __ksymtab_strings 00022833 ffffffff80b8d488 0000000000b8d488 007d6488 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
12 __param 00002170 ffffffff80bafcc0 0000000000bafcc0 007f8cc0 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
13 __modver 000001f8 ffffffff80bb1e30 0000000000bb1e30 007fae30 2**3
CONTENTS, ALLOC, LOAD, DATA
14 __ex_table 000019ec ffffffff80bb2028 0000000000bb2028 007fb028 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
15 .notes 00000054 ffffffff80bb3a14 0000000000bb3a14 007fca14 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
16 .srodata 00000960 ffffffff80c00000 0000000000c00000 007fd000 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
17 .data 000ba460 ffffffff80e00000 0000000000e00000 007fe000 2**12
CONTENTS, ALLOC, LOAD, DATA
18 __bug_table 00015798 ffffffff80eba460 0000000000eba460 008b8460 2**0
CONTENTS, ALLOC, LOAD, DATA
19 .sdata 00000934 ffffffff80ecfbf8 0000000000ecfbf8 008cdbf8 2**3
CONTENTS, ALLOC, LOAD, DATA
20 .sbss 00001dac ffffffff80ed1000 0000000000ed1000 008ce52c 2**6
ALLOC
21 .bss 0005fc28 ffffffff80ed3000 0000000000ed3000 008ce52c 2**12
ALLOC
22 .debug_aranges 000157b0 0000000000000000 0000000000000000 008ce530 2**4
CONTENTS, READONLY, DEBUGGING, OCTETS
23 .debug_info 05c15652 0000000000000000 0000000000000000 008e3ce0 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
24 .debug_abbrev 002ec6e9 0000000000000000 0000000000000000 064f9332 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
25 .debug_line 0127e177 0000000000000000 0000000000000000 067e5a1b 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
26 .debug_frame 001c9e50 0000000000000000 0000000000000000 07a63b98 2**3
CONTENTS, READONLY, DEBUGGING, OCTETS
27 .debug_str 002287ec 0000000000000000 0000000000000000 07c2d9e8 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
28 .debug_line_str 0000af3c 0000000000000000 0000000000000000 07e561d4 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
29 .debug_loclists 01367310 0000000000000000 0000000000000000 07e61110 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
30 .debug_rnglists 00552cc6 0000000000000000 0000000000000000 091c8420 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
31 .comment 00000012 0000000000000000 0000000000000000 0971b0e6 2**0
CONTENTS, READONLY
32 .riscv.attributes 00000037 0000000000000000 0000000000000000 0971b0f8 2**0
CONTENTS, READONLY

#4 lore raw

PATCH 1/1 docs/firmware: Update FW_JUMP documentation

In reply to Nylon Chen
Quoted 18 lines · Nylon Chen

From: "Nylon.Chen" <[email protected]>

Add a tip for OpenSBI's Jump mode.

help user avoids the kernel overwritten.

---
docs/firmware/fw_jump.md | 18 ++++++++++++++++++

1 file changed, 18 insertions(+)
docs/firmware/fw_jump.md +0 -0
index 35a4301..c20d722 100644

docs/firmware/fw_jump.md follows: · line 46

Quoted 7 lines
docs/firmware/fw_jump.md +4 -0
@@ -40,6 +40,24 @@ follows:
  the booting stage following the OpenSBI firmware. If this option is not
  provided, then the OpenSBI firmware will pass the FDT address passed by the
  previous booting stage to the next booting stage.
+  
+  If your *PLATFORM=generic* and your *FW_JUMP_FDT_ADDR* is default, you must check
+  your Linux size because Linux will be overwritten in OpneSBI's FDT copy loop.
+  You can use the following method.

Use kernel not Linux, OpenSBI should be OS-agnostic.

docs/firmware/fw_jump.md follows: · line 55

Quoted 9 lines
docs/firmware/fw_jump.md +9 -0
+
+  ```
+  LAST_SECTION=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" | awk '{print $5,$3}'\
+  | sort -rfu | head -n 1 | awk '{split($0,addr," ");print addr[1]}'` \
+  && LAST_SECTION_SIZE=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" |awk '{print $5,$3}'\
+  | sort -rfu | head -n 1 | awk '{split($0,addr,"")}'` \
+  && OFFSET_ADDR=$(( 16#$LAST_SECTION_SIZE + 16#$LAST_SECTION)) \
+  && printf "The LMA of the last section of the Kernel is 0x%X\n" ${OFFSET_ADDR}
+  ```

This uses GNU names for the tools, so won?t work with LLVM.

Quoted 16 lines
docs/firmware/fw_jump.md +5 -1
+  
+  If the result is bigger than the default of FW_JUMP_FDT_ADDR(0x2200000), 
+  you must change it to avoid the problem of being overwritten.
+
+
 
 *FW_JUMP* Example
-----------------
Signature · 7 lines
2.36.1


-- 
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
#5 lore raw

PATCH 1/1 docs/firmware: Update FW_JUMP documentation

In reply to Nylon Chen
Quoted 17 lines · Nylon Chen

From: "Nylon.Chen" <[email protected]>

Add a tip for OpenSBI's Jump mode.

help user avoids the kernel overwritten.

---
 docs/firmware/fw_jump.md | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
docs/firmware/fw_jump.md +0 -0
index 35a4301..c20d722 100644

docs/firmware/fw_jump.md follows: · line 46

Quoted 7 lines
docs/firmware/fw_jump.md +4 -0
@@ -40,6 +40,24 @@ follows:
   the booting stage following the OpenSBI firmware. If this option is not
   provided, then the OpenSBI firmware will pass the FDT address passed by the
   previous booting stage to the next booting stage.
+  
+  If your *PLATFORM=generic* and your *FW_JUMP_FDT_ADDR* is default, you must check
+  your Linux size because Linux will be overwritten in OpneSBI's FDT copy loop.
+  You can use the following method.

Ensure FW_JUMP_FDT_ADDR is set high enough to avoid overwriting the kernel. The following method may be used to check if the default (0x2200000) is sufficient:

docs/firmware/fw_jump.md follows: · line 55

Quoted 9 lines
docs/firmware/fw_jump.md +9 -0
+
+  ```
+  LAST_SECTION=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" | awk '{print $5,$3}'\
+  | sort -rfu | head -n 1 | awk '{split($0,addr," ");print addr[1]}'` \
+  && LAST_SECTION_SIZE=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" |awk '{print $5,$3}'\
+  | sort -rfu | head -n 1 | awk '{split($0,addr,"")}'` \
+  && OFFSET_ADDR=$(( 16#$LAST_SECTION_SIZE + 16#$LAST_SECTION)) \
+  && printf "The LMA of the last section of the Kernel is 0x%X\n" ${OFFSET_ADDR}
+  ```

Once we've decided to use awk, we might as well use all of it

${CROSS_COMPILE}objdump -h $KERNEL_ELF | sort -k 5,5 |

        awk '/^ +[0-9]+ /                                                       \
        { s = strtonum("0x"$3) + strtonum("0x"$5) }                             \
        END {                                                                   \
                if (s > 0x2200000) {                                            \
                        print "fdt overlaps kernel, increase FW_JUMP_FDT_ADDR"; \
                        exit(1)                                                 \
                }                                                               \
        }'

Thanks,
drew

Quoted 16 lines
docs/firmware/fw_jump.md +5 -0
+  
+  If the result is bigger than the default of FW_JUMP_FDT_ADDR(0x2200000), 
+  you must change it to avoid the problem of being overwritten.
+
+
 
 *FW_JUMP* Example
 -----------------
Signature · 7 lines
2.36.1


-- 
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
#6 lore raw

PATCH 1/1 docs/firmware: Update FW_JUMP documentation

Quoted 43 lines · Andrew Jones
Quoted 17 lines · Nylon Chen

From: "Nylon.Chen" <[email protected]>

Add a tip for OpenSBI's Jump mode.

help user avoids the kernel overwritten.

---
docs/firmware/fw_jump.md | 18 ++++++++++++++++++

1 file changed, 18 insertions(+)
docs/firmware/fw_jump.md +0 -0
index 35a4301..c20d722 100644
@@ -40,6 +40,24 @@ follows:
Quoted 7 lines

the booting stage following the OpenSBI firmware. If this option is not provided, then the OpenSBI firmware will pass the FDT address passed by the previous booting stage to the next booting stage.
+
+ If your *PLATFORM=generic* and your *FW_JUMP_FDT_ADDR* is default, you must check
+ your Linux size because Linux will be overwritten in OpneSBI's FDT copy loop.
+ You can use the following method.

Ensure FW_JUMP_FDT_ADDR is set high enough to avoid overwriting the kernel. The following method may be used to check if the default (0x2200000) is sufficient:

Quoted 9 lines

+
+ ```
+ LAST_SECTION=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" | awk '{print $5,$3}'\
+ | sort -rfu | head -n 1 | awk '{split($0,addr," ");print addr[1]}'` \
+ && LAST_SECTION_SIZE=`${CROSS_COMPILE}objdump -h vmlinux | grep "00*" |awk '{print $5,$3}'\
+ | sort -rfu | head -n 1 | awk '{split($0,addr,"")}'` \
+ && OFFSET_ADDR=$(( 16#$LAST_SECTION_SIZE + 16#$LAST_SECTION)) \
+ && printf "The LMA of the last section of the Kernel is 0x%X\n" ${OFFSET_ADDR}
+ ```

Once we've decided to use awk, we might as well use all of it

Quoted 9 lines

${CROSS_COMPILE}objdump -h $KERNEL_ELF | sort -k 5,5 | awk '/^ +[0-9]+ / \
{ s = strtonum("0x"$3) + strtonum("0x"$5) } \
END { \
if (s > 0x2200000) { \
print "fdt overlaps kernel, increase FW_JUMP_FDT_ADDR"; \
exit(1) \
} \
}'

strtonum is a GNU awk extension that isn?t in One True Awk as used by FreeBSD and macOS.

Jess

Quoted 24 lines

Thanks,
drew

Quoted 16 lines

+
+ If the result is bigger than the default of FW_JUMP_FDT_ADDR(0x2200000),
+ you must change it to avoid the problem of being overwritten.

docs/firmware/fw_jump.md +2 -0
+
+

*FW_JUMP* Example
-----------------

Signature · 7 lines
2.36.1


-- 
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Signature · 3 lines
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi