aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2015-03-02 21:37:09 -0500
committerFranklin Wei <frankhwei536@gmail.com>2015-03-02 21:37:09 -0500
commit46e94578765d3d2f03b83421d752e5dfc3e56d34 (patch)
tree0a7d4187e8e62e1fccdf0dc8ee89e4ffcdf7aac7 /tools
parent35d98182c5b86c25eb4e7fd18fc68f240683960b (diff)
downloadkappa-46e94578765d3d2f03b83421d752e5dfc3e56d34.zip
kappa-46e94578765d3d2f03b83421d752e5dfc3e56d34.tar.gz
kappa-46e94578765d3d2f03b83421d752e5dfc3e56d34.tar.bz2
kappa-46e94578765d3d2f03b83421d752e5dfc3e56d34.tar.xz
initrd support, not used yet
Diffstat (limited to 'tools')
-rw-r--r--tools/mkinitrd.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/mkinitrd.c b/tools/mkinitrd.c
new file mode 100644
index 0000000..d61bbba
--- /dev/null
+++ b/tools/mkinitrd.c
@@ -0,0 +1,34 @@
+#include <assert.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+void write_le32(int fd, uint32_t n)
+{
+ write(fd, &n, 4);
+}
+
+#define MIN(x,y) (x<y?x:y)
+
+int main(int argc, char* argv[])
+{
+ int fd = open("initrd.img", O_APPEND | O_WRONLY | O_CREAT, 0666);
+ char buf[32];
+ assert(strlen(argv[1]) < 32);
+ memset(buf, 0, 32);
+ memcpy(buf, argv[1], strlen(argv[1]));
+ write(fd, buf, 32);
+ int datafd = open(argv[1], O_RDONLY, 0666);
+ lseek(datafd, 0, SEEK_END);
+ FILE *f = fdopen(datafd, "rb");
+ uint32_t len = ftell(f);
+ write_le32(fd, ftell(f));
+ int ch;
+ lseek(datafd, 0, SEEK_SET);
+ do {
+ ch = getc(f);
+ if(ch != EOF)
+ write(fd, &ch, 1);
+ } while(ch != EOF);
+}