Skip to content

Commit 3317fba

Browse files
dgarskedanielinux
authored andcommitted
Cleanups and improvements
1 parent 0292da5 commit 3317fba

File tree

8 files changed

+116
-87
lines changed

8 files changed

+116
-87
lines changed

config/examples/polarfire_mpfs250.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ DUALBANK_SWAP?=0
2222
PKA?=0
2323
ENCRYPT=0
2424
WOLFTPM?=0
25+
ELF?=1
26+
#DEBUG_ELF?=1
2527

2628
# Optionally allow downgrade to older valid version in update partition
2729
ALLOW_DOWNGRADE?=0

docs/Targets.md

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -831,63 +831,92 @@ Example one-shot command:
831831
cp ./config/examples/polarfire_mpfs250.config .config && make clean && make wolfboot.elf && size wolfboot.elf && hss-payload-generator -vvv -c ./hal/mpfs.yaml wolfboot.bin && file wolfboot.bin && ls -la wolfboot.bin
832832
```
833833

834-
#### Build PolarFire test-application, sign it and apply to uSD
834+
### Flashing PolarFire SoC
835+
836+
The HSS MMC boot source looks for GPT with GUID "21686148-6449-6E6F-744E-656564454649" or sector "0" if no GPT found. That GUID is the default "BIOS" boot partition.
837+
838+
The resulting image from `hss-payload-generator` can be directly placed into GPT BIOS partition. The HSS tinyCLI supports the `USBDMSC` command to mount the eMMC or SD card as a USB device. You can then use "dd" to copy the boot image to the BOOT partition 2. Example:
839+
840+
```
841+
sudo dd if=wolfboot.bin of=/dev/sdc2 bs=512
842+
```
843+
844+
### PolarFire testing
845+
846+
This section describes how to build the test-application, create a custom uSD with required partitions and copying signing test-application to uSD partitions.
847+
848+
To use your own application (Linux FIT Image, ELF, etc) just replace test-app/image.elf with your own filename.
835849

836850
```sh
837851
# make test-app
838852
make test-app/image.elf
853+
```
839854

840-
# assemble GPT image
841-
dd if=/dev/zero of=app.bin bs=1M count=64
842-
/sbin/fdisk app.bin <<EOF
855+
```sh
856+
# Partition uSD card
857+
sudo fdisk /dev/sdc <<EOF
843858
g
844859
n
845860
1
846861
847-
+16M
862+
+8M
863+
848864
n
865+
2
849866
867+
+64M
868+
n
869+
3
850870
851-
+16M
852-
x
871+
+64M
853872
n
873+
4
874+
875+
t
854876
1
855-
OFP_A
877+
4
878+
x
856879
n
857880
2
881+
OFP_A
882+
n
883+
3
858884
OFP_B
859885
r
886+
p
860887
w
861888
EOF
862-
863-
cp test-app/image.elf image.bin
864-
tools/keytools/sign $SIGN $HASH image.bin wolfboot_signing_private_key.der 1
865-
tools/keytools/sign $SIGN $HASH image.bin wolfboot_signing_private_key.der 2
866-
dd if=image_v1_signed.bin of=app.bin bs=512 seek=2048 conv=notrunc
867-
dd if=image_v2_signed.bin of=app.bin bs=512 seek=34816 conv=notrunc
868889
```
869890

870-
### Flashing PolarFire SoC
871-
891+
Result should look like:
872892

873-
The HSS MMC boot source looks for GPT with GUID "21686148-6449-6E6F-744E-656564454649" or sector "0" if no GPT found. That GUID is the default "BIOS" boot partition.
874-
875-
The resulting image from `hss-payload-generator` can be directly placed into GPT BIOS partition. The HSS tinyCLI supports the `USBDMSC` command to mount the eMMC or SD card as a USB device. You can then use "dd" to copy the boot image to the BOOT partition 2. Example:
876-
877-
```
878-
sudo dd if=wolfboot.bin of=/dev/sde2 bs=1024
879893
```
894+
Disk /dev/sdc: 29.72 GiB, 31914983424 bytes, 62333952 sectors
895+
Disk model: MassStorageClass
896+
Units: sectors of 1 * 512 = 512 bytes
897+
Sector size (logical/physical): 512 bytes / 512 bytes
898+
I/O size (minimum/optimal): 512 bytes / 512 bytes
899+
Disklabel type: gpt
900+
Disk identifier: 9A5E3FBC-AAB2-483E-941C-7797802BD173
880901
881-
Flashing to eNVM:
882-
883-
The boot rom expects a 0x100 byte secure boot header added. It also requires the .ld is offset by 0x100 to leave room for this. The mpfsBootmodeProgrammer adds 0x100 of meta information for secure boot.
902+
Device Start End Sectors Size Type
903+
/dev/sdc1 2048 18431 16384 8M BIOS boot
904+
/dev/sdc2 18432 149503 131072 64M Linux filesystem
905+
/dev/sdc3 149504 280575 131072 64M Linux filesystem
906+
/dev/sdc4 280576 62332927 62052352 29.6G Linux filesystem
907+
```
884908

