diff mbox series

[v4] firmware: remove FW_TEXT_START

Message ID 20240408153013.653350-1-wxjstz@126.com
State Accepted
Headers show
Series [v4] firmware: remove FW_TEXT_START | expand

Commit Message

Xiang W April 8, 2024, 3:27 p.m. UTC
Now opensbi can run at any address via dynamic relocation. We can
remove FW_TEXT_START.

Signed-off-by: Xiang W <wxjstz@126.com>
---

v4 changes:
- only remove FW_TEXT_START by anup's suggestion

 docs/firmware/fw.md                |  2 --
 docs/firmware/fw_jump.md           |  4 ++--
 docs/firmware/fw_payload.md        |  6 +++---
 docs/platform/generic.md           | 11 +++--------
 firmware/fw_base.S                 |  4 +---
 firmware/fw_base.ldS               |  3 +--
 firmware/fw_payload.elf.ldS        |  2 +-
 firmware/objects.mk                |  4 ----
 firmware/payloads/test.elf.ldS     |  2 +-
 platform/fpga/ariane/objects.mk    |  1 -
 platform/fpga/openpiton/objects.mk |  1 -
 platform/generic/objects.mk        |  3 +--
 platform/kendryte/k210/objects.mk  |  1 -
 platform/nuclei/ux600/objects.mk   |  1 -
 platform/template/objects.mk       |  9 ++-------
 15 files changed, 15 insertions(+), 39 deletions(-)

Comments

Anup Patel April 10, 2024, 5:18 a.m. UTC | #1
On Mon, Apr 8, 2024 at 9:01 PM Xiang W <wxjstz@126.com> wrote:
>
> Now opensbi can run at any address via dynamic relocation. We can
> remove FW_TEXT_START.
>
> Signed-off-by: Xiang W <wxjstz@126.com>

LGTM.

Reviewed-by: Anup Patel <anup@brainfault.org>
Tested-by: Anup Patel <anup@brainfault.org>

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

> ---
>
> v4 changes:
> - only remove FW_TEXT_START by anup's suggestion
>
>  docs/firmware/fw.md                |  2 --
>  docs/firmware/fw_jump.md           |  4 ++--
>  docs/firmware/fw_payload.md        |  6 +++---
>  docs/platform/generic.md           | 11 +++--------
>  firmware/fw_base.S                 |  4 +---
>  firmware/fw_base.ldS               |  3 +--
>  firmware/fw_payload.elf.ldS        |  2 +-
>  firmware/objects.mk                |  4 ----
>  firmware/payloads/test.elf.ldS     |  2 +-
>  platform/fpga/ariane/objects.mk    |  1 -
>  platform/fpga/openpiton/objects.mk |  1 -
>  platform/generic/objects.mk        |  3 +--
>  platform/kendryte/k210/objects.mk  |  1 -
>  platform/nuclei/ux600/objects.mk   |  1 -
>  platform/template/objects.mk       |  9 ++-------
>  15 files changed, 15 insertions(+), 39 deletions(-)
>
> diff --git a/docs/firmware/fw.md b/docs/firmware/fw.md
> index 2f4deb5..3cc0262 100644
> --- a/docs/firmware/fw.md
> +++ b/docs/firmware/fw.md
> @@ -61,8 +61,6 @@ Firmware Configuration and Compilation
>  All firmware types support the following common compile time configuration
>  parameters:
>
> -* **FW_TEXT_START** - Defines the execution address of the OpenSBI firmware.
> -  This configuration parameter is mandatory.
>  * **FW_FDT_PATH** - Path to an external flattened device tree binary file to
>    be embedded in the *.rodata* section of the final firmware. If this option
>    is not provided then the firmware will expect the FDT to be passed as an
> diff --git a/docs/firmware/fw_jump.md b/docs/firmware/fw_jump.md
> index 2ee6b29..66be016 100644
> --- a/docs/firmware/fw_jump.md
> +++ b/docs/firmware/fw_jump.md
> @@ -35,7 +35,7 @@ follows:
>    At least one of *FW_JUMP_ADDR* and *FW_JUMP_OFFSET* (see below) should be
>    defined. Compilation errors will result from not defining one of them.
>
> -* **FW_JUMP_OFFSET** - Address offset from the *FW_TEXT_START* where the
> +* **FW_JUMP_OFFSET** - Address offset from the opensbi load address where the
>    entry point of the next booting stage is located. This offset is used as
>    relocatable address of the next booting stage entry point. If *FW_JUMP_ADDR*
>    is also defined, the firmware will prefer *FW_JUMP_ADDR*.
> @@ -62,7 +62,7 @@ follows:
>    echo fdt overlaps kernel, increase FW_JUMP_FDT_ADDR
>    ```
>
> -* **FW_JUMP_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
> +* **FW_JUMP_FDT_OFFSET** - Address offset from the opensbi load address where
>    the FDT will be passed to the next booting stage. This offset is used
>    as relocatable address of the FDT passed to the next booting stage. If
>    *FW_JUMP_FDT_ADDR* is also defined, the firmware will prefer
> diff --git a/docs/firmware/fw_payload.md b/docs/firmware/fw_payload.md
> index a67fc50..d25be60 100644
> --- a/docs/firmware/fw_payload.md
> +++ b/docs/firmware/fw_payload.md
> @@ -36,8 +36,8 @@ options. These configuration parameters can be defined using either the top
>  level `make` command line or the target platform *objects.mk* configuration
>  file. The parameters currently defined are as follows:
>
> -* **FW_PAYLOAD_OFFSET** - Offset from *FW_TEXT_START* where the payload binary
> -  will be linked in the final *FW_PAYLOAD* firmware binary image. This
> +* **FW_PAYLOAD_OFFSET** - Offset from the opensbi load address where the payload
> +  binary will be linked in the final *FW_PAYLOAD* firmware binary image. This
>    configuration parameter is mandatory if *FW_PAYLOAD_ALIGN* is not defined.
>    Compilation errors will result from an incorrect definition of
>    *FW_PAYLOAD_OFFSET* or of *FW_PAYLOAD_ALIGN*, or if neither of these
> @@ -62,7 +62,7 @@ file. The parameters currently defined are as follows:
>    firmware will pass the FDT address passed by the previous booting stage
>    to the next booting stage.
>
> -* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
> +* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the opensbi load address where
>    the FDT will be passed to the next booting stage. This offset is used as
>    relocatable address of the FDT passed to the next booting stage. If
>    *FW_PAYLOAD_FDT_ADDR* is also defined, the firmware will prefer *FW_PAYLOAD_FDT_ADDR*.
> diff --git a/docs/platform/generic.md b/docs/platform/generic.md
> index c29eb04..709b436 100644
> --- a/docs/platform/generic.md
> +++ b/docs/platform/generic.md
> @@ -9,10 +9,9 @@ boards.
>
>  By default, the generic FDT platform makes following assumptions:
>
> -1. platform FW_TEXT_START is 0x80000000
> -2. platform features are default
> -3. platform stack size is default
> -4. platform has no quirks or work-arounds
> +1. platform features are default
> +2. platform stack size is default
> +3. platform has no quirks or work-arounds
>
>  The above assumptions (except 1) can be overridden by adding special platform
>  callbacks which will be called based on FDT root node compatible string.
> @@ -33,10 +32,6 @@ Users of the generic FDT platform will have to ensure that:
>  To build the platform-specific library and firmware images, provide the
>  *PLATFORM=generic* parameter to the top level `make` command.
>
> -For custom FW_TEXT_START, we can build the platform-specific library and
> -firmware images by passing *PLATFORM=generic FW_TEXT_START=<custom_text_start>*
> -parameter to the top level `make` command.
> -
>  Platform Options
>  ----------------
>
> diff --git a/firmware/fw_base.S b/firmware/fw_base.S
> index b950c0b..9f995a2 100644
> --- a/firmware/fw_base.S
> +++ b/firmware/fw_base.S
> @@ -53,9 +53,7 @@ _try_lottery:
>         bnez    a6, _wait_for_boot_hart
>
>         /* relocate the global table content */
> -       li      t0, FW_TEXT_START       /* link start */
> -       lla     t1, _fw_start           /* load start */
> -       sub     t2, t1, t0              /* load offset */
> +       lla     t2, _fw_start
>         lla     t0, __rel_dyn_start
>         lla     t1, __rel_dyn_end
>         beq     t0, t1, _relocate_done
> diff --git a/firmware/fw_base.ldS b/firmware/fw_base.ldS
> index fb47984..9d11db5 100644
> --- a/firmware/fw_base.ldS
> +++ b/firmware/fw_base.ldS
> @@ -7,8 +7,7 @@
>   *   Anup Patel <anup.patel@wdc.com>
>   */
>
> -       . = FW_TEXT_START;
> -       /* Don't add any section between FW_TEXT_START and _fw_start */
> +       /* Don't add any section before _fw_start */
>         PROVIDE(_fw_start = .);
>
>         . = ALIGN(0x1000); /* Need this to create proper sections */
> diff --git a/firmware/fw_payload.elf.ldS b/firmware/fw_payload.elf.ldS
> index f1a544b..94e1ac6 100644
> --- a/firmware/fw_payload.elf.ldS
> +++ b/firmware/fw_payload.elf.ldS
> @@ -15,7 +15,7 @@ SECTIONS
>         #include "fw_base.ldS"
>
>  #ifdef FW_PAYLOAD_OFFSET
> -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
> +       . = FW_PAYLOAD_OFFSET;
>  #else
>         . = ALIGN(FW_PAYLOAD_ALIGN);
>  #endif
> diff --git a/firmware/objects.mk b/firmware/objects.mk
> index e6b364b..a51ff65 100644
> --- a/firmware/objects.mk
> +++ b/firmware/objects.mk
> @@ -13,10 +13,6 @@ firmware-cflags-y +=
>  firmware-asflags-y +=
>  firmware-ldflags-y +=
>
> -ifdef FW_TEXT_START
> -firmware-genflags-y += -DFW_TEXT_START=$(FW_TEXT_START)
> -endif
> -
>  ifdef FW_FDT_PATH
>  firmware-genflags-y += -DFW_FDT_PATH=\"$(FW_FDT_PATH)\"
>  ifdef FW_FDT_PADDING
> diff --git a/firmware/payloads/test.elf.ldS b/firmware/payloads/test.elf.ldS
> index 2328a1b..08e008f 100644
> --- a/firmware/payloads/test.elf.ldS
> +++ b/firmware/payloads/test.elf.ldS
> @@ -13,7 +13,7 @@ ENTRY(_start)
>  SECTIONS
>  {
>  #ifdef FW_PAYLOAD_OFFSET
> -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
> +       . = FW_PAYLOAD_OFFSET;
>  #else
>         . = ALIGN(FW_PAYLOAD_ALIGN);
>  #endif
> diff --git a/platform/fpga/ariane/objects.mk b/platform/fpga/ariane/objects.mk
> index 83581ac..d1177f4 100644
> --- a/platform/fpga/ariane/objects.mk
> +++ b/platform/fpga/ariane/objects.mk
> @@ -17,7 +17,6 @@ platform-objs-y += platform.o
>  PLATFORM_RISCV_XLEN = 64
>
>  # Blobs to build
> -FW_TEXT_START=0x80000000
>  FW_JUMP=n
>
>  ifeq ($(PLATFORM_RISCV_XLEN), 32)
> diff --git a/platform/fpga/openpiton/objects.mk b/platform/fpga/openpiton/objects.mk
> index c8c345a..1a0ce0c 100644
> --- a/platform/fpga/openpiton/objects.mk
> +++ b/platform/fpga/openpiton/objects.mk
> @@ -16,7 +16,6 @@ platform-objs-y += platform.o
>  PLATFORM_RISCV_XLEN = 64
>
>  # Blobs to build
> -FW_TEXT_START=0x80000000
>  FW_JUMP=n
>
>  ifeq ($(PLATFORM_RISCV_XLEN), 32)
> diff --git a/platform/generic/objects.mk b/platform/generic/objects.mk
> index 85aa723..c215935 100644
> --- a/platform/generic/objects.mk
> +++ b/platform/generic/objects.mk
> @@ -15,14 +15,13 @@ platform-ldflags-y =
>
>  # Command for platform specific "make run"
>  platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \
> -  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.elf
> +  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.bin
>
>  # Objects to build
>  platform-objs-y += platform.o
>  platform-objs-y += platform_override_modules.o
>
>  # Blobs to build
> -FW_TEXT_START=0x80000000
>  FW_DYNAMIC=y
>  FW_JUMP=y
>  ifeq ($(PLATFORM_RISCV_XLEN), 32)
> diff --git a/platform/kendryte/k210/objects.mk b/platform/kendryte/k210/objects.mk
> index 1bfb898..efac3d2 100644
> --- a/platform/kendryte/k210/objects.mk
> +++ b/platform/kendryte/k210/objects.mk
> @@ -21,6 +21,5 @@ platform-varprefix-k210.o = dt_k210
>  platform-padding-k210.o = 2048
>
>  # Blobs to build
> -FW_TEXT_START=0x80000000
>  FW_PAYLOAD=y
>  FW_PAYLOAD_ALIGN=0x1000
> diff --git a/platform/nuclei/ux600/objects.mk b/platform/nuclei/ux600/objects.mk
> index 7c429e0..2753a7f 100644
> --- a/platform/nuclei/ux600/objects.mk
> +++ b/platform/nuclei/ux600/objects.mk
> @@ -22,7 +22,6 @@ platform-runcmd = xl_spike \
>  platform-objs-y += platform.o
>
>  # Blobs to build
> -FW_TEXT_START=0xA0000000
>  FW_DYNAMIC=y
>  FW_JUMP=y
>
> diff --git a/platform/template/objects.mk b/platform/template/objects.mk
> index b143cbc..f240a55 100644
> --- a/platform/template/objects.mk
> +++ b/platform/template/objects.mk
> @@ -41,9 +41,6 @@ platform-objs-y += platform.o
>  #
>  # platform-objs-y += <dt file name>.o
>
> -# Firmware load address configuration. This is mandatory.
> -FW_TEXT_START=0x80000000
> -
>  # Optional parameter for path to external FDT
>  # FW_FDT_PATH="path to platform flattened device tree file"
>
> @@ -69,8 +66,7 @@ FW_JUMP=<y|n>
>  # endif
>  # FW_JUMP_FDT_OFFSET=0x2200000
>  #
> -# You can use fixed address for jump firmware as an alternative option,
> -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
> +# You can use fixed address for jump firmware as an alternative option.
>  # SBI will prefer "<X>_ADDR" if both "<X>_ADDR" and "<X>_OFFSET" are
>  # defined
>  # ifeq ($(PLATFORM_RISCV_XLEN), 32)
> @@ -97,8 +93,7 @@ endif
>  # FW_PAYLOAD_PATH="path to next boot stage binary image file"
>  # FW_PAYLOAD_FDT_OFFSET=0x2200000
>  #
> -# You can use fixed address for payload firmware as an alternative option,
> -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
> +# You can use fixed address for payload firmware as an alternative option.
>  # SBI will prefer "FW_PAYLOAD_FDT_ADDR" if both "FW_PAYLOAD_FDT_OFFSET"
>  # and "FW_PAYLOAD_FDT_ADDR" are defined.
>  # FW_PAYLOAD_FDT_ADDR=0x82200000
> --
> 2.43.0
>
Clément Léger May 14, 2024, 4:28 p.m. UTC | #2
On 10/04/2024 07:18, Anup Patel wrote:
> On Mon, Apr 8, 2024 at 9:01 PM Xiang W <wxjstz@126.com> wrote:
>>
>> Now opensbi can run at any address via dynamic relocation. We can
>> remove FW_TEXT_START.
>>
>> Signed-off-by: Xiang W <wxjstz@126.com>
> 
> LGTM.
> 
> Reviewed-by: Anup Patel <anup@brainfault.org>
> Tested-by: Anup Patel <anup@brainfault.org>
> 
> Applied this patch to the riscv/opensbi repo.
> 
> Thanks,
> Anup

Hi Anup,

This patch seems to break spike support. The newly created ELF is not
marked as EXEC anymore but DYNAMIC and it fails with the following error:

spike: ../fesvr/elfloader.cc:45:
std::map<std::__cxx11::basic_string<char>, long unsigned int>
load_elf(const char*, memif_t*, reg_t*, unsigned int): Assertion
`IS_ELF_EXEC(*eh64)' failed.

Should we fixed OpenSBI or allow spike to load a DYNAMIC elf ?

Thanks,

Clément

