[rom_ctrl] Switch padding scheme to zeroes

As elaborated in #5771, we decided to switch the padding scheme so that
the ROM is padded out with zeroes as opposed to pseudo-random data.
This has been deemed the better approach, since confidentiality is not
required, and padding out with zero makes sure that there are no
"gadget" instructions in invalid ROM regions, since zeroes are
interpreted as invalid instructions in Ibex.

Signed-off-by: Michael Schaffner <msf@google.com>
diff --git a/hw/ip/rom_ctrl/util/mem.py b/hw/ip/rom_ctrl/util/mem.py
index 3ec7129..be914d0 100644
--- a/hw/ip/rom_ctrl/util/mem.py
+++ b/hw/ip/rom_ctrl/util/mem.py
@@ -3,7 +3,6 @@
 # Licensed under the Apache License, Version 2.0, see LICENSE for details.
 # SPDX-License-Identifier: Apache-2.0
 
-import random
 import re
 import subprocess
 import tempfile
@@ -276,8 +275,8 @@
         for chunk in self.chunks:
             chunk.write_vmem(self.width, outfile)
 
-    def flatten(self, size: int, rnd_seed: int) -> 'MemFile':
-        '''Flatten into a single chunk, padding with pseudo-random data
+    def flatten(self, size: int) -> 'MemFile':
+        '''Flatten into a single chunk, padding with zeroes
 
         As well as padding between the chunks, this expands the result up to
         size words by adding padding after the last chunk if necessary.
@@ -285,40 +284,31 @@
         '''
         assert self.next_addr() <= size
 
-        old_rnd_state = random.getstate()
-        random.seed(rnd_seed)
-
-        try:
-            acc = MemChunk(0, [])
-            # Add each chunk
-            for chunk in self.chunks:
-                acc_end = acc.next_addr()
-                assert acc_end <= chunk.base_addr
-
-                # If there's a gap before the chunk, insert some random bits
-                padding_len = chunk.base_addr - acc_end
-                if padding_len:
-                    acc.words += [random.getrandbits(32)
-                                  for _ in range(padding_len)]
-
-                assert acc.next_addr() == chunk.base_addr
-                acc.words += chunk.words
-
+        acc = MemChunk(0, [])
+        # Add each chunk
+        for chunk in self.chunks:
             acc_end = acc.next_addr()
-            assert acc_end == self.next_addr()
+            assert acc_end <= chunk.base_addr
 
-            # If there's a gap after the last chunk, insert some more random
-            # bits
-            padding_len = size - acc_end
+            # If there's a gap before the chunk, pad it out with zeroes
+            padding_len = chunk.base_addr - acc_end
             if padding_len:
-                acc.words += [random.getrandbits(32)
-                              for _ in range(padding_len)]
+                acc.words += [0 for _ in range(padding_len)]
 
-            assert acc.next_addr() == size
+            assert acc.next_addr() == chunk.base_addr
+            acc.words += chunk.words
 
-            return MemFile(self.width, [acc])
-        finally:
-            random.setstate(old_rnd_state)
+        acc_end = acc.next_addr()
+        assert acc_end == self.next_addr()
+
+        # If there's a gap after the last chunk, pad it out with zeroes
+        padding_len = size - acc_end
+        if padding_len:
+            acc.words += [0 for _ in range(padding_len)]
+
+        assert acc.next_addr() == size
+
+        return MemFile(self.width, [acc])
 
     def add_ecc32(self) -> None:
         '''Add ECC32 integrity bits
diff --git a/hw/ip/rom_ctrl/util/scramble_image.py b/hw/ip/rom_ctrl/util/scramble_image.py
index 917c687..fd5c8c6 100755
--- a/hw/ip/rom_ctrl/util/scramble_image.py
+++ b/hw/ip/rom_ctrl/util/scramble_image.py
@@ -358,9 +358,8 @@
         '''
         digest_size_words = 8
         initial_len = self.rom_size_words - digest_size_words
-        seed = self.key + self.nonce
 
-        flattened = mem.flatten(initial_len, seed)
+        flattened = mem.flatten(initial_len)
         assert len(flattened.chunks) == 1
         assert len(flattened.chunks[0].words) == initial_len