885909
```sh
886-
$SC_INSTALL_DIR/eclipse/jre/bin/java -jar \
887-
$SC_INSTALL_DIR/extras/mpfs/mpfsBootmodeProgrammer.jar \
888-
--bootmode 1 --die MPFS250T --package FCVG484 --workdir $PWD wolfboot.elf
910+
# Sign image with version 1
911+
./tools/keytools/sign --ecc384 --sha384 test-app/image.elf wolfboot_signing_private_key.der 1
912+
# Copy signed image to both OFP partitions
913+
sudo dd if=image_v1_signed.bin of=/dev/sdc2 bs=512
914+
sudo dd if=image_v1_signed.bin of=/dev/sdc2 bs=512
915+
916+
# Copy wolfBoot to BIOS boot partition
917+
sudo dd if=wolfboot.bin of=/dev/sdc1 bs=512
889918
```
890-
Note: wolfBoot does not support running from eNVM in machine mode yet.
919+
891920

892921
### Debugging PolarFire Soc
893922

hal/mpfs250.c

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646

4747
#define DEBUG_MMC
4848

49-
/* Placeholder functions - to be implemented */
5049
void hal_init(void)
5150
{
5251
wolfBoot_printf("wolfBoot Version: %s (%s %s)\n",
@@ -269,7 +268,7 @@ uint32_t mmc_set_clock(uint32_t clock_khz)
269268
base_clk_khz = (reg & EMMC_SD_SRS16_BCSDCLK_MASK) >> EMMC_SD_SRS16_BCSDCLK_SHIFT;
270269
if (base_clk_khz == 0) {
271270
/* error getting base clock */
272-
return 0;
271+
return -1;
273272
}
274273
base_clk_khz *= 1000; /* convert MHz to kHz */
275274

@@ -427,14 +426,13 @@ int mmc_power_init_seq(uint32_t voltage)
427426
if (status == 0) {
428427
/* send CMD0 (go idle) to reset card */
429428
status = mmc_send_cmd(MMC_CMD0_GO_IDLE, 0, EMMC_SD_RESP_NONE);
429+
}
430+
if (status == 0) {
431+
mmc_delay(DEFAULT_DELAY);
430432

431-
if (status == 0) {
432-
mmc_delay(DEFAULT_DELAY);
433-
434-
/* send the operating conditions command */
435-
status = mmc_send_cmd(SD_CMD8_SEND_IF_COND, IF_COND_27V_33V,
436-
EMMC_SD_RESP_R7);
437-
}
433+
/* send the operating conditions command */
434+
status = mmc_send_cmd(SD_CMD8_SEND_IF_COND, IF_COND_27V_33V,
435+
EMMC_SD_RESP_R7);
438436
}
439437
return status;
440438
}
@@ -553,6 +551,7 @@ int mmc_set_bus_width(uint32_t bus_width)
553551
return status;
554552
}
555553

