Rev 35 | Rev 41 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 35 | Rev 38 | ||
---|---|---|---|
Line 20... | Line 20... | ||
20 | #ifdef _MSC_VER |
20 | #ifdef _MSC_VER |
21 | #include <sys/utime.h> |
21 | #include <sys/utime.h> |
22 | #include <process.h> |
22 | #include <process.h> |
23 | #else // !_MSC_VER |
23 | #else // !_MSC_VER |
24 | #include <sys/param.h> |
24 | #include <sys/param.h> |
- | 25 | #ifndef __APPLE__ |
|
25 | #include <sys/sysmacros.h> |
26 | #include <sys/sysmacros.h> |
- | 27 | #endif // !__APPLE__ |
|
26 | #include <sys/wait.h> |
28 | #include <sys/wait.h> |
27 | #include <unistd.h> |
29 | #include <unistd.h> |
28 | #include <dirent.h> |
30 | #include <dirent.h> |
29 | #include <utime.h> |
31 | #include <utime.h> |
30 | #endif // _MSC_VER |
32 | #endif // _MSC_VER |
Line 208... | Line 210... | ||
208 | current_char_ptr = data; |
210 | current_char_ptr = data; |
209 | for (i = 0; i < data_len; i++) |
211 | for (i = 0; i < data_len; i++) |
210 | { |
212 | { |
211 | accumulator[i % 4] = *current_char_ptr; |
213 | accumulator[i % 4] = *current_char_ptr; |
212 | if (i % 4 == 3) |
214 | if (i % 4 == 3) |
- | 215 | { |
|
213 | if (is_foreign_endianness) |
216 | if (is_foreign_endianness) |
214 | image_cksum += (accumulator[3] << 0) + (accumulator[2] << 8) + (accumulator[1] << 16) + (accumulator[0] << 24); |
217 | image_cksum += (accumulator[3] << 0) + (accumulator[2] << 8) + (accumulator[1] << 16) + (accumulator[0] << 24); |
215 | else |
218 | else |
216 | image_cksum += (accumulator[0] << 0) + (accumulator[1] << 8) + (accumulator[2] << 16) + (accumulator[3] << 24); |
219 | image_cksum += (accumulator[0] << 0) + (accumulator[1] << 8) + (accumulator[2] << 16) + (accumulator[3] << 24); |
- | 220 | } |
|
217 | current_char_ptr++; |
221 | current_char_ptr++; |
218 | } |
222 | } |
219 | 223 | ||
220 | return (is_foreign_endianness ? __builtin_bswap32 (-image_cksum) : -image_cksum); |
224 | return (is_foreign_endianness ? __builtin_bswap32 (-image_cksum) : -image_cksum); |
221 | } |
225 | } |
Line 868... | Line 872... | ||
868 | } |
872 | } |
869 | else if (buildhost_pathname != NULL) // else was a source file pathname supplied ? |
873 | else if (buildhost_pathname != NULL) // else was a source file pathname supplied ? |
870 | { |
874 | { |
871 | entry_parms->data.bytes = malloc (MAXPATHLEN); // allocate enough space for symlink data |
875 | entry_parms->data.bytes = malloc (MAXPATHLEN); // allocate enough space for symlink data |
872 | ASSERT_WITH_ERRNO (entry_parms->data.bytes); |
876 | ASSERT_WITH_ERRNO (entry_parms->data.bytes); |
873 | retval = readlink (buildhost_pathname, entry_parms->data.bytes, MAXPATHLEN); // read symlink contents |
877 | retval = readlink (buildhost_pathname, (char *) entry_parms->data.bytes, MAXPATHLEN); // read symlink contents |
874 | ASSERT_WITH_ERRNO (retval > 0); |
878 | ASSERT_WITH_ERRNO (retval > 0); |
875 | entry_parms->data.size = retval; // save symlink target length |
879 | entry_parms->data.size = retval; // save symlink target length |
876 | } |
880 | } |
877 | else |
881 | else |
878 | DIE_WITH_EXITCODE (1, "unexpected code path: can't store a symlink without neither explicit contents nor a host pathname. This is a bug in the program. Please contact the author."); |
882 | DIE_WITH_EXITCODE (1, "unexpected code path: can't store a symlink without neither explicit contents nor a host pathname. This is a bug in the program. Please contact the author."); |
879 | } |
883 | } |
880 | else if (S_ISFIFO (entry_parms->st_mode)) // else are we storing a FIFO ? |
884 | else if (S_ISFIFO (entry_parms->st_mode)) // else are we storing a FIFO ? |
881 | { |
885 | { |
882 | if ((entry_parms->data.bytes == NULL) || (strchr (entry_parms->data.bytes, ':') == NULL)) |
886 | if ((entry_parms->data.bytes == NULL) || (strchr ((char *) entry_parms->data.bytes, ':') == NULL)) |
883 | DIE_WITH_EXITCODE (1, "device entry \"%s\" malformed (no 'dev:rdev' pair)", stored_pathname); |
887 | DIE_WITH_EXITCODE (1, "device entry \"%s\" malformed (no 'dev:rdev' pair)", stored_pathname); |
884 | LOG_INFO ("fifo: ino 0x%x uid %d gid %d mode 0%o path \"%s\" dev:rdev %s)", inode_count + 1, entry_parms->uid, entry_parms->gid, entry_parms->st_mode, stored_pathname, entry_parms->data.bytes); |
888 | LOG_INFO ("fifo: ino 0x%x uid %d gid %d mode 0%o path \"%s\" dev:rdev %s)", inode_count + 1, entry_parms->uid, entry_parms->gid, entry_parms->st_mode, stored_pathname, entry_parms->data.bytes); |
885 | } |
889 | } |
886 | else // necessarily a regular file (either S_IFREG is specified, or st_mode is zero) |
890 | else // necessarily a regular file (either S_IFREG is specified, or st_mode is zero) |
887 | { |
891 | { |
Line 918... | Line 922... | ||
918 | 922 | ||
919 | // parse buffer (non-destructively) line after line |
923 | // parse buffer (non-destructively) line after line |
920 | Buffer_Initialize (¤t_line); |
924 | Buffer_Initialize (¤t_line); |
921 | for (line_index = 0; Buffer_GetNthLine (&entry_parms->data, line_index, ¤t_line); line_index++) |
925 | for (line_index = 0; Buffer_GetNthLine (&entry_parms->data, line_index, ¤t_line); line_index++) |
922 | { |
926 | { |
923 | read_ptr = current_line.bytes; |
927 | read_ptr = (char *) current_line.bytes; |
924 | while (isspace (*read_ptr)) |
928 | while (isspace (*read_ptr)) |
925 | read_ptr++; // skip leading spaces |
929 | read_ptr++; // skip leading spaces |
926 | if ((*read_ptr == '#') || (*read_ptr == 0)) |
930 | if ((*read_ptr == '#') || (*read_ptr == 0)) |
927 | continue; // skip comments and empty lines |
931 | continue; // skip comments and empty lines |
928 | 932 | ||
Line 1074... | Line 1078... | ||
1074 | static thread_local char linker_sysroot_arg[MAXPATHLEN] = ""; |
1078 | static thread_local char linker_sysroot_arg[MAXPATHLEN] = ""; |
1075 | static thread_local char linker_script_pathname_arg[MAXPATHLEN] = ""; |
1079 | static thread_local char linker_script_pathname_arg[MAXPATHLEN] = ""; |
1076 | static thread_local char procnto_buildhost_pathname[MAXPATHLEN] = ""; |
1080 | static thread_local char procnto_buildhost_pathname[MAXPATHLEN] = ""; |
1077 | static thread_local char procnto_sym_filename[MAXPATHLEN] = ""; |
1081 | static thread_local char procnto_sym_filename[MAXPATHLEN] = ""; |
1078 | buffer_t bootargs_buffer = { 0 }; |
1082 | buffer_t bootargs_buffer = { 0 }; |
1079 |
|
1083 | void *bootargs_location; |
1080 | 1084 | ||
1081 | // construct the arguments that are based on environment variables (infer QNX_HOST from QNX_TARGET) |
1085 | // construct the arguments that are based on environment variables (infer QNX_HOST from QNX_TARGET) |
1082 | #if defined(_WIN32) |
1086 | #if defined(_WIN32) |
1083 | sprintf_s (linker_pathname, sizeof (linker_pathname), "%s/../../host/win64/x86_64/usr/bin/%s-ld" /*"-2.41.0"*/ ".exe", QNX_TARGET, (strcmp (image_processor, "x86_64") == 0 ? "x86_64-pc-nto-qnx8.0.0" : "aarch64-unknown-nto-qnx8.0.0")); // Win32: note the .exe extension |
1087 | sprintf_s (linker_pathname, sizeof (linker_pathname), "%s/../../host/win64/x86_64/usr/bin/%s-ld" /*"-2.41.0"*/ ".exe", QNX_TARGET, (strcmp (image_processor, "x86_64") == 0 ? "x86_64-pc-nto-qnx8.0.0" : "aarch64-unknown-nto-qnx8.0.0")); // Win32: note the .exe extension |
1084 | #elif defined(__linux__) |
1088 | #elif defined(__linux__) |
1085 | sprintf_s (linker_pathname, sizeof (linker_pathname), "%s/../../host/linux/x86_64/usr/bin/%s-ld" /*"-2.41.0"*/, QNX_TARGET, (strcmp (image_processor, "x86_64") == 0 ? "x86_64-pc-nto-qnx8.0.0" : "aarch64-unknown-nto-qnx8.0.0")); |
1089 | sprintf_s (linker_pathname, sizeof (linker_pathname), "%s/../../host/linux/x86_64/usr/bin/%s-ld" /*"-2.41.0"*/, QNX_TARGET, (strcmp (image_processor, "x86_64") == 0 ? "x86_64-pc-nto-qnx8.0.0" : "aarch64-unknown-nto-qnx8.0.0")); |
1086 | #elif defined(__QNXNTO__) |
1090 | #elif defined(__QNXNTO__) |
1087 | sprintf_s (linker_pathname, sizeof (linker_pathname), "%s/../../host/qnx8/x86_64/usr/bin/%s-ld" /*"-2.41.0"*/, QNX_TARGET, (strcmp (image_processor, "x86_64") == 0 ? "x86_64-pc-nto-qnx8.0.0" : "aarch64-unknown-nto-qnx8.0.0")); |
1091 | sprintf_s (linker_pathname, sizeof (linker_pathname), "%s/../../host/qnx8/x86_64/usr/bin/%s-ld" /*"-2.41.0"*/, QNX_TARGET, (strcmp (image_processor, "x86_64") == 0 ? "x86_64-pc-nto-qnx8.0.0" : "aarch64-unknown-nto-qnx8.0.0")); |
- | 1092 | #elif defined(__APPLE__) // why not!? |
|
- | 1093 | sprintf_s (linker_pathname, sizeof (linker_pathname), "%s/../../host/darwin/x86_64/usr/bin/%s-ld" /*"-2.41.0"*/, QNX_TARGET, (strcmp (image_processor, "x86_64") == 0 ? "x86_64-pc-nto-qnx8.0.0" : "aarch64-unknown-nto-qnx8.0.0")); |
|
1088 | #else // wtf are you building this on? |
1094 | #else // wtf are you building this on? |
1089 | #error Please port the GNU linker x86_64-pc-nto-qnx8.0.0-ld and aarch64-unknown-nto-qnx8.0.0-ld to your host architecture first before compiling ifstool. |
1095 | #error Please port the GNU linker x86_64-pc-nto-qnx8.0.0-ld and aarch64-unknown-nto-qnx8.0.0-ld to your host architecture first before compiling ifstool. |
1090 | #endif |
1096 | #endif |
1091 | ASSERT (access (linker_pathname, 0) == 0, "host cross-linker for QNX8 \"%s\" not found", linker_pathname); |
1097 | ASSERT (access (linker_pathname, 0) == 0, "host cross-linker for QNX8 \"%s\" not found", linker_pathname); |
1092 | sprintf_s (linker_sysroot_arg, sizeof (linker_sysroot_arg), "--sysroot=%s/%s/", QNX_TARGET, image_processor); |
1098 | sprintf_s (linker_sysroot_arg, sizeof (linker_sysroot_arg), "--sysroot=%s/%s/", QNX_TARGET, image_processor); |
Line 1186... | Line 1192... | ||
1186 | 1192 | ||
1187 | // parse buffer (non-destructively) line after line |
1193 | // parse buffer (non-destructively) line after line |
1188 | Buffer_Initialize (¤t_line); |
1194 | Buffer_Initialize (¤t_line); |
1189 | for (line_index = 0; Buffer_GetNthLine (&entry_parms->data, line_index, ¤t_line); line_index++) |
1195 | for (line_index = 0; Buffer_GetNthLine (&entry_parms->data, line_index, ¤t_line); line_index++) |
1190 | { |
1196 | { |
1191 | read_ptr = current_line.bytes; |
1197 | read_ptr = (char *) current_line.bytes; |
1192 | while (isspace (*read_ptr)) |
1198 | while (isspace (*read_ptr)) |
1193 | read_ptr++; // skip leading spaces |
1199 | read_ptr++; // skip leading spaces |
1194 | if ((*read_ptr == '#') || (*read_ptr == 0)) |
1200 | if ((*read_ptr == '#') || (*read_ptr == 0)) |
1195 | continue; // skip comments and empty lines |
1201 | continue; // skip comments and empty lines |
1196 | 1202 | ||
Line 1584... | Line 1590... | ||
1584 | else if (S_ISLNK (entry_parms->st_mode)) |
1590 | else if (S_ISLNK (entry_parms->st_mode)) |
1585 | { |
1591 | { |
1586 | fsentry->u.symlink.sym_offset = (uint16_t) (strlen (stored_pathname_without_leading_slash) + 1); |
1592 | fsentry->u.symlink.sym_offset = (uint16_t) (strlen (stored_pathname_without_leading_slash) + 1); |
1587 | fsentry->u.symlink.sym_size = (uint16_t) entry_parms->data.size; |
1593 | fsentry->u.symlink.sym_size = (uint16_t) entry_parms->data.size; |
1588 | fsentry->u.symlink.path = strdup (stored_pathname_without_leading_slash); |
1594 | fsentry->u.symlink.path = strdup (stored_pathname_without_leading_slash); |
1589 | fsentry->u.symlink.contents = strdup (entry_parms->data.bytes); |
1595 | fsentry->u.symlink.contents = strdup ((const char *) entry_parms->data.bytes); |
1590 | ASSERT_WITH_ERRNO (fsentry->u.symlink.contents); |
1596 | ASSERT_WITH_ERRNO (fsentry->u.symlink.contents); |
1591 | 1597 | ||
1592 | fsentry->header.size = (uint16_t) ROUND_TO_UPPER_MULTIPLE (sizeof (fsentry->header) + sizeof (uint16_t) + sizeof (uint16_t) + (size_t) fsentry->u.symlink.sym_offset + fsentry->u.symlink.sym_size + 1, image_align); // now we can set the size |
1598 | fsentry->header.size = (uint16_t) ROUND_TO_UPPER_MULTIPLE (sizeof (fsentry->header) + sizeof (uint16_t) + sizeof (uint16_t) + (size_t) fsentry->u.symlink.sym_offset + fsentry->u.symlink.sym_size + 1, image_align); // now we can set the size |
1593 | fsentry->UNSAVED_was_data_written = true; // no data to save |
1599 | fsentry->UNSAVED_was_data_written = true; // no data to save |
1594 | } |
1600 | } |
1595 | else // necessarily a device node |
1601 | else // necessarily a device node |
1596 | { |
1602 | { |
1597 | fsentry->u.device.dev = strtol (entry_parms->data.bytes, NULL, 0); // use strtol() to parse decimal (...), hexadecimal (0x...) and octal (0...) numbers |
1603 | fsentry->u.device.dev = strtol ((const char *) entry_parms->data.bytes, NULL, 0); // use strtol() to parse decimal (...), hexadecimal (0x...) and octal (0...) numbers |
1598 | fsentry->u.device.rdev = strtol (strchr (entry_parms->data.bytes, ':') + 1, NULL, 0); // use strtol() to parse decimal (...), hexadecimal (0x...) and octal (0...) numbers |
1604 | fsentry->u.device.rdev = strtol (strchr ((const char *) entry_parms->data.bytes, ':') + 1, NULL, 0); // use strtol() to parse decimal (...), hexadecimal (0x...) and octal (0...) numbers |
1599 | fsentry->u.device.path = strdup (stored_pathname_without_leading_slash); |
1605 | fsentry->u.device.path = strdup (stored_pathname_without_leading_slash); |
1600 | 1606 | ||
1601 | fsentry->header.size = (uint16_t) ROUND_TO_UPPER_MULTIPLE (sizeof (fsentry->header) + sizeof (uint32_t) + sizeof (uint32_t) + strlen (fsentry->u.device.path), image_align); // now we can set the size |
1607 | fsentry->header.size = (uint16_t) ROUND_TO_UPPER_MULTIPLE (sizeof (fsentry->header) + sizeof (uint32_t) + sizeof (uint32_t) + strlen (fsentry->u.device.path), image_align); // now we can set the size |
1602 | fsentry->UNSAVED_was_data_written = true; // no data to save |
1608 | fsentry->UNSAVED_was_data_written = true; // no data to save |
1603 | } |
1609 | } |
Line 1612... | Line 1618... | ||
1612 | entry_parms->should_autosymlink_dylib = false; |
1618 | entry_parms->should_autosymlink_dylib = false; |
1613 | entry_parms->should_follow_symlinks = false; |
1619 | entry_parms->should_follow_symlinks = false; |
1614 | entry_parms->st_mode = S_IFLNK | 0777; // NOTE: mkifs stores symlink permissions as rwxrwxrwx ! |
1620 | entry_parms->st_mode = S_IFLNK | 0777; // NOTE: mkifs stores symlink permissions as rwxrwxrwx ! |
1615 | entry_parms->extra_ino_flags = (fsentry->header.ino & (IFS_INO_PROCESSED_ELF | IFS_INO_RUNONCE_ELF | IFS_INO_BOOTSTRAP_EXE)); // preserve target's inode flags |
1621 | entry_parms->extra_ino_flags = (fsentry->header.ino & (IFS_INO_PROCESSED_ELF | IFS_INO_RUNONCE_ELF | IFS_INO_BOOTSTRAP_EXE)); // preserve target's inode flags |
1616 | entry_parms->data.bytes = (uint8_t *) ((last_dirsep = strrchr (stored_pathname, '/')) == NULL ? stored_pathname : last_dirsep + 1); // store symlink target in dirent data |
1622 | entry_parms->data.bytes = (uint8_t *) ((last_dirsep = strrchr (stored_pathname, '/')) == NULL ? stored_pathname : last_dirsep + 1); // store symlink target in dirent data |
1617 | entry_parms->data.size = strlen (entry_parms->data.bytes); |
1623 | entry_parms->data.size = strlen ((const char *) entry_parms->data.bytes); |
1618 | add_fsentry (fsentries, fsentry_count, entry_parms, original_stored_pathname, NULL); |
1624 | add_fsentry (fsentries, fsentry_count, entry_parms, original_stored_pathname, NULL); |
1619 | entry_parms->data.bytes = old_data; // restore previous data pointer so that it can be freed normally |
1625 | entry_parms->data.bytes = old_data; // restore previous data pointer so that it can be freed normally |
1620 | } |
1626 | } |
1621 | 1627 | ||
1622 | #if 0 // DISABLED: not the right place to do that (causes duplicates) |
1628 | #if 0 // DISABLED: not the right place to do that (causes duplicates) |
Line 1688... | Line 1694... | ||
1688 | } |
1694 | } |
1689 | else if (S_ISFIFO (stat_buf.st_mode)) |
1695 | else if (S_ISFIFO (stat_buf.st_mode)) |
1690 | { |
1696 | { |
1691 | entry_parms.st_mode |= entry_parms.perms; // apply FILE default permissions |
1697 | entry_parms.st_mode |= entry_parms.perms; // apply FILE default permissions |
1692 | sprintf_s (major_minor, sizeof (major_minor), "%u:%u", (unsigned int) major (stat_buf.st_rdev), (unsigned int) minor (stat_buf.st_rdev)); |
1698 | sprintf_s (major_minor, sizeof (major_minor), "%u:%u", (unsigned int) major (stat_buf.st_rdev), (unsigned int) minor (stat_buf.st_rdev)); |
1693 | entry_parms.data.bytes = major_minor; |
1699 | entry_parms.data.bytes = (uint8_t *) major_minor; |
1694 | add_fsentry (fsentries, fsentry_count, &entry_parms, &item_pathname[start_pathname_len], NULL); // add a filesystem entry of type "FIFO" |
1700 | add_fsentry (fsentries, fsentry_count, &entry_parms, &item_pathname[start_pathname_len], NULL); // add a filesystem entry of type "FIFO" |
1695 | } |
1701 | } |
1696 | else |
1702 | else |
1697 | LOG_WARNING ("ignoring unsupported directory entry: \"%s\" (type 0%o)", item_pathname, stat_buf.st_mode & S_IFMT); |
1703 | LOG_WARNING ("ignoring unsupported directory entry: \"%s\" (type 0%o)", item_pathname, stat_buf.st_mode & S_IFMT); |
1698 | } |
1704 | } |