> 
>> ---
>>
>> v4 changes:
>> - only remove FW_TEXT_START by anup's suggestion
>>
>>  docs/firmware/fw.md                |  2 --
>>  docs/firmware/fw_jump.md           |  4 ++--
>>  docs/firmware/fw_payload.md        |  6 +++---
>>  docs/platform/generic.md           | 11 +++--------
>>  firmware/fw_base.S                 |  4 +---
>>  firmware/fw_base.ldS               |  3 +--
>>  firmware/fw_payload.elf.ldS        |  2 +-
>>  firmware/objects.mk                |  4 ----
>>  firmware/payloads/test.elf.ldS     |  2 +-
>>  platform/fpga/ariane/objects.mk    |  1 -
>>  platform/fpga/openpiton/objects.mk |  1 -
>>  platform/generic/objects.mk        |  3 +--
>>  platform/kendryte/k210/objects.mk  |  1 -
>>  platform/nuclei/ux600/objects.mk   |  1 -
>>  platform/template/objects.mk       |  9 ++-------
>>  15 files changed, 15 insertions(+), 39 deletions(-)
>>
>> diff --git a/docs/firmware/fw.md b/docs/firmware/fw.md
>> index 2f4deb5..3cc0262 100644
>> --- a/docs/firmware/fw.md
>> +++ b/docs/firmware/fw.md
>> @@ -61,8 +61,6 @@ Firmware Configuration and Compilation
>>  All firmware types support the following common compile time configuration
>>  parameters:
>>
>> -* **FW_TEXT_START** - Defines the execution address of the OpenSBI firmware.
>> -  This configuration parameter is mandatory.
>>  * **FW_FDT_PATH** - Path to an external flattened device tree binary file to
>>    be embedded in the *.rodata* section of the final firmware. If this option
>>    is not provided then the firmware will expect the FDT to be passed as an
>> diff --git a/docs/firmware/fw_jump.md b/docs/firmware/fw_jump.md
>> index 2ee6b29..66be016 100644
>> --- a/docs/firmware/fw_jump.md
>> +++ b/docs/firmware/fw_jump.md
>> @@ -35,7 +35,7 @@ follows:
>>    At least one of *FW_JUMP_ADDR* and *FW_JUMP_OFFSET* (see below) should be
>>    defined. Compilation errors will result from not defining one of them.
>>
>> -* **FW_JUMP_OFFSET** - Address offset from the *FW_TEXT_START* where the
>> +* **FW_JUMP_OFFSET** - Address offset from the opensbi load address where the
>>    entry point of the next booting stage is located. This offset is used as
>>    relocatable address of the next booting stage entry point. If *FW_JUMP_ADDR*
>>    is also defined, the firmware will prefer *FW_JUMP_ADDR*.
>> @@ -62,7 +62,7 @@ follows:
>>    echo fdt overlaps kernel, increase FW_JUMP_FDT_ADDR
>>    ```
>>
>> -* **FW_JUMP_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
>> +* **FW_JUMP_FDT_OFFSET** - Address offset from the opensbi load address where
>>    the FDT will be passed to the next booting stage. This offset is used
>>    as relocatable address of the FDT passed to the next booting stage. If
>>    *FW_JUMP_FDT_ADDR* is also defined, the firmware will prefer
>> diff --git a/docs/firmware/fw_payload.md b/docs/firmware/fw_payload.md
>> index a67fc50..d25be60 100644
>> --- a/docs/firmware/fw_payload.md
>> +++ b/docs/firmware/fw_payload.md
>> @@ -36,8 +36,8 @@ options. These configuration parameters can be defined using either the top
>>  level `make` command line or the target platform *objects.mk* configuration
>>  file. The parameters currently defined are as follows:
>>
>> -* **FW_PAYLOAD_OFFSET** - Offset from *FW_TEXT_START* where the payload binary
>> -  will be linked in the final *FW_PAYLOAD* firmware binary image. This
>> +* **FW_PAYLOAD_OFFSET** - Offset from the opensbi load address where the payload
>> +  binary will be linked in the final *FW_PAYLOAD* firmware binary image. This
>>    configuration parameter is mandatory if *FW_PAYLOAD_ALIGN* is not defined.
>>    Compilation errors will result from an incorrect definition of
>>    *FW_PAYLOAD_OFFSET* or of *FW_PAYLOAD_ALIGN*, or if neither of these
>> @@ -62,7 +62,7 @@ file. The parameters currently defined are as follows:
>>    firmware will pass the FDT address passed by the previous booting stage
>>    to the next booting stage.
>>
>> -* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
>> +* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the opensbi load address where
>>    the FDT will be passed to the next booting stage. This offset is used as
>>    relocatable address of the FDT passed to the next booting stage. If
>>    *FW_PAYLOAD_FDT_ADDR* is also defined, the firmware will prefer *FW_PAYLOAD_FDT_ADDR*.
>> diff --git a/docs/platform/generic.md b/docs/platform/generic.md
>> index c29eb04..709b436 100644
>> --- a/docs/platform/generic.md
>> +++ b/docs/platform/generic.md
>> @@ -9,10 +9,9 @@ boards.
>>
>>  By default, the generic FDT platform makes following assumptions:
>>
>> -1. platform FW_TEXT_START is 0x80000000
>> -2. platform features are default
>> -3. platform stack size is default
>> -4. platform has no quirks or work-arounds
>> +1. platform features are default
>> +2. platform stack size is default
>> +3. platform has no quirks or work-arounds
>>
>>  The above assumptions (except 1) can be overridden by adding special platform
>>  callbacks which will be called based on FDT root node compatible string.
>> @@ -33,10 +32,6 @@ Users of the generic FDT platform will have to ensure that:
>>  To build the platform-specific library and firmware images, provide the
>>  *PLATFORM=generic* parameter to the top level `make` command.
>>
>> -For custom FW_TEXT_START, we can build the platform-specific library and
>> -firmware images by passing *PLATFORM=generic FW_TEXT_START=<custom_text_start>*
>> -parameter to the top level `make` command.
>> -
>>  Platform Options
>>  ----------------
>>
>> diff --git a/firmware/fw_base.S b/firmware/fw_base.S
>> index b950c0b..9f995a2 100644
>> --- a/firmware/fw_base.S
>> +++ b/firmware/fw_base.S
>> @@ -53,9 +53,7 @@ _try_lottery:
>>         bnez    a6, _wait_for_boot_hart
>>
>>         /* relocate the global table content */
>> -       li      t0, FW_TEXT_START       /* link start */
>> -       lla     t1, _fw_start           /* load start */
>> -       sub     t2, t1, t0              /* load offset */
>> +       lla     t2, _fw_start
>>         lla     t0, __rel_dyn_start
>>         lla     t1, __rel_dyn_end
>>         beq     t0, t1, _relocate_done
>> diff --git a/firmware/fw_base.ldS b/firmware/fw_base.ldS
>> index fb47984..9d11db5 100644
>> --- a/firmware/fw_base.ldS
>> +++ b/firmware/fw_base.ldS
>> @@ -7,8 +7,7 @@
>>   *   Anup Patel <anup.patel@wdc.com>
>>   */
>>
>> -       . = FW_TEXT_START;
>> -       /* Don't add any section between FW_TEXT_START and _fw_start */
>> +       /* Don't add any section before _fw_start */
>>         PROVIDE(_fw_start = .);
>>
>>         . = ALIGN(0x1000); /* Need this to create proper sections */
>> diff --git a/firmware/fw_payload.elf.ldS b/firmware/fw_payload.elf.ldS
>> index f1a544b..94e1ac6 100644
>> --- a/firmware/fw_payload.elf.ldS
>> +++ b/firmware/fw_payload.elf.ldS
>> @@ -15,7 +15,7 @@ SECTIONS
>>         #include "fw_base.ldS"
>>
>>  #ifdef FW_PAYLOAD_OFFSET
>> -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
>> +       . = FW_PAYLOAD_OFFSET;
>>  #else
>>         . = ALIGN(FW_PAYLOAD_ALIGN);
>>  #endif
>> diff --git a/firmware/objects.mk b/firmware/objects.mk
>> index e6b364b..a51ff65 100644
>> --- a/firmware/objects.mk
>> +++ b/firmware/objects.mk
>> @@ -13,10 +13,6 @@ firmware-cflags-y +=
>>  firmware-asflags-y +=
>>  firmware-ldflags-y +=
>>
>> -ifdef FW_TEXT_START
>> -firmware-genflags-y += -DFW_TEXT_START=$(FW_TEXT_START)
>> -endif
>> -
>>  ifdef FW_FDT_PATH
>>  firmware-genflags-y += -DFW_FDT_PATH=\"$(FW_FDT_PATH)\"
>>  ifdef FW_FDT_PADDING
>> diff --git a/firmware/payloads/test.elf.ldS b/firmware/payloads/test.elf.ldS
>> index 2328a1b..08e008f 100644
>> --- a/firmware/payloads/test.elf.ldS
>> +++ b/firmware/payloads/test.elf.ldS
>> @@ -13,7 +13,7 @@ ENTRY(_start)
>>  SECTIONS
>>  {
>>  #ifdef FW_PAYLOAD_OFFSET
>> -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
>> +       . = FW_PAYLOAD_OFFSET;
>>  #else
>>         . = ALIGN(FW_PAYLOAD_ALIGN);
>>  #endif
>> diff --git a/platform/fpga/ariane/objects.mk b/platform/fpga/ariane/objects.mk
>> index 83581ac..d1177f4 100644
>> --- a/platform/fpga/ariane/objects.mk
>> +++ b/platform/fpga/ariane/objects.mk
>> @@ -17,7 +17,6 @@ platform-objs-y += platform.o
>>  PLATFORM_RISCV_XLEN = 64
>>
>>  # Blobs to build
>> -FW_TEXT_START=0x80000000
>>  FW_JUMP=n
>>
>>  ifeq ($(PLATFORM_RISCV_XLEN), 32)
>> diff --git a/platform/fpga/openpiton/objects.mk b/platform/fpga/openpiton/objects.mk
>> index c8c345a..1a0ce0c 100644
>> --- a/platform/fpga/openpiton/objects.mk
>> +++ b/platform/fpga/openpiton/objects.mk
>> @@ -16,7 +16,6 @@ platform-objs-y += platform.o
>>  PLATFORM_RISCV_XLEN = 64
>>
>>  # Blobs to build
>> -FW_TEXT_START=0x80000000
>>  FW_JUMP=n
>>
>>  ifeq ($(PLATFORM_RISCV_XLEN), 32)
>> diff --git a/platform/generic/objects.mk b/platform/generic/objects.mk
>> index 85aa723..c215935 100644
>> --- a/platform/generic/objects.mk
>> +++ b/platform/generic/objects.mk
>> @@ -15,14 +15,13 @@ platform-ldflags-y =
>>
>>  # Command for platform specific "make run"
>>  platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \
>> -  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.elf
>> +  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.bin
>>
>>  # Objects to build
>>  platform-objs-y += platform.o
>>  platform-objs-y += platform_override_modules.o
>>
>>  # Blobs to build
>> -FW_TEXT_START=0x80000000
>>  FW_DYNAMIC=y
>>  FW_JUMP=y
>>  ifeq ($(PLATFORM_RISCV_XLEN), 32)
>> diff --git a/platform/kendryte/k210/objects.mk b/platform/kendryte/k210/objects.mk
>> index 1bfb898..efac3d2 100644
>> --- a/platform/kendryte/k210/objects.mk
>> +++ b/platform/kendryte/k210/objects.mk
>> @@ -21,6 +21,5 @@ platform-varprefix-k210.o = dt_k210
>>  platform-padding-k210.o = 2048
>>
>>  # Blobs to build
>> -FW_TEXT_START=0x80000000
>>  FW_PAYLOAD=y
>>  FW_PAYLOAD_ALIGN=0x1000
>> diff --git a/platform/nuclei/ux600/objects.mk b/platform/nuclei/ux600/objects.mk
>> index 7c429e0..2753a7f 100644
>> --- a/platform/nuclei/ux600/objects.mk
>> +++ b/platform/nuclei/ux600/objects.mk
>> @@ -22,7 +22,6 @@ platform-runcmd = xl_spike \
>>  platform-objs-y += platform.o
>>
>>  # Blobs to build
>> -FW_TEXT_START=0xA0000000
>>  FW_DYNAMIC=y
>>  FW_JUMP=y
>>
>> diff --git a/platform/template/objects.mk b/platform/template/objects.mk
>> index b143cbc..f240a55 100644
>> --- a/platform/template/objects.mk
>> +++ b/platform/template/objects.mk
>> @@ -41,9 +41,6 @@ platform-objs-y += platform.o
>>  #
>>  # platform-objs-y += <dt file name>.o
>>
>> -# Firmware load address configuration. This is mandatory.
>> -FW_TEXT_START=0x80000000
>> -
>>  # Optional parameter for path to external FDT
>>  # FW_FDT_PATH="path to platform flattened device tree file"
>>
>> @@ -69,8 +66,7 @@ FW_JUMP=<y|n>
>>  # endif
>>  # FW_JUMP_FDT_OFFSET=0x2200000
>>  #
>> -# You can use fixed address for jump firmware as an alternative option,
>> -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
>> +# You can use fixed address for jump firmware as an alternative option.
>>  # SBI will prefer "<X>_ADDR" if both "<X>_ADDR" and "<X>_OFFSET" are
>>  # defined
>>  # ifeq ($(PLATFORM_RISCV_XLEN), 32)
>> @@ -97,8 +93,7 @@ endif
>>  # FW_PAYLOAD_PATH="path to next boot stage binary image file"
>>  # FW_PAYLOAD_FDT_OFFSET=0x2200000
>>  #
>> -# You can use fixed address for payload firmware as an alternative option,
>> -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
>> +# You can use fixed address for payload firmware as an alternative option.
>>  # SBI will prefer "FW_PAYLOAD_FDT_ADDR" if both "FW_PAYLOAD_FDT_OFFSET"
>>  # and "FW_PAYLOAD_FDT_ADDR" are defined.
>>  # FW_PAYLOAD_FDT_ADDR=0x82200000
>> --
>> 2.43.0
>>
>
Anup Patel May 14, 2024, 4:33 p.m. UTC | #3
On Tue, May 14, 2024 at 9:58 PM Clément Léger <cleger@rivosinc.com> wrote:
>
>
>
> On 10/04/2024 07:18, Anup Patel wrote:
> > On Mon, Apr 8, 2024 at 9:01 PM Xiang W <wxjstz@126.com> wrote:
> >>
> >> Now opensbi can run at any address via dynamic relocation. We can
> >> remove FW_TEXT_START.
> >>
> >> Signed-off-by: Xiang W <wxjstz@126.com>
> >
> > LGTM.
> >
> > Reviewed-by: Anup Patel <anup@brainfault.org>
> > Tested-by: Anup Patel <anup@brainfault.org>
> >
> > Applied this patch to the riscv/opensbi repo.
> >
> > Thanks,
> > Anup
>
> Hi Anup,
>
> This patch seems to break spike support. The newly created ELF is not
> marked as EXEC anymore but DYNAMIC and it fails with the following error:
>
> spike: ../fesvr/elfloader.cc:45:
> std::map<std::__cxx11::basic_string<char>, long unsigned int>
> load_elf(const char*, memif_t*, reg_t*, unsigned int): Assertion
> `IS_ELF_EXEC(*eh64)' failed.
>
> Should we fixed OpenSBI or allow spike to load a DYNAMIC elf ?

I think it is better to use FW_DYNAMIC in Spike because various
other projects (such as U-Boot, QEMU, etc) use it.

Also, Spike should support loading M-mode firmware in BIN
(flat binary) format as well.

Regards,
Anup

>
> Thanks,
>
> Clément
>
> >
> >> ---
> >>
> >> v4 changes:
> >> - only remove FW_TEXT_START by anup's suggestion
> >>
> >>  docs/firmware/fw.md                |  2 --
> >>  docs/firmware/fw_jump.md           |  4 ++--
> >>  docs/firmware/fw_payload.md        |  6 +++---
> >>  docs/platform/generic.md           | 11 +++--------
> >>  firmware/fw_base.S                 |  4 +---
> >>  firmware/fw_base.ldS               |  3 +--
> >>  firmware/fw_payload.elf.ldS        |  2 +-
> >>  firmware/objects.mk                |  4 ----
> >>  firmware/payloads/test.elf.ldS     |  2 +-
> >>  platform/fpga/ariane/objects.mk    |  1 -
> >>  platform/fpga/openpiton/objects.mk |  1 -
> >>  platform/generic/objects.mk        |  3 +--
> >>  platform/kendryte/k210/objects.mk  |  1 -
> >>  platform/nuclei/ux600/objects.mk   |  1 -
> >>  platform/template/objects.mk       |  9 ++-------
> >>  15 files changed, 15 insertions(+), 39 deletions(-)
> >>
> >> diff --git a/docs/firmware/fw.md b/docs/firmware/fw.md
> >> index 2f4deb5..3cc0262 100644
> >> --- a/docs/firmware/fw.md
> >> +++ b/docs/firmware/fw.md
> >> @@ -61,8 +61,6 @@ Firmware Configuration and Compilation
> >>  All firmware types support the following common compile time configuration
> >>  parameters:
> >>
> >> -* **FW_TEXT_START** - Defines the execution address of the OpenSBI firmware.
> >> -  This configuration parameter is mandatory.
> >>  * **FW_FDT_PATH** - Path to an external flattened device tree binary file to
> >>    be embedded in the *.rodata* section of the final firmware. If this option
> >>    is not provided then the firmware will expect the FDT to be passed as an
> >> diff --git a/docs/firmware/fw_jump.md b/docs/firmware/fw_jump.md
> >> index 2ee6b29..66be016 100644
> >> --- a/docs/firmware/fw_jump.md
> >> +++ b/docs/firmware/fw_jump.md
> >> @@ -35,7 +35,7 @@ follows:
> >>    At least one of *FW_JUMP_ADDR* and *FW_JUMP_OFFSET* (see below) should be
> >>    defined. Compilation errors will result from not defining one of them.
> >>
> >> -* **FW_JUMP_OFFSET** - Address offset from the *FW_TEXT_START* where the
> >> +* **FW_JUMP_OFFSET** - Address offset from the opensbi load address where the
> >>    entry point of the next booting stage is located. This offset is used as
> >>    relocatable address of the next booting stage entry point. If *FW_JUMP_ADDR*
> >>    is also defined, the firmware will prefer *FW_JUMP_ADDR*.
> >> @@ -62,7 +62,7 @@ follows:
> >>    echo fdt overlaps kernel, increase FW_JUMP_FDT_ADDR
> >>    ```
> >>
> >> -* **FW_JUMP_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
> >> +* **FW_JUMP_FDT_OFFSET** - Address offset from the opensbi load address where
> >>    the FDT will be passed to the next booting stage. This offset is used
> >>    as relocatable address of the FDT passed to the next booting stage. If
> >>    *FW_JUMP_FDT_ADDR* is also defined, the firmware will prefer
> >> diff --git a/docs/firmware/fw_payload.md b/docs/firmware/fw_payload.md
> >> index a67fc50..d25be60 100644
> >> --- a/docs/firmware/fw_payload.md
> >> +++ b/docs/firmware/fw_payload.md
> >> @@ -36,8 +36,8 @@ options. These configuration parameters can be defined using either the top
> >>  level `make` command line or the target platform *objects.mk* configuration
> >>  file. The parameters currently defined are as follows:
> >>
> >> -* **FW_PAYLOAD_OFFSET** - Offset from *FW_TEXT_START* where the payload binary
> >> -  will be linked in the final *FW_PAYLOAD* firmware binary image. This
> >> +* **FW_PAYLOAD_OFFSET** - Offset from the opensbi load address where the payload
> >> +  binary will be linked in the final *FW_PAYLOAD* firmware binary image. This
> >>    configuration parameter is mandatory if *FW_PAYLOAD_ALIGN* is not defined.
> >>    Compilation errors will result from an incorrect definition of
> >>    *FW_PAYLOAD_OFFSET* or of *FW_PAYLOAD_ALIGN*, or if neither of these
> >> @@ -62,7 +62,7 @@ file. The parameters currently defined are as follows:
> >>    firmware will pass the FDT address passed by the previous booting stage
> >>    to the next booting stage.
> >>
> >> -* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
> >> +* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the opensbi load address where
> >>    the FDT will be passed to the next booting stage. This offset is used as
> >>    relocatable address of the FDT passed to the next booting stage. If
> >>    *FW_PAYLOAD_FDT_ADDR* is also defined, the firmware will prefer *FW_PAYLOAD_FDT_ADDR*.
> >> diff --git a/docs/platform/generic.md b/docs/platform/generic.md
> >> index c29eb04..709b436 100644
> >> --- a/docs/platform/generic.md
> >> +++ b/docs/platform/generic.md
> >> @@ -9,10 +9,9 @@ boards.
> >>
> >>  By default, the generic FDT platform makes following assumptions:
> >>
> >> -1. platform FW_TEXT_START is 0x80000000
> >> -2. platform features are default
> >> -3. platform stack size is default
> >> -4. platform has no quirks or work-arounds
> >> +1. platform features are default
> >> +2. platform stack size is default
> >> +3. platform has no quirks or work-arounds
> >>
> >>  The above assumptions (except 1) can be overridden by adding special platform
> >>  callbacks which will be called based on FDT root node compatible string.
> >> @@ -33,10 +32,6 @@ Users of the generic FDT platform will have to ensure that:
> >>  To build the platform-specific library and firmware images, provide the
> >>  *PLATFORM=generic* parameter to the top level `make` command.
> >>
> >> -For custom FW_TEXT_START, we can build the platform-specific library and
> >> -firmware images by passing *PLATFORM=generic FW_TEXT_START=<custom_text_start>*
> >> -parameter to the top level `make` command.
> >> -
> >>  Platform Options
> >>  ----------------
> >>
> >> diff --git a/firmware/fw_base.S b/firmware/fw_base.S
> >> index b950c0b..9f995a2 100644
> >> --- a/firmware/fw_base.S
> >> +++ b/firmware/fw_base.S
> >> @@ -53,9 +53,7 @@ _try_lottery:
> >>         bnez    a6, _wait_for_boot_hart
> >>
> >>         /* relocate the global table content */
> >> -       li      t0, FW_TEXT_START       /* link start */
> >> -       lla     t1, _fw_start           /* load start */
> >> -       sub     t2, t1, t0              /* load offset */
> >> +       lla     t2, _fw_start
> >>         lla     t0, __rel_dyn_start
> >>         lla     t1, __rel_dyn_end
> >>         beq     t0, t1, _relocate_done
> >> diff --git a/firmware/fw_base.ldS b/firmware/fw_base.ldS
> >> index fb47984..9d11db5 100644
> >> --- a/firmware/fw_base.ldS
> >> +++ b/firmware/fw_base.ldS
> >> @@ -7,8 +7,7 @@
> >>   *   Anup Patel <anup.patel@wdc.com>
> >>   */
> >>
> >> -       . = FW_TEXT_START;
> >> -       /* Don't add any section between FW_TEXT_START and _fw_start */
> >> +       /* Don't add any section before _fw_start */
> >>         PROVIDE(_fw_start = .);
> >>
> >>         . = ALIGN(0x1000); /* Need this to create proper sections */
> >> diff --git a/firmware/fw_payload.elf.ldS b/firmware/fw_payload.elf.ldS
> >> index f1a544b..94e1ac6 100644
> >> --- a/firmware/fw_payload.elf.ldS
> >> +++ b/firmware/fw_payload.elf.ldS
> >> @@ -15,7 +15,7 @@ SECTIONS
> >>         #include "fw_base.ldS"
> >>
> >>  #ifdef FW_PAYLOAD_OFFSET
> >> -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
> >> +       . = FW_PAYLOAD_OFFSET;
> >>  #else
> >>         . = ALIGN(FW_PAYLOAD_ALIGN);
> >>  #endif
> >> diff --git a/firmware/objects.mk b/firmware/objects.mk
> >> index e6b364b..a51ff65 100644
> >> --- a/firmware/objects.mk
> >> +++ b/firmware/objects.mk
> >> @@ -13,10 +13,6 @@ firmware-cflags-y +=
> >>  firmware-asflags-y +=
> >>  firmware-ldflags-y +=
> >>
> >> -ifdef FW_TEXT_START
> >> -firmware-genflags-y += -DFW_TEXT_START=$(FW_TEXT_START)
> >> -endif
> >> -
> >>  ifdef FW_FDT_PATH
> >>  firmware-genflags-y += -DFW_FDT_PATH=\"$(FW_FDT_PATH)\"
> >>  ifdef FW_FDT_PADDING
> >> diff --git a/firmware/payloads/test.elf.ldS b/firmware/payloads/test.elf.ldS
> >> index 2328a1b..08e008f 100644
> >> --- a/firmware/payloads/test.elf.ldS
> >> +++ b/firmware/payloads/test.elf.ldS
> >> @@ -13,7 +13,7 @@ ENTRY(_start)
> >>  SECTIONS
> >>  {
> >>  #ifdef FW_PAYLOAD_OFFSET
> >> -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
> >> +       . = FW_PAYLOAD_OFFSET;
> >>  #else
> >>         . = ALIGN(FW_PAYLOAD_ALIGN);
> >>  #endif
> >> diff --git a/platform/fpga/ariane/objects.mk b/platform/fpga/ariane/objects.mk
> >> index 83581ac..d1177f4 100644
> >> --- a/platform/fpga/ariane/objects.mk
> >> +++ b/platform/fpga/ariane/objects.mk
> >> @@ -17,7 +17,6 @@ platform-objs-y += platform.o
> >>  PLATFORM_RISCV_XLEN = 64
> >>
> >>  # Blobs to build
> >> -FW_TEXT_START=0x80000000
> >>  FW_JUMP=n
> >>
> >>  ifeq ($(PLATFORM_RISCV_XLEN), 32)
> >> diff --git a/platform/fpga/openpiton/objects.mk b/platform/fpga/openpiton/objects.mk
> >> index c8c345a..1a0ce0c 100644
> >> --- a/platform/fpga/openpiton/objects.mk
> >> +++ b/platform/fpga/openpiton/objects.mk
> >> @@ -16,7 +16,6 @@ platform-objs-y += platform.o
> >>  PLATFORM_RISCV_XLEN = 64
> >>
> >>  # Blobs to build
> >> -FW_TEXT_START=0x80000000
> >>  FW_JUMP=n
> >>
> >>  ifeq ($(PLATFORM_RISCV_XLEN), 32)
> >> diff --git a/platform/generic/objects.mk b/platform/generic/objects.mk
> >> index 85aa723..c215935 100644
> >> --- a/platform/generic/objects.mk
> >> +++ b/platform/generic/objects.mk
> >> @@ -15,14 +15,13 @@ platform-ldflags-y =
> >>
> >>  # Command for platform specific "make run"
> >>  platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \
> >> -  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.elf
> >> +  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.bin
> >>
> >>  # Objects to build
> >>  platform-objs-y += platform.o
> >>  platform-objs-y += platform_override_modules.o
> >>
> >>  # Blobs to build
> >> -FW_TEXT_START=0x80000000
> >>  FW_DYNAMIC=y
> >>  FW_JUMP=y
> >>  ifeq ($(PLATFORM_RISCV_XLEN), 32)
> >> diff --git a/platform/kendryte/k210/objects.mk b/platform/kendryte/k210/objects.mk
> >> index 1bfb898..efac3d2 100644
> >> --- a/platform/kendryte/k210/objects.mk
> >> +++ b/platform/kendryte/k210/objects.mk
> >> @@ -21,6 +21,5 @@ platform-varprefix-k210.o = dt_k210
> >>  platform-padding-k210.o = 2048
> >>
> >>  # Blobs to build
> >> -FW_TEXT_START=0x80000000
> >>  FW_PAYLOAD=y
> >>  FW_PAYLOAD_ALIGN=0x1000
> >> diff --git a/platform/nuclei/ux600/objects.mk b/platform/nuclei/ux600/objects.mk
> >> index 7c429e0..2753a7f 100644
> >> --- a/platform/nuclei/ux600/objects.mk
> >> +++ b/platform/nuclei/ux600/objects.mk
> >> @@ -22,7 +22,6 @@ platform-runcmd = xl_spike \
> >>  platform-objs-y += platform.o
> >>
> >>  # Blobs to build
> >> -FW_TEXT_START=0xA0000000
> >>  FW_DYNAMIC=y
> >>  FW_JUMP=y
> >>
> >> diff --git a/platform/template/objects.mk b/platform/template/objects.mk
> >> index b143cbc..f240a55 100644
> >> --- a/platform/template/objects.mk
> >> +++ b/platform/template/objects.mk
> >> @@ -41,9 +41,6 @@ platform-objs-y += platform.o
> >>  #
> >>  # platform-objs-y += <dt file name>.o
> >>
> >> -# Firmware load address configuration. This is mandatory.
> >> -FW_TEXT_START=0x80000000
> >> -
> >>  # Optional parameter for path to external FDT
> >>  # FW_FDT_PATH="path to platform flattened device tree file"
> >>
> >> @@ -69,8 +66,7 @@ FW_JUMP=<y|n>
> >>  # endif
> >>  # FW_JUMP_FDT_OFFSET=0x2200000
> >>  #
> >> -# You can use fixed address for jump firmware as an alternative option,
> >> -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
> >> +# You can use fixed address for jump firmware as an alternative option.
> >>  # SBI will prefer "<X>_ADDR" if both "<X>_ADDR" and "<X>_OFFSET" are
> >>  # defined
> >>  # ifeq ($(PLATFORM_RISCV_XLEN), 32)
> >> @@ -97,8 +93,7 @@ endif
> >>  # FW_PAYLOAD_PATH="path to next boot stage binary image file"
> >>  # FW_PAYLOAD_FDT_OFFSET=0x2200000
> >>  #
> >> -# You can use fixed address for payload firmware as an alternative option,
> >> -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
> >> +# You can use fixed address for payload firmware as an alternative option.
> >>  # SBI will prefer "FW_PAYLOAD_FDT_ADDR" if both "FW_PAYLOAD_FDT_OFFSET"
> >>  # and "FW_PAYLOAD_FDT_ADDR" are defined.
> >>  # FW_PAYLOAD_FDT_ADDR=0x82200000
> >> --
> >> 2.43.0
> >>
> >
Cheng Yang May 14, 2024, 4:50 p.m. UTC | #4
&gt;On Tue, May 14, 2024 at 9:58 PM Clément Léger <cleger@rivosinc.com> wrote:
&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt;&gt; On 10/04/2024 07:18, Anup Patel wrote:
&gt;&gt; &gt; On Mon, Apr 8, 2024 at 9:01 PM Xiang W <wxjstz@126.com> wrote:
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; Now opensbi can run at any address via dynamic relocation. We can
&gt;&gt; &gt;&gt; remove FW_TEXT_START.
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; Signed-off-by: Xiang W <wxjstz@126.com>
&gt;&gt; &gt;
&gt;&gt; &gt; LGTM.
&gt;&gt; &gt;
&gt;&gt; &gt; Reviewed-by: Anup Patel <anup@brainfault.org>
&gt;&gt; &gt; Tested-by: Anup Patel <anup@brainfault.org>
&gt;&gt; &gt;
&gt;&gt; &gt; Applied this patch to the riscv/opensbi repo.
&gt;&gt; &gt;
&gt;&gt; &gt; Thanks,
&gt;&gt; &gt; Anup
&gt;&gt;
&gt;&gt; Hi Anup,
&gt;&gt;
&gt;&gt; This patch seems to break spike support. The newly created ELF is not
&gt;&gt; marked as EXEC anymore but DYNAMIC and it fails with the following error:
&gt;&gt;
&gt;&gt; spike: ../fesvr/elfloader.cc:45:
&gt;&gt; std::map<std::__cxx11::basic_string<char>, long unsigned int&gt;
&gt;&gt; load_elf(const char*, memif_t*, reg_t*, unsigned int): Assertion
&gt;&gt; `IS_ELF_EXEC(*eh64)' failed.
&gt;&gt;
&gt;&gt; Should we fixed OpenSBI or allow spike to load a DYNAMIC elf ?
&gt;
&gt;I think it is better to use FW_DYNAMIC in Spike because various
&gt;other projects (such as U-Boot, QEMU, etc) use it.
&gt;
&gt;Also, Spike should support loading M-mode firmware in BIN
&gt;(flat binary) format as well.
&gt;
&gt;Regards,
&gt;Anup
&gt;
&gt;&gt;
&gt;&gt; Thanks,
&gt;&gt;
&gt;&gt; Clément
&gt;&gt;

