ARM: imx: ddr: Add missing PHY reset
[oweals/u-boot.git] / tools / prelink-riscv.c
index 632d2da6baae65ec891957f1995d4383ebb4db9e..b0467949ebe3f19feae0140ccda8d3283bf6fed8 100644 (file)
@@ -1,18 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2017 Andes Technology
  * Chih-Mao Chen <cmchen@andestech.com>
  *
- * SPDX-License-Identifier:     GPL-2.0+
- *
  * Statically process runtime relocations on RISC-V ELF images
  * so that it can be directly executed when loaded at LMA
  * without fixup. Both RV32 and RV64 are supported.
  */
 
-#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
-#error "Only little-endian host is supported"
-#endif
-
 #include <errno.h>
 #include <stdbool.h>
 #include <stdint.h>
@@ -26,6 +21,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <compiler.h>
 
 #ifndef EM_RISCV
 #define EM_RISCV 243
@@ -51,12 +47,28 @@ const char *argv0;
                exit(EXIT_FAILURE); \
        } while (0)
 
+#define PRELINK_BYTEORDER le
 #define PRELINK_INC_BITS 32
 #include "prelink-riscv.inc"
+#undef PRELINK_BYTEORDER
 #undef PRELINK_INC_BITS
 
+#define PRELINK_BYTEORDER le
 #define PRELINK_INC_BITS 64
 #include "prelink-riscv.inc"
+#undef PRELINK_BYTEORDER
+#undef PRELINK_INC_BITS
+
+#define PRELINK_BYTEORDER be
+#define PRELINK_INC_BITS 32
+#include "prelink-riscv.inc"
+#undef PRELINK_BYTEORDER
+#undef PRELINK_INC_BITS
+
+#define PRELINK_BYTEORDER be
+#define PRELINK_INC_BITS 64
+#include "prelink-riscv.inc"
+#undef PRELINK_BYTEORDER
 #undef PRELINK_INC_BITS
 
 int main(int argc, const char *const *argv)
@@ -92,11 +104,19 @@ int main(int argc, const char *const *argv)
                die("Invalid ELF file %s", argv[1]);
 
        bool is64 = e_ident[EI_CLASS] == ELFCLASS64;
-
-       if (is64)
-               prelink64(data);
-       else
-               prelink32(data);
+       bool isbe = e_ident[EI_DATA] == ELFDATA2MSB;
+
+       if (is64) {
+               if (isbe)
+                       prelink_be64(data);
+               else
+                       prelink_le64(data);
+       } else {
+               if (isbe)
+                       prelink_be32(data);
+               else
+                       prelink_le32(data);
+       }
 
        return 0;
 }