Write init files that respect CPU's endianness.
authorSergiusz Bazanski <q3k@q3k.org>
Mon, 22 Jan 2018 18:19:40 +0000 (18:19 +0000)
committerSergiusz Bazanski <q3k@q3k.org>
Mon, 22 Jan 2018 18:50:26 +0000 (18:50 +0000)
This is required for PicoRV32 support. We also drive-by enable
explicit specification of run= in Builder.build() by callers.

litex/soc/integration/builder.py

index 3cfe1ab292e719cc9d62b06f16bc03ae6507aaaa..066c847a1d2439188c060225b4aab3f3a94a1530 100644 (file)
@@ -130,13 +130,17 @@ class Builder:
     def _initialize_rom(self):
         bios_file = os.path.join(self.output_dir, "software", "bios",
                                  "bios.bin")
+        endianness =  cpu_interface.cpu_endianness[self.soc.cpu_type]
         with open(bios_file, "rb") as boot_file:
             boot_data = []
             while True:
                 w = boot_file.read(4)
                 if not w:
                     break
-                boot_data.append(struct.unpack(">I", w)[0])
+                if endianness == 'little':
+                    boot_data.append(struct.unpack("<I", w)[0])
+                else:
+                    boot_data.append(struct.unpack(">I", w)[0])
         self.soc.initialize_rom(boot_data)
 
     def build(self, toolchain_path=None, **kwargs):
@@ -157,9 +161,11 @@ class Builder:
 
         if self.gateware_toolchain_path is not None:
             toolchain_path = self.gateware_toolchain_path
+
+        if 'run' not in kwargs:
+            kwargs['run'] = self.compile_gateware
         vns = self.soc.build(build_dir=os.path.join(self.output_dir, "gateware"),
-                             run=self.compile_gateware, toolchain_path=toolchain_path,
-                             **kwargs)
+                             toolchain_path=toolchain_path, **kwargs)
         return vns