Hi Anup,

I think this patch is not that necessary, and after applying 
this patch, we lost an elf file that can disassemble or directly 
provide symbol addresses to gdb, which caused some difficulties 
in debugging. In the past, I could pass it in Specify the address 
of FW_TEXT_START during compilation to generate an ELF file containing 
accurate symbol addresses, which is useful for debugging OpenSBI.

Best regards,
Cheng Yang

&gt;&gt; &gt;
&gt;&gt; &gt;&gt; ---
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; v4 changes:
&gt;&gt; &gt;&gt; - only remove FW_TEXT_START by anup's suggestion
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;  docs/firmware/fw.md                |  2 --
&gt;&gt; &gt;&gt;  docs/firmware/fw_jump.md           |  4 ++--
&gt;&gt; &gt;&gt;  docs/firmware/fw_payload.md        |  6 +++---
&gt;&gt; &gt;&gt;  docs/platform/generic.md           | 11 +++--------
&gt;&gt; &gt;&gt;  firmware/fw_base.S                 |  4 +---
&gt;&gt; &gt;&gt;  firmware/fw_base.ldS               |  3 +--
&gt;&gt; &gt;&gt;  firmware/fw_payload.elf.ldS        |  2 +-
&gt;&gt; &gt;&gt;  firmware/objects.mk                |  4 ----
&gt;&gt; &gt;&gt;  firmware/payloads/test.elf.ldS     |  2 +-
&gt;&gt; &gt;&gt;  platform/fpga/ariane/objects.mk    |  1 -
&gt;&gt; &gt;&gt;  platform/fpga/openpiton/objects.mk |  1 -
&gt;&gt; &gt;&gt;  platform/generic/objects.mk        |  3 +--
&gt;&gt; &gt;&gt;  platform/kendryte/k210/objects.mk  |  1 -
&gt;&gt; &gt;&gt;  platform/nuclei/ux600/objects.mk   |  1 -
&gt;&gt; &gt;&gt;  platform/template/objects.mk       |  9 ++-------
&gt;&gt; &gt;&gt;  15 files changed, 15 insertions(+), 39 deletions(-)
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; diff --git a/docs/firmware/fw.md b/docs/firmware/fw.md
&gt;&gt; &gt;&gt; index 2f4deb5..3cc0262 100644
&gt;&gt; &gt;&gt; --- a/docs/firmware/fw.md
&gt;&gt; &gt;&gt; +++ b/docs/firmware/fw.md
&gt;&gt; &gt;&gt; @@ -61,8 +61,6 @@ Firmware Configuration and Compilation
&gt;&gt; &gt;&gt;  All firmware types support the following common compile time configuration
&gt;&gt; &gt;&gt;  parameters:
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; -* **FW_TEXT_START** - Defines the execution address of the OpenSBI firmware.
&gt;&gt; &gt;&gt; -  This configuration parameter is mandatory.
&gt;&gt; &gt;&gt;  * **FW_FDT_PATH** - Path to an external flattened device tree binary file to
&gt;&gt; &gt;&gt;    be embedded in the *.rodata* section of the final firmware. If this option
&gt;&gt; &gt;&gt;    is not provided then the firmware will expect the FDT to be passed as an
&gt;&gt; &gt;&gt; diff --git a/docs/firmware/fw_jump.md b/docs/firmware/fw_jump.md
&gt;&gt; &gt;&gt; index 2ee6b29..66be016 100644
&gt;&gt; &gt;&gt; --- a/docs/firmware/fw_jump.md
&gt;&gt; &gt;&gt; +++ b/docs/firmware/fw_jump.md
&gt;&gt; &gt;&gt; @@ -35,7 +35,7 @@ follows:
&gt;&gt; &gt;&gt;    At least one of *FW_JUMP_ADDR* and *FW_JUMP_OFFSET* (see below) should be
&gt;&gt; &gt;&gt;    defined. Compilation errors will result from not defining one of them.
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; -* **FW_JUMP_OFFSET** - Address offset from the *FW_TEXT_START* where the
&gt;&gt; &gt;&gt; +* **FW_JUMP_OFFSET** - Address offset from the opensbi load address where the
&gt;&gt; &gt;&gt;    entry point of the next booting stage is located. This offset is used as
&gt;&gt; &gt;&gt;    relocatable address of the next booting stage entry point. If *FW_JUMP_ADDR*
&gt;&gt; &gt;&gt;    is also defined, the firmware will prefer *FW_JUMP_ADDR*.
&gt;&gt; &gt;&gt; @@ -62,7 +62,7 @@ follows:
&gt;&gt; &gt;&gt;    echo fdt overlaps kernel, increase FW_JUMP_FDT_ADDR
&gt;&gt; &gt;&gt;    ```
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; -* **FW_JUMP_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
&gt;&gt; &gt;&gt; +* **FW_JUMP_FDT_OFFSET** - Address offset from the opensbi load address where
&gt;&gt; &gt;&gt;    the FDT will be passed to the next booting stage. This offset is used
&gt;&gt; &gt;&gt;    as relocatable address of the FDT passed to the next booting stage. If
&gt;&gt; &gt;&gt;    *FW_JUMP_FDT_ADDR* is also defined, the firmware will prefer
&gt;&gt; &gt;&gt; diff --git a/docs/firmware/fw_payload.md b/docs/firmware/fw_payload.md
&gt;&gt; &gt;&gt; index a67fc50..d25be60 100644
&gt;&gt; &gt;&gt; --- a/docs/firmware/fw_payload.md
&gt;&gt; &gt;&gt; +++ b/docs/firmware/fw_payload.md
&gt;&gt; &gt;&gt; @@ -36,8 +36,8 @@ options. These configuration parameters can be defined using either the top
&gt;&gt; &gt;&gt;  level `make` command line or the target platform *objects.mk* configuration
&gt;&gt; &gt;&gt;  file. The parameters currently defined are as follows:
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; -* **FW_PAYLOAD_OFFSET** - Offset from *FW_TEXT_START* where the payload binary
&gt;&gt; &gt;&gt; -  will be linked in the final *FW_PAYLOAD* firmware binary image. This
&gt;&gt; &gt;&gt; +* **FW_PAYLOAD_OFFSET** - Offset from the opensbi load address where the payload
&gt;&gt; &gt;&gt; +  binary will be linked in the final *FW_PAYLOAD* firmware binary image. This
&gt;&gt; &gt;&gt;    configuration parameter is mandatory if *FW_PAYLOAD_ALIGN* is not defined.
&gt;&gt; &gt;&gt;    Compilation errors will result from an incorrect definition of
&gt;&gt; &gt;&gt;    *FW_PAYLOAD_OFFSET* or of *FW_PAYLOAD_ALIGN*, or if neither of these
&gt;&gt; &gt;&gt; @@ -62,7 +62,7 @@ file. The parameters currently defined are as follows:
&gt;&gt; &gt;&gt;    firmware will pass the FDT address passed by the previous booting stage
&gt;&gt; &gt;&gt;    to the next booting stage.
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; -* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
&gt;&gt; &gt;&gt; +* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the opensbi load address where
&gt;&gt; &gt;&gt;    the FDT will be passed to the next booting stage. This offset is used as
&gt;&gt; &gt;&gt;    relocatable address of the FDT passed to the next booting stage. If
&gt;&gt; &gt;&gt;    *FW_PAYLOAD_FDT_ADDR* is also defined, the firmware will prefer *FW_PAYLOAD_FDT_ADDR*.
&gt;&gt; &gt;&gt; diff --git a/docs/platform/generic.md b/docs/platform/generic.md
&gt;&gt; &gt;&gt; index c29eb04..709b436 100644
&gt;&gt; &gt;&gt; --- a/docs/platform/generic.md
&gt;&gt; &gt;&gt; +++ b/docs/platform/generic.md
&gt;&gt; &gt;&gt; @@ -9,10 +9,9 @@ boards.
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;  By default, the generic FDT platform makes following assumptions:
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; -1. platform FW_TEXT_START is 0x80000000
&gt;&gt; &gt;&gt; -2. platform features are default
&gt;&gt; &gt;&gt; -3. platform stack size is default
&gt;&gt; &gt;&gt; -4. platform has no quirks or work-arounds
&gt;&gt; &gt;&gt; +1. platform features are default
&gt;&gt; &gt;&gt; +2. platform stack size is default
&gt;&gt; &gt;&gt; +3. platform has no quirks or work-arounds
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;  The above assumptions (except 1) can be overridden by adding special platform
&gt;&gt; &gt;&gt;  callbacks which will be called based on FDT root node compatible string.
&gt;&gt; &gt;&gt; @@ -33,10 +32,6 @@ Users of the generic FDT platform will have to ensure that:
&gt;&gt; &gt;&gt;  To build the platform-specific library and firmware images, provide the
&gt;&gt; &gt;&gt;  *PLATFORM=generic* parameter to the top level `make` command.
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; -For custom FW_TEXT_START, we can build the platform-specific library and
&gt;&gt; &gt;&gt; -firmware images by passing *PLATFORM=generic FW_TEXT_START=<custom_text_start>*
&gt;&gt; &gt;&gt; -parameter to the top level `make` command.
&gt;&gt; &gt;&gt; -
&gt;&gt; &gt;&gt;  Platform Options
&gt;&gt; &gt;&gt;  ----------------
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; diff --git a/firmware/fw_base.S b/firmware/fw_base.S
&gt;&gt; &gt;&gt; index b950c0b..9f995a2 100644
&gt;&gt; &gt;&gt; --- a/firmware/fw_base.S
&gt;&gt; &gt;&gt; +++ b/firmware/fw_base.S
&gt;&gt; &gt;&gt; @@ -53,9 +53,7 @@ _try_lottery:
&gt;&gt; &gt;&gt;         bnez    a6, _wait_for_boot_hart
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;         /* relocate the global table content */
&gt;&gt; &gt;&gt; -       li      t0, FW_TEXT_START       /* link start */
&gt;&gt; &gt;&gt; -       lla     t1, _fw_start           /* load start */
&gt;&gt; &gt;&gt; -       sub     t2, t1, t0              /* load offset */
&gt;&gt; &gt;&gt; +       lla     t2, _fw_start
&gt;&gt; &gt;&gt;         lla     t0, __rel_dyn_start
&gt;&gt; &gt;&gt;         lla     t1, __rel_dyn_end
&gt;&gt; &gt;&gt;         beq     t0, t1, _relocate_done
&gt;&gt; &gt;&gt; diff --git a/firmware/fw_base.ldS b/firmware/fw_base.ldS
&gt;&gt; &gt;&gt; index fb47984..9d11db5 100644
&gt;&gt; &gt;&gt; --- a/firmware/fw_base.ldS
&gt;&gt; &gt;&gt; +++ b/firmware/fw_base.ldS
&gt;&gt; &gt;&gt; @@ -7,8 +7,7 @@
&gt;&gt; &gt;&gt;   *   Anup Patel <anup.patel@wdc.com>
&gt;&gt; &gt;&gt;   */
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; -       . = FW_TEXT_START;
&gt;&gt; &gt;&gt; -       /* Don't add any section between FW_TEXT_START and _fw_start */
&gt;&gt; &gt;&gt; +       /* Don't add any section before _fw_start */
&gt;&gt; &gt;&gt;         PROVIDE(_fw_start = .);
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;         . = ALIGN(0x1000); /* Need this to create proper sections */
&gt;&gt; &gt;&gt; diff --git a/firmware/fw_payload.elf.ldS b/firmware/fw_payload.elf.ldS
&gt;&gt; &gt;&gt; index f1a544b..94e1ac6 100644
&gt;&gt; &gt;&gt; --- a/firmware/fw_payload.elf.ldS
&gt;&gt; &gt;&gt; +++ b/firmware/fw_payload.elf.ldS
&gt;&gt; &gt;&gt; @@ -15,7 +15,7 @@ SECTIONS
&gt;&gt; &gt;&gt;         #include "fw_base.ldS"
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;  #ifdef FW_PAYLOAD_OFFSET
&gt;&gt; &gt;&gt; -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
&gt;&gt; &gt;&gt; +       . = FW_PAYLOAD_OFFSET;
&gt;&gt; &gt;&gt;  #else
&gt;&gt; &gt;&gt;         . = ALIGN(FW_PAYLOAD_ALIGN);
&gt;&gt; &gt;&gt;  #endif
&gt;&gt; &gt;&gt; diff --git a/firmware/objects.mk b/firmware/objects.mk
&gt;&gt; &gt;&gt; index e6b364b..a51ff65 100644
&gt;&gt; &gt;&gt; --- a/firmware/objects.mk
&gt;&gt; &gt;&gt; +++ b/firmware/objects.mk
&gt;&gt; &gt;&gt; @@ -13,10 +13,6 @@ firmware-cflags-y +=
&gt;&gt; &gt;&gt;  firmware-asflags-y +=
&gt;&gt; &gt;&gt;  firmware-ldflags-y +=
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; -ifdef FW_TEXT_START
&gt;&gt; &gt;&gt; -firmware-genflags-y += -DFW_TEXT_START=$(FW_TEXT_START)
&gt;&gt; &gt;&gt; -endif
&gt;&gt; &gt;&gt; -
&gt;&gt; &gt;&gt;  ifdef FW_FDT_PATH
&gt;&gt; &gt;&gt;  firmware-genflags-y += -DFW_FDT_PATH=\"$(FW_FDT_PATH)\"
&gt;&gt; &gt;&gt;  ifdef FW_FDT_PADDING
&gt;&gt; &gt;&gt; diff --git a/firmware/payloads/test.elf.ldS b/firmware/payloads/test.elf.ldS
&gt;&gt; &gt;&gt; index 2328a1b..08e008f 100644
&gt;&gt; &gt;&gt; --- a/firmware/payloads/test.elf.ldS
&gt;&gt; &gt;&gt; +++ b/firmware/payloads/test.elf.ldS
&gt;&gt; &gt;&gt; @@ -13,7 +13,7 @@ ENTRY(_start)
&gt;&gt; &gt;&gt;  SECTIONS
&gt;&gt; &gt;&gt;  {
&gt;&gt; &gt;&gt;  #ifdef FW_PAYLOAD_OFFSET
&gt;&gt; &gt;&gt; -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
&gt;&gt; &gt;&gt; +       . = FW_PAYLOAD_OFFSET;
&gt;&gt; &gt;&gt;  #else
&gt;&gt; &gt;&gt;         . = ALIGN(FW_PAYLOAD_ALIGN);
&gt;&gt; &gt;&gt;  #endif
&gt;&gt; &gt;&gt; diff --git a/platform/fpga/ariane/objects.mk b/platform/fpga/ariane/objects.mk
&gt;&gt; &gt;&gt; index 83581ac..d1177f4 100644
&gt;&gt; &gt;&gt; --- a/platform/fpga/ariane/objects.mk
&gt;&gt; &gt;&gt; +++ b/platform/fpga/ariane/objects.mk
&gt;&gt; &gt;&gt; @@ -17,7 +17,6 @@ platform-objs-y += platform.o
&gt;&gt; &gt;&gt;  PLATFORM_RISCV_XLEN = 64
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;  # Blobs to build
&gt;&gt; &gt;&gt; -FW_TEXT_START=0x80000000
&gt;&gt; &gt;&gt;  FW_JUMP=n
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;  ifeq ($(PLATFORM_RISCV_XLEN), 32)
&gt;&gt; &gt;&gt; diff --git a/platform/fpga/openpiton/objects.mk b/platform/fpga/openpiton/objects.mk
&gt;&gt; &gt;&gt; index c8c345a..1a0ce0c 100644
&gt;&gt; &gt;&gt; --- a/platform/fpga/openpiton/objects.mk
&gt;&gt; &gt;&gt; +++ b/platform/fpga/openpiton/objects.mk
&gt;&gt; &gt;&gt; @@ -16,7 +16,6 @@ platform-objs-y += platform.o
&gt;&gt; &gt;&gt;  PLATFORM_RISCV_XLEN = 64
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;  # Blobs to build
&gt;&gt; &gt;&gt; -FW_TEXT_START=0x80000000
&gt;&gt; &gt;&gt;  FW_JUMP=n
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;  ifeq ($(PLATFORM_RISCV_XLEN), 32)
&gt;&gt; &gt;&gt; diff --git a/platform/generic/objects.mk b/platform/generic/objects.mk
&gt;&gt; &gt;&gt; index 85aa723..c215935 100644
&gt;&gt; &gt;&gt; --- a/platform/generic/objects.mk
&gt;&gt; &gt;&gt; +++ b/platform/generic/objects.mk
&gt;&gt; &gt;&gt; @@ -15,14 +15,13 @@ platform-ldflags-y =
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;  # Command for platform specific "make run"
&gt;&gt; &gt;&gt;  platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \
&gt;&gt; &gt;&gt; -  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.elf
&gt;&gt; &gt;&gt; +  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.bin
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;  # Objects to build
&gt;&gt; &gt;&gt;  platform-objs-y += platform.o
&gt;&gt; &gt;&gt;  platform-objs-y += platform_override_modules.o
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;  # Blobs to build
&gt;&gt; &gt;&gt; -FW_TEXT_START=0x80000000
&gt;&gt; &gt;&gt;  FW_DYNAMIC=y
&gt;&gt; &gt;&gt;  FW_JUMP=y
&gt;&gt; &gt;&gt;  ifeq ($(PLATFORM_RISCV_XLEN), 32)
&gt;&gt; &gt;&gt; diff --git a/platform/kendryte/k210/objects.mk b/platform/kendryte/k210/objects.mk
&gt;&gt; &gt;&gt; index 1bfb898..efac3d2 100644
&gt;&gt; &gt;&gt; --- a/platform/kendryte/k210/objects.mk
&gt;&gt; &gt;&gt; +++ b/platform/kendryte/k210/objects.mk
&gt;&gt; &gt;&gt; @@ -21,6 +21,5 @@ platform-varprefix-k210.o = dt_k210
&gt;&gt; &gt;&gt;  platform-padding-k210.o = 2048
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;  # Blobs to build
&gt;&gt; &gt;&gt; -FW_TEXT_START=0x80000000
&gt;&gt; &gt;&gt;  FW_PAYLOAD=y
&gt;&gt; &gt;&gt;  FW_PAYLOAD_ALIGN=0x1000
&gt;&gt; &gt;&gt; diff --git a/platform/nuclei/ux600/objects.mk b/platform/nuclei/ux600/objects.mk
&gt;&gt; &gt;&gt; index 7c429e0..2753a7f 100644
&gt;&gt; &gt;&gt; --- a/platform/nuclei/ux600/objects.mk
&gt;&gt; &gt;&gt; +++ b/platform/nuclei/ux600/objects.mk
&gt;&gt; &gt;&gt; @@ -22,7 +22,6 @@ platform-runcmd = xl_spike \
&gt;&gt; &gt;&gt;  platform-objs-y += platform.o
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;  # Blobs to build
&gt;&gt; &gt;&gt; -FW_TEXT_START=0xA0000000
&gt;&gt; &gt;&gt;  FW_DYNAMIC=y
&gt;&gt; &gt;&gt;  FW_JUMP=y
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; diff --git a/platform/template/objects.mk b/platform/template/objects.mk
&gt;&gt; &gt;&gt; index b143cbc..f240a55 100644
&gt;&gt; &gt;&gt; --- a/platform/template/objects.mk
&gt;&gt; &gt;&gt; +++ b/platform/template/objects.mk
&gt;&gt; &gt;&gt; @@ -41,9 +41,6 @@ platform-objs-y += platform.o
&gt;&gt; &gt;&gt;  #
&gt;&gt; &gt;&gt;  # platform-objs-y += <dt file="" name="">.o
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; -# Firmware load address configuration. This is mandatory.
&gt;&gt; &gt;&gt; -FW_TEXT_START=0x80000000
&gt;&gt; &gt;&gt; -
&gt;&gt; &gt;&gt;  # Optional parameter for path to external FDT
&gt;&gt; &gt;&gt;  # FW_FDT_PATH="path to platform flattened device tree file"
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; @@ -69,8 +66,7 @@ FW_JUMP=<y|n>
&gt;&gt; &gt;&gt;  # endif
&gt;&gt; &gt;&gt;  # FW_JUMP_FDT_OFFSET=0x2200000
&gt;&gt; &gt;&gt;  #
&gt;&gt; &gt;&gt; -# You can use fixed address for jump firmware as an alternative option,
&gt;&gt; &gt;&gt; -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
&gt;&gt; &gt;&gt; +# You can use fixed address for jump firmware as an alternative option.
&gt;&gt; &gt;&gt;  # SBI will prefer "<x>_ADDR" if both "<x>_ADDR" and "<x>_OFFSET" are
&gt;&gt; &gt;&gt;  # defined
&gt;&gt; &gt;&gt;  # ifeq ($(PLATFORM_RISCV_XLEN), 32)
&gt;&gt; &gt;&gt; @@ -97,8 +93,7 @@ endif
&gt;&gt; &gt;&gt;  # FW_PAYLOAD_PATH="path to next boot stage binary image file"
&gt;&gt; &gt;&gt;  # FW_PAYLOAD_FDT_OFFSET=0x2200000
&gt;&gt; &gt;&gt;  #
&gt;&gt; &gt;&gt; -# You can use fixed address for payload firmware as an alternative option,
&gt;&gt; &gt;&gt; -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
&gt;&gt; &gt;&gt; +# You can use fixed address for payload firmware as an alternative option.
&gt;&gt; &gt;&gt;  # SBI will prefer "FW_PAYLOAD_FDT_ADDR" if both "FW_PAYLOAD_FDT_OFFSET"
&gt;&gt; &gt;&gt;  # and "FW_PAYLOAD_FDT_ADDR" are defined.
&gt;&gt; &gt;&gt;  # FW_PAYLOAD_FDT_ADDR=0x82200000
&gt;&gt; &gt;&gt; --
&gt;&gt; &gt;&gt; 2.43.0
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;
&gt;
&gt;--
&gt;opensbi mailing list
&gt;opensbi@lists.infradead.org
&gt;http://lists.infradead.org/mailman/listinfo/opensbi</x></x></x></y|n></dt></anup.patel@wdc.com></custom_text_start></std::__cxx11::basic_string<char></anup@brainfault.org></anup@brainfault.org></wxjstz@126.com></wxjstz@126.com></cleger@rivosinc.com>
Jessica Clarke May 14, 2024, 4:56 p.m. UTC | #5
On 14 May 2024, at 17:33, Anup Patel <anup@brainfault.org> wrote:
> 
> On Tue, May 14, 2024 at 9:58 PM Clément Léger <cleger@rivosinc.com> wrote:
>> 
>> 
>> 
>> On 10/04/2024 07:18, Anup Patel wrote:
>>> On Mon, Apr 8, 2024 at 9:01 PM Xiang W <wxjstz@126.com> wrote:
>>>> 
>>>> Now opensbi can run at any address via dynamic relocation. We can
>>>> remove FW_TEXT_START.
>>>> 
>>>> Signed-off-by: Xiang W <wxjstz@126.com>
>>> 
>>> LGTM.
>>> 
>>> Reviewed-by: Anup Patel <anup@brainfault.org>
>>> Tested-by: Anup Patel <anup@brainfault.org>
>>> 
>>> Applied this patch to the riscv/opensbi repo.
>>> 
>>> Thanks,
>>> Anup
>> 
>> Hi Anup,
>> 
>> This patch seems to break spike support. The newly created ELF is not
>> marked as EXEC anymore but DYNAMIC and it fails with the following error:
>> 
>> spike: ../fesvr/elfloader.cc:45:
>> std::map<std::__cxx11::basic_string<char>, long unsigned int>
>> load_elf(const char*, memif_t*, reg_t*, unsigned int): Assertion
>> `IS_ELF_EXEC(*eh64)' failed.
>> 
>> Should we fixed OpenSBI or allow spike to load a DYNAMIC elf ?
> 
> I think it is better to use FW_DYNAMIC in Spike because various
> other projects (such as U-Boot, QEMU, etc) use it.

