Open josch opened 3 weeks ago
I guess this would be fixed by #329 ?
Thank you! In the mean-time I had this patch cooked up:
--- a/tools/elf2uf2/main.cpp 2023-06-13 22:27:33.000000000 +0000
+++ b/tools/elf2uf2/main.cpp 2024-06-05 08:20:56.156138030 +0000
@@ -11,6 +11,7 @@
#include <cstring>
#include <cstdarg>
#include <algorithm>
+#include <endian.h>
#include "boot/uf2.h"
#include "elf.h"
@@ -101,6 +103,20 @@
if (1 != fread(&eh_out, sizeof(eh_out), 1, in)) {
return fail(ERROR_READ_FAILED, "Unable to read ELF header");
}
+ eh_out.common.magic = le32toh(eh_out.common.magic);
+ eh_out.common.type = le16toh(eh_out.common.type);
+ eh_out.common.machine = le16toh(eh_out.common.machine);
+ eh_out.common.version2 = le32toh(eh_out.common.version2);
+ eh_out.entry = le32toh(eh_out.entry);
+ eh_out.ph_offset = le32toh(eh_out.ph_offset);
+ eh_out.sh_offset = le32toh(eh_out.sh_offset);
+ eh_out.flags = le32toh(eh_out.flags);
+ eh_out.eh_size = le16toh(eh_out.eh_size);
+ eh_out.ph_entry_size = le16toh(eh_out.ph_entry_size);
+ eh_out.ph_num = le16toh(eh_out.ph_num);
+ eh_out.sh_entry_size = le16toh(eh_out.sh_entry_size);
+ eh_out.sh_num = le16toh(eh_out.sh_num);
+ eh_out.sh_str_index = le16toh(eh_out.sh_str_index);
if (eh_out.common.magic != ELF_MAGIC) {
return fail(ERROR_FORMAT, "Not an ELF file");
}
@@ -154,6 +175,16 @@
if (eh.ph_num != fread(&entries[0], sizeof(struct elf32_ph_entry), eh.ph_num, in)) {
return fail_read_error();
}
+ for (int i = 0; i < eh.ph_num; i++) {
+ entries[i].type = le32toh(entries[i].type);
+ entries[i].offset = le32toh(entries[i].offset);
+ entries[i].vaddr = le32toh(entries[i].vaddr);
+ entries[i].paddr = le32toh(entries[i].paddr);
+ entries[i].filez = le32toh(entries[i].filez);
+ entries[i].memsz = le32toh(entries[i].memsz);
+ entries[i].flags = le32toh(entries[i].flags);
+ entries[i].align = le32toh(entries[i].align);
+ }
}
return 0;
}
I also rebased the patch from #329 onto my local pico-sdk version and:
[100%] Linking CXX executable hello_world.elf
[100%] Built target hello_world
It works fine, thank you!
Hi,
I have this
CMakeLists.txt
:and this hello-world program (yes this program is not even making use of the pico sdk but the problem is also there if we add that):
On s390x the build will fail like this:
I added some printfs into
tools/elf2uf2/main.cpp
to investigate the values ofELF_MAGIC
andeh_out.common.magic
inread_and_check_elf32_header
and got this:There seems to be an endian problem somewhere? The
file
utility seems to think that myhello_world.elf
has the correct magic:Any ideas?