<p>Philipp Hug has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/27397">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">riscv: add trampoline in MBR block to support boot mode 1<br><br>Add "J pc + 0x1000" at the beginning of the MBR to jump to bootlock.<br>Changed first usable lba to 4 (0x1000) as prevent stack alignment<br>issues.<br><br>Change-Id: I16e762d9f027346b124412f1f7ee6ff37f431d86<br>---<br>M util/riscv/sifive-gpt.py<br>1 file changed, 9 insertions(+), 7 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/97/27397/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/util/riscv/sifive-gpt.py b/util/riscv/sifive-gpt.py</span><br><span>index cb77302..2619a21 100755</span><br><span>--- a/util/riscv/sifive-gpt.py</span><br><span>+++ b/util/riscv/sifive-gpt.py</span><br><span>@@ -25,6 +25,12 @@</span><br><span> # Size of the bootcode part of the MBR</span><br><span> MBR_BOOTCODE_SIZE = 0x1be</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+# MBR trampoline to bootblock</span><br><span style="color: hsl(120, 100%, 40%);">+MBR_BOOTCODE = bytes([</span><br><span style="color: hsl(120, 100%, 40%);">+    # j pc + 0x1000</span><br><span style="color: hsl(120, 100%, 40%);">+    0x6f, 0x10, 0x00, 0x00,</span><br><span style="color: hsl(120, 100%, 40%);">+])</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> # A protecive MBR, without the bootcode part</span><br><span> PROTECTIVE_MBR_FOOTER = bytes([</span><br><span>     0x00, 0x00, 0x02, 0x00, 0xee, 0xff, 0xff, 0xff,</span><br><span>@@ -43,7 +49,7 @@</span><br><span> # [1]: https://en.wikipedia.org/wiki/GUID_Partition_Table#PROTECTIVE-MBR</span><br><span> class ProtectiveMBR:</span><br><span>     def __init__(self):</span><br><span style="color: hsl(0, 100%, 40%);">-        self.bootcode = bytes(MBR_BOOTCODE_SIZE)</span><br><span style="color: hsl(120, 100%, 40%);">+        self.bootcode = MBR_BOOTCODE + bytes(MBR_BOOTCODE_SIZE - len(MBR_BOOTCODE))</span><br><span> </span><br><span>     def generate(self, stream):</span><br><span>         assert len(self.bootcode) == MBR_BOOTCODE_SIZE</span><br><span>@@ -71,7 +77,7 @@</span><br><span>     def __init__(self):</span><br><span>         self.current_lba = 1</span><br><span>         self.backup_lba = 1</span><br><span style="color: hsl(0, 100%, 40%);">-        self.first_usable_lba = 2</span><br><span style="color: hsl(120, 100%, 40%);">+        self.first_usable_lba = 8       # hard-coded to match jump</span><br><span>         self.last_usable_lba = 0xff     # dummy value</span><br><span>         self.uniq = DUMMY_GUID_DISK_UNIQUE</span><br><span>         self.part_entries_lba = 2</span><br><span>@@ -126,7 +132,7 @@</span><br><span>     def __init__(self):</span><br><span>         self.mbr = ProtectiveMBR()</span><br><span>         self.header = GPTHeader()</span><br><span style="color: hsl(0, 100%, 40%);">-        self.partitions = [ GPTPartition() for i in range(8) ]</span><br><span style="color: hsl(120, 100%, 40%);">+        self.partitions = [ GPTPartition() for i in range(24) ]</span><br><span>         self.bootblock = b''</span><br><span> </span><br><span> </span><br><span>@@ -137,10 +143,6 @@</span><br><span>         bootblock_size = (len(self.bootblock) + BLOCK_SIZE - 1) & ~BLOCK_MASK</span><br><span>         self.bootblock = self.bootblock.ljust(bootblock_size)</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-        # Propagate the number of partition entries</span><br><span style="color: hsl(0, 100%, 40%);">-        self.header.part_entries_number = len(self.partitions)</span><br><span style="color: hsl(0, 100%, 40%);">-        self.header.first_usable_lba = 2 + self.header.part_entries_number // 4</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span>         # Create a partition entry for the bootblock</span><br><span>         self.partitions[0].type = GUID_TYPE_FSBL</span><br><span>         self.partitions[0].uniq = DUMMY_GUID_PART_UNIQUE</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/27397">change 27397</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/27397"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I16e762d9f027346b124412f1f7ee6ff37f431d86 </div>
<div style="display:none"> Gerrit-Change-Number: 27397 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Philipp Hug <philipp@hug.cx> </div>