Xiang Wang has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: add support boot from sdcard ......................................................................
soc/sifive/fu540: add support boot from sdcard
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 98 insertions(+), 7 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/35119/1
diff --git a/src/mainboard/sifive/hifive-unleashed/Kconfig b/src/mainboard/sifive/hifive-unleashed/Kconfig index 2453178..fc9bc1e 100644 --- a/src/mainboard/sifive/hifive-unleashed/Kconfig +++ b/src/mainboard/sifive/hifive-unleashed/Kconfig @@ -19,6 +19,7 @@ select BOARD_ROMSIZE_KB_32768 select MISSING_BOARD_RESET select FLATTENED_DEVICE_TREE + select SPI_SDCARD
config HEAP_SIZE default 0x10000 diff --git a/src/mainboard/sifive/hifive-unleashed/media.c b/src/mainboard/sifive/hifive-unleashed/media.c index b0198a7..29cca08 100644 --- a/src/mainboard/sifive/hifive-unleashed/media.c +++ b/src/mainboard/sifive/hifive-unleashed/media.c @@ -15,15 +15,91 @@ */
#include <boot_device.h> +#include <symbols.h> +#include <cbfs.h> +#include <arch/mmio.h> +#include <soc/addressmap.h> #include <soc/spi.h> +#include <soc/clock.h> +#include <console/console.h> +#include <string.h> +#include <spi_sdcard.h> + +static struct spi_sdcard card;
/* At 0x20000000: A 256MiB long memory-mapped view of the flash at QSPI0 */ -static struct mem_region_device mdev = +static struct mem_region_device spi_mdev = MEM_REGION_DEV_RO_INIT((void *)0x20000000, CONFIG_ROM_SIZE);
+static ssize_t unleashed_sd_readat(const struct region_device *rdev, void *dest, + size_t offset, size_t count) +{ + size_t start_block_address = offset / 512; + size_t end_block_address = (offset + count - 1) / 512; + size_t has_begin = !!(offset % 512); + size_t has_end = !!((offset + count) % 512); + + if (start_block_address == end_block_address) { + uint8_t tmp[512]; + size_t o = offset % 512; + size_t l = count; + spi_sdcard_single_read(&card, start_block_address, tmp); + memcpy(dest, tmp + o, l); + return count; + } + + if (has_begin) { + uint8_t tmp[512]; + size_t o = offset % 512; + size_t l = 512 - o; + spi_sdcard_single_read(&card, start_block_address, tmp); + memcpy(dest, tmp + o, l); + } + + if (start_block_address + has_begin <= end_block_address - has_end) { + size_t start_lba = start_block_address + has_begin; + size_t end_lba = end_block_address - has_end; + size_t o = has_begin ? 512 - offset % 512 : 0; + if (start_lba < end_lba) + spi_sdcard_multiple_read(&card, + start_lba, end_lba, dest + o); + else + spi_sdcard_single_read(&card, start_lba, dest + o); + } + + if (has_end) { + uint8_t tmp[512]; + size_t o = 0; + size_t l = (offset + count) % 512; + spi_sdcard_single_read(&card, end_block_address, tmp); + memcpy(dest + count - l, tmp + o, l); + } + + return count; +} + +static const struct region_device_ops unleashed_sd_ops = { + .mmap = mmap_helper_rdev_mmap, + .munmap = mmap_helper_rdev_munmap, + .readat = unleashed_sd_readat, +}; + + +static struct mmap_helper_region_device sd_mdev = + MMAP_HELPER_REGION_INIT(&unleashed_sd_ops, 0, CONFIG_ROM_SIZE); + const struct region_device *boot_device_ro(void) { - return &mdev.rdev; + + switch (read32((uint32_t *)FU540_MSEL)) { + case 6: + case 10: + case 15: + return &spi_mdev.rdev; + case 11: + return &sd_mdev.rdev; + } + return NULL; }
const static struct fu540_spi_mmap_config spi_mmap_config = { @@ -40,10 +116,22 @@ void boot_device_init(void) { struct spi_slave slave; + switch (read32((uint32_t *)FU540_MSEL)) { + case 6: + case 10: + case 15: + /* initialize spi controller */ + spi_setup_slave(0, 0, &slave);
- /* initialize spi controller */ - spi_setup_slave(0, 0, &slave); - - /* map flash to memory space */ - fu540_spi_mmap(&slave, &spi_mmap_config); + /* map flash to memory space */ + fu540_spi_mmap(&slave, &spi_mmap_config); + break; + case 11: + spi_sdcard_init(&card, 2, 0); + mmap_helper_device_init(&sd_mdev, + _cbfs_cache, REGION_SIZE(cbfs_cache)); + break; + default: + die("Wrong configuration of MSEL"); + } } diff --git a/src/soc/sifive/fu540/include/soc/memlayout.ld b/src/soc/sifive/fu540/include/soc/memlayout.ld index b9b9c47..81a7f9b 100644 --- a/src/soc/sifive/fu540/include/soc/memlayout.ld +++ b/src/soc/sifive/fu540/include/soc/memlayout.ld @@ -28,9 +28,11 @@ CAR_STACK(FU540_L2LIM + 64K, 20K) PRERAM_CBMEM_CONSOLE(FU540_L2LIM + 84K, 8K) ROMSTAGE(FU540_L2LIM + 128K, 128K) + PRERAM_CBFS_CACHE(FU540_L2LIM + 256K, 128K) L2LIM_END(FU540_L2LIM + 2M)
DRAM_START(FU540_DRAM) RAMSTAGE(FU540_DRAM, 256K) MEM_STACK(FU540_DRAM + 256K, 20K) + POSTRAM_CBFS_CACHE(FU540_DRAM + 512K, 32M - 512K) }
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: add support boot from sdcard ......................................................................
Patch Set 1:
(11 comments)
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 94: switch (read32((uint32_t *)FU540_MSEL)) { please, no spaces at the start of a line
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 95: case 6: please, no spaces at the start of a line
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 96: case 10: please, no spaces at the start of a line
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 97: case 15: please, no spaces at the start of a line
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 98: return &spi_mdev.rdev; code indent should use tabs where possible
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 98: return &spi_mdev.rdev; please, no spaces at the start of a line
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 99: case 11: please, no spaces at the start of a line
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 100: return &sd_mdev.rdev; code indent should use tabs where possible
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 100: return &sd_mdev.rdev; please, no spaces at the start of a line
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 101: } please, no spaces at the start of a line
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 102: return NULL; please, no spaces at the start of a line
Hello ron minnich, Julius Werner, Philipp Hug,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35119
to look at the new patch set (#2).
Change subject: soc/sifive/fu540: add support boot from sdcard ......................................................................
soc/sifive/fu540: add support boot from sdcard
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 97 insertions(+), 7 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/35119/2
Hello ron minnich, Julius Werner, Philipp Hug,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35119
to look at the new patch set (#3).
Change subject: soc/sifive/fu540: add support boot from sdcard ......................................................................
soc/sifive/fu540: add support boot from sdcard
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 97 insertions(+), 7 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/35119/3
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: add support boot from sdcard ......................................................................
Patch Set 4:
(2 comments)
https://review.coreboot.org/c/coreboot/+/35119/4//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/35119/4//COMMIT_MSG@7 PS4, Line 7: soc/sifive/fu540: add support boot from sdcard Support booting from SD card
https://review.coreboot.org/c/coreboot/+/35119/4/src/mainboard/sifive/hifive... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/4/src/mainboard/sifive/hifive... PS4, Line 37: 512 Should this be an enum or macro?
Hello Patrick Rudolph, ron minnich, Julius Werner, Shawn C, build bot (Jenkins), Philipp Hug,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35119
to look at the new patch set (#5).
Change subject: soc/sifive/fu540: add support boot from sdcard ......................................................................
soc/sifive/fu540: add support boot from sdcard
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 97 insertions(+), 7 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/35119/5
Hello Patrick Rudolph, ron minnich, Julius Werner, Shawn C, build bot (Jenkins), Philipp Hug,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35119
to look at the new patch set (#6).
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
soc/sifive/fu540: Support booting from SD card
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 99 insertions(+), 7 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/35119/6
Xiang Wang has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 6:
(2 comments)
https://review.coreboot.org/c/coreboot/+/35119/4//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/35119/4//COMMIT_MSG@7 PS4, Line 7: soc/sifive/fu540: add support boot from sdcard
Support booting from SD card
Done
https://review.coreboot.org/c/coreboot/+/35119/4/src/mainboard/sifive/hifive... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/4/src/mainboard/sifive/hifive... PS4, Line 37: 512
Should this be an enum or macro?
Done
Hello Patrick Rudolph, ron minnich, Julius Werner, Shawn C, build bot (Jenkins), Philipp Hug,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35119
to look at the new patch set (#7).
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
soc/sifive/fu540: Support booting from SD card
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 99 insertions(+), 7 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/35119/7
Xiang Wang has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 7:
(13 comments)
https://review.coreboot.org/c/coreboot/+/35119/4//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/35119/4//COMMIT_MSG@7 PS4, Line 7: soc/sifive/fu540: add support boot from sdcard
Done
Done
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 94: switch (read32((uint32_t *)FU540_MSEL)) {
please, no spaces at the start of a line
Done
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 95: case 6:
please, no spaces at the start of a line
Done
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 96: case 10:
please, no spaces at the start of a line
Done
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 97: case 15:
please, no spaces at the start of a line
Done
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 98: return &spi_mdev.rdev;
code indent should use tabs where possible
Done
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 98: return &spi_mdev.rdev;
please, no spaces at the start of a line
Done
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 99: case 11:
please, no spaces at the start of a line
Done
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 100: return &sd_mdev.rdev;
please, no spaces at the start of a line
Done
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 100: return &sd_mdev.rdev;
code indent should use tabs where possible
Done
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 101: }
please, no spaces at the start of a line
Done
https://review.coreboot.org/c/coreboot/+/35119/1/src/mainboard/sifive/hifive... PS1, Line 102: return NULL;
please, no spaces at the start of a line
Done
https://review.coreboot.org/c/coreboot/+/35119/4/src/mainboard/sifive/hifive... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/4/src/mainboard/sifive/hifive... PS4, Line 37: 512
Done
Done
Xiang Wang has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 7:
Have anything update?
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 7: Code-Review+1
(2 comments)
https://review.coreboot.org/c/coreboot/+/35119/7/src/mainboard/sifive/hifive... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/7/src/mainboard/sifive/hifive... PS7, Line 28: #define BLOCK_SIZE 512 where does that value come from? is it mmc specific?
https://review.coreboot.org/c/coreboot/+/35119/7/src/mainboard/sifive/hifive... PS7, Line 121: case 6: that should not compile... Please add explicit /* fallthrough */ or /* fall-through */ It might be a good idea to use an enum instead of plain numbers.
Hello Patrick Rudolph, ron minnich, Julius Werner, Shawn C, build bot (Jenkins), Philipp Hug,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35119
to look at the new patch set (#8).
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
soc/sifive/fu540: Support booting from SD card
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 106 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/35119/8
Hello Patrick Rudolph, ron minnich, Julius Werner, Shawn C, build bot (Jenkins), Philipp Hug,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35119
to look at the new patch set (#9).
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
soc/sifive/fu540: Support booting from SD card
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 110 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/35119/9
Xiang Wang has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 9:
(1 comment)
https://review.coreboot.org/c/coreboot/+/35119/7/src/mainboard/sifive/hifive... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/7/src/mainboard/sifive/hifive... PS7, Line 28: #define BLOCK_SIZE 512
where does that value come from? is it mmc specific?
This is set when the sd card is initialized, see the spi_sdcard_init function in src/drivers/spi/spi_sdcard.c
```c /* CMD16, set block length to 512 bytes */ if (spi_sdcard_do_command(card, SET_BLOCKLEN, 512, NULL)) return -1; ```
Xiang Wang has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 9:
(2 comments)
https://review.coreboot.org/c/coreboot/+/35119/7/src/mainboard/sifive/hifive... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/7/src/mainboard/sifive/hifive... PS7, Line 28: #define BLOCK_SIZE 512
This is set when the sd card is initialized, see the spi_sdcard_init function in src/drivers/spi/spi […]
Done
https://review.coreboot.org/c/coreboot/+/35119/7/src/mainboard/sifive/hifive... PS7, Line 121: case 6:
that should not compile... […]
Done
Hello Patrick Rudolph, ron minnich, Julius Werner, Shawn C, build bot (Jenkins), Philipp Hug,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35119
to look at the new patch set (#10).
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
soc/sifive/fu540: Support booting from SD card
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 109 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/35119/10
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 10:
(1 comment)
https://review.coreboot.org/c/coreboot/+/35119/10/src/mainboard/sifive/hifiv... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/10/src/mainboard/sifive/hifiv... PS10, Line 115: else else is not generally useful after a break or return
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 11:
(1 comment)
https://review.coreboot.org/c/coreboot/+/35119/11/src/mainboard/sifive/hifiv... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/11/src/mainboard/sifive/hifiv... PS11, Line 115: else else is not generally useful after a break or return
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 12:
(1 comment)
https://review.coreboot.org/c/coreboot/+/35119/12/src/mainboard/sifive/hifiv... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/12/src/mainboard/sifive/hifiv... PS12, Line 115: else else is not generally useful after a break or return
Hello Patrick Rudolph, ron minnich, Julius Werner, Shawn C, build bot (Jenkins), Philipp Hug,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35119
to look at the new patch set (#13).
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
soc/sifive/fu540: Support booting from SD card
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 111 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/35119/13
Xiang Wang has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 13:
Have anything update?
Arthur Heymans has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 13:
(2 comments)
https://review.coreboot.org/c/coreboot/+/35119/13/src/mainboard/sifive/hifiv... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/13/src/mainboard/sifive/hifiv... PS13, Line 51: static ssize_t unleashed_sd_readat(const struct region_device *rdev, void *dest, : size_t offset, size_t count) : { : size_t start_block_address = offset / BLOCK_SIZE; : size_t end_block_address = (offset + count - 1) / BLOCK_SIZE; : size_t has_begin = !!(offset % BLOCK_SIZE); : size_t has_end = !!((offset + count) % BLOCK_SIZE); : : if (start_block_address == end_block_address) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = offset % BLOCK_SIZE; : size_t l = count; : spi_sdcard_single_read(&card, start_block_address, tmp); : memcpy(dest, tmp + o, l); : return count; : } : : if (has_begin) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = offset % BLOCK_SIZE; : size_t l = BLOCK_SIZE - o; : spi_sdcard_single_read(&card, start_block_address, tmp); : memcpy(dest, tmp + o, l); : } : : if (start_block_address + has_begin <= end_block_address - has_end) { : size_t start_lba = start_block_address + has_begin; : size_t end_lba = end_block_address - has_end; : size_t o = has_begin ? BLOCK_SIZE - offset % BLOCK_SIZE : 0; : if (start_lba < end_lba) : spi_sdcard_multiple_read(&card, : start_lba, end_lba, dest + o); : else : spi_sdcard_single_read(&card, start_lba, dest + o); : } : : if (has_end) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = 0; : size_t l = (offset + count) % BLOCK_SIZE; : spi_sdcard_single_read(&card, end_block_address, tmp); : memcpy(dest + count - l, tmp + o, l); : } : : return count; : } This looks like a rather generic readat implementation to use SD card over SPI as a region device. Put it into drivers just like drivers/spi/cbfs_spi.c does that too?
https://review.coreboot.org/c/coreboot/+/35119/13/src/mainboard/sifive/hifiv... PS13, Line 115: L" add a newline char.
Hello Patrick Rudolph, ron minnich, Julius Werner, Shawn C, build bot (Jenkins), Philipp Hug,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35119
to look at the new patch set (#14).
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
soc/sifive/fu540: Support booting from SD card
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 111 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/35119/14
Xiang Wang has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 14:
(1 comment)
https://review.coreboot.org/c/coreboot/+/35119/13/src/mainboard/sifive/hifiv... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/13/src/mainboard/sifive/hifiv... PS13, Line 51: static ssize_t unleashed_sd_readat(const struct region_device *rdev, void *dest, : size_t offset, size_t count) : { : size_t start_block_address = offset / BLOCK_SIZE; : size_t end_block_address = (offset + count - 1) / BLOCK_SIZE; : size_t has_begin = !!(offset % BLOCK_SIZE); : size_t has_end = !!((offset + count) % BLOCK_SIZE); : : if (start_block_address == end_block_address) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = offset % BLOCK_SIZE; : size_t l = count; : spi_sdcard_single_read(&card, start_block_address, tmp); : memcpy(dest, tmp + o, l); : return count; : } : : if (has_begin) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = offset % BLOCK_SIZE; : size_t l = BLOCK_SIZE - o; : spi_sdcard_single_read(&card, start_block_address, tmp); : memcpy(dest, tmp + o, l); : } : : if (start_block_address + has_begin <= end_block_address - has_end) { : size_t start_lba = start_block_address + has_begin; : size_t end_lba = end_block_address - has_end; : size_t o = has_begin ? BLOCK_SIZE - offset % BLOCK_SIZE : 0; : if (start_lba < end_lba) : spi_sdcard_multiple_read(&card, : start_lba, end_lba, dest + o); : else : spi_sdcard_single_read(&card, start_lba, dest + o); : } : : if (has_end) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = 0; : size_t l = (offset + count) % BLOCK_SIZE; : spi_sdcard_single_read(&card, end_block_address, tmp); : memcpy(dest + count - l, tmp + o, l); : } : : return count; : }
This looks like a rather generic readat implementation to use SD card over SPI as a region device. […]
on cbfs_spi.c, decide where to boot at compile time. On HiFive-Unleashed, decide where to boot at runtime. So it is more appropriate to put it in the original place.
Xiang Wang has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 14:
(1 comment)
https://review.coreboot.org/c/coreboot/+/35119/13/src/mainboard/sifive/hifiv... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/13/src/mainboard/sifive/hifiv... PS13, Line 115: L"
add a newline char.
Done
Arthur Heymans has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 14:
(1 comment)
https://review.coreboot.org/c/coreboot/+/35119/13/src/mainboard/sifive/hifiv... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/13/src/mainboard/sifive/hifiv... PS13, Line 51: static ssize_t unleashed_sd_readat(const struct region_device *rdev, void *dest, : size_t offset, size_t count) : { : size_t start_block_address = offset / BLOCK_SIZE; : size_t end_block_address = (offset + count - 1) / BLOCK_SIZE; : size_t has_begin = !!(offset % BLOCK_SIZE); : size_t has_end = !!((offset + count) % BLOCK_SIZE); : : if (start_block_address == end_block_address) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = offset % BLOCK_SIZE; : size_t l = count; : spi_sdcard_single_read(&card, start_block_address, tmp); : memcpy(dest, tmp + o, l); : return count; : } : : if (has_begin) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = offset % BLOCK_SIZE; : size_t l = BLOCK_SIZE - o; : spi_sdcard_single_read(&card, start_block_address, tmp); : memcpy(dest, tmp + o, l); : } : : if (start_block_address + has_begin <= end_block_address - has_end) { : size_t start_lba = start_block_address + has_begin; : size_t end_lba = end_block_address - has_end; : size_t o = has_begin ? BLOCK_SIZE - offset % BLOCK_SIZE : 0; : if (start_lba < end_lba) : spi_sdcard_multiple_read(&card, : start_lba, end_lba, dest + o); : else : spi_sdcard_single_read(&card, start_lba, dest + o); : } : : if (has_end) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = 0; : size_t l = (offset + count) % BLOCK_SIZE; : spi_sdcard_single_read(&card, end_block_address, tmp); : memcpy(dest + count - l, tmp + o, l); : } : : return count; : }
on cbfs_spi.c, decide where to boot at compile time. On HiFive-Unleashed, decide where to boot at runtime. So it is more appropriate to put it in the original place.
That is indeed decided by const struct region_device *boot_device_ro(void). You could put the definition of the region_device ops in a common place.
Hello Patrick Rudolph, ron minnich, Julius Werner, Shawn C, build bot (Jenkins), Philipp Hug,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35119
to look at the new patch set (#15).
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
soc/sifive/fu540: Support booting from SD card
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 66 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/35119/15
Xiang Wang has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 15:
(1 comment)
https://review.coreboot.org/c/coreboot/+/35119/13/src/mainboard/sifive/hifiv... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/13/src/mainboard/sifive/hifiv... PS13, Line 51: static ssize_t unleashed_sd_readat(const struct region_device *rdev, void *dest, : size_t offset, size_t count) : { : size_t start_block_address = offset / BLOCK_SIZE; : size_t end_block_address = (offset + count - 1) / BLOCK_SIZE; : size_t has_begin = !!(offset % BLOCK_SIZE); : size_t has_end = !!((offset + count) % BLOCK_SIZE); : : if (start_block_address == end_block_address) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = offset % BLOCK_SIZE; : size_t l = count; : spi_sdcard_single_read(&card, start_block_address, tmp); : memcpy(dest, tmp + o, l); : return count; : } : : if (has_begin) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = offset % BLOCK_SIZE; : size_t l = BLOCK_SIZE - o; : spi_sdcard_single_read(&card, start_block_address, tmp); : memcpy(dest, tmp + o, l); : } : : if (start_block_address + has_begin <= end_block_address - has_end) { : size_t start_lba = start_block_address + has_begin; : size_t end_lba = end_block_address - has_end; : size_t o = has_begin ? BLOCK_SIZE - offset % BLOCK_SIZE : 0; : if (start_lba < end_lba) : spi_sdcard_multiple_read(&card, : start_lba, end_lba, dest + o); : else : spi_sdcard_single_read(&card, start_lba, dest + o); : } : : if (has_end) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = 0; : size_t l = (offset + count) % BLOCK_SIZE; : spi_sdcard_single_read(&card, end_block_address, tmp); : memcpy(dest + count - l, tmp + o, l); : } : : return count; : }
on cbfs_spi.c, decide where to boot at compile time. On HiFive-Unleashed, decide […]
How change like this?
Arthur Heymans has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 15: Code-Review+2
Xiang Wang has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 15:
Have anything update?
Hello Patrick Rudolph, ron minnich, Julius Werner, Arthur Heymans, Shawn C, build bot (Jenkins), Philipp Hug,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/35119
to look at the new patch set (#18).
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
soc/sifive/fu540: Support booting from SD card
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 66 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/35119/18
Xiang Wang has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 18:
Have anything update?
Xiang Wang has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 18:
Have anything update?
Patrick Georgi has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
Patch Set 18:
(1 comment)
Patch Set 18:
Have anything update?
Waiting on the parent commit where one last change is necessary. as far as I can see, this one doesn't need any more changes.
https://review.coreboot.org/c/coreboot/+/35119/13/src/mainboard/sifive/hifiv... File src/mainboard/sifive/hifive-unleashed/media.c:
https://review.coreboot.org/c/coreboot/+/35119/13/src/mainboard/sifive/hifiv... PS13, Line 51: static ssize_t unleashed_sd_readat(const struct region_device *rdev, void *dest, : size_t offset, size_t count) : { : size_t start_block_address = offset / BLOCK_SIZE; : size_t end_block_address = (offset + count - 1) / BLOCK_SIZE; : size_t has_begin = !!(offset % BLOCK_SIZE); : size_t has_end = !!((offset + count) % BLOCK_SIZE); : : if (start_block_address == end_block_address) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = offset % BLOCK_SIZE; : size_t l = count; : spi_sdcard_single_read(&card, start_block_address, tmp); : memcpy(dest, tmp + o, l); : return count; : } : : if (has_begin) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = offset % BLOCK_SIZE; : size_t l = BLOCK_SIZE - o; : spi_sdcard_single_read(&card, start_block_address, tmp); : memcpy(dest, tmp + o, l); : } : : if (start_block_address + has_begin <= end_block_address - has_end) { : size_t start_lba = start_block_address + has_begin; : size_t end_lba = end_block_address - has_end; : size_t o = has_begin ? BLOCK_SIZE - offset % BLOCK_SIZE : 0; : if (start_lba < end_lba) : spi_sdcard_multiple_read(&card, : start_lba, end_lba, dest + o); : else : spi_sdcard_single_read(&card, start_lba, dest + o); : } : : if (has_end) { : uint8_t tmp[BLOCK_SIZE]; : size_t o = 0; : size_t l = (offset + count) % BLOCK_SIZE; : spi_sdcard_single_read(&card, end_block_address, tmp); : memcpy(dest + count - l, tmp + o, l); : } : : return count; : }
How change like this?
Done
Patrick Georgi has submitted this change. ( https://review.coreboot.org/c/coreboot/+/35119 )
Change subject: soc/sifive/fu540: Support booting from SD card ......................................................................
soc/sifive/fu540: Support booting from SD card
Change-Id: I18948d31c0bf0bf9d641480a35fc710b9ee8ae84 Signed-off-by: Xiang Wang merle@hardenedlinux.org Reviewed-on: https://review.coreboot.org/c/coreboot/+/35119 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Arthur Heymans arthur@aheymans.xyz --- M src/mainboard/sifive/hifive-unleashed/Kconfig M src/mainboard/sifive/hifive-unleashed/media.c M src/soc/sifive/fu540/include/soc/memlayout.ld 3 files changed, 66 insertions(+), 9 deletions(-)
Approvals: build bot (Jenkins): Verified Arthur Heymans: Looks good to me, approved
diff --git a/src/mainboard/sifive/hifive-unleashed/Kconfig b/src/mainboard/sifive/hifive-unleashed/Kconfig index 2453178..fc9bc1e 100644 --- a/src/mainboard/sifive/hifive-unleashed/Kconfig +++ b/src/mainboard/sifive/hifive-unleashed/Kconfig @@ -19,6 +19,7 @@ select BOARD_ROMSIZE_KB_32768 select MISSING_BOARD_RESET select FLATTENED_DEVICE_TREE + select SPI_SDCARD
config HEAP_SIZE default 0x10000 diff --git a/src/mainboard/sifive/hifive-unleashed/media.c b/src/mainboard/sifive/hifive-unleashed/media.c index b0198a7..45d1f1a 100644 --- a/src/mainboard/sifive/hifive-unleashed/media.c +++ b/src/mainboard/sifive/hifive-unleashed/media.c @@ -15,15 +15,60 @@ */
#include <boot_device.h> +#include <symbols.h> +#include <cbfs.h> +#include <arch/mmio.h> +#include <soc/addressmap.h> #include <soc/spi.h> +#include <soc/clock.h> +#include <console/console.h> +#include <spi_sdcard.h> + +/* follow is the FSBL boot device defined by ZSBL of sifive + * FSBL replaced by bootblock of coreboot + * MSEL_SPInx1 -> test if boot from memory-mapped on SPIn + * MSEL_SPInx4 -> test if boot from memory-mapped on QPIn + * MSEL_SPInSD -> test if boot from sdcard mount on SPIn */ +#define MSEL_SPI0x1(m) (((m) == 5) || ((m) == 14)) +#define MSEL_SPI0x4(m) (((m) == 6) || ((m) == 10) || ((m) == 15)) +#define MSEL_SPI1x1(m) ((m) == 12) +#define MSEL_SPI1x4(m) (((m) == 7) || ((m) == 13)) +#define MSEL_SPI1SD(m) ((m) == 8) +#define MSEL_SPI2x1(m) ((m) == 9) +#define MSEL_SPI2SD(m) ((m) == 11) + +static struct spi_sdcard card;
/* At 0x20000000: A 256MiB long memory-mapped view of the flash at QSPI0 */ -static struct mem_region_device mdev = +static struct mem_region_device spi_mdev = MEM_REGION_DEV_RO_INIT((void *)0x20000000, CONFIG_ROM_SIZE);
+static ssize_t unleashed_sd_readat(const struct region_device *rdev, void *dest, + size_t offset, size_t count) +{ + spi_sdcard_read(&card, dest, offset, count); + return count; +} + +static const struct region_device_ops unleashed_sd_ops = { + .mmap = mmap_helper_rdev_mmap, + .munmap = mmap_helper_rdev_munmap, + .readat = unleashed_sd_readat, +}; + + +static struct mmap_helper_region_device sd_mdev = + MMAP_HELPER_REGION_INIT(&unleashed_sd_ops, 0, CONFIG_ROM_SIZE); + const struct region_device *boot_device_ro(void) { - return &mdev.rdev; + uint32_t m = read32((uint32_t *)FU540_MSEL); + if (MSEL_SPI0x1(m) || MSEL_SPI0x4(m)) + return &spi_mdev.rdev; + if (MSEL_SPI2SD(m)) + return &sd_mdev.rdev; + die("Wrong configuration of MSEL\n"); + return NULL; }
const static struct fu540_spi_mmap_config spi_mmap_config = { @@ -39,11 +84,20 @@
void boot_device_init(void) { - struct spi_slave slave; - - /* initialize spi controller */ - spi_setup_slave(0, 0, &slave); - - /* map flash to memory space */ - fu540_spi_mmap(&slave, &spi_mmap_config); + uint32_t m = read32((uint32_t *)FU540_MSEL); + if (MSEL_SPI0x1(m) || MSEL_SPI0x4(m)) { + struct spi_slave slave; + /* initialize spi controller */ + spi_setup_slave(0, 0, &slave); + /* map flash to memory space */ + fu540_spi_mmap(&slave, &spi_mmap_config); + return; + } + if (MSEL_SPI2SD(m)) { + spi_sdcard_init(&card, 2, 0); + mmap_helper_device_init(&sd_mdev, + _cbfs_cache, REGION_SIZE(cbfs_cache)); + return; + } + die("Wrong configuration of MSEL\n"); } diff --git a/src/soc/sifive/fu540/include/soc/memlayout.ld b/src/soc/sifive/fu540/include/soc/memlayout.ld index 1d11aa0..df30ede 100644 --- a/src/soc/sifive/fu540/include/soc/memlayout.ld +++ b/src/soc/sifive/fu540/include/soc/memlayout.ld @@ -28,10 +28,12 @@ CAR_STACK(FU540_L2LIM + 64K, 20K) PRERAM_CBMEM_CONSOLE(FU540_L2LIM + 84K, 8K) ROMSTAGE(FU540_L2LIM + 128K, 128K) + PRERAM_CBFS_CACHE(FU540_L2LIM + 256K, 128K) L2LIM_END(FU540_L2LIM + 2M)
DRAM_START(FU540_DRAM) REGION(opensbi, FU540_DRAM, 128K, 4K) RAMSTAGE(FU540_DRAM + 128K, 256K) MEM_STACK(FU540_DRAM + 448K, 20K) + POSTRAM_CBFS_CACHE(FU540_DRAM + 512K, 32M - 512K) }