That’s an orthogonal concern. This is about the ELF file type, not the
boot method used, but supporting more boot methods is good too.

Spike should support ET_DYN files, but will need to adjust all the load
addresses as they’ll be zero, so it’s not just a case of adding an
option to the assert.

> Also, Spike should support loading M-mode firmware in BIN
> (flat binary) format as well.

There’s not really a good reason to prefer a flat binary over an ELF
for an emulator*. For a board it makes sense because you want to have
the flat binary ready to go in memory, but for an emulator it’s more
useful to have the richer structure that an ELF provides, especially if
that includes debug info. Historically Spike needed it to be an ELF so
it could extract the HTIF symbol information as otherwise you’d have no
console I/O, but I believe these days Spike can emulate an 8250 so that
may no longer be a requirement?

Jess

* Space savings are minimal to non-existent; Debian’s U-Boot
  qemu-riscv64_smode saves 0.8%, and the generic OpenSBI flat
  binaries are bigger than the ELF files

> Regards,
> Anup
> 
>> 
>> Thanks,
>> 
>> Clément
>> 
>>> 
>>>> ---
>>>> 
>>>> v4 changes:
>>>> - only remove FW_TEXT_START by anup's suggestion
>>>> 
>>>> docs/firmware/fw.md                |  2 --
>>>> docs/firmware/fw_jump.md           |  4 ++--
>>>> docs/firmware/fw_payload.md        |  6 +++---
>>>> docs/platform/generic.md           | 11 +++--------
>>>> firmware/fw_base.S                 |  4 +---
>>>> firmware/fw_base.ldS               |  3 +--
>>>> firmware/fw_payload.elf.ldS        |  2 +-
>>>> firmware/objects.mk                |  4 ----
>>>> firmware/payloads/test.elf.ldS     |  2 +-
>>>> platform/fpga/ariane/objects.mk    |  1 -
>>>> platform/fpga/openpiton/objects.mk |  1 -
>>>> platform/generic/objects.mk        |  3 +--
>>>> platform/kendryte/k210/objects.mk  |  1 -
>>>> platform/nuclei/ux600/objects.mk   |  1 -
>>>> platform/template/objects.mk       |  9 ++-------
>>>> 15 files changed, 15 insertions(+), 39 deletions(-)
>>>> 
>>>> diff --git a/docs/firmware/fw.md b/docs/firmware/fw.md
>>>> index 2f4deb5..3cc0262 100644
>>>> --- a/docs/firmware/fw.md
>>>> +++ b/docs/firmware/fw.md
>>>> @@ -61,8 +61,6 @@ Firmware Configuration and Compilation
>>>> All firmware types support the following common compile time configuration
>>>> parameters:
>>>> 
>>>> -* **FW_TEXT_START** - Defines the execution address of the OpenSBI firmware.
>>>> -  This configuration parameter is mandatory.
>>>> * **FW_FDT_PATH** - Path to an external flattened device tree binary file to
>>>>   be embedded in the *.rodata* section of the final firmware. If this option
>>>>   is not provided then the firmware will expect the FDT to be passed as an
>>>> diff --git a/docs/firmware/fw_jump.md b/docs/firmware/fw_jump.md
>>>> index 2ee6b29..66be016 100644
>>>> --- a/docs/firmware/fw_jump.md
>>>> +++ b/docs/firmware/fw_jump.md
>>>> @@ -35,7 +35,7 @@ follows:
>>>>   At least one of *FW_JUMP_ADDR* and *FW_JUMP_OFFSET* (see below) should be
>>>>   defined. Compilation errors will result from not defining one of them.
>>>> 
>>>> -* **FW_JUMP_OFFSET** - Address offset from the *FW_TEXT_START* where the
>>>> +* **FW_JUMP_OFFSET** - Address offset from the opensbi load address where the
>>>>   entry point of the next booting stage is located. This offset is used as
>>>>   relocatable address of the next booting stage entry point. If *FW_JUMP_ADDR*
>>>>   is also defined, the firmware will prefer *FW_JUMP_ADDR*.
>>>> @@ -62,7 +62,7 @@ follows:
>>>>   echo fdt overlaps kernel, increase FW_JUMP_FDT_ADDR
>>>>   ```
>>>> 
>>>> -* **FW_JUMP_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
>>>> +* **FW_JUMP_FDT_OFFSET** - Address offset from the opensbi load address where
>>>>   the FDT will be passed to the next booting stage. This offset is used
>>>>   as relocatable address of the FDT passed to the next booting stage. If
>>>>   *FW_JUMP_FDT_ADDR* is also defined, the firmware will prefer
>>>> diff --git a/docs/firmware/fw_payload.md b/docs/firmware/fw_payload.md
>>>> index a67fc50..d25be60 100644
>>>> --- a/docs/firmware/fw_payload.md
>>>> +++ b/docs/firmware/fw_payload.md
>>>> @@ -36,8 +36,8 @@ options. These configuration parameters can be defined using either the top
>>>> level `make` command line or the target platform *objects.mk* configuration
>>>> file. The parameters currently defined are as follows:
>>>> 
>>>> -* **FW_PAYLOAD_OFFSET** - Offset from *FW_TEXT_START* where the payload binary
>>>> -  will be linked in the final *FW_PAYLOAD* firmware binary image. This
>>>> +* **FW_PAYLOAD_OFFSET** - Offset from the opensbi load address where the payload
>>>> +  binary will be linked in the final *FW_PAYLOAD* firmware binary image. This
>>>>   configuration parameter is mandatory if *FW_PAYLOAD_ALIGN* is not defined.
>>>>   Compilation errors will result from an incorrect definition of
>>>>   *FW_PAYLOAD_OFFSET* or of *FW_PAYLOAD_ALIGN*, or if neither of these
>>>> @@ -62,7 +62,7 @@ file. The parameters currently defined are as follows:
>>>>   firmware will pass the FDT address passed by the previous booting stage
>>>>   to the next booting stage.
>>>> 
>>>> -* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
>>>> +* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the opensbi load address where
>>>>   the FDT will be passed to the next booting stage. This offset is used as
>>>>   relocatable address of the FDT passed to the next booting stage. If
>>>>   *FW_PAYLOAD_FDT_ADDR* is also defined, the firmware will prefer *FW_PAYLOAD_FDT_ADDR*.
>>>> diff --git a/docs/platform/generic.md b/docs/platform/generic.md
>>>> index c29eb04..709b436 100644
>>>> --- a/docs/platform/generic.md
>>>> +++ b/docs/platform/generic.md
>>>> @@ -9,10 +9,9 @@ boards.
>>>> 
>>>> By default, the generic FDT platform makes following assumptions:
>>>> 
>>>> -1. platform FW_TEXT_START is 0x80000000
>>>> -2. platform features are default
>>>> -3. platform stack size is default
>>>> -4. platform has no quirks or work-arounds
>>>> +1. platform features are default
>>>> +2. platform stack size is default
>>>> +3. platform has no quirks or work-arounds
>>>> 
>>>> The above assumptions (except 1) can be overridden by adding special platform
>>>> callbacks which will be called based on FDT root node compatible string.
>>>> @@ -33,10 +32,6 @@ Users of the generic FDT platform will have to ensure that:
>>>> To build the platform-specific library and firmware images, provide the
>>>> *PLATFORM=generic* parameter to the top level `make` command.
>>>> 
>>>> -For custom FW_TEXT_START, we can build the platform-specific library and
>>>> -firmware images by passing *PLATFORM=generic FW_TEXT_START=<custom_text_start>*
>>>> -parameter to the top level `make` command.
>>>> -
>>>> Platform Options
>>>> ----------------
>>>> 
>>>> diff --git a/firmware/fw_base.S b/firmware/fw_base.S
>>>> index b950c0b..9f995a2 100644
>>>> --- a/firmware/fw_base.S
>>>> +++ b/firmware/fw_base.S
>>>> @@ -53,9 +53,7 @@ _try_lottery:
>>>>        bnez    a6, _wait_for_boot_hart
>>>> 
>>>>        /* relocate the global table content */
>>>> -       li      t0, FW_TEXT_START       /* link start */
>>>> -       lla     t1, _fw_start           /* load start */
>>>> -       sub     t2, t1, t0              /* load offset */
>>>> +       lla     t2, _fw_start
>>>>        lla     t0, __rel_dyn_start
>>>>        lla     t1, __rel_dyn_end
>>>>        beq     t0, t1, _relocate_done
>>>> diff --git a/firmware/fw_base.ldS b/firmware/fw_base.ldS
>>>> index fb47984..9d11db5 100644
>>>> --- a/firmware/fw_base.ldS
>>>> +++ b/firmware/fw_base.ldS
>>>> @@ -7,8 +7,7 @@
>>>>  *   Anup Patel <anup.patel@wdc.com>
>>>>  */
>>>> 
>>>> -       . = FW_TEXT_START;
>>>> -       /* Don't add any section between FW_TEXT_START and _fw_start */
>>>> +       /* Don't add any section before _fw_start */
>>>>        PROVIDE(_fw_start = .);
>>>> 
>>>>        . = ALIGN(0x1000); /* Need this to create proper sections */
>>>> diff --git a/firmware/fw_payload.elf.ldS b/firmware/fw_payload.elf.ldS
>>>> index f1a544b..94e1ac6 100644
>>>> --- a/firmware/fw_payload.elf.ldS
>>>> +++ b/firmware/fw_payload.elf.ldS
>>>> @@ -15,7 +15,7 @@ SECTIONS
>>>>        #include "fw_base.ldS"
>>>> 
>>>> #ifdef FW_PAYLOAD_OFFSET
>>>> -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
>>>> +       . = FW_PAYLOAD_OFFSET;
>>>> #else
>>>>        . = ALIGN(FW_PAYLOAD_ALIGN);
>>>> #endif
>>>> diff --git a/firmware/objects.mk b/firmware/objects.mk
>>>> index e6b364b..a51ff65 100644
>>>> --- a/firmware/objects.mk
>>>> +++ b/firmware/objects.mk
>>>> @@ -13,10 +13,6 @@ firmware-cflags-y +=
>>>> firmware-asflags-y +=
>>>> firmware-ldflags-y +=
>>>> 
>>>> -ifdef FW_TEXT_START
>>>> -firmware-genflags-y += -DFW_TEXT_START=$(FW_TEXT_START)
>>>> -endif
>>>> -
>>>> ifdef FW_FDT_PATH
>>>> firmware-genflags-y += -DFW_FDT_PATH=\"$(FW_FDT_PATH)\"
>>>> ifdef FW_FDT_PADDING
>>>> diff --git a/firmware/payloads/test.elf.ldS b/firmware/payloads/test.elf.ldS
>>>> index 2328a1b..08e008f 100644
>>>> --- a/firmware/payloads/test.elf.ldS
>>>> +++ b/firmware/payloads/test.elf.ldS
>>>> @@ -13,7 +13,7 @@ ENTRY(_start)
>>>> SECTIONS
>>>> {
>>>> #ifdef FW_PAYLOAD_OFFSET
>>>> -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
>>>> +       . = FW_PAYLOAD_OFFSET;
>>>> #else
>>>>        . = ALIGN(FW_PAYLOAD_ALIGN);
>>>> #endif
>>>> diff --git a/platform/fpga/ariane/objects.mk b/platform/fpga/ariane/objects.mk
>>>> index 83581ac..d1177f4 100644
>>>> --- a/platform/fpga/ariane/objects.mk
>>>> +++ b/platform/fpga/ariane/objects.mk
>>>> @@ -17,7 +17,6 @@ platform-objs-y += platform.o
>>>> PLATFORM_RISCV_XLEN = 64
>>>> 
>>>> # Blobs to build
>>>> -FW_TEXT_START=0x80000000
>>>> FW_JUMP=n
>>>> 
>>>> ifeq ($(PLATFORM_RISCV_XLEN), 32)
>>>> diff --git a/platform/fpga/openpiton/objects.mk b/platform/fpga/openpiton/objects.mk
>>>> index c8c345a..1a0ce0c 100644
>>>> --- a/platform/fpga/openpiton/objects.mk
>>>> +++ b/platform/fpga/openpiton/objects.mk
>>>> @@ -16,7 +16,6 @@ platform-objs-y += platform.o
>>>> PLATFORM_RISCV_XLEN = 64
>>>> 
>>>> # Blobs to build
>>>> -FW_TEXT_START=0x80000000
>>>> FW_JUMP=n
>>>> 
>>>> ifeq ($(PLATFORM_RISCV_XLEN), 32)
>>>> diff --git a/platform/generic/objects.mk b/platform/generic/objects.mk
>>>> index 85aa723..c215935 100644
>>>> --- a/platform/generic/objects.mk
>>>> +++ b/platform/generic/objects.mk
>>>> @@ -15,14 +15,13 @@ platform-ldflags-y =
>>>> 
>>>> # Command for platform specific "make run"
>>>> platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \
>>>> -  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.elf
>>>> +  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.bin
>>>> 
>>>> # Objects to build
>>>> platform-objs-y += platform.o
>>>> platform-objs-y += platform_override_modules.o
>>>> 
>>>> # Blobs to build
>>>> -FW_TEXT_START=0x80000000
>>>> FW_DYNAMIC=y
>>>> FW_JUMP=y
>>>> ifeq ($(PLATFORM_RISCV_XLEN), 32)
>>>> diff --git a/platform/kendryte/k210/objects.mk b/platform/kendryte/k210/objects.mk
>>>> index 1bfb898..efac3d2 100644
>>>> --- a/platform/kendryte/k210/objects.mk
>>>> +++ b/platform/kendryte/k210/objects.mk
>>>> @@ -21,6 +21,5 @@ platform-varprefix-k210.o = dt_k210
>>>> platform-padding-k210.o = 2048
>>>> 
>>>> # Blobs to build
>>>> -FW_TEXT_START=0x80000000
>>>> FW_PAYLOAD=y
>>>> FW_PAYLOAD_ALIGN=0x1000
>>>> diff --git a/platform/nuclei/ux600/objects.mk b/platform/nuclei/ux600/objects.mk
>>>> index 7c429e0..2753a7f 100644
>>>> --- a/platform/nuclei/ux600/objects.mk
>>>> +++ b/platform/nuclei/ux600/objects.mk
>>>> @@ -22,7 +22,6 @@ platform-runcmd = xl_spike \
>>>> platform-objs-y += platform.o
>>>> 
>>>> # Blobs to build
>>>> -FW_TEXT_START=0xA0000000
>>>> FW_DYNAMIC=y
>>>> FW_JUMP=y
>>>> 
>>>> diff --git a/platform/template/objects.mk b/platform/template/objects.mk
>>>> index b143cbc..f240a55 100644
>>>> --- a/platform/template/objects.mk
>>>> +++ b/platform/template/objects.mk
>>>> @@ -41,9 +41,6 @@ platform-objs-y += platform.o
>>>> #
>>>> # platform-objs-y += <dt file name>.o
>>>> 
>>>> -# Firmware load address configuration. This is mandatory.
>>>> -FW_TEXT_START=0x80000000
>>>> -
>>>> # Optional parameter for path to external FDT
>>>> # FW_FDT_PATH="path to platform flattened device tree file"
>>>> 
>>>> @@ -69,8 +66,7 @@ FW_JUMP=<y|n>
>>>> # endif
>>>> # FW_JUMP_FDT_OFFSET=0x2200000
>>>> #
>>>> -# You can use fixed address for jump firmware as an alternative option,
>>>> -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
>>>> +# You can use fixed address for jump firmware as an alternative option.
>>>> # SBI will prefer "<X>_ADDR" if both "<X>_ADDR" and "<X>_OFFSET" are
>>>> # defined
>>>> # ifeq ($(PLATFORM_RISCV_XLEN), 32)
>>>> @@ -97,8 +93,7 @@ endif
>>>> # FW_PAYLOAD_PATH="path to next boot stage binary image file"
>>>> # FW_PAYLOAD_FDT_OFFSET=0x2200000
>>>> #
>>>> -# You can use fixed address for payload firmware as an alternative option,
>>>> -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
>>>> +# You can use fixed address for payload firmware as an alternative option.
>>>> # SBI will prefer "FW_PAYLOAD_FDT_ADDR" if both "FW_PAYLOAD_FDT_OFFSET"
>>>> # and "FW_PAYLOAD_FDT_ADDR" are defined.
>>>> # FW_PAYLOAD_FDT_ADDR=0x82200000
>>>> --
>>>> 2.43.0
Jessica Clarke May 14, 2024, 4:59 p.m. UTC | #6
On 14 May 2024, at 17:50, Cheng Yang <yangcheng.work@foxmail.com> wrote:
> 
> &gt;On Tue, May 14, 2024 at 9:58 PM Clément Léger <cleger@rivosinc.com> wrote:
> &gt;&gt;
> &gt;&gt;
> &gt;&gt;
> &gt;&gt; On 10/04/2024 07:18, Anup Patel wrote:
> &gt;&gt; &gt; On Mon, Apr 8, 2024 at 9:01 PM Xiang W <wxjstz@126.com> wrote:
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; Now opensbi can run at any address via dynamic relocation. We can
> &gt;&gt; &gt;&gt; remove FW_TEXT_START.
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; Signed-off-by: Xiang W <wxjstz@126.com>
> &gt;&gt; &gt;
> &gt;&gt; &gt; LGTM.
> &gt;&gt; &gt;
> &gt;&gt; &gt; Reviewed-by: Anup Patel <anup@brainfault.org>
> &gt;&gt; &gt; Tested-by: Anup Patel <anup@brainfault.org>
> &gt;&gt; &gt;
> &gt;&gt; &gt; Applied this patch to the riscv/opensbi repo.
> &gt;&gt; &gt;
> &gt;&gt; &gt; Thanks,
> &gt;&gt; &gt; Anup
> &gt;&gt;
> &gt;&gt; Hi Anup,
> &gt;&gt;
> &gt;&gt; This patch seems to break spike support. The newly created ELF is not
> &gt;&gt; marked as EXEC anymore but DYNAMIC and it fails with the following error:
> &gt;&gt;
> &gt;&gt; spike: ../fesvr/elfloader.cc:45:
> &gt;&gt; std::map<std::__cxx11::basic_string<char>, long unsigned int&gt;
> &gt;&gt; load_elf(const char*, memif_t*, reg_t*, unsigned int): Assertion
> &gt;&gt; `IS_ELF_EXEC(*eh64)' failed.
> &gt;&gt;
> &gt;&gt; Should we fixed OpenSBI or allow spike to load a DYNAMIC elf ?
> &gt;
> &gt;I think it is better to use FW_DYNAMIC in Spike because various
> &gt;other projects (such as U-Boot, QEMU, etc) use it.
> &gt;
> &gt;Also, Spike should support loading M-mode firmware in BIN
> &gt;(flat binary) format as well.
> &gt;
> &gt;Regards,
> &gt;Anup
> &gt;
> &gt;&gt;
> &gt;&gt; Thanks,
> &gt;&gt;
> &gt;&gt; Clément
> &gt;&gt;
> 
> Hi Anup,
> 
> I think this patch is not that necessary, and after applying 
> this patch, we lost an elf file that can disassemble or directly 
> provide symbol addresses to gdb, which caused some difficulties 
> in debugging. In the past, I could pass it in Specify the address 
> of FW_TEXT_START during compilation to generate an ELF file containing 
> accurate symbol addresses, which is useful for debugging OpenSBI.

That’s what symbol-file /path/to/elf -o offset is for.

