aboutsummaryrefslogtreecommitdiff
path: root/src/bootloader/make_initrd.c
diff options
context:
space:
mode:
authorMarvin Borner2019-10-31 17:47:40 +0100
committerGitHub2019-10-31 17:47:40 +0100
commitc7e755cb843593db1eedb26c5c24932bbe743745 (patch)
treead14da17e6d0d883e68cc6eacc99ae522036dda8 /src/bootloader/make_initrd.c
parentfd4f0a11126a20e75d72f8f2e6d418598fd5f37d (diff)
parent40a214f3c69a3d7da8c2f9bed5038dfa0ab72d4b (diff)
Merged pull request usermode
Added usermode
Diffstat (limited to 'src/bootloader/make_initrd.c')
-rw-r--r--src/bootloader/make_initrd.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/bootloader/make_initrd.c b/src/bootloader/make_initrd.c
new file mode 100644
index 0000000..d7e0487
--- /dev/null
+++ b/src/bootloader/make_initrd.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+
+struct initrd_header {
+ unsigned char magic;
+ char name[64];
+ unsigned int offset;
+ unsigned int length;
+};
+
+int main(char argc, char **argv) {
+ int nheaders = (argc - 1) / 2;
+ struct initrd_header headers[64];
+ printf("size of header: %d\n", sizeof(struct initrd_header));
+ unsigned int off = sizeof(struct initrd_header) * 64 + sizeof(int);
+
+ for (int i = 0; i < nheaders; i++) {
+ printf("writing file %s->%s at 0x%x\n", argv[i * 2 + 1], argv[i * 2 + 2], off);
+ strcpy(headers[i].name, argv[i * 2 + 2]);
+ headers[i].name[strlen(argv[i * 2 + 2])] = '\0';
+ headers[i].offset = off;
+ FILE *stream = fopen(argv[i * 2 + 1], "r");
+ if (stream == 0) {
+ printf("Error: file not found: %s\n", argv[i * 2 + 1]);
+ return 1;
+ }
+ fseek(stream, 0, SEEK_END);
+ headers[i].length = ftell(stream);
+ off += headers[i].length;
+ fclose(stream);
+ headers[i].magic = 0xBF;
+ }
+
+ printf(headers[1].name);
+
+ FILE *wstream = fopen("./initrd.img", "w");
+ unsigned char *data = (unsigned char *) malloc(off);
+ fwrite(&nheaders, sizeof(int), 1, wstream);
+ fwrite(headers, sizeof(struct initrd_header), 64, wstream);
+
+ for (int i = 0; i < nheaders; i++) {
+ FILE *stream = fopen(argv[i * 2 + 1], "r");
+ unsigned char *buf = (unsigned char *) malloc(headers[i].length);
+ fread(buf, 1, headers[i].length, stream);
+ fwrite(buf, 1, headers[i].length, wstream);
+ fclose(stream);
+ free(buf);
+ }
+
+ fclose(wstream);
+ free(data);
+
+ return 0;
+}