From a17d1cf43eef7c9e29ad2b89cc2e526664940f5d Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 17 Feb 2008 13:45:47 +0000 Subject: [PATCH] axeld + bonefish: Added parameter --start-offset to allow writing the boot code not only at the beginning of the given file. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23971 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../platform/bios_ia32/makebootable.cpp | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/bin/makebootable/platform/bios_ia32/makebootable.cpp b/src/bin/makebootable/platform/bios_ia32/makebootable.cpp index c206d5e6a0..efd2244061 100644 --- a/src/bin/makebootable/platform/bios_ia32/makebootable.cpp +++ b/src/bin/makebootable/platform/bios_ia32/makebootable.cpp @@ -161,15 +161,12 @@ read_boot_code_data(const char* programPath) // write_boot_code_part static void -write_boot_code_part(const char *fileName, int fd, const uint8 *bootCodeData, - int offset, int size, bool dryRun) +write_boot_code_part(const char *fileName, int fd, off_t imageOffset, + const uint8 *bootCodeData, int offset, int size, bool dryRun) { - printf("writing %d bytes at offset %d%s\n", size, offset, - (dryRun ? " (dry run)" : "")); - if (!dryRun) { - ssize_t bytesWritten = write_pos(fd, offset, bootCodeData + offset, - size); + ssize_t bytesWritten = write_pos(fd, imageOffset + offset, + bootCodeData + offset, size); if (bytesWritten != size) { fprintf(stderr, "Error: Failed to write to \"%s\": %s\n", fileName, strerror(bytesWritten < 0 ? errno : B_ERROR)); @@ -192,6 +189,7 @@ main(int argc, const char *const *argv) const char **files = new const char*[argc]; int fileCount = 0; bool dryRun = false; + off_t startOffset = 0; // parse arguments for (int argi = 1; argi < argc;) { @@ -206,6 +204,10 @@ main(int argc, const char *const *argv) // ignore } else if (strcmp(arg, "-full") == 0) { // ignore + } else if (strcmp(arg, "--start-offset") == 0) { + if (argi >= argc) + print_usage_and_exit(true); + startOffset = strtoll(argv[argi++], NULL, 0); } else if (strcmp(arg, "-safe") == 0) { fprintf(stderr, "Error: Sorry, BeOS R3 isn't supported!\n"); exit(1); @@ -498,10 +500,11 @@ main(int argc, const char *const *argv) printf("Writing boot code to \"%s\" (partition offset: %lld bytes) " "...\n", fileName, partitionOffset); - write_boot_code_part(fileName, fd, bootCodeData, 0, + write_boot_code_part(fileName, fd, startOffset, bootCodeData, 0, kFirstBootCodePartSize, dryRun); - write_boot_code_part(fileName, fd, bootCodeData, - kSecondBootcodePartOffset, kSecondBootcodePartSize, dryRun); + write_boot_code_part(fileName, fd, startOffset, bootCodeData, + kSecondBootcodePartOffset, kSecondBootcodePartSize, + dryRun); close(fd); }