Jess
Cheng Yang May 14, 2024, 5:25 p.m. UTC | #7
On 14 May 2024, at 17:50, Cheng Yang <yangcheng.work at="" foxmail.com=""> wrote:
&gt;&gt; 
&gt;&gt; &gt;On Tue, May 14, 2024 at 9:58 PM Clément Léger <cleger at="" rivosinc.com=""> wrote:
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; On 10/04/2024 07:18, Anup Patel wrote:
&gt;&gt; &gt;&gt; &gt; On Mon, Apr 8, 2024 at 9:01 PM Xiang W <wxjstz at="" 126.com=""> wrote:
&gt;&gt; &gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; &gt;&gt; Now opensbi can run at any address via dynamic relocation. We can
&gt;&gt; &gt;&gt; &gt;&gt; remove FW_TEXT_START.
&gt;&gt; &gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; &gt;&gt; Signed-off-by: Xiang W <wxjstz at="" 126.com="">
&gt;&gt; &gt;&gt; &gt;
&gt;&gt; &gt;&gt; &gt; LGTM.
&gt;&gt; &gt;&gt; &gt;
&gt;&gt; &gt;&gt; &gt; Reviewed-by: Anup Patel <anup at="" brainfault.org="">
&gt;&gt; &gt;&gt; &gt; Tested-by: Anup Patel <anup at="" brainfault.org="">
&gt;&gt; &gt;&gt; &gt;
&gt;&gt; &gt;&gt; &gt; Applied this patch to the riscv/opensbi repo.
&gt;&gt; &gt;&gt; &gt;
&gt;&gt; &gt;&gt; &gt; Thanks,
&gt;&gt; &gt;&gt; &gt; Anup
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; Hi Anup,
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; This patch seems to break spike support. The newly created ELF is not
&gt;&gt; &gt;&gt; marked as EXEC anymore but DYNAMIC and it fails with the following error:
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; spike: ../fesvr/elfloader.cc:45:
&gt;&gt; &gt;&gt; std::map<std::__cxx11::basic_string<char>, long unsigned int&gt;
&gt;&gt; &gt;&gt; load_elf(const char*, memif_t*, reg_t*, unsigned int): Assertion
&gt;&gt; &gt;&gt; `IS_ELF_EXEC(*eh64)' failed.
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; Should we fixed OpenSBI or allow spike to load a DYNAMIC elf ?
&gt;&gt; &gt;
&gt;&gt; &gt;I think it is better to use FW_DYNAMIC in Spike because various
&gt;&gt; &gt;other projects (such as U-Boot, QEMU, etc) use it.
&gt;&gt; &gt;
&gt;&gt; &gt;Also, Spike should support loading M-mode firmware in BIN
&gt;&gt; &gt;(flat binary) format as well.
&gt;&gt; &gt;
&gt;&gt; &gt;Regards,
&gt;&gt; &gt;Anup
&gt;&gt; &gt;
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; Thanks,
&gt;&gt; &gt;&gt;
&gt;&gt; &gt;&gt; Clément
&gt;&gt; &gt;&gt;
&gt;&gt; 
&gt;&gt; Hi Anup,
&gt;&gt; 
&gt;&gt; I think this patch is not that necessary, and after applying 
&gt;&gt; this patch, we lost an elf file that can disassemble or directly 
&gt;&gt; provide symbol addresses to gdb, which caused some difficulties 
&gt;&gt; in debugging. In the past, I could pass it in Specify the address 
&gt;&gt; of FW_TEXT_START during compilation to generate an ELF file containing 
&gt;&gt; accurate symbol addresses, which is useful for debugging OpenSBI.
&gt;
&gt;That’s what symbol-file /path/to/elf -o offset is for.
&gt;
&gt;Jess
&gt;

Hi Jess,

Thanks for your tip, it can indeed solve the problem of gdb debugging. 
But I use vscode to start gdb for opensbi debugging. It reads symbols 
from the elf file in the specified "program" option by default, so I 
still need some other settings. I still recommend keeping FW_TEXT_START 
instead of removing it.

Best regards,
Cheng Yang</std::__cxx11::basic_string<char></anup></anup></wxjstz></wxjstz></cleger></yangcheng.work>
Clément Léger May 14, 2024, 5:44 p.m. UTC | #8
On 14/05/2024 18:56, Jessica Clarke wrote:
> On 14 May 2024, at 17:33, Anup Patel <anup@brainfault.org> wrote:
>>
>> On Tue, May 14, 2024 at 9:58 PM Clément Léger <cleger@rivosinc.com> wrote:
>>>
>>>
>>>
>>> On 10/04/2024 07:18, Anup Patel wrote:
>>>> On Mon, Apr 8, 2024 at 9:01 PM Xiang W <wxjstz@126.com> wrote:
>>>>>
>>>>> Now opensbi can run at any address via dynamic relocation. We can
>>>>> remove FW_TEXT_START.
>>>>>
>>>>> Signed-off-by: Xiang W <wxjstz@126.com>
>>>>
>>>> LGTM.
>>>>
>>>> Reviewed-by: Anup Patel <anup@brainfault.org>
>>>> Tested-by: Anup Patel <anup@brainfault.org>
>>>>
>>>> Applied this patch to the riscv/opensbi repo.
>>>>
>>>> Thanks,
>>>> Anup
>>>
>>> Hi Anup,
>>>
>>> This patch seems to break spike support. The newly created ELF is not
>>> marked as EXEC anymore but DYNAMIC and it fails with the following error:
>>>
>>> spike: ../fesvr/elfloader.cc:45:
>>> std::map<std::__cxx11::basic_string<char>, long unsigned int>
>>> load_elf(const char*, memif_t*, reg_t*, unsigned int): Assertion
>>> `IS_ELF_EXEC(*eh64)' failed.
>>>
>>> Should we fixed OpenSBI or allow spike to load a DYNAMIC elf ?
>>
>> I think it is better to use FW_DYNAMIC in Spike because various
>> other projects (such as U-Boot, QEMU, etc) use it.
> 
> That’s an orthogonal concern. This is about the ELF file type, not the
> boot method used, but supporting more boot methods is good too.
> 
> Spike should support ET_DYN files, but will need to adjust all the load
> addresses as they’ll be zero, so it’s not just a case of adding an
> option to the assert.

Yes sure. If nobody is looking at that, I'll see if I can take care of it.

Clément

> 
>> Also, Spike should support loading M-mode firmware in BIN
>> (flat binary) format as well.
> 
> There’s not really a good reason to prefer a flat binary over an ELF
> for an emulator*. For a board it makes sense because you want to have
> the flat binary ready to go in memory, but for an emulator it’s more
> useful to have the richer structure that an ELF provides, especially if
> that includes debug info. Historically Spike needed it to be an ELF so
> it could extract the HTIF symbol information as otherwise you’d have no
> console I/O, but I believe these days Spike can emulate an 8250 so that
> may no longer be a requirement?
> 
> Jess
> 
> * Space savings are minimal to non-existent; Debian’s U-Boot
>   qemu-riscv64_smode saves 0.8%, and the generic OpenSBI flat
>   binaries are bigger than the ELF files
> 
>> Regards,
>> Anup
>>
>>>
>>> Thanks,
>>>
>>> Clément
>>>
>>>>
>>>>> ---
>>>>>
>>>>> v4 changes:
>>>>> - only remove FW_TEXT_START by anup's suggestion
>>>>>
>>>>> docs/firmware/fw.md                |  2 --
>>>>> docs/firmware/fw_jump.md           |  4 ++--
>>>>> docs/firmware/fw_payload.md        |  6 +++---
>>>>> docs/platform/generic.md           | 11 +++--------
>>>>> firmware/fw_base.S                 |  4 +---
>>>>> firmware/fw_base.ldS               |  3 +--
>>>>> firmware/fw_payload.elf.ldS        |  2 +-
>>>>> firmware/objects.mk                |  4 ----
>>>>> firmware/payloads/test.elf.ldS     |  2 +-
>>>>> platform/fpga/ariane/objects.mk    |  1 -
>>>>> platform/fpga/openpiton/objects.mk |  1 -
>>>>> platform/generic/objects.mk        |  3 +--
>>>>> platform/kendryte/k210/objects.mk  |  1 -
>>>>> platform/nuclei/ux600/objects.mk   |  1 -
>>>>> platform/template/objects.mk       |  9 ++-------
>>>>> 15 files changed, 15 insertions(+), 39 deletions(-)
>>>>>
>>>>> diff --git a/docs/firmware/fw.md b/docs/firmware/fw.md
>>>>> index 2f4deb5..3cc0262 100644
>>>>> --- a/docs/firmware/fw.md
>>>>> +++ b/docs/firmware/fw.md
>>>>> @@ -61,8 +61,6 @@ Firmware Configuration and Compilation
>>>>> All firmware types support the following common compile time configuration
>>>>> parameters:
>>>>>
>>>>> -* **FW_TEXT_START** - Defines the execution address of the OpenSBI firmware.
>>>>> -  This configuration parameter is mandatory.
>>>>> * **FW_FDT_PATH** - Path to an external flattened device tree binary file to
>>>>>   be embedded in the *.rodata* section of the final firmware. If this option
>>>>>   is not provided then the firmware will expect the FDT to be passed as an
>>>>> diff --git a/docs/firmware/fw_jump.md b/docs/firmware/fw_jump.md
>>>>> index 2ee6b29..66be016 100644
>>>>> --- a/docs/firmware/fw_jump.md
>>>>> +++ b/docs/firmware/fw_jump.md
>>>>> @@ -35,7 +35,7 @@ follows:
>>>>>   At least one of *FW_JUMP_ADDR* and *FW_JUMP_OFFSET* (see below) should be
>>>>>   defined. Compilation errors will result from not defining one of them.
>>>>>
>>>>> -* **FW_JUMP_OFFSET** - Address offset from the *FW_TEXT_START* where the
>>>>> +* **FW_JUMP_OFFSET** - Address offset from the opensbi load address where the
>>>>>   entry point of the next booting stage is located. This offset is used as
>>>>>   relocatable address of the next booting stage entry point. If *FW_JUMP_ADDR*
>>>>>   is also defined, the firmware will prefer *FW_JUMP_ADDR*.
>>>>> @@ -62,7 +62,7 @@ follows:
>>>>>   echo fdt overlaps kernel, increase FW_JUMP_FDT_ADDR
>>>>>   ```
>>>>>
>>>>> -* **FW_JUMP_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
>>>>> +* **FW_JUMP_FDT_OFFSET** - Address offset from the opensbi load address where
>>>>>   the FDT will be passed to the next booting stage. This offset is used
>>>>>   as relocatable address of the FDT passed to the next booting stage. If
>>>>>   *FW_JUMP_FDT_ADDR* is also defined, the firmware will prefer
>>>>> diff --git a/docs/firmware/fw_payload.md b/docs/firmware/fw_payload.md
>>>>> index a67fc50..d25be60 100644
>>>>> --- a/docs/firmware/fw_payload.md
>>>>> +++ b/docs/firmware/fw_payload.md
>>>>> @@ -36,8 +36,8 @@ options. These configuration parameters can be defined using either the top
>>>>> level `make` command line or the target platform *objects.mk* configuration
>>>>> file. The parameters currently defined are as follows:
>>>>>
>>>>> -* **FW_PAYLOAD_OFFSET** - Offset from *FW_TEXT_START* where the payload binary
>>>>> -  will be linked in the final *FW_PAYLOAD* firmware binary image. This
>>>>> +* **FW_PAYLOAD_OFFSET** - Offset from the opensbi load address where the payload
>>>>> +  binary will be linked in the final *FW_PAYLOAD* firmware binary image. This
>>>>>   configuration parameter is mandatory if *FW_PAYLOAD_ALIGN* is not defined.
>>>>>   Compilation errors will result from an incorrect definition of
>>>>>   *FW_PAYLOAD_OFFSET* or of *FW_PAYLOAD_ALIGN*, or if neither of these
>>>>> @@ -62,7 +62,7 @@ file. The parameters currently defined are as follows:
>>>>>   firmware will pass the FDT address passed by the previous booting stage
>>>>>   to the next booting stage.
>>>>>
>>>>> -* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
>>>>> +* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the opensbi load address where
>>>>>   the FDT will be passed to the next booting stage. This offset is used as
>>>>>   relocatable address of the FDT passed to the next booting stage. If
>>>>>   *FW_PAYLOAD_FDT_ADDR* is also defined, the firmware will prefer *FW_PAYLOAD_FDT_ADDR*.
>>>>> diff --git a/docs/platform/generic.md b/docs/platform/generic.md
>>>>> index c29eb04..709b436 100644
>>>>> --- a/docs/platform/generic.md
>>>>> +++ b/docs/platform/generic.md
>>>>> @@ -9,10 +9,9 @@ boards.
>>>>>
>>>>> By default, the generic FDT platform makes following assumptions:
>>>>>
>>>>> -1. platform FW_TEXT_START is 0x80000000
>>>>> -2. platform features are default
>>>>> -3. platform stack size is default
>>>>> -4. platform has no quirks or work-arounds
>>>>> +1. platform features are default
>>>>> +2. platform stack size is default
>>>>> +3. platform has no quirks or work-arounds
>>>>>
>>>>> The above assumptions (except 1) can be overridden by adding special platform
>>>>> callbacks which will be called based on FDT root node compatible string.
>>>>> @@ -33,10 +32,6 @@ Users of the generic FDT platform will have to ensure that:
>>>>> To build the platform-specific library and firmware images, provide the
>>>>> *PLATFORM=generic* parameter to the top level `make` command.
>>>>>
>>>>> -For custom FW_TEXT_START, we can build the platform-specific library and
>>>>> -firmware images by passing *PLATFORM=generic FW_TEXT_START=<custom_text_start>*
>>>>> -parameter to the top level `make` command.
>>>>> -
>>>>> Platform Options
>>>>> ----------------
>>>>>
>>>>> diff --git a/firmware/fw_base.S b/firmware/fw_base.S
>>>>> index b950c0b..9f995a2 100644
>>>>> --- a/firmware/fw_base.S
>>>>> +++ b/firmware/fw_base.S
>>>>> @@ -53,9 +53,7 @@ _try_lottery:
>>>>>        bnez    a6, _wait_for_boot_hart
>>>>>
>>>>>        /* relocate the global table content */
>>>>> -       li      t0, FW_TEXT_START       /* link start */
>>>>> -       lla     t1, _fw_start           /* load start */
>>>>> -       sub     t2, t1, t0              /* load offset */
>>>>> +       lla     t2, _fw_start
>>>>>        lla     t0, __rel_dyn_start
>>>>>        lla     t1, __rel_dyn_end
>>>>>        beq     t0, t1, _relocate_done
>>>>> diff --git a/firmware/fw_base.ldS b/firmware/fw_base.ldS
>>>>> index fb47984..9d11db5 100644
>>>>> --- a/firmware/fw_base.ldS
>>>>> +++ b/firmware/fw_base.ldS
>>>>> @@ -7,8 +7,7 @@
>>>>>  *   Anup Patel <anup.patel@wdc.com>
>>>>>  */
>>>>>
>>>>> -       . = FW_TEXT_START;
>>>>> -       /* Don't add any section between FW_TEXT_START and _fw_start */
>>>>> +       /* Don't add any section before _fw_start */
>>>>>        PROVIDE(_fw_start = .);
>>>>>
>>>>>        . = ALIGN(0x1000); /* Need this to create proper sections */
>>>>> diff --git a/firmware/fw_payload.elf.ldS b/firmware/fw_payload.elf.ldS
>>>>> index f1a544b..94e1ac6 100644
>>>>> --- a/firmware/fw_payload.elf.ldS
>>>>> +++ b/firmware/fw_payload.elf.ldS
>>>>> @@ -15,7 +15,7 @@ SECTIONS
>>>>>        #include "fw_base.ldS"
>>>>>
>>>>> #ifdef FW_PAYLOAD_OFFSET
>>>>> -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
>>>>> +       . = FW_PAYLOAD_OFFSET;
>>>>> #else
>>>>>        . = ALIGN(FW_PAYLOAD_ALIGN);
>>>>> #endif
>>>>> diff --git a/firmware/objects.mk b/firmware/objects.mk
>>>>> index e6b364b..a51ff65 100644
>>>>> --- a/firmware/objects.mk
>>>>> +++ b/firmware/objects.mk
>>>>> @@ -13,10 +13,6 @@ firmware-cflags-y +=
>>>>> firmware-asflags-y +=
>>>>> firmware-ldflags-y +=
>>>>>
>>>>> -ifdef FW_TEXT_START
>>>>> -firmware-genflags-y += -DFW_TEXT_START=$(FW_TEXT_START)
>>>>> -endif
>>>>> -
>>>>> ifdef FW_FDT_PATH
>>>>> firmware-genflags-y += -DFW_FDT_PATH=\"$(FW_FDT_PATH)\"
>>>>> ifdef FW_FDT_PADDING
>>>>> diff --git a/firmware/payloads/test.elf.ldS b/firmware/payloads/test.elf.ldS
>>>>> index 2328a1b..08e008f 100644
>>>>> --- a/firmware/payloads/test.elf.ldS
>>>>> +++ b/firmware/payloads/test.elf.ldS
>>>>> @@ -13,7 +13,7 @@ ENTRY(_start)
>>>>> SECTIONS
>>>>> {
>>>>> #ifdef FW_PAYLOAD_OFFSET
>>>>> -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
>>>>> +       . = FW_PAYLOAD_OFFSET;
>>>>> #else
>>>>>        . = ALIGN(FW_PAYLOAD_ALIGN);
>>>>> #endif
>>>>> diff --git a/platform/fpga/ariane/objects.mk b/platform/fpga/ariane/objects.mk
>>>>> index 83581ac..d1177f4 100644
>>>>> --- a/platform/fpga/ariane/objects.mk
>>>>> +++ b/platform/fpga/ariane/objects.mk
>>>>> @@ -17,7 +17,6 @@ platform-objs-y += platform.o
>>>>> PLATFORM_RISCV_XLEN = 64
>>>>>
>>>>> # Blobs to build
>>>>> -FW_TEXT_START=0x80000000
>>>>> FW_JUMP=n
>>>>>
>>>>> ifeq ($(PLATFORM_RISCV_XLEN), 32)
>>>>> diff --git a/platform/fpga/openpiton/objects.mk b/platform/fpga/openpiton/objects.mk
>>>>> index c8c345a..1a0ce0c 100644
>>>>> --- a/platform/fpga/openpiton/objects.mk
>>>>> +++ b/platform/fpga/openpiton/objects.mk
>>>>> @@ -16,7 +16,6 @@ platform-objs-y += platform.o
>>>>> PLATFORM_RISCV_XLEN = 64
>>>>>
>>>>> # Blobs to build
>>>>> -FW_TEXT_START=0x80000000
>>>>> FW_JUMP=n
>>>>>
>>>>> ifeq ($(PLATFORM_RISCV_XLEN), 32)
>>>>> diff --git a/platform/generic/objects.mk b/platform/generic/objects.mk
>>>>> index 85aa723..c215935 100644
>>>>> --- a/platform/generic/objects.mk
>>>>> +++ b/platform/generic/objects.mk
>>>>> @@ -15,14 +15,13 @@ platform-ldflags-y =
>>>>>
>>>>> # Command for platform specific "make run"
>>>>> platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \
>>>>> -  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.elf
>>>>> +  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.bin
>>>>>
>>>>> # Objects to build
>>>>> platform-objs-y += platform.o
>>>>> platform-objs-y += platform_override_modules.o
>>>>>
>>>>> # Blobs to build
>>>>> -FW_TEXT_START=0x80000000
>>>>> FW_DYNAMIC=y
>>>>> FW_JUMP=y
>>>>> ifeq ($(PLATFORM_RISCV_XLEN), 32)
>>>>> diff --git a/platform/kendryte/k210/objects.mk b/platform/kendryte/k210/objects.mk
>>>>> index 1bfb898..efac3d2 100644
>>>>> --- a/platform/kendryte/k210/objects.mk
>>>>> +++ b/platform/kendryte/k210/objects.mk
>>>>> @@ -21,6 +21,5 @@ platform-varprefix-k210.o = dt_k210
>>>>> platform-padding-k210.o = 2048
>>>>>
>>>>> # Blobs to build
>>>>> -FW_TEXT_START=0x80000000
>>>>> FW_PAYLOAD=y
>>>>> FW_PAYLOAD_ALIGN=0x1000
>>>>> diff --git a/platform/nuclei/ux600/objects.mk b/platform/nuclei/ux600/objects.mk
>>>>> index 7c429e0..2753a7f 100644
>>>>> --- a/platform/nuclei/ux600/objects.mk
>>>>> +++ b/platform/nuclei/ux600/objects.mk
>>>>> @@ -22,7 +22,6 @@ platform-runcmd = xl_spike \
>>>>> platform-objs-y += platform.o
>>>>>
>>>>> # Blobs to build
>>>>> -FW_TEXT_START=0xA0000000
>>>>> FW_DYNAMIC=y
>>>>> FW_JUMP=y
>>>>>
>>>>> diff --git a/platform/template/objects.mk b/platform/template/objects.mk
>>>>> index b143cbc..f240a55 100644
>>>>> --- a/platform/template/objects.mk
>>>>> +++ b/platform/template/objects.mk
>>>>> @@ -41,9 +41,6 @@ platform-objs-y += platform.o
>>>>> #
>>>>> # platform-objs-y += <dt file name>.o
>>>>>
>>>>> -# Firmware load address configuration. This is mandatory.
>>>>> -FW_TEXT_START=0x80000000
>>>>> -
>>>>> # Optional parameter for path to external FDT
>>>>> # FW_FDT_PATH="path to platform flattened device tree file"
>>>>>
>>>>> @@ -69,8 +66,7 @@ FW_JUMP=<y|n>
>>>>> # endif
>>>>> # FW_JUMP_FDT_OFFSET=0x2200000
>>>>> #
>>>>> -# You can use fixed address for jump firmware as an alternative option,
>>>>> -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
>>>>> +# You can use fixed address for jump firmware as an alternative option.
>>>>> # SBI will prefer "<X>_ADDR" if both "<X>_ADDR" and "<X>_OFFSET" are
>>>>> # defined
>>>>> # ifeq ($(PLATFORM_RISCV_XLEN), 32)
>>>>> @@ -97,8 +93,7 @@ endif
>>>>> # FW_PAYLOAD_PATH="path to next boot stage binary image file"
>>>>> # FW_PAYLOAD_FDT_OFFSET=0x2200000
>>>>> #
>>>>> -# You can use fixed address for payload firmware as an alternative option,
>>>>> -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
>>>>> +# You can use fixed address for payload firmware as an alternative option.
>>>>> # SBI will prefer "FW_PAYLOAD_FDT_ADDR" if both "FW_PAYLOAD_FDT_OFFSET"
>>>>> # and "FW_PAYLOAD_FDT_ADDR" are defined.
>>>>> # FW_PAYLOAD_FDT_ADDR=0x82200000
>>>>> --
>>>>> 2.43.0
> 
>
Jessica Clarke May 14, 2024, 5:46 p.m. UTC | #9
On 14 May 2024, at 18:25, Cheng Yang <yangcheng.work@foxmail.com> wrote:
> 
> On 14 May 2024, at 17:50, Cheng Yang <yangcheng.work at="" foxmail.com=""> wrote:
> &gt;&gt; 
> &gt;&gt; &gt;On Tue, May 14, 2024 at 9:58 PM Clément Léger <cleger at="" rivosinc.com=""> wrote:
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; On 10/04/2024 07:18, Anup Patel wrote:
> &gt;&gt; &gt;&gt; &gt; On Mon, Apr 8, 2024 at 9:01 PM Xiang W <wxjstz at="" 126.com=""> wrote:
> &gt;&gt; &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; &gt;&gt; Now opensbi can run at any address via dynamic relocation. We can
> &gt;&gt; &gt;&gt; &gt;&gt; remove FW_TEXT_START.
> &gt;&gt; &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; &gt;&gt; Signed-off-by: Xiang W <wxjstz at="" 126.com="">
> &gt;&gt; &gt;&gt; &gt;
> &gt;&gt; &gt;&gt; &gt; LGTM.
> &gt;&gt; &gt;&gt; &gt;
> &gt;&gt; &gt;&gt; &gt; Reviewed-by: Anup Patel <anup at="" brainfault.org="">
> &gt;&gt; &gt;&gt; &gt; Tested-by: Anup Patel <anup at="" brainfault.org="">
> &gt;&gt; &gt;&gt; &gt;
> &gt;&gt; &gt;&gt; &gt; Applied this patch to the riscv/opensbi repo.
> &gt;&gt; &gt;&gt; &gt;
> &gt;&gt; &gt;&gt; &gt; Thanks,
> &gt;&gt; &gt;&gt; &gt; Anup
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; Hi Anup,
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; This patch seems to break spike support. The newly created ELF is not
> &gt;&gt; &gt;&gt; marked as EXEC anymore but DYNAMIC and it fails with the following error:
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; spike: ../fesvr/elfloader.cc:45:
> &gt;&gt; &gt;&gt; std::map<std::__cxx11::basic_string<char>, long unsigned int&gt;
> &gt;&gt; &gt;&gt; load_elf(const char*, memif_t*, reg_t*, unsigned int): Assertion
> &gt;&gt; &gt;&gt; `IS_ELF_EXEC(*eh64)' failed.
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; Should we fixed OpenSBI or allow spike to load a DYNAMIC elf ?
> &gt;&gt; &gt;
> &gt;&gt; &gt;I think it is better to use FW_DYNAMIC in Spike because various
> &gt;&gt; &gt;other projects (such as U-Boot, QEMU, etc) use it.
> &gt;&gt; &gt;
> &gt;&gt; &gt;Also, Spike should support loading M-mode firmware in BIN
> &gt;&gt; &gt;(flat binary) format as well.
> &gt;&gt; &gt;
> &gt;&gt; &gt;Regards,
> &gt;&gt; &gt;Anup
> &gt;&gt; &gt;
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; Thanks,
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; Clément
> &gt;&gt; &gt;&gt;
> &gt;&gt; 
> &gt;&gt; Hi Anup,
> &gt;&gt; 
> &gt;&gt; I think this patch is not that necessary, and after applying 
> &gt;&gt; this patch, we lost an elf file that can disassemble or directly 
> &gt;&gt; provide symbol addresses to gdb, which caused some difficulties 
> &gt;&gt; in debugging. In the past, I could pass it in Specify the address 
> &gt;&gt; of FW_TEXT_START during compilation to generate an ELF file containing 
> &gt;&gt; accurate symbol addresses, which is useful for debugging OpenSBI.
> &gt;
> &gt;That’s what symbol-file /path/to/elf -o offset is for.
> &gt;
> &gt;Jess
> &gt;
> 
> Hi Jess,
> 
> Thanks for your tip, it can indeed solve the problem of gdb debugging. 
> But I use vscode to start gdb for opensbi debugging. It reads symbols 
> from the elf file in the specified "program" option by default, so I 
> still need some other settings. I still recommend keeping FW_TEXT_START 
> instead of removing it.