554+
/* helper to get bits from the response registers */
556555
static uint32_t get_srs_bits(int from, int count)
557556
{
558557
volatile uint32_t *resp = ((volatile uint32_t*)(EMMC_SD_BASE + 0x210));
@@ -564,8 +563,8 @@ static uint32_t get_srs_bits(int from, int count)
564563
off = from / 32;
565564
shft = from & 31;
566565
ret = resp[off] >> shft;
567-
if (from + shft > 32) {
568-
ret |= resp[off + 1] << (32 - shft) % 32;
566+
if ((from + shft) > 32) {
567+
ret |= resp[off + 1] << ((32 - shft) % 32);
569568
}
570569
return ret & mask;
571570
}
@@ -806,34 +805,29 @@ int mmc_init(void)
806805
if (status == 0) {
807806
/* Get sector size and count */
808807
uint32_t csd_struct;
809-
uint32_t c_size = 0;
810-
#define SECT_SIZE_CSD_MASK 0x03C000
811-
#define SECT_SIZE_CSD_SHIFT 14
812-
c_size = (EMMC_SD_SRS04 & SECT_SIZE_CSD_MASK) >> SECT_SIZE_CSD_SHIFT;
813-
if (c_size < 32) {
814-
g_sector_size = (1U << c_size);
815-
#ifdef DEBUG_MMC
816-
wolfBoot_printf("mmc_init: sector size: %d\n", g_sector_size);
817-
#endif
818-
}
808+
uint32_t bl_len, c_size, c_size_mult;
809+
bl_len = get_srs_bits(22, 4);
810+
g_sector_size = (1U << bl_len);
819811

820812
csd_struct = get_srs_bits(126, 2);
821813
switch (csd_struct) {
822814
case 0:
823815
c_size = get_srs_bits(62, 12);
824-
g_sector_count = (c_size + 1) << (get_srs_bits(47, 3) + 2);
816+
c_size_mult = get_srs_bits(47, 3);
817+
g_sector_count = (c_size + 1) << (c_size_mult + 2);
825818
break;
826819
case 1:
827820
c_size = get_srs_bits(48, 22);
828821
g_sector_count = (c_size + 1) << 10;
829822
break;
830823
default:
831-
/* invalid CSR structure */
824+
/* invalid CSD structure */
832825
status = -1;
833826
break;
834827
}
835828
#ifdef DEBUG_MMC
836-
wolfBoot_printf("mmc_init: sector count: %d\n", g_sector_count);
829+
wolfBoot_printf("mmc_init: csd_version: %d, sector: size %d count %d\n",
830+
csd_struct, g_sector_size, g_sector_count);
837831
#endif
838832
}
839833
if (status == 0) {
@@ -890,11 +884,10 @@ int mmc_init(void)
890884
}
891885

892886
/* returns number of bytes read on success or negative on error */
893-
int disk_read(int drv, uint64_t start, uint32_t count, uint32_t *buf)
887+
int disk_read(int drv, uint64_t start, uint32_t count, uint8_t *buf)
894888
{
895889
int status = 0;
896890
uint32_t read_sz, block_addr;
897-
uint8_t* p_buf = (uint8_t*)buf;
898891
uint32_t tmp_block[EMMC_SD_BLOCK_SIZE/sizeof(uint32_t)];
899892
(void)drv; /* only one drive supported */
900893

@@ -906,33 +899,34 @@ int disk_read(int drv, uint64_t start, uint32_t count, uint32_t *buf)
906899
while (count > 0) {
907900
block_addr = (start / EMMC_SD_BLOCK_SIZE);
908901
read_sz = count;
909-
if (read_sz < EMMC_SD_BLOCK_SIZE) {
910-
/* last partial block read */
902+
if (read_sz > EMMC_SD_BLOCK_SIZE) {
903+
read_sz = EMMC_SD_BLOCK_SIZE;
904+
}
905+
if (read_sz < EMMC_SD_BLOCK_SIZE || ((uintptr_t)buf % 4) != 0) {
906+
/* partial or unaligned block read */
911907
status = mmc_read(MMC_CMD17_READ_SINGLE, block_addr,
912908
tmp_block, EMMC_SD_BLOCK_SIZE);
913909
if (status == 0) {
914-
memcpy(p_buf, tmp_block, read_sz);
915-
break; /* last partial block read */
910+
memcpy(buf, tmp_block, read_sz);
916911
}
917912
}
918913
else {
919914
/* full block read */
920-
read_sz = EMMC_SD_BLOCK_SIZE;
921915
status = mmc_read(MMC_CMD17_READ_SINGLE, block_addr,
922-
(uint32_t*)p_buf, read_sz);
916+
(uint32_t*)buf, read_sz);
923917
}
924918
if (status != 0) {
925919
break;
926920
}
927921

928922
start += read_sz;
929-
p_buf += read_sz;
923+
buf += read_sz;
930924
count -= read_sz;
931925
}
932926
return status;
933927
}
934928

935-
int disk_write(int drv, uint64_t start, uint32_t count, const uint32_t *buf)
929+
int disk_write(int drv, uint64_t start, uint32_t count, const uint8_t *buf)
936930
{
937931
/* not supported */
938932
(void)drv;

hal/mpfs250.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,7 @@
836836
#define MMC_CMD0_GO_IDLE 0 /* Reset card to idle state */
837837
#define MMC_CMD1_SEND_OP_COND 1 /* MMC: Send operating conditions */
838838
#define MMC_CMD2_ALL_SEND_CID 2 /* Get card identification */
839-
#define MMC_CMD3_SET_REL_ADDR 3 /* MMC: Set relative address */
840-
#define SD_CMD3_SEND_REL_ADDR 3 /* SD: Get relative address */
839+
#define MMC_CMD3_SET_REL_ADDR 3 /* Set relative address */
841840
#define MMC_CMD_4_SET_DSR 4
842841
#define SD_CMD_6_SWITCH_FUNC 6 /* SD: Switch function */
843842
#define MMC_CMD7_SELECT_CARD 7 /* Select/deselect card */
@@ -873,11 +872,11 @@
873872

874873
#define MAX_CURRENT_MA 150 /* mA */
875874

876-
#define SD_RCA_SHIFT 16
875+
#define SD_RCA_SHIFT 16 /* relative card address */
876+
#define SD_RCA_MASK (0xFFFFU << SD_RCA_SHIFT) /* relative card address mask */
877877

878878
#define SCR_REG_DATA_SIZE 8
879879

880-
881880
/* Switch Function Command Arguments */
882881
#define SDCARD_SWITCH_FUNC_MODE_SWITCH (0x1u << 31) /* Set function mode */
883882
#define SDCARD_SWITCH_FUNC_MODE_CHECK (0x0u << 31) /* Check mode */

hal/x86_fsp_tgl.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* fsp_tgl.c
1+
/* x86_fsp_tgl.c
22
*
33
* Copyright (C) 2025 wolfSSL Inc.
44
*
@@ -70,18 +70,19 @@ void disk_close(int drv)
7070
{
7171
#ifdef WOLFBOOT_FSP
7272
sata_disable(sata_bar);
73+
sata_bar = 0;
7374
#endif
7475
(void)drv;
7576
}
7677

77-
int disk_read(int drv, uint64_t start, uint32_t count, uint32_t *buf)
78+
int disk_read(int drv, uint64_t start, uint32_t count, uint8_t *buf)
7879
{
79-
return ata_drive_read(drv, start, count, (uint8_t*)buf);
80+
return ata_drive_read(drv, start, count, buf);
8081
}
8182

82-
int disk_write(int drv, uint64_t start, uint32_t count, const uint32_t *buf)
83+
int disk_write(int drv, uint64_t start, uint32_t count, const uint8_t *buf)
8384
{
84-
return ata_drive_write(drv, start, count, (const uint8_t*)buf);
85+
return ata_drive_write(drv, start, count, buf);
8586
}
8687

8788
/*!

include/disk.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ struct disk_drive {
5858

5959
/* user supplied functions */
6060
int disk_init(int drv);
61-
int disk_read(int drv, uint64_t start, uint32_t count, uint32_t *buf);
62-
int disk_write(int drv, uint64_t start, uint32_t count, const uint32_t *buf);
61+
int disk_read(int drv, uint64_t start, uint32_t count, uint8_t *buf);
62+
int disk_write(int drv, uint64_t start, uint32_t count, const uint8_t *buf);
6363
void disk_close(int drv);
6464

6565
/* standard functions */
6666
int disk_open(int drv);
67-
int disk_part_read(int drv, int part, uint64_t off, uint64_t sz, uint32_t *buf);
68-
int disk_part_write(int drv, int part, uint64_t off, uint64_t sz, const uint32_t *buf);
67+
int disk_part_read(int drv, int part, uint64_t off, uint64_t sz, uint8_t *buf);
68+
int disk_part_write(int drv, int part, uint64_t off, uint64_t sz, const uint8_t *buf);
6969
int disk_find_partition_by_label(int drv, const char *label);
7070

7171
#endif /* _WOLFBOOT_DISK_H */

0 commit comments

Comments
 (0)