riscv: Only enable OF_BOARD_FIXUP for S-Mode
PATCH 1/1 riscv: Only enable OF_BOARD_FIXUP for S-Mode
It is unsafe to enable OF_BOARD_FIXUP only based on OF_SEPARATE. OF_SEPARATE may indicate that the user wishes U-Boot to use a different device tree than one obtained via OF_PRIOR_STAGE. However, OF_SEPARATE may also indicate that the device tree which would be obtained via OF_PRIOR_STAGE is invalid, nonexistant, or otherwise unusable. In this latter case, enabling OF_BOARD_FIXUP will result in corruption of the device tree. To remedy this, only enable OF_BOARD_FIXUP if U-Boot is configured for S-Mode.
---
arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/Kconfig +1 -1
@@ -288,6 +288,6 @@ config STACK_SIZE_SHIFT default 14 config OF_BOARD_FIXUP - default y if OF_SEPARATE + default y if OF_SEPARATE && RISCV_SMODE endmenu
Signature · 1 line
2.28.0
PATCH 1/1 riscv: Only enable OF_BOARD_FIXUP for S-Mode
Quoted 21 lines · Sean Anderson
It is unsafe to enable
OF_BOARD_FIXUPonly based onOF_SEPARATE.OF_SEPARATEmay indicate that the user wishes U-Boot to use a different device tree than one obtained viaOF_PRIOR_STAGE. However,OF_SEPARATEmay also indicate that the device tree which would be obtained viaOF_PRIOR_STAGEis invalid, nonexistant, or otherwise unusable. In this latter case, enablingOF_BOARD_FIXUPwill result in corruption of the device tree. To remedy this, only enableOF_BOARD_FIXUPif U-Boot is configured for S-Mode.Fixes 1c17e55594a394ced7de88d91be294eaf8c564c1Signed-off-by Sean Anderson <[email protected]>---
arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/Kconfig +0
-0
arch/riscv/Kconfig config STACK_SIZE_SHIFT · line 291
Quoted 5 lines
arch/riscv/Kconfig +1
-1@@ -288,6 +288,6 @@ config STACK_SIZE_SHIFT default 14 config OF_BOARD_FIXUP - default y if OF_SEPARATE + default y if OF_SEPARATE && RISCV_SMODE
OF_BOARD_FIXUP is also defined in dts/Kconfig.
Moving the "default" line to dts/Kconfig would simplify the code.
Why do we need the dependency on OF_SEPARATE? Isn't RISCV_SMODE enough?
Best regards
Heinrich
Quoted 3 lines
arch/riscv/Kconfig +0
-0endmenu
PATCH 1/1 riscv: Only enable OF_BOARD_FIXUP for S-Mode
Quoted 24 lines · Heinrich Schuchardt
Quoted 23 lines · Sean Anderson
It is unsafe to enable
OF_BOARD_FIXUPonly based onOF_SEPARATE.OF_SEPARATEmay indicate that the user wishes U-Boot to use a different device tree than one obtained viaOF_PRIOR_STAGE. However,OF_SEPARATEmay also indicate that the device tree which would be obtained viaOF_PRIOR_STAGEis invalid, nonexistant, or otherwise unusable. In this latter case, enablingOF_BOARD_FIXUPwill result in corruption of the device tree. To remedy this, only enableOF_BOARD_FIXUPif U-Boot is configured for S-Mode.Fixes 1c17e55594a394ced7de88d91be294eaf8c564c1Signed-off-by Sean Anderson <[email protected]>---
arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/Kconfig +0
-0@@ -288,6 +288,6 @@ config STACK_SIZE_SHIFT default 14
Quoted 7 lines
arch/riscv/Kconfig config STACK_SIZE_SHIFT · line 291
Quoted 3 lines
arch/riscv/Kconfig +1
-1config OF_BOARD_FIXUP - default y if OF_SEPARATE + default y if OF_SEPARATE && RISCV_SMODE
OF_BOARD_FIXUPis also defined in dts/Kconfig.
Moving the "default" line to dts/Kconfig would simplify the code.
Probably.
Quoted 2 lines
Why do we need the dependency on
OF_SEPARATE? Isn'tRISCV_SMODEenough?
Because there is no need to do this fixup if we are using sbi's device tree. From the commit referenced above:
Quoted 4 lines
Starting from OpenSBI v0.7, the SBI firmware inserts/fixes up the reserved memory node for PMP protected memory regions. All RISC-V boards need to copy the reserved memory node from the device tree provided by the firmware to the device tree used by U-Boot.
--Sean
PATCH 1/1 riscv: Only enable OF_BOARD_FIXUP for S-Mode
In reply to Sean AndersonHi Sean,
Quoted 6 lines · Sean Anderson
It is unsafe to enable
OF_BOARD_FIXUPonly based onOF_SEPARATE.OF_SEPARATEmay indicate that the user wishes U-Boot to use a different device tree than one obtained viaOF_PRIOR_STAGE. However,OF_SEPARATEmay also indicate that the device tree which would be obtained viaOF_PRIOR_STAGEis invalid, nonexistant, or otherwise unusable. In this
typo: nonexistent
Quoted 5 lines
latter case, enabling
OF_BOARD_FIXUPwill result in corruption of the device tree. To remedy this, only enableOF_BOARD_FIXUPif U-Boot is configured for S-Mode.Fixes 1c17e55594a394ced7de88d91be294eaf8c564c1
nits: the format should be: commit_id ("description")
Quoted 11 lines
Signed-off-by Sean Anderson <[email protected]>---
arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/Kconfig +0
-0
arch/riscv/Kconfig config STACK_SIZE_SHIFT · line 291
Quoted 5 lines
arch/riscv/Kconfig +1
-1@@ -288,6 +288,6 @@ config STACK_SIZE_SHIFT default 14 config OF_BOARD_FIXUP - default y if OF_SEPARATE + default y if OF_SEPARATE && RISCV_SMODE
Is that your board is running U-Boot M-mode with OF_SEPARATE that does not work?
arch/riscv/Kconfig config STACK_SIZE_SHIFT · line 293
Quoted 3 lines
arch/riscv/Kconfig +0
-1endmenu --
Regards,
Bin
PATCH 1/1 riscv: Only enable OF_BOARD_FIXUP for S-Mode
Quoted 32 lines · Bin Meng
Hi Sean,
Quoted 6 lines · Sean Anderson
It is unsafe to enable
OF_BOARD_FIXUPonly based onOF_SEPARATE.OF_SEPARATEmay indicate that the user wishes U-Boot to use a different device tree than one obtained viaOF_PRIOR_STAGE. However,OF_SEPARATEmay also indicate that the device tree which would be obtained viaOF_PRIOR_STAGEis invalid, nonexistant, or otherwise unusable. In thistypo: nonexistent
Quoted 5 lines
latter case, enabling
OF_BOARD_FIXUPwill result in corruption of the device tree. To remedy this, only enableOF_BOARD_FIXUPif U-Boot is configured for S-Mode.Fixes 1c17e55594a394ced7de88d91be294eaf8c564c1nits: the format should be:
commit_id("description")>Quoted 13 lines
Signed-off-by Sean Anderson <[email protected]>---
arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/Kconfig +0
-0@@ -288,6 +288,6 @@ config STACK_SIZE_SHIFT default 14
Quoted 5 lines
arch/riscv/Kconfig config STACK_SIZE_SHIFT · line 291
Quoted 3 lines
arch/riscv/Kconfig +1
-1config OF_BOARD_FIXUP - default y if OF_SEPARATE + default y if OF_SEPARATE && RISCV_SMODEIs that your board is running U-Boot M-mode with
OF_SEPARATEthat does not work?
Yes, because the reason we use OF_SEPARATE is because no device tree is passed to U-Boot. Trying to use the device tree passed to U-Boot even though OF_SEPARATE is enabled results in garbage being written to the actual device tree. Without this patch, booting on the K210 randomly fails.
Quoted 8 lines
arch/riscv/Kconfig config STACK_SIZE_SHIFT · line 293
Quoted 4 lines
arch/riscv/Kconfig +0
-1endmenu --Regards,
Bin
PATCH 1/1 riscv: Only enable OF_BOARD_FIXUP for S-Mode
Quoted 34 lines · Sean Anderson
Quoted 32 lines · Bin Meng
Hi Sean,
Quoted 6 lines · Sean Anderson
It is unsafe to enable
OF_BOARD_FIXUPonly based onOF_SEPARATE.OF_SEPARATEmay indicate that the user wishes U-Boot to use a different device tree than one obtained viaOF_PRIOR_STAGE. However,OF_SEPARATEmay also indicate that the device tree which would be obtained viaOF_PRIOR_STAGEis invalid, nonexistant, or otherwise unusable. In thistypo: nonexistent
Quoted 5 lines
latter case, enabling
OF_BOARD_FIXUPwill result in corruption of the device tree. To remedy this, only enableOF_BOARD_FIXUPif U-Boot is configured for S-Mode.Fixes 1c17e55594a394ced7de88d91be294eaf8c564c1nits: the format should be:
commit_id("description")>Quoted 13 lines
Signed-off-by Sean Anderson <[email protected]>---
arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/Kconfig +0
-0@@ -288,6 +288,6 @@ config STACK_SIZE_SHIFT default 14
Quoted 8 lines
Quoted 5 lines
arch/riscv/Kconfig config STACK_SIZE_SHIFT · line 291
Quoted 3 lines
arch/riscv/Kconfig +1
-1config OF_BOARD_FIXUP - default y if OF_SEPARATE + default y if OF_SEPARATE && RISCV_SMODEIs that your board is running U-Boot M-mode with
OF_SEPARATEthat does not work?Yes, because the reason we use
OF_SEPARATEis because no device tree is passed to U-Boot. Trying to use the device tree passed to U-Boot even
I don't get it. If no device tree is passed to U-Boot, why using OF_SEPARATE in the first place?
Quoted 1 line
though
OF_SEPARATEis enabled results in garbage being written to the
What garbage data is written?
Quoted 2 lines
actual device tree. Without this patch, booting on the K210 randomly fails.
Regards,
Bin
PATCH 1/1 riscv: Only enable OF_BOARD_FIXUP for S-Mode
Quoted 41 lines · Bin Meng
Quoted 40 lines · Sean Anderson
Quoted 37 lines · Bin Meng
Hi Sean,
Quoted 6 lines · Sean Anderson
It is unsafe to enable
OF_BOARD_FIXUPonly based onOF_SEPARATE.OF_SEPARATEmay indicate that the user wishes U-Boot to use a different device tree than one obtained viaOF_PRIOR_STAGE. However,OF_SEPARATEmay also indicate that the device tree which would be obtained viaOF_PRIOR_STAGEis invalid, nonexistant, or otherwise unusable. In thistypo: nonexistent
Quoted 5 lines
latter case, enabling
OF_BOARD_FIXUPwill result in corruption of the device tree. To remedy this, only enableOF_BOARD_FIXUPif U-Boot is configured for S-Mode.Fixes 1c17e55594a394ced7de88d91be294eaf8c564c1nits: the format should be:
commit_id("description")>Quoted 11 lines
Signed-off-by Sean Anderson <[email protected]>---
arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/Kconfig +0
-0arch/riscv/Kconfig config STACK_SIZE_SHIFT · line 291
Quoted 5 lines
arch/riscv/Kconfig +1
-1@@ -288,6 +288,6 @@ config STACK_SIZE_SHIFT default 14 config OF_BOARD_FIXUP - default y if OF_SEPARATE + default y if OF_SEPARATE && RISCV_SMODEIs that your board is running U-Boot M-mode with
OF_SEPARATEthat does not work?
Quoted 5 lines
Quoted 2 lines
Yes, because the reason we use
OF_SEPARATEis because no device tree is passed to U-Boot. Trying to use the device tree passed to U-Boot evenI don't get it. If no device tree is passed to U-Boot, why using
OF_SEPARATEin the first place?
Because it has to come from somewhere. Where else would U-Boot get the device tree?
Quoted 3 lines
Quoted 1 line
though
OF_SEPARATEis enabled results in garbage being written to theWhat garbage data is written?
It might not be garbage written. I didn't document the exact failure mode at the time I discovered this bug, so I went back to try and reproduce it for a more thorough analysis. However, I was unable to reproduce this bug, even on the branch where I originally triggered it. I documented my reasoning behind this patch at [1]. In my testing, I could only trigger a "periodic-32" bug.
In any case, this behavior could still cause problems in the future. From my testing, on the k210, a1 usually holds some address on the ROM's stack. However, if it (for instance) instead held an address which raised a load access fault, or was misaligned, then booting would fail. In the general case, I was very surpised that U-Boot was using the value of a1 on entry even with OF_SEPARATE specified. I would expect it only to use that value if configured with OF_PRIOR_STAGE.
--Sean
[1] https://patchwork.ozlabs.org/project/uboot/patch/20200815155237.467720-12-seanga2 at gmail.com/#2520514
PATCH 1/1 riscv: Only enable OF_BOARD_FIXUP for S-Mode
Quoted 43 lines · Sean Anderson
Quoted 41 lines · Bin Meng
Quoted 40 lines · Sean Anderson
Quoted 37 lines · Bin Meng
Hi Sean,
Quoted 6 lines · Sean Anderson
It is unsafe to enable
OF_BOARD_FIXUPonly based onOF_SEPARATE.OF_SEPARATEmay indicate that the user wishes U-Boot to use a different device tree than one obtained viaOF_PRIOR_STAGE. However,OF_SEPARATEmay also indicate that the device tree which would be obtained viaOF_PRIOR_STAGEis invalid, nonexistant, or otherwise unusable. In thistypo: nonexistent
Quoted 5 lines
latter case, enabling
OF_BOARD_FIXUPwill result in corruption of the device tree. To remedy this, only enableOF_BOARD_FIXUPif U-Boot is configured for S-Mode.Fixes 1c17e55594a394ced7de88d91be294eaf8c564c1nits: the format should be:
commit_id("description")>Quoted 11 lines
Signed-off-by Sean Anderson <[email protected]>---
arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/Kconfig +0
-0arch/riscv/Kconfig config STACK_SIZE_SHIFT · line 291
Quoted 5 lines
arch/riscv/Kconfig +1
-1@@ -288,6 +288,6 @@ config STACK_SIZE_SHIFT default 14 config OF_BOARD_FIXUP - default y if OF_SEPARATE + default y if OF_SEPARATE && RISCV_SMODEIs that your board is running U-Boot M-mode with
OF_SEPARATEthat does not work?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Yes, because the reason we use
OF_SEPARATEis because no device tree is passed to U-Boot. Trying to use the device tree passed to U-Boot evenI don't get it. If no device tree is passed to U-Boot, why using
OF_SEPARATEin the first place?Because it has to come from somewhere. Where else would U-Boot get the device tree?
Sounds like there was some misunderstanding on "passed to U-Boot" .. But I got it now.
Quoted 12 lines
Quoted 4 lines
Quoted 2 lines
though
OF_SEPARATEis enabled results in garbage being written to theWhat garbage data is written?
It might not be garbage written. I didn't document the exact failure mode at the time I discovered this bug, so I went back to try and reproduce it for a more thorough analysis. However, I was unable to reproduce this bug, even on the branch where I originally triggered it. I documented my reasoning behind this patch at [1]. In my testing, I could only trigger a "periodic-32" bug.
Quoted 3 lines
In any case, this behavior could still cause problems in the future. From my testing, on the k210, a1 usually holds some address on the ROM's stack. However, if it (for instance) instead held an address which
So U-Boot on K210 boots with M-mode from the K210 ROM, and the ROM code does not hold DTB address in a1 before jumping to U-Boot, right?
Quoted 4 lines
raised a load access fault, or was misaligned, then booting would fail. In the general case, I was very surpised that U-Boot was using the value of a1 on entry even with
OF_SEPARATEspecified. I would expect it only to use that value if configured withOF_PRIOR_STAGE.
Because U-Boot S-mode needs to fix up the DT when OF_SEPERATE is used.
Quoted 4 lines
--Sean
[1] https://patchwork.ozlabs.org/project/uboot/patch/20200815155237.467720-12-seanga2 at gmail.com/#2520514
Regards,
Bin
PATCH 1/1 riscv: Only enable OF_BOARD_FIXUP for S-Mode
Quoted 75 lines · Bin Meng
Quoted 43 lines · Sean Anderson
Quoted 41 lines · Bin Meng
Quoted 40 lines · Sean Anderson
Quoted 37 lines · Bin Meng
Hi Sean,
Quoted 6 lines · Sean Anderson
It is unsafe to enable
OF_BOARD_FIXUPonly based onOF_SEPARATE.OF_SEPARATEmay indicate that the user wishes U-Boot to use a different device tree than one obtained viaOF_PRIOR_STAGE. However,OF_SEPARATEmay also indicate that the device tree which would be obtained viaOF_PRIOR_STAGEis invalid, nonexistant, or otherwise unusable. In thistypo: nonexistent
Quoted 5 lines
latter case, enabling
OF_BOARD_FIXUPwill result in corruption of the device tree. To remedy this, only enableOF_BOARD_FIXUPif U-Boot is configured for S-Mode.Fixes 1c17e55594a394ced7de88d91be294eaf8c564c1nits: the format should be:
commit_id("description")>Quoted 11 lines
Signed-off-by Sean Anderson <[email protected]>---
arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/Kconfig +0
-0arch/riscv/Kconfig config STACK_SIZE_SHIFT · line 291
Quoted 5 lines
arch/riscv/Kconfig +1
-1@@ -288,6 +288,6 @@ config STACK_SIZE_SHIFT default 14 config OF_BOARD_FIXUP - default y if OF_SEPARATE + default y if OF_SEPARATE && RISCV_SMODEIs that your board is running U-Boot M-mode with
OF_SEPARATEthat does not work?Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Yes, because the reason we use
OF_SEPARATEis because no device tree is passed to U-Boot. Trying to use the device tree passed to U-Boot evenI don't get it. If no device tree is passed to U-Boot, why using
OF_SEPARATEin the first place?Because it has to come from somewhere. Where else would U-Boot get the device tree?
Sounds like there was some misunderstanding on "passed to U-Boot" .. But I got it now.
Quoted 12 lines
Quoted 4 lines
Quoted 2 lines
though
OF_SEPARATEis enabled results in garbage being written to theWhat garbage data is written?
It might not be garbage written. I didn't document the exact failure mode at the time I discovered this bug, so I went back to try and reproduce it for a more thorough analysis. However, I was unable to reproduce this bug, even on the branch where I originally triggered it. I documented my reasoning behind this patch at [1]. In my testing, I could only trigger a "periodic-32" bug.
Quoted 3 lines
In any case, this behavior could still cause problems in the future. From my testing, on the k210, a1 usually holds some address on the ROM's stack. However, if it (for instance) instead held an address which
So U-Boot on K210 boots with M-mode from the K210 ROM, and the ROM code does not hold DTB address in a1 before jumping to U-Boot, right?
Quoted 6 lines
Quoted 4 lines
raised a load access fault, or was misaligned, then booting would fail. In the general case, I was very surpised that U-Boot was using the value of a1 on entry even with
OF_SEPARATEspecified. I would expect it only to use that value if configured withOF_PRIOR_STAGE.Because U-Boot S-mode needs to fix up the DT when
OF_SEPERATEis used.
Right. It's just unexpected because OF_SEPARATE appears to imply to both use a separate device tree and to not use the passed-in device tree. This is because it is mutually exclusive with OF_PRIOR_STAGE. However, with OF_BOARD_FIXUP, it's as if one has selected both OF_SEPARATE and OF_PRIOR_STAGE at once. I think defaulting OF_BOARD_FIXUP to y only S-Mode is more likely to result in unsurprising behavior on new boards.
--Sean
PATCH 1/1 riscv: Only enable OF_BOARD_FIXUP for S-Mode
Quoted 83 lines · Sean Anderson
Quoted 75 lines · Bin Meng
Quoted 43 lines · Sean Anderson
Quoted 41 lines · Bin Meng
Quoted 40 lines · Sean Anderson
Quoted 37 lines · Bin Meng
Hi Sean,
Quoted 6 lines · Sean Anderson
It is unsafe to enable
OF_BOARD_FIXUPonly based onOF_SEPARATE.OF_SEPARATEmay indicate that the user wishes U-Boot to use a different device tree than one obtained viaOF_PRIOR_STAGE. However,OF_SEPARATEmay also indicate that the device tree which would be obtained viaOF_PRIOR_STAGEis invalid, nonexistant, or otherwise unusable. In thistypo: nonexistent
Quoted 5 lines
latter case, enabling
OF_BOARD_FIXUPwill result in corruption of the device tree. To remedy this, only enableOF_BOARD_FIXUPif U-Boot is configured for S-Mode.Fixes 1c17e55594a394ced7de88d91be294eaf8c564c1nits: the format should be:
commit_id("description")>Quoted 11 lines
Signed-off-by Sean Anderson <[email protected]>---
arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/Kconfig +0
-0arch/riscv/Kconfig config STACK_SIZE_SHIFT · line 291
Quoted 5 lines
arch/riscv/Kconfig +1
-1@@ -288,6 +288,6 @@ config STACK_SIZE_SHIFT default 14 config OF_BOARD_FIXUP - default y if OF_SEPARATE + default y if OF_SEPARATE && RISCV_SMODEIs that your board is running U-Boot M-mode with
OF_SEPARATEthat does not work?Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Yes, because the reason we use
OF_SEPARATEis because no device tree is passed to U-Boot. Trying to use the device tree passed to U-Boot evenI don't get it. If no device tree is passed to U-Boot, why using
OF_SEPARATEin the first place?Because it has to come from somewhere. Where else would U-Boot get the device tree?
Sounds like there was some misunderstanding on "passed to U-Boot" .. But I got it now.
Quoted 12 lines
Quoted 4 lines
Quoted 2 lines
though
OF_SEPARATEis enabled results in garbage being written to theWhat garbage data is written?
It might not be garbage written. I didn't document the exact failure mode at the time I discovered this bug, so I went back to try and reproduce it for a more thorough analysis. However, I was unable to reproduce this bug, even on the branch where I originally triggered it. I documented my reasoning behind this patch at [1]. In my testing, I could only trigger a "periodic-32" bug.
Quoted 3 lines
In any case, this behavior could still cause problems in the future. From my testing, on the k210, a1 usually holds some address on the ROM's stack. However, if it (for instance) instead held an address which
So U-Boot on K210 boots with M-mode from the K210 ROM, and the ROM code does not hold DTB address in a1 before jumping to U-Boot, right?
Quoted 6 lines
Quoted 4 lines
raised a load access fault, or was misaligned, then booting would fail. In the general case, I was very surpised that U-Boot was using the value of a1 on entry even with
OF_SEPARATEspecified. I would expect it only to use that value if configured withOF_PRIOR_STAGE.Because U-Boot S-mode needs to fix up the DT when
OF_SEPERATEis used.
Quoted 8 lines
Right. It's just unexpected because
OF_SEPARATEappears to imply to both use a separate device tree and to not use the passed-in device tree. This is because it is mutually exclusive withOF_PRIOR_STAGE. However, withOF_BOARD_FIXUP, it's as if one has selected bothOF_SEPARATEandOF_PRIOR_STAGEat once. I think defaultingOF_BOARD_FIXUPto y only S-Mode is more likely to result in unsurprising behavior on new boards.--Sean