“My editor of choice is deficient” isn’t suitable justification for
imposing complexity like this on everyone IMO. But regardless, Visual
Studio Code has the ability to run custom commands on GDB startup[1].

Jess

[1] https://code.visualstudio.com/docs/cpp/launch-json-reference#_setupcommands
Anup Patel May 15, 2024, 5:47 a.m. UTC | #10
On Tue, May 14, 2024 at 10:26 PM Jessica Clarke <jrtc27@jrtc27.com> wrote:
>
> On 14 May 2024, at 17:33, Anup Patel <anup@brainfault.org> wrote:
> >
> > On Tue, May 14, 2024 at 9:58 PM Clément Léger <cleger@rivosinc.com> wrote:
> >>
> >>
> >>
> >> On 10/04/2024 07:18, Anup Patel wrote:
> >>> On Mon, Apr 8, 2024 at 9:01 PM Xiang W <wxjstz@126.com> wrote:
> >>>>
> >>>> Now opensbi can run at any address via dynamic relocation. We can
> >>>> remove FW_TEXT_START.
> >>>>
> >>>> Signed-off-by: Xiang W <wxjstz@126.com>
> >>>
> >>> LGTM.
> >>>
> >>> Reviewed-by: Anup Patel <anup@brainfault.org>
> >>> Tested-by: Anup Patel <anup@brainfault.org>
> >>>
> >>> Applied this patch to the riscv/opensbi repo.
> >>>
> >>> Thanks,
> >>> Anup
> >>
> >> Hi Anup,
> >>
> >> This patch seems to break spike support. The newly created ELF is not
> >> marked as EXEC anymore but DYNAMIC and it fails with the following error:
> >>
> >> spike: ../fesvr/elfloader.cc:45:
> >> std::map<std::__cxx11::basic_string<char>, long unsigned int>
> >> load_elf(const char*, memif_t*, reg_t*, unsigned int): Assertion
> >> `IS_ELF_EXEC(*eh64)' failed.
> >>
> >> Should we fixed OpenSBI or allow spike to load a DYNAMIC elf ?
> >
> > I think it is better to use FW_DYNAMIC in Spike because various
> > other projects (such as U-Boot, QEMU, etc) use it.
>
> That’s an orthogonal concern. This is about the ELF file type, not the
> boot method used, but supporting more boot methods is good too.
>
> Spike should support ET_DYN files, but will need to adjust all the load
> addresses as they’ll be zero, so it’s not just a case of adding an
> option to the assert.

Ahh, I misinterpreted "DYNAMIC" as FW_DYNAMIC. Thanks for
clarifying.

>
> > Also, Spike should support loading M-mode firmware in BIN
> > (flat binary) format as well.
>
> There’s not really a good reason to prefer a flat binary over an ELF
> for an emulator*. For a board it makes sense because you want to have
> the flat binary ready to go in memory, but for an emulator it’s more
> useful to have the richer structure that an ELF provides, especially if
> that includes debug info. Historically Spike needed it to be an ELF so
> it could extract the HTIF symbol information as otherwise you’d have no
> console I/O, but I believe these days Spike can emulate an 8250 so that
> may no longer be a requirement?

Nothing against using ELF on emulators but it is generally
better to use the same firmware binary on both real board
and emulators. In fact, the same fw_dynamic.bin works on
QEMU RISC-V and a variety of RISC-V boards.

Regarding HTIF location, both OpenSBI and U-Boot support
detecting HTIF location through DT so even flat firmware binary
can use HTIF.

Regards,
Anup


>
> Jess
>
> * Space savings are minimal to non-existent; Debian’s U-Boot
>   qemu-riscv64_smode saves 0.8%, and the generic OpenSBI flat
>   binaries are bigger than the ELF files
>
> > Regards,
> > Anup
> >
> >>
> >> Thanks,
> >>
> >> Clément
> >>
> >>>
> >>>> ---
> >>>>
> >>>> v4 changes:
> >>>> - only remove FW_TEXT_START by anup's suggestion
> >>>>
> >>>> docs/firmware/fw.md                |  2 --
> >>>> docs/firmware/fw_jump.md           |  4 ++--
> >>>> docs/firmware/fw_payload.md        |  6 +++---
> >>>> docs/platform/generic.md           | 11 +++--------
> >>>> firmware/fw_base.S                 |  4 +---
> >>>> firmware/fw_base.ldS               |  3 +--
> >>>> firmware/fw_payload.elf.ldS        |  2 +-
> >>>> firmware/objects.mk                |  4 ----
> >>>> firmware/payloads/test.elf.ldS     |  2 +-
> >>>> platform/fpga/ariane/objects.mk    |  1 -
> >>>> platform/fpga/openpiton/objects.mk |  1 -
> >>>> platform/generic/objects.mk        |  3 +--
> >>>> platform/kendryte/k210/objects.mk  |  1 -
> >>>> platform/nuclei/ux600/objects.mk   |  1 -
> >>>> platform/template/objects.mk       |  9 ++-------
> >>>> 15 files changed, 15 insertions(+), 39 deletions(-)
> >>>>
> >>>> diff --git a/docs/firmware/fw.md b/docs/firmware/fw.md
> >>>> index 2f4deb5..3cc0262 100644
> >>>> --- a/docs/firmware/fw.md
> >>>> +++ b/docs/firmware/fw.md
> >>>> @@ -61,8 +61,6 @@ Firmware Configuration and Compilation
> >>>> All firmware types support the following common compile time configuration
> >>>> parameters:
> >>>>
> >>>> -* **FW_TEXT_START** - Defines the execution address of the OpenSBI firmware.
> >>>> -  This configuration parameter is mandatory.
> >>>> * **FW_FDT_PATH** - Path to an external flattened device tree binary file to
> >>>>   be embedded in the *.rodata* section of the final firmware. If this option
> >>>>   is not provided then the firmware will expect the FDT to be passed as an
> >>>> diff --git a/docs/firmware/fw_jump.md b/docs/firmware/fw_jump.md
> >>>> index 2ee6b29..66be016 100644
> >>>> --- a/docs/firmware/fw_jump.md
> >>>> +++ b/docs/firmware/fw_jump.md
> >>>> @@ -35,7 +35,7 @@ follows:
> >>>>   At least one of *FW_JUMP_ADDR* and *FW_JUMP_OFFSET* (see below) should be
> >>>>   defined. Compilation errors will result from not defining one of them.
> >>>>
> >>>> -* **FW_JUMP_OFFSET** - Address offset from the *FW_TEXT_START* where the
> >>>> +* **FW_JUMP_OFFSET** - Address offset from the opensbi load address where the
> >>>>   entry point of the next booting stage is located. This offset is used as
> >>>>   relocatable address of the next booting stage entry point. If *FW_JUMP_ADDR*
> >>>>   is also defined, the firmware will prefer *FW_JUMP_ADDR*.
> >>>> @@ -62,7 +62,7 @@ follows:
> >>>>   echo fdt overlaps kernel, increase FW_JUMP_FDT_ADDR
> >>>>   ```
> >>>>
> >>>> -* **FW_JUMP_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
> >>>> +* **FW_JUMP_FDT_OFFSET** - Address offset from the opensbi load address where
> >>>>   the FDT will be passed to the next booting stage. This offset is used
> >>>>   as relocatable address of the FDT passed to the next booting stage. If
> >>>>   *FW_JUMP_FDT_ADDR* is also defined, the firmware will prefer
> >>>> diff --git a/docs/firmware/fw_payload.md b/docs/firmware/fw_payload.md
> >>>> index a67fc50..d25be60 100644
> >>>> --- a/docs/firmware/fw_payload.md
> >>>> +++ b/docs/firmware/fw_payload.md
> >>>> @@ -36,8 +36,8 @@ options. These configuration parameters can be defined using either the top
> >>>> level `make` command line or the target platform *objects.mk* configuration
> >>>> file. The parameters currently defined are as follows:
> >>>>
> >>>> -* **FW_PAYLOAD_OFFSET** - Offset from *FW_TEXT_START* where the payload binary
> >>>> -  will be linked in the final *FW_PAYLOAD* firmware binary image. This
> >>>> +* **FW_PAYLOAD_OFFSET** - Offset from the opensbi load address where the payload
> >>>> +  binary will be linked in the final *FW_PAYLOAD* firmware binary image. This
> >>>>   configuration parameter is mandatory if *FW_PAYLOAD_ALIGN* is not defined.
> >>>>   Compilation errors will result from an incorrect definition of
> >>>>   *FW_PAYLOAD_OFFSET* or of *FW_PAYLOAD_ALIGN*, or if neither of these
> >>>> @@ -62,7 +62,7 @@ file. The parameters currently defined are as follows:
> >>>>   firmware will pass the FDT address passed by the previous booting stage
> >>>>   to the next booting stage.
> >>>>
> >>>> -* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
> >>>> +* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the opensbi load address where
> >>>>   the FDT will be passed to the next booting stage. This offset is used as
> >>>>   relocatable address of the FDT passed to the next booting stage. If
> >>>>   *FW_PAYLOAD_FDT_ADDR* is also defined, the firmware will prefer *FW_PAYLOAD_FDT_ADDR*.
> >>>> diff --git a/docs/platform/generic.md b/docs/platform/generic.md
> >>>> index c29eb04..709b436 100644
> >>>> --- a/docs/platform/generic.md
> >>>> +++ b/docs/platform/generic.md
> >>>> @@ -9,10 +9,9 @@ boards.
> >>>>
> >>>> By default, the generic FDT platform makes following assumptions:
> >>>>
> >>>> -1. platform FW_TEXT_START is 0x80000000
> >>>> -2. platform features are default
> >>>> -3. platform stack size is default
> >>>> -4. platform has no quirks or work-arounds
> >>>> +1. platform features are default
> >>>> +2. platform stack size is default
> >>>> +3. platform has no quirks or work-arounds
> >>>>
> >>>> The above assumptions (except 1) can be overridden by adding special platform
> >>>> callbacks which will be called based on FDT root node compatible string.
> >>>> @@ -33,10 +32,6 @@ Users of the generic FDT platform will have to ensure that:
> >>>> To build the platform-specific library and firmware images, provide the
> >>>> *PLATFORM=generic* parameter to the top level `make` command.
> >>>>
> >>>> -For custom FW_TEXT_START, we can build the platform-specific library and
> >>>> -firmware images by passing *PLATFORM=generic FW_TEXT_START=<custom_text_start>*
> >>>> -parameter to the top level `make` command.
> >>>> -
> >>>> Platform Options
> >>>> ----------------
> >>>>
> >>>> diff --git a/firmware/fw_base.S b/firmware/fw_base.S
> >>>> index b950c0b..9f995a2 100644
> >>>> --- a/firmware/fw_base.S
> >>>> +++ b/firmware/fw_base.S
> >>>> @@ -53,9 +53,7 @@ _try_lottery:
> >>>>        bnez    a6, _wait_for_boot_hart
> >>>>
> >>>>        /* relocate the global table content */
> >>>> -       li      t0, FW_TEXT_START       /* link start */
> >>>> -       lla     t1, _fw_start           /* load start */
> >>>> -       sub     t2, t1, t0              /* load offset */
> >>>> +       lla     t2, _fw_start
> >>>>        lla     t0, __rel_dyn_start
> >>>>        lla     t1, __rel_dyn_end
> >>>>        beq     t0, t1, _relocate_done
> >>>> diff --git a/firmware/fw_base.ldS b/firmware/fw_base.ldS
> >>>> index fb47984..9d11db5 100644
> >>>> --- a/firmware/fw_base.ldS
> >>>> +++ b/firmware/fw_base.ldS
> >>>> @@ -7,8 +7,7 @@
> >>>>  *   Anup Patel <anup.patel@wdc.com>
> >>>>  */
> >>>>
> >>>> -       . = FW_TEXT_START;
> >>>> -       /* Don't add any section between FW_TEXT_START and _fw_start */
> >>>> +       /* Don't add any section before _fw_start */
> >>>>        PROVIDE(_fw_start = .);
> >>>>
> >>>>        . = ALIGN(0x1000); /* Need this to create proper sections */
> >>>> diff --git a/firmware/fw_payload.elf.ldS b/firmware/fw_payload.elf.ldS
> >>>> index f1a544b..94e1ac6 100644
> >>>> --- a/firmware/fw_payload.elf.ldS
> >>>> +++ b/firmware/fw_payload.elf.ldS
> >>>> @@ -15,7 +15,7 @@ SECTIONS
> >>>>        #include "fw_base.ldS"
> >>>>
> >>>> #ifdef FW_PAYLOAD_OFFSET
> >>>> -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
> >>>> +       . = FW_PAYLOAD_OFFSET;
> >>>> #else
> >>>>        . = ALIGN(FW_PAYLOAD_ALIGN);
> >>>> #endif
> >>>> diff --git a/firmware/objects.mk b/firmware/objects.mk
> >>>> index e6b364b..a51ff65 100644
> >>>> --- a/firmware/objects.mk
> >>>> +++ b/firmware/objects.mk
> >>>> @@ -13,10 +13,6 @@ firmware-cflags-y +=
> >>>> firmware-asflags-y +=
> >>>> firmware-ldflags-y +=
> >>>>
> >>>> -ifdef FW_TEXT_START
> >>>> -firmware-genflags-y += -DFW_TEXT_START=$(FW_TEXT_START)
> >>>> -endif
> >>>> -
> >>>> ifdef FW_FDT_PATH
> >>>> firmware-genflags-y += -DFW_FDT_PATH=\"$(FW_FDT_PATH)\"
> >>>> ifdef FW_FDT_PADDING
> >>>> diff --git a/firmware/payloads/test.elf.ldS b/firmware/payloads/test.elf.ldS
> >>>> index 2328a1b..08e008f 100644
> >>>> --- a/firmware/payloads/test.elf.ldS
> >>>> +++ b/firmware/payloads/test.elf.ldS
> >>>> @@ -13,7 +13,7 @@ ENTRY(_start)
> >>>> SECTIONS
> >>>> {
> >>>> #ifdef FW_PAYLOAD_OFFSET
> >>>> -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
> >>>> +       . = FW_PAYLOAD_OFFSET;
> >>>> #else
> >>>>        . = ALIGN(FW_PAYLOAD_ALIGN);
> >>>> #endif
> >>>> diff --git a/platform/fpga/ariane/objects.mk b/platform/fpga/ariane/objects.mk
> >>>> index 83581ac..d1177f4 100644
> >>>> --- a/platform/fpga/ariane/objects.mk
> >>>> +++ b/platform/fpga/ariane/objects.mk
> >>>> @@ -17,7 +17,6 @@ platform-objs-y += platform.o
> >>>> PLATFORM_RISCV_XLEN = 64
> >>>>
> >>>> # Blobs to build
> >>>> -FW_TEXT_START=0x80000000
> >>>> FW_JUMP=n
> >>>>
> >>>> ifeq ($(PLATFORM_RISCV_XLEN), 32)
> >>>> diff --git a/platform/fpga/openpiton/objects.mk b/platform/fpga/openpiton/objects.mk
> >>>> index c8c345a..1a0ce0c 100644
> >>>> --- a/platform/fpga/openpiton/objects.mk
> >>>> +++ b/platform/fpga/openpiton/objects.mk
> >>>> @@ -16,7 +16,6 @@ platform-objs-y += platform.o
> >>>> PLATFORM_RISCV_XLEN = 64
> >>>>
> >>>> # Blobs to build
> >>>> -FW_TEXT_START=0x80000000
> >>>> FW_JUMP=n
> >>>>
> >>>> ifeq ($(PLATFORM_RISCV_XLEN), 32)
> >>>> diff --git a/platform/generic/objects.mk b/platform/generic/objects.mk
> >>>> index 85aa723..c215935 100644
> >>>> --- a/platform/generic/objects.mk
> >>>> +++ b/platform/generic/objects.mk
> >>>> @@ -15,14 +15,13 @@ platform-ldflags-y =
> >>>>
> >>>> # Command for platform specific "make run"
> >>>> platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \
> >>>> -  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.elf
> >>>> +  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.bin
> >>>>
> >>>> # Objects to build
> >>>> platform-objs-y += platform.o
> >>>> platform-objs-y += platform_override_modules.o
> >>>>
> >>>> # Blobs to build
> >>>> -FW_TEXT_START=0x80000000
> >>>> FW_DYNAMIC=y
> >>>> FW_JUMP=y
> >>>> ifeq ($(PLATFORM_RISCV_XLEN), 32)
> >>>> diff --git a/platform/kendryte/k210/objects.mk b/platform/kendryte/k210/objects.mk
> >>>> index 1bfb898..efac3d2 100644
> >>>> --- a/platform/kendryte/k210/objects.mk
> >>>> +++ b/platform/kendryte/k210/objects.mk
> >>>> @@ -21,6 +21,5 @@ platform-varprefix-k210.o = dt_k210
> >>>> platform-padding-k210.o = 2048
> >>>>
> >>>> # Blobs to build
> >>>> -FW_TEXT_START=0x80000000
> >>>> FW_PAYLOAD=y
> >>>> FW_PAYLOAD_ALIGN=0x1000
> >>>> diff --git a/platform/nuclei/ux600/objects.mk b/platform/nuclei/ux600/objects.mk
> >>>> index 7c429e0..2753a7f 100644
> >>>> --- a/platform/nuclei/ux600/objects.mk
> >>>> +++ b/platform/nuclei/ux600/objects.mk
> >>>> @@ -22,7 +22,6 @@ platform-runcmd = xl_spike \
> >>>> platform-objs-y += platform.o
> >>>>
> >>>> # Blobs to build
> >>>> -FW_TEXT_START=0xA0000000
> >>>> FW_DYNAMIC=y
> >>>> FW_JUMP=y
> >>>>
> >>>> diff --git a/platform/template/objects.mk b/platform/template/objects.mk
> >>>> index b143cbc..f240a55 100644
> >>>> --- a/platform/template/objects.mk
> >>>> +++ b/platform/template/objects.mk
> >>>> @@ -41,9 +41,6 @@ platform-objs-y += platform.o
> >>>> #
> >>>> # platform-objs-y += <dt file name>.o
> >>>>
> >>>> -# Firmware load address configuration. This is mandatory.
> >>>> -FW_TEXT_START=0x80000000
> >>>> -
> >>>> # Optional parameter for path to external FDT
> >>>> # FW_FDT_PATH="path to platform flattened device tree file"
> >>>>
> >>>> @@ -69,8 +66,7 @@ FW_JUMP=<y|n>
> >>>> # endif
> >>>> # FW_JUMP_FDT_OFFSET=0x2200000
> >>>> #
> >>>> -# You can use fixed address for jump firmware as an alternative option,
> >>>> -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
> >>>> +# You can use fixed address for jump firmware as an alternative option.
> >>>> # SBI will prefer "<X>_ADDR" if both "<X>_ADDR" and "<X>_OFFSET" are
> >>>> # defined
> >>>> # ifeq ($(PLATFORM_RISCV_XLEN), 32)
> >>>> @@ -97,8 +93,7 @@ endif
> >>>> # FW_PAYLOAD_PATH="path to next boot stage binary image file"
> >>>> # FW_PAYLOAD_FDT_OFFSET=0x2200000
> >>>> #
> >>>> -# You can use fixed address for payload firmware as an alternative option,
> >>>> -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
> >>>> +# You can use fixed address for payload firmware as an alternative option.
> >>>> # SBI will prefer "FW_PAYLOAD_FDT_ADDR" if both "FW_PAYLOAD_FDT_OFFSET"
> >>>> # and "FW_PAYLOAD_FDT_ADDR" are defined.
> >>>> # FW_PAYLOAD_FDT_ADDR=0x82200000
> >>>> --
> >>>> 2.43.0
>
>
Anup Patel May 15, 2024, 6 a.m. UTC | #11
On Tue, May 14, 2024 at 10:20 PM Cheng Yang <yangcheng.work@foxmail.com> wrote:
>
> &gt;On Tue, May 14, 2024 at 9:58 PM Clément Léger <cleger@rivosinc.com> wrote:
> &gt;&gt;
> &gt;&gt;
> &gt;&gt;
> &gt;&gt; On 10/04/2024 07:18, Anup Patel wrote:
> &gt;&gt; &gt; On Mon, Apr 8, 2024 at 9:01 PM Xiang W <wxjstz@126.com> wrote:
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; Now opensbi can run at any address via dynamic relocation. We can
> &gt;&gt; &gt;&gt; remove FW_TEXT_START.
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; Signed-off-by: Xiang W <wxjstz@126.com>
> &gt;&gt; &gt;
> &gt;&gt; &gt; LGTM.
> &gt;&gt; &gt;
> &gt;&gt; &gt; Reviewed-by: Anup Patel <anup@brainfault.org>
> &gt;&gt; &gt; Tested-by: Anup Patel <anup@brainfault.org>
> &gt;&gt; &gt;
> &gt;&gt; &gt; Applied this patch to the riscv/opensbi repo.
> &gt;&gt; &gt;
> &gt;&gt; &gt; Thanks,
> &gt;&gt; &gt; Anup
> &gt;&gt;
> &gt;&gt; Hi Anup,
> &gt;&gt;
> &gt;&gt; This patch seems to break spike support. The newly created ELF is not
> &gt;&gt; marked as EXEC anymore but DYNAMIC and it fails with the following error:
> &gt;&gt;
> &gt;&gt; spike: ../fesvr/elfloader.cc:45:
> &gt;&gt; std::map<std::__cxx11::basic_string<char>, long unsigned int&gt;
> &gt;&gt; load_elf(const char*, memif_t*, reg_t*, unsigned int): Assertion
> &gt;&gt; `IS_ELF_EXEC(*eh64)' failed.
> &gt;&gt;
> &gt;&gt; Should we fixed OpenSBI or allow spike to load a DYNAMIC elf ?
> &gt;
> &gt;I think it is better to use FW_DYNAMIC in Spike because various
> &gt;other projects (such as U-Boot, QEMU, etc) use it.
> &gt;
> &gt;Also, Spike should support loading M-mode firmware in BIN
> &gt;(flat binary) format as well.
> &gt;
> &gt;Regards,
> &gt;Anup
> &gt;
> &gt;&gt;
> &gt;&gt; Thanks,
> &gt;&gt;
> &gt;&gt; Clément
> &gt;&gt;
>
> Hi Anup,
>
> I think this patch is not that necessary, and after applying
> this patch, we lost an elf file that can disassemble or directly
> provide symbol addresses to gdb, which caused some difficulties
> in debugging. In the past, I could pass it in Specify the address
> of FW_TEXT_START during compilation to generate an ELF file containing
> accurate symbol addresses, which is useful for debugging OpenSBI.

If FW_TEXT_START is needed only for convenience in debugging
then we can bring it back as an optional parameter which is by default
set to 0x0.

Regards,
Anup

>
> Best regards,
> Cheng Yang
>
> &gt;&gt; &gt;
> &gt;&gt; &gt;&gt; ---
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; v4 changes:
> &gt;&gt; &gt;&gt; - only remove FW_TEXT_START by anup's suggestion
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;  docs/firmware/fw.md                |  2 --
> &gt;&gt; &gt;&gt;  docs/firmware/fw_jump.md           |  4 ++--
> &gt;&gt; &gt;&gt;  docs/firmware/fw_payload.md        |  6 +++---
> &gt;&gt; &gt;&gt;  docs/platform/generic.md           | 11 +++--------
> &gt;&gt; &gt;&gt;  firmware/fw_base.S                 |  4 +---
> &gt;&gt; &gt;&gt;  firmware/fw_base.ldS               |  3 +--
> &gt;&gt; &gt;&gt;  firmware/fw_payload.elf.ldS        |  2 +-
> &gt;&gt; &gt;&gt;  firmware/objects.mk                |  4 ----
> &gt;&gt; &gt;&gt;  firmware/payloads/test.elf.ldS     |  2 +-
> &gt;&gt; &gt;&gt;  platform/fpga/ariane/objects.mk    |  1 -
> &gt;&gt; &gt;&gt;  platform/fpga/openpiton/objects.mk |  1 -
> &gt;&gt; &gt;&gt;  platform/generic/objects.mk        |  3 +--
> &gt;&gt; &gt;&gt;  platform/kendryte/k210/objects.mk  |  1 -
> &gt;&gt; &gt;&gt;  platform/nuclei/ux600/objects.mk   |  1 -
> &gt;&gt; &gt;&gt;  platform/template/objects.mk       |  9 ++-------
> &gt;&gt; &gt;&gt;  15 files changed, 15 insertions(+), 39 deletions(-)
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; diff --git a/docs/firmware/fw.md b/docs/firmware/fw.md
> &gt;&gt; &gt;&gt; index 2f4deb5..3cc0262 100644
> &gt;&gt; &gt;&gt; --- a/docs/firmware/fw.md
> &gt;&gt; &gt;&gt; +++ b/docs/firmware/fw.md
> &gt;&gt; &gt;&gt; @@ -61,8 +61,6 @@ Firmware Configuration and Compilation
> &gt;&gt; &gt;&gt;  All firmware types support the following common compile time configuration
> &gt;&gt; &gt;&gt;  parameters:
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; -* **FW_TEXT_START** - Defines the execution address of the OpenSBI firmware.
> &gt;&gt; &gt;&gt; -  This configuration parameter is mandatory.
> &gt;&gt; &gt;&gt;  * **FW_FDT_PATH** - Path to an external flattened device tree binary file to
> &gt;&gt; &gt;&gt;    be embedded in the *.rodata* section of the final firmware. If this option
> &gt;&gt; &gt;&gt;    is not provided then the firmware will expect the FDT to be passed as an
> &gt;&gt; &gt;&gt; diff --git a/docs/firmware/fw_jump.md b/docs/firmware/fw_jump.md
> &gt;&gt; &gt;&gt; index 2ee6b29..66be016 100644
> &gt;&gt; &gt;&gt; --- a/docs/firmware/fw_jump.md
> &gt;&gt; &gt;&gt; +++ b/docs/firmware/fw_jump.md
> &gt;&gt; &gt;&gt; @@ -35,7 +35,7 @@ follows:
> &gt;&gt; &gt;&gt;    At least one of *FW_JUMP_ADDR* and *FW_JUMP_OFFSET* (see below) should be
> &gt;&gt; &gt;&gt;    defined. Compilation errors will result from not defining one of them.
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; -* **FW_JUMP_OFFSET** - Address offset from the *FW_TEXT_START* where the
> &gt;&gt; &gt;&gt; +* **FW_JUMP_OFFSET** - Address offset from the opensbi load address where the
> &gt;&gt; &gt;&gt;    entry point of the next booting stage is located. This offset is used as
> &gt;&gt; &gt;&gt;    relocatable address of the next booting stage entry point. If *FW_JUMP_ADDR*
> &gt;&gt; &gt;&gt;    is also defined, the firmware will prefer *FW_JUMP_ADDR*.
> &gt;&gt; &gt;&gt; @@ -62,7 +62,7 @@ follows:
> &gt;&gt; &gt;&gt;    echo fdt overlaps kernel, increase FW_JUMP_FDT_ADDR
> &gt;&gt; &gt;&gt;    ```
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; -* **FW_JUMP_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
> &gt;&gt; &gt;&gt; +* **FW_JUMP_FDT_OFFSET** - Address offset from the opensbi load address where
> &gt;&gt; &gt;&gt;    the FDT will be passed to the next booting stage. This offset is used
> &gt;&gt; &gt;&gt;    as relocatable address of the FDT passed to the next booting stage. If
> &gt;&gt; &gt;&gt;    *FW_JUMP_FDT_ADDR* is also defined, the firmware will prefer
> &gt;&gt; &gt;&gt; diff --git a/docs/firmware/fw_payload.md b/docs/firmware/fw_payload.md
> &gt;&gt; &gt;&gt; index a67fc50..d25be60 100644
> &gt;&gt; &gt;&gt; --- a/docs/firmware/fw_payload.md
> &gt;&gt; &gt;&gt; +++ b/docs/firmware/fw_payload.md
> &gt;&gt; &gt;&gt; @@ -36,8 +36,8 @@ options. These configuration parameters can be defined using either the top
> &gt;&gt; &gt;&gt;  level `make` command line or the target platform *objects.mk* configuration
> &gt;&gt; &gt;&gt;  file. The parameters currently defined are as follows:
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; -* **FW_PAYLOAD_OFFSET** - Offset from *FW_TEXT_START* where the payload binary
> &gt;&gt; &gt;&gt; -  will be linked in the final *FW_PAYLOAD* firmware binary image. This
> &gt;&gt; &gt;&gt; +* **FW_PAYLOAD_OFFSET** - Offset from the opensbi load address where the payload
> &gt;&gt; &gt;&gt; +  binary will be linked in the final *FW_PAYLOAD* firmware binary image. This
> &gt;&gt; &gt;&gt;    configuration parameter is mandatory if *FW_PAYLOAD_ALIGN* is not defined.
> &gt;&gt; &gt;&gt;    Compilation errors will result from an incorrect definition of
> &gt;&gt; &gt;&gt;    *FW_PAYLOAD_OFFSET* or of *FW_PAYLOAD_ALIGN*, or if neither of these
> &gt;&gt; &gt;&gt; @@ -62,7 +62,7 @@ file. The parameters currently defined are as follows:
> &gt;&gt; &gt;&gt;    firmware will pass the FDT address passed by the previous booting stage
> &gt;&gt; &gt;&gt;    to the next booting stage.
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; -* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
> &gt;&gt; &gt;&gt; +* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the opensbi load address where
> &gt;&gt; &gt;&gt;    the FDT will be passed to the next booting stage. This offset is used as
> &gt;&gt; &gt;&gt;    relocatable address of the FDT passed to the next booting stage. If
> &gt;&gt; &gt;&gt;    *FW_PAYLOAD_FDT_ADDR* is also defined, the firmware will prefer *FW_PAYLOAD_FDT_ADDR*.
> &gt;&gt; &gt;&gt; diff --git a/docs/platform/generic.md b/docs/platform/generic.md
> &gt;&gt; &gt;&gt; index c29eb04..709b436 100644
> &gt;&gt; &gt;&gt; --- a/docs/platform/generic.md
> &gt;&gt; &gt;&gt; +++ b/docs/platform/generic.md
> &gt;&gt; &gt;&gt; @@ -9,10 +9,9 @@ boards.
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;  By default, the generic FDT platform makes following assumptions:
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; -1. platform FW_TEXT_START is 0x80000000
> &gt;&gt; &gt;&gt; -2. platform features are default
> &gt;&gt; &gt;&gt; -3. platform stack size is default
> &gt;&gt; &gt;&gt; -4. platform has no quirks or work-arounds
> &gt;&gt; &gt;&gt; +1. platform features are default
> &gt;&gt; &gt;&gt; +2. platform stack size is default
> &gt;&gt; &gt;&gt; +3. platform has no quirks or work-arounds
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;  The above assumptions (except 1) can be overridden by adding special platform
> &gt;&gt; &gt;&gt;  callbacks which will be called based on FDT root node compatible string.
> &gt;&gt; &gt;&gt; @@ -33,10 +32,6 @@ Users of the generic FDT platform will have to ensure that:
> &gt;&gt; &gt;&gt;  To build the platform-specific library and firmware images, provide the
> &gt;&gt; &gt;&gt;  *PLATFORM=generic* parameter to the top level `make` command.
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; -For custom FW_TEXT_START, we can build the platform-specific library and
> &gt;&gt; &gt;&gt; -firmware images by passing *PLATFORM=generic FW_TEXT_START=<custom_text_start>*
> &gt;&gt; &gt;&gt; -parameter to the top level `make` command.
> &gt;&gt; &gt;&gt; -
> &gt;&gt; &gt;&gt;  Platform Options
> &gt;&gt; &gt;&gt;  ----------------
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; diff --git a/firmware/fw_base.S b/firmware/fw_base.S
> &gt;&gt; &gt;&gt; index b950c0b..9f995a2 100644
> &gt;&gt; &gt;&gt; --- a/firmware/fw_base.S
> &gt;&gt; &gt;&gt; +++ b/firmware/fw_base.S
> &gt;&gt; &gt;&gt; @@ -53,9 +53,7 @@ _try_lottery:
> &gt;&gt; &gt;&gt;         bnez    a6, _wait_for_boot_hart
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;         /* relocate the global table content */
> &gt;&gt; &gt;&gt; -       li      t0, FW_TEXT_START       /* link start */
> &gt;&gt; &gt;&gt; -       lla     t1, _fw_start           /* load start */
> &gt;&gt; &gt;&gt; -       sub     t2, t1, t0              /* load offset */
> &gt;&gt; &gt;&gt; +       lla     t2, _fw_start
> &gt;&gt; &gt;&gt;         lla     t0, __rel_dyn_start
> &gt;&gt; &gt;&gt;         lla     t1, __rel_dyn_end
> &gt;&gt; &gt;&gt;         beq     t0, t1, _relocate_done
> &gt;&gt; &gt;&gt; diff --git a/firmware/fw_base.ldS b/firmware/fw_base.ldS
> &gt;&gt; &gt;&gt; index fb47984..9d11db5 100644
> &gt;&gt; &gt;&gt; --- a/firmware/fw_base.ldS
> &gt;&gt; &gt;&gt; +++ b/firmware/fw_base.ldS
> &gt;&gt; &gt;&gt; @@ -7,8 +7,7 @@
> &gt;&gt; &gt;&gt;   *   Anup Patel <anup.patel@wdc.com>
> &gt;&gt; &gt;&gt;   */
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; -       . = FW_TEXT_START;
> &gt;&gt; &gt;&gt; -       /* Don't add any section between FW_TEXT_START and _fw_start */
> &gt;&gt; &gt;&gt; +       /* Don't add any section before _fw_start */
> &gt;&gt; &gt;&gt;         PROVIDE(_fw_start = .);
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;         . = ALIGN(0x1000); /* Need this to create proper sections */
> &gt;&gt; &gt;&gt; diff --git a/firmware/fw_payload.elf.ldS b/firmware/fw_payload.elf.ldS
> &gt;&gt; &gt;&gt; index f1a544b..94e1ac6 100644
> &gt;&gt; &gt;&gt; --- a/firmware/fw_payload.elf.ldS
> &gt;&gt; &gt;&gt; +++ b/firmware/fw_payload.elf.ldS
> &gt;&gt; &gt;&gt; @@ -15,7 +15,7 @@ SECTIONS
> &gt;&gt; &gt;&gt;         #include "fw_base.ldS"
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;  #ifdef FW_PAYLOAD_OFFSET
> &gt;&gt; &gt;&gt; -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
> &gt;&gt; &gt;&gt; +       . = FW_PAYLOAD_OFFSET;
> &gt;&gt; &gt;&gt;  #else
> &gt;&gt; &gt;&gt;         . = ALIGN(FW_PAYLOAD_ALIGN);
> &gt;&gt; &gt;&gt;  #endif
> &gt;&gt; &gt;&gt; diff --git a/firmware/objects.mk b/firmware/objects.mk
> &gt;&gt; &gt;&gt; index e6b364b..a51ff65 100644
> &gt;&gt; &gt;&gt; --- a/firmware/objects.mk
> &gt;&gt; &gt;&gt; +++ b/firmware/objects.mk
> &gt;&gt; &gt;&gt; @@ -13,10 +13,6 @@ firmware-cflags-y +=
> &gt;&gt; &gt;&gt;  firmware-asflags-y +=
> &gt;&gt; &gt;&gt;  firmware-ldflags-y +=
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; -ifdef FW_TEXT_START
> &gt;&gt; &gt;&gt; -firmware-genflags-y += -DFW_TEXT_START=$(FW_TEXT_START)
> &gt;&gt; &gt;&gt; -endif
> &gt;&gt; &gt;&gt; -
> &gt;&gt; &gt;&gt;  ifdef FW_FDT_PATH
> &gt;&gt; &gt;&gt;  firmware-genflags-y += -DFW_FDT_PATH=\"$(FW_FDT_PATH)\"
> &gt;&gt; &gt;&gt;  ifdef FW_FDT_PADDING
> &gt;&gt; &gt;&gt; diff --git a/firmware/payloads/test.elf.ldS b/firmware/payloads/test.elf.ldS
> &gt;&gt; &gt;&gt; index 2328a1b..08e008f 100644
> &gt;&gt; &gt;&gt; --- a/firmware/payloads/test.elf.ldS
> &gt;&gt; &gt;&gt; +++ b/firmware/payloads/test.elf.ldS
> &gt;&gt; &gt;&gt; @@ -13,7 +13,7 @@ ENTRY(_start)
> &gt;&gt; &gt;&gt;  SECTIONS
> &gt;&gt; &gt;&gt;  {
> &gt;&gt; &gt;&gt;  #ifdef FW_PAYLOAD_OFFSET
> &gt;&gt; &gt;&gt; -       . = FW_TEXT_START + FW_PAYLOAD_OFFSET;
> &gt;&gt; &gt;&gt; +       . = FW_PAYLOAD_OFFSET;
> &gt;&gt; &gt;&gt;  #else
> &gt;&gt; &gt;&gt;         . = ALIGN(FW_PAYLOAD_ALIGN);
> &gt;&gt; &gt;&gt;  #endif
> &gt;&gt; &gt;&gt; diff --git a/platform/fpga/ariane/objects.mk b/platform/fpga/ariane/objects.mk
> &gt;&gt; &gt;&gt; index 83581ac..d1177f4 100644
> &gt;&gt; &gt;&gt; --- a/platform/fpga/ariane/objects.mk
> &gt;&gt; &gt;&gt; +++ b/platform/fpga/ariane/objects.mk
> &gt;&gt; &gt;&gt; @@ -17,7 +17,6 @@ platform-objs-y += platform.o
> &gt;&gt; &gt;&gt;  PLATFORM_RISCV_XLEN = 64
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;  # Blobs to build
> &gt;&gt; &gt;&gt; -FW_TEXT_START=0x80000000
> &gt;&gt; &gt;&gt;  FW_JUMP=n
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;  ifeq ($(PLATFORM_RISCV_XLEN), 32)
> &gt;&gt; &gt;&gt; diff --git a/platform/fpga/openpiton/objects.mk b/platform/fpga/openpiton/objects.mk
> &gt;&gt; &gt;&gt; index c8c345a..1a0ce0c 100644
> &gt;&gt; &gt;&gt; --- a/platform/fpga/openpiton/objects.mk
> &gt;&gt; &gt;&gt; +++ b/platform/fpga/openpiton/objects.mk
> &gt;&gt; &gt;&gt; @@ -16,7 +16,6 @@ platform-objs-y += platform.o
> &gt;&gt; &gt;&gt;  PLATFORM_RISCV_XLEN = 64
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;  # Blobs to build
> &gt;&gt; &gt;&gt; -FW_TEXT_START=0x80000000
> &gt;&gt; &gt;&gt;  FW_JUMP=n
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;  ifeq ($(PLATFORM_RISCV_XLEN), 32)
> &gt;&gt; &gt;&gt; diff --git a/platform/generic/objects.mk b/platform/generic/objects.mk
> &gt;&gt; &gt;&gt; index 85aa723..c215935 100644
> &gt;&gt; &gt;&gt; --- a/platform/generic/objects.mk
> &gt;&gt; &gt;&gt; +++ b/platform/generic/objects.mk
> &gt;&gt; &gt;&gt; @@ -15,14 +15,13 @@ platform-ldflags-y =
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;  # Command for platform specific "make run"
> &gt;&gt; &gt;&gt;  platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \
> &gt;&gt; &gt;&gt; -  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.elf
> &gt;&gt; &gt;&gt; +  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.bin
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;  # Objects to build
> &gt;&gt; &gt;&gt;  platform-objs-y += platform.o
> &gt;&gt; &gt;&gt;  platform-objs-y += platform_override_modules.o
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;  # Blobs to build
> &gt;&gt; &gt;&gt; -FW_TEXT_START=0x80000000
> &gt;&gt; &gt;&gt;  FW_DYNAMIC=y
> &gt;&gt; &gt;&gt;  FW_JUMP=y
> &gt;&gt; &gt;&gt;  ifeq ($(PLATFORM_RISCV_XLEN), 32)
> &gt;&gt; &gt;&gt; diff --git a/platform/kendryte/k210/objects.mk b/platform/kendryte/k210/objects.mk
> &gt;&gt; &gt;&gt; index 1bfb898..efac3d2 100644
> &gt;&gt; &gt;&gt; --- a/platform/kendryte/k210/objects.mk
> &gt;&gt; &gt;&gt; +++ b/platform/kendryte/k210/objects.mk
> &gt;&gt; &gt;&gt; @@ -21,6 +21,5 @@ platform-varprefix-k210.o = dt_k210
> &gt;&gt; &gt;&gt;  platform-padding-k210.o = 2048
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;  # Blobs to build
> &gt;&gt; &gt;&gt; -FW_TEXT_START=0x80000000
> &gt;&gt; &gt;&gt;  FW_PAYLOAD=y
> &gt;&gt; &gt;&gt;  FW_PAYLOAD_ALIGN=0x1000
> &gt;&gt; &gt;&gt; diff --git a/platform/nuclei/ux600/objects.mk b/platform/nuclei/ux600/objects.mk
> &gt;&gt; &gt;&gt; index 7c429e0..2753a7f 100644
> &gt;&gt; &gt;&gt; --- a/platform/nuclei/ux600/objects.mk
> &gt;&gt; &gt;&gt; +++ b/platform/nuclei/ux600/objects.mk
> &gt;&gt; &gt;&gt; @@ -22,7 +22,6 @@ platform-runcmd = xl_spike \
> &gt;&gt; &gt;&gt;  platform-objs-y += platform.o
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt;  # Blobs to build
> &gt;&gt; &gt;&gt; -FW_TEXT_START=0xA0000000
> &gt;&gt; &gt;&gt;  FW_DYNAMIC=y
> &gt;&gt; &gt;&gt;  FW_JUMP=y
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; diff --git a/platform/template/objects.mk b/platform/template/objects.mk
> &gt;&gt; &gt;&gt; index b143cbc..f240a55 100644
> &gt;&gt; &gt;&gt; --- a/platform/template/objects.mk
> &gt;&gt; &gt;&gt; +++ b/platform/template/objects.mk
> &gt;&gt; &gt;&gt; @@ -41,9 +41,6 @@ platform-objs-y += platform.o
> &gt;&gt; &gt;&gt;  #
> &gt;&gt; &gt;&gt;  # platform-objs-y += <dt file="" name="">.o
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; -# Firmware load address configuration. This is mandatory.
> &gt;&gt; &gt;&gt; -FW_TEXT_START=0x80000000
> &gt;&gt; &gt;&gt; -
> &gt;&gt; &gt;&gt;  # Optional parameter for path to external FDT
> &gt;&gt; &gt;&gt;  # FW_FDT_PATH="path to platform flattened device tree file"
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;&gt; @@ -69,8 +66,7 @@ FW_JUMP=<y|n>
> &gt;&gt; &gt;&gt;  # endif
> &gt;&gt; &gt;&gt;  # FW_JUMP_FDT_OFFSET=0x2200000
> &gt;&gt; &gt;&gt;  #
> &gt;&gt; &gt;&gt; -# You can use fixed address for jump firmware as an alternative option,
> &gt;&gt; &gt;&gt; -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
> &gt;&gt; &gt;&gt; +# You can use fixed address for jump firmware as an alternative option.
> &gt;&gt; &gt;&gt;  # SBI will prefer "<x>_ADDR" if both "<x>_ADDR" and "<x>_OFFSET" are
> &gt;&gt; &gt;&gt;  # defined
> &gt;&gt; &gt;&gt;  # ifeq ($(PLATFORM_RISCV_XLEN), 32)
> &gt;&gt; &gt;&gt; @@ -97,8 +93,7 @@ endif
> &gt;&gt; &gt;&gt;  # FW_PAYLOAD_PATH="path to next boot stage binary image file"
> &gt;&gt; &gt;&gt;  # FW_PAYLOAD_FDT_OFFSET=0x2200000
> &gt;&gt; &gt;&gt;  #
> &gt;&gt; &gt;&gt; -# You can use fixed address for payload firmware as an alternative option,
> &gt;&gt; &gt;&gt; -# but this may fail when setting wrong FW_TEXT_START. Use with caution.
> &gt;&gt; &gt;&gt; +# You can use fixed address for payload firmware as an alternative option.
> &gt;&gt; &gt;&gt;  # SBI will prefer "FW_PAYLOAD_FDT_ADDR" if both "FW_PAYLOAD_FDT_OFFSET"
> &gt;&gt; &gt;&gt;  # and "FW_PAYLOAD_FDT_ADDR" are defined.
> &gt;&gt; &gt;&gt;  # FW_PAYLOAD_FDT_ADDR=0x82200000
> &gt;&gt; &gt;&gt; --
> &gt;&gt; &gt;&gt; 2.43.0
> &gt;&gt; &gt;&gt;
> &gt;&gt; &gt;
> &gt;
> &gt;--
> &gt;opensbi mailing list
> &gt;opensbi@lists.infradead.org
> &gt;http://lists.infradead.org/mailman/listinfo/opensbi</x></x></x></y|n></dt></anup.patel@wdc.com></custom_text_start></std::__cxx11::basic_string<char></anup@brainfault.org></anup@brainfault.org></wxjstz@126.com></wxjstz@126.com></cleger@rivosinc.com>
Clément Léger May 15, 2024, 7:42 a.m. UTC | #12
On 14/05/2024 19:46, Jessica Clarke wrote:
> On 14 May 2024, at 18:25, Cheng Yang <yangcheng.work@foxmail.com> wrote:
>>
>> On 14 May 2024, at 17:50, Cheng Yang <yangcheng.work at="" foxmail.com=""> wrote:
>> &gt;&gt; 
>> &gt;&gt; &gt;On Tue, May 14, 2024 at 9:58 PM Clément Léger <cleger at="" rivosinc.com=""> wrote:
>> &gt;&gt; &gt;&gt;
>> &gt;&gt; &gt;&gt;
>> &gt;&gt; &gt;&gt;
>> &gt;&gt; &gt;&gt; On 10/04/2024 07:18, Anup Patel wrote:
>> &gt;&gt; &gt;&gt; &gt; On Mon, Apr 8, 2024 at 9:01 PM Xiang W <wxjstz at="" 126.com=""> wrote:
>> &gt;&gt; &gt;&gt; &gt;&gt;
>> &gt;&gt; &gt;&gt; &gt;&gt; Now opensbi can run at any address via dynamic relocation. We can
>> &gt;&gt; &gt;&gt; &gt;&gt; remove FW_TEXT_START.
>> &gt;&gt; &gt;&gt; &gt;&gt;
>> &gt;&gt; &gt;&gt; &gt;&gt; Signed-off-by: Xiang W <wxjstz at="" 126.com="">
>> &gt;&gt; &gt;&gt; &gt;
>> &gt;&gt; &gt;&gt; &gt; LGTM.
>> &gt;&gt; &gt;&gt; &gt;
>> &gt;&gt; &gt;&gt; &gt; Reviewed-by: Anup Patel <anup at="" brainfault.org="">
>> &gt;&gt; &gt;&gt; &gt; Tested-by: Anup Patel <anup at="" brainfault.org="">
>> &gt;&gt; &gt;&gt; &gt;
>> &gt;&gt; &gt;&gt; &gt; Applied this patch to the riscv/opensbi repo.
>> &gt;&gt; &gt;&gt; &gt;
>> &gt;&gt; &gt;&gt; &gt; Thanks,
>> &gt;&gt; &gt;&gt; &gt; Anup
>> &gt;&gt; &gt;&gt;
>> &gt;&gt; &gt;&gt; Hi Anup,
>> &gt;&gt; &gt;&gt;
>> &gt;&gt; &gt;&gt; This patch seems to break spike support. The newly created ELF is not
>> &gt;&gt; &gt;&gt; marked as EXEC anymore but DYNAMIC and it fails with the following error:
>> &gt;&gt; &gt;&gt;
>> &gt;&gt; &gt;&gt; spike: ../fesvr/elfloader.cc:45:
>> &gt;&gt; &gt;&gt; std::map<std::__cxx11::basic_string<char>, long unsigned int&gt;
>> &gt;&gt; &gt;&gt; load_elf(const char*, memif_t*, reg_t*, unsigned int): Assertion
>> &gt;&gt; &gt;&gt; `IS_ELF_EXEC(*eh64)' failed.
>> &gt;&gt; &gt;&gt;
>> &gt;&gt; &gt;&gt; Should we fixed OpenSBI or allow spike to load a DYNAMIC elf ?
>> &gt;&gt; &gt;
>> &gt;&gt; &gt;I think it is better to use FW_DYNAMIC in Spike because various
>> &gt;&gt; &gt;other projects (such as U-Boot, QEMU, etc) use it.
>> &gt;&gt; &gt;
>> &gt;&gt; &gt;Also, Spike should support loading M-mode firmware in BIN
>> &gt;&gt; &gt;(flat binary) format as well.
>> &gt;&gt; &gt;
>> &gt;&gt; &gt;Regards,
>> &gt;&gt; &gt;Anup
>> &gt;&gt; &gt;
>> &gt;&gt; &gt;&gt;
>> &gt;&gt; &gt;&gt; Thanks,
>> &gt;&gt; &gt;&gt;
>> &gt;&gt; &gt;&gt; Clément
>> &gt;&gt; &gt;&gt;
>> &gt;&gt; 
>> &gt;&gt; Hi Anup,
>> &gt;&gt; 
>> &gt;&gt; I think this patch is not that necessary, and after applying 
>> &gt;&gt; this patch, we lost an elf file that can disassemble or directly 
>> &gt;&gt; provide symbol addresses to gdb, which caused some difficulties 
>> &gt;&gt; in debugging. In the past, I could pass it in Specify the address 
>> &gt;&gt; of FW_TEXT_START during compilation to generate an ELF file containing 
>> &gt;&gt; accurate symbol addresses, which is useful for debugging OpenSBI.
>> &gt;
>> &gt;That’s what symbol-file /path/to/elf -o offset is for.
>> &gt;
>> &gt;Jess
>> &gt;
>>
>> Hi Jess,
>>
>> Thanks for your tip, it can indeed solve the problem of gdb debugging. 
>> But I use vscode to start gdb for opensbi debugging. It reads symbols 
>> from the elf file in the specified "program" option by default, so I 
>> still need some other settings. I still recommend keeping FW_TEXT_START 
>> instead of removing it.
> 
> “My editor of choice is deficient” isn’t suitable justification for
> imposing complexity like this on everyone IMO. But regardless, Visual
> Studio Code has the ability to run custom commands on GDB startup[1].

Yeah, clearly, using (add-)symbol-file is common practice. That's not a
good argument against reverting the current change. Moreover, OpenSBI
DYNAMIC version works fine with Qemu (and gdb debugging providing you
give it a correct loading address) so it should be supported under spike
as well.

Clément

> 
> Jess
> 
> [1] https://code.visualstudio.com/docs/cpp/launch-json-reference#_setupcommands
> 
>
Anup Patel May 15, 2024, 8:27 a.m. UTC | #13
On Wed, May 15, 2024 at 1:12 PM Clément Léger <cleger@rivosinc.com> wrote:
>
>
>
> On 14/05/2024 19:46, Jessica Clarke wrote:
> > On 14 May 2024, at 18:25, Cheng Yang <yangcheng.work@foxmail.com> wrote:
> >>
> >> On 14 May 2024, at 17:50, Cheng Yang <yangcheng.work at="" foxmail.com=""> wrote:
> >> &gt;&gt;
> >> &gt;&gt; &gt;On Tue, May 14, 2024 at 9:58 PM Clément Léger <cleger at="" rivosinc.com=""> wrote:
> >> &gt;&gt; &gt;&gt;
> >> &gt;&gt; &gt;&gt;
> >> &gt;&gt; &gt;&gt;
> >> &gt;&gt; &gt;&gt; On 10/04/2024 07:18, Anup Patel wrote:
> >> &gt;&gt; &gt;&gt; &gt; On Mon, Apr 8, 2024 at 9:01 PM Xiang W <wxjstz at="" 126.com=""> wrote:
> >> &gt;&gt; &gt;&gt; &gt;&gt;
> >> &gt;&gt; &gt;&gt; &gt;&gt; Now opensbi can run at any address via dynamic relocation. We can
> >> &gt;&gt; &gt;&gt; &gt;&gt; remove FW_TEXT_START.
> >> &gt;&gt; &gt;&gt; &gt;&gt;
> >> &gt;&gt; &gt;&gt; &gt;&gt; Signed-off-by: Xiang W <wxjstz at="" 126.com="">
> >> &gt;&gt; &gt;&gt; &gt;
> >> &gt;&gt; &gt;&gt; &gt; LGTM.
> >> &gt;&gt; &gt;&gt; &gt;
> >> &gt;&gt; &gt;&gt; &gt; Reviewed-by: Anup Patel <anup at="" brainfault.org="">
> >> &gt;&gt; &gt;&gt; &gt; Tested-by: Anup Patel <anup at="" brainfault.org="">
> >> &gt;&gt; &gt;&gt; &gt;
> >> &gt;&gt; &gt;&gt; &gt; Applied this patch to the riscv/opensbi repo.
> >> &gt;&gt; &gt;&gt; &gt;
> >> &gt;&gt; &gt;&gt; &gt; Thanks,
> >> &gt;&gt; &gt;&gt; &gt; Anup
> >> &gt;&gt; &gt;&gt;
> >> &gt;&gt; &gt;&gt; Hi Anup,
> >> &gt;&gt; &gt;&gt;
> >> &gt;&gt; &gt;&gt; This patch seems to break spike support. The newly created ELF is not
> >> &gt;&gt; &gt;&gt; marked as EXEC anymore but DYNAMIC and it fails with the following error:
> >> &gt;&gt; &gt;&gt;
> >> &gt;&gt; &gt;&gt; spike: ../fesvr/elfloader.cc:45:
> >> &gt;&gt; &gt;&gt; std::map<std::__cxx11::basic_string<char>, long unsigned int&gt;
> >> &gt;&gt; &gt;&gt; load_elf(const char*, memif_t*, reg_t*, unsigned int): Assertion
> >> &gt;&gt; &gt;&gt; `IS_ELF_EXEC(*eh64)' failed.
> >> &gt;&gt; &gt;&gt;
> >> &gt;&gt; &gt;&gt; Should we fixed OpenSBI or allow spike to load a DYNAMIC elf ?
> >> &gt;&gt; &gt;
> >> &gt;&gt; &gt;I think it is better to use FW_DYNAMIC in Spike because various
> >> &gt;&gt; &gt;other projects (such as U-Boot, QEMU, etc) use it.
> >> &gt;&gt; &gt;
> >> &gt;&gt; &gt;Also, Spike should support loading M-mode firmware in BIN
> >> &gt;&gt; &gt;(flat binary) format as well.
> >> &gt;&gt; &gt;
> >> &gt;&gt; &gt;Regards,
> >> &gt;&gt; &gt;Anup
> >> &gt;&gt; &gt;
> >> &gt;&gt; &gt;&gt;
> >> &gt;&gt; &gt;&gt; Thanks,
> >> &gt;&gt; &gt;&gt;
> >> &gt;&gt; &gt;&gt; Clément
> >> &gt;&gt; &gt;&gt;
> >> &gt;&gt;
> >> &gt;&gt; Hi Anup,
> >> &gt;&gt;
> >> &gt;&gt; I think this patch is not that necessary, and after applying
> >> &gt;&gt; this patch, we lost an elf file that can disassemble or directly
> >> &gt;&gt; provide symbol addresses to gdb, which caused some difficulties
> >> &gt;&gt; in debugging. In the past, I could pass it in Specify the address
> >> &gt;&gt; of FW_TEXT_START during compilation to generate an ELF file containing
> >> &gt;&gt; accurate symbol addresses, which is useful for debugging OpenSBI.
> >> &gt;
> >> &gt;That’s what symbol-file /path/to/elf -o offset is for.
> >> &gt;
> >> &gt;Jess
> >> &gt;
> >>
> >> Hi Jess,
> >>
> >> Thanks for your tip, it can indeed solve the problem of gdb debugging.
> >> But I use vscode to start gdb for opensbi debugging. It reads symbols
> >> from the elf file in the specified "program" option by default, so I
> >> still need some other settings. I still recommend keeping FW_TEXT_START
> >> instead of removing it.
> >
> > “My editor of choice is deficient” isn’t suitable justification for
> > imposing complexity like this on everyone IMO. But regardless, Visual
> > Studio Code has the ability to run custom commands on GDB startup[1].
>
> Yeah, clearly, using (add-)symbol-file is common practice. That's not a
> good argument against reverting the current change. Moreover, OpenSBI
> DYNAMIC version works fine with Qemu (and gdb debugging providing you
> give it a correct loading address) so it should be supported under spike
> as well.

I have sent a patch to bring back the FW_TEXT_START parameter
as optional (partially reverting the removal of FW_TEXT_START).

I am not a fan of this patch and I will drop it if more people
disagree with it.

Regards,
Anup

>
> Clément
>
> >
> > Jess
> >
> > [1] https://code.visualstudio.com/docs/cpp/launch-json-reference#_setupcommands
> >
> >
>
> --
> opensbi mailing list
> opensbi@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
diff mbox series

Patch

diff --git a/docs/firmware/fw.md b/docs/firmware/fw.md
index 2f4deb5..3cc0262 100644
--- a/docs/firmware/fw.md
+++ b/docs/firmware/fw.md
@@ -61,8 +61,6 @@  Firmware Configuration and Compilation
 All firmware types support the following common compile time configuration
 parameters:
 
-* **FW_TEXT_START** - Defines the execution address of the OpenSBI firmware.
-  This configuration parameter is mandatory.
 * **FW_FDT_PATH** - Path to an external flattened device tree binary file to
   be embedded in the *.rodata* section of the final firmware. If this option
   is not provided then the firmware will expect the FDT to be passed as an
diff --git a/docs/firmware/fw_jump.md b/docs/firmware/fw_jump.md
index 2ee6b29..66be016 100644
--- a/docs/firmware/fw_jump.md
+++ b/docs/firmware/fw_jump.md
@@ -35,7 +35,7 @@  follows:
   At least one of *FW_JUMP_ADDR* and *FW_JUMP_OFFSET* (see below) should be
   defined. Compilation errors will result from not defining one of them.
 
-* **FW_JUMP_OFFSET** - Address offset from the *FW_TEXT_START* where the
+* **FW_JUMP_OFFSET** - Address offset from the opensbi load address where the
   entry point of the next booting stage is located. This offset is used as
   relocatable address of the next booting stage entry point. If *FW_JUMP_ADDR*
   is also defined, the firmware will prefer *FW_JUMP_ADDR*.
@@ -62,7 +62,7 @@  follows:
   echo fdt overlaps kernel, increase FW_JUMP_FDT_ADDR
   ```
 
-* **FW_JUMP_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
+* **FW_JUMP_FDT_OFFSET** - Address offset from the opensbi load address where
   the FDT will be passed to the next booting stage. This offset is used
   as relocatable address of the FDT passed to the next booting stage. If
   *FW_JUMP_FDT_ADDR* is also defined, the firmware will prefer
diff --git a/docs/firmware/fw_payload.md b/docs/firmware/fw_payload.md
index a67fc50..d25be60 100644
--- a/docs/firmware/fw_payload.md
+++ b/docs/firmware/fw_payload.md
@@ -36,8 +36,8 @@  options. These configuration parameters can be defined using either the top
 level `make` command line or the target platform *objects.mk* configuration
 file. The parameters currently defined are as follows:
 
-* **FW_PAYLOAD_OFFSET** - Offset from *FW_TEXT_START* where the payload binary
-  will be linked in the final *FW_PAYLOAD* firmware binary image. This
+* **FW_PAYLOAD_OFFSET** - Offset from the opensbi load address where the payload
+  binary will be linked in the final *FW_PAYLOAD* firmware binary image. This
   configuration parameter is mandatory if *FW_PAYLOAD_ALIGN* is not defined.
   Compilation errors will result from an incorrect definition of
   *FW_PAYLOAD_OFFSET* or of *FW_PAYLOAD_ALIGN*, or if neither of these
@@ -62,7 +62,7 @@  file. The parameters currently defined are as follows:
   firmware will pass the FDT address passed by the previous booting stage
   to the next booting stage.
 
-* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the *FW_TEXT_START* where
+* **FW_PAYLOAD_FDT_OFFSET** - Address offset from the opensbi load address where
   the FDT will be passed to the next booting stage. This offset is used as
   relocatable address of the FDT passed to the next booting stage. If
   *FW_PAYLOAD_FDT_ADDR* is also defined, the firmware will prefer *FW_PAYLOAD_FDT_ADDR*.
diff --git a/docs/platform/generic.md b/docs/platform/generic.md
index c29eb04..709b436 100644
--- a/docs/platform/generic.md
+++ b/docs/platform/generic.md
@@ -9,10 +9,9 @@  boards.
 
 By default, the generic FDT platform makes following assumptions:
 
-1. platform FW_TEXT_START is 0x80000000
-2. platform features are default
-3. platform stack size is default
-4. platform has no quirks or work-arounds
+1. platform features are default
+2. platform stack size is default
+3. platform has no quirks or work-arounds
 
 The above assumptions (except 1) can be overridden by adding special platform
 callbacks which will be called based on FDT root node compatible string.
@@ -33,10 +32,6 @@  Users of the generic FDT platform will have to ensure that:
 To build the platform-specific library and firmware images, provide the
 *PLATFORM=generic* parameter to the top level `make` command.
 
-For custom FW_TEXT_START, we can build the platform-specific library and
-firmware images by passing *PLATFORM=generic FW_TEXT_START=<custom_text_start>*
-parameter to the top level `make` command.
-
 Platform Options
 ----------------
 
diff --git a/firmware/fw_base.S b/firmware/fw_base.S
index b950c0b..9f995a2 100644
--- a/firmware/fw_base.S
+++ b/firmware/fw_base.S
@@ -53,9 +53,7 @@  _try_lottery:
 	bnez	a6, _wait_for_boot_hart
 
 	/* relocate the global table content */
-	li	t0, FW_TEXT_START	/* link start */
-	lla	t1, _fw_start		/* load start */
-	sub	t2, t1, t0		/* load offset */
+	lla	t2, _fw_start
 	lla	t0, __rel_dyn_start
 	lla	t1, __rel_dyn_end
 	beq	t0, t1, _relocate_done
diff --git a/firmware/fw_base.ldS b/firmware/fw_base.ldS
index fb47984..9d11db5 100644
--- a/firmware/fw_base.ldS
+++ b/firmware/fw_base.ldS
@@ -7,8 +7,7 @@ 
  *   Anup Patel <anup.patel@wdc.com>
  */
 
-	. = FW_TEXT_START;
-	/* Don't add any section between FW_TEXT_START and _fw_start */
+	/* Don't add any section before _fw_start */
 	PROVIDE(_fw_start = .);
 
 	. = ALIGN(0x1000); /* Need this to create proper sections */
diff --git a/firmware/fw_payload.elf.ldS b/firmware/fw_payload.elf.ldS
index f1a544b..94e1ac6 100644
--- a/firmware/fw_payload.elf.ldS
+++ b/firmware/fw_payload.elf.ldS
@@ -15,7 +15,7 @@  SECTIONS
 	#include "fw_base.ldS"
 
 #ifdef FW_PAYLOAD_OFFSET
-	. = FW_TEXT_START + FW_PAYLOAD_OFFSET;
+	. = FW_PAYLOAD_OFFSET;
 #else
 	. = ALIGN(FW_PAYLOAD_ALIGN);
 #endif
diff --git a/firmware/objects.mk b/firmware/objects.mk
index e6b364b..a51ff65 100644
--- a/firmware/objects.mk
+++ b/firmware/objects.mk
@@ -13,10 +13,6 @@  firmware-cflags-y +=
 firmware-asflags-y +=
 firmware-ldflags-y +=
 
-ifdef FW_TEXT_START
-firmware-genflags-y += -DFW_TEXT_START=$(FW_TEXT_START)
-endif
-
 ifdef FW_FDT_PATH
 firmware-genflags-y += -DFW_FDT_PATH=\"$(FW_FDT_PATH)\"
 ifdef FW_FDT_PADDING
diff --git a/firmware/payloads/test.elf.ldS b/firmware/payloads/test.elf.ldS
index 2328a1b..08e008f 100644
--- a/firmware/payloads/test.elf.ldS
+++ b/firmware/payloads/test.elf.ldS
@@ -13,7 +13,7 @@  ENTRY(_start)
 SECTIONS
 {
 #ifdef FW_PAYLOAD_OFFSET
-	. = FW_TEXT_START + FW_PAYLOAD_OFFSET;
+	. = FW_PAYLOAD_OFFSET;
 #else
 	. = ALIGN(FW_PAYLOAD_ALIGN);
 #endif
diff --git a/platform/fpga/ariane/objects.mk b/platform/fpga/ariane/objects.mk
index 83581ac..d1177f4 100644
--- a/platform/fpga/ariane/objects.mk
+++ b/platform/fpga/ariane/objects.mk
@@ -17,7 +17,6 @@  platform-objs-y += platform.o
 PLATFORM_RISCV_XLEN = 64
 
 # Blobs to build
-FW_TEXT_START=0x80000000
 FW_JUMP=n
 
 ifeq ($(PLATFORM_RISCV_XLEN), 32)
diff --git a/platform/fpga/openpiton/objects.mk b/platform/fpga/openpiton/objects.mk
index c8c345a..1a0ce0c 100644
--- a/platform/fpga/openpiton/objects.mk
+++ b/platform/fpga/openpiton/objects.mk
@@ -16,7 +16,6 @@  platform-objs-y += platform.o
 PLATFORM_RISCV_XLEN = 64
 
 # Blobs to build
-FW_TEXT_START=0x80000000
 FW_JUMP=n
 
 ifeq ($(PLATFORM_RISCV_XLEN), 32)
diff --git a/platform/generic/objects.mk b/platform/generic/objects.mk
index 85aa723..c215935 100644
--- a/platform/generic/objects.mk
+++ b/platform/generic/objects.mk
@@ -15,14 +15,13 @@  platform-ldflags-y =
 
 # Command for platform specific "make run"
 platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \
-  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.elf
+  -nographic -bios $(build_dir)/platform/generic/firmware/fw_payload.bin
 
 # Objects to build
 platform-objs-y += platform.o
 platform-objs-y += platform_override_modules.o
 
 # Blobs to build
-FW_TEXT_START=0x80000000
 FW_DYNAMIC=y
 FW_JUMP=y
 ifeq ($(PLATFORM_RISCV_XLEN), 32)
diff --git a/platform/kendryte/k210/objects.mk b/platform/kendryte/k210/objects.mk
index 1bfb898..efac3d2 100644
--- a/platform/kendryte/k210/objects.mk
+++ b/platform/kendryte/k210/objects.mk
@@ -21,6 +21,5 @@  platform-varprefix-k210.o = dt_k210
 platform-padding-k210.o = 2048
 
 # Blobs to build
-FW_TEXT_START=0x80000000
 FW_PAYLOAD=y
 FW_PAYLOAD_ALIGN=0x1000
diff --git a/platform/nuclei/ux600/objects.mk b/platform/nuclei/ux600/objects.mk
index 7c429e0..2753a7f 100644
--- a/platform/nuclei/ux600/objects.mk
+++ b/platform/nuclei/ux600/objects.mk
@@ -22,7 +22,6 @@  platform-runcmd = xl_spike \
 platform-objs-y += platform.o
 
 # Blobs to build
-FW_TEXT_START=0xA0000000
 FW_DYNAMIC=y
 FW_JUMP=y
 
diff --git a/platform/template/objects.mk b/platform/template/objects.mk
index b143cbc..f240a55 100644
--- a/platform/template/objects.mk
+++ b/platform/template/objects.mk
@@ -41,9 +41,6 @@  platform-objs-y += platform.o
 #
 # platform-objs-y += <dt file name>.o
 
-# Firmware load address configuration. This is mandatory.
-FW_TEXT_START=0x80000000
-
 # Optional parameter for path to external FDT
 # FW_FDT_PATH="path to platform flattened device tree file"
 
@@ -69,8 +66,7 @@  FW_JUMP=<y|n>
 # endif
 # FW_JUMP_FDT_OFFSET=0x2200000
 #
-# You can use fixed address for jump firmware as an alternative option,
-# but this may fail when setting wrong FW_TEXT_START. Use with caution.
+# You can use fixed address for jump firmware as an alternative option.
 # SBI will prefer "<X>_ADDR" if both "<X>_ADDR" and "<X>_OFFSET" are
 # defined
 # ifeq ($(PLATFORM_RISCV_XLEN), 32)
@@ -97,8 +93,7 @@  endif
 # FW_PAYLOAD_PATH="path to next boot stage binary image file"
 # FW_PAYLOAD_FDT_OFFSET=0x2200000
 #
-# You can use fixed address for payload firmware as an alternative option,
-# but this may fail when setting wrong FW_TEXT_START. Use with caution.
+# You can use fixed address for payload firmware as an alternative option.
 # SBI will prefer "FW_PAYLOAD_FDT_ADDR" if both "FW_PAYLOAD_FDT_OFFSET"
 # and "FW_PAYLOAD_FDT_ADDR" are defined.
 # FW_PAYLOAD_FDT_ADDR=0x82200000