[oe-commits] org.oe.dreambox dreambox-boottool: add package and sources
tmbinc commit
openembedded-commits at lists.openembedded.org
Thu Jun 28 03:16:59 UTC 2007
dreambox-boottool: add package and sources
Author: tmbinc at openembedded.org
Branch: org.openembedded.dreambox
Revision: 5d589ee67deadcf39eda5e1e3f72acbb593b9e71
ViewMTN: http://monotone.openembedded.org/revision.psp?id=5d589ee67deadcf39eda5e1e3f72acbb593b9e71
Files:
1
packages/dreambox/dreambox-boottool
packages/dreambox/dreambox-boottool/boottool-dm7025.c
packages/dreambox/dreambox-boottool.bb
Diffs:
#
# mt diff -re958d33e10109778a485ec8e7a29afb86a44b424 -r5d589ee67deadcf39eda5e1e3f72acbb593b9e71
#
#
#
# add_dir "packages/dreambox/dreambox-boottool"
#
# add_file "packages/dreambox/dreambox-boottool/boottool-dm7025.c"
# content [88c0256895e89fb173c2b4af80a1e5b883feecaf]
#
# add_file "packages/dreambox/dreambox-boottool.bb"
# content [4d9403f3ccead849401848aec98b861f3d842354]
#
============================================================
--- packages/dreambox/dreambox-boottool/boottool-dm7025.c 88c0256895e89fb173c2b4af80a1e5b883feecaf
+++ packages/dreambox/dreambox-boottool/boottool-dm7025.c 88c0256895e89fb173c2b4af80a1e5b883feecaf
@@ -0,0 +1,206 @@
+#include <sys/mount.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <linux/loop.h>
+#include <dirent.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define PREFIX
+//#define PREFIX "/boot"
+#define SQUASHFS_FILENAME PREFIX"/flash/squashfs"
+
+#define streq(a,b) (strcmp((a),(b)) == 0)
+
+/* This really needs to be in a header file... */
+extern long init_module(void *, unsigned long, const char *);
+
+/* We use error numbers in a loose translation... */
+static const char *moderror(int err)
+{
+ switch (err) {
+ case ENOEXEC:
+ return "Invalid module format";
+ case ENOENT:
+ return "Unknown symbol in module";
+ case ESRCH:
+ return "Module has wrong symbol version";
+ case EINVAL:
+ return "Invalid parameters";
+ default:
+ return strerror(err);
+ }
+}
+
+static void *grab_file(const char *filename, unsigned long *size)
+{
+ unsigned int max = 16384;
+ int ret, fd;
+ void *buffer = malloc(max);
+
+ if (streq(filename, "-"))
+ fd = dup(STDIN_FILENO);
+ else
+ fd = open(filename, O_RDONLY, 0);
+
+ if (fd < 0)
+ return NULL;
+
+ *size = 0;
+ while ((ret = read(fd, buffer + *size, max - *size)) > 0) {
+ *size += ret;
+ if (*size == max)
+ buffer = realloc(buffer, max *= 2);
+ }
+ if (ret < 0) {
+ free(buffer);
+ buffer = NULL;
+ }
+ close(fd);
+ return buffer;
+}
+
+
+int insmod(const char *filename)
+{
+ void *file;
+ unsigned long len;
+ long int ret;
+
+
+ file = grab_file(filename, &len);
+ if (!file) {
+ fprintf(stderr, "insmod: can't read '%s': %s\n",
+ filename, strerror(errno));
+ return 1;
+ }
+
+ ret = init_module(file, len, "");
+ if (ret != 0) {
+ fprintf(stderr, "insmod: error inserting '%s': %li %s\n",
+ filename, ret, moderror(errno));
+ return 1;
+ }
+ return 0;
+}
+
+int main(int argc, char *argv[], char *envp[])
+{
+ int res, x;
+
+ printf("Hello world!\n");
+
+ /* first, load some needed kernel modules located in the root of our boot partition */
+ const char *modules[] = { "fs/squashfs/unlzma.ko", "fs/squashfs/sqlzma.ko", "fs/squashfs/squashfs.ko", "fs/unionfs.ko", "drivers/block/loop.ko", 0 };
+ const char *modules_path = PREFIX"/lib/modules/2.6.12.6/kernel/";
+ char path[255];
+
+ x=0;
+ while(modules[x]) {
+ strcpy(path, modules_path);
+ strcat(path, modules[x++]);
+ printf("insmodding %s..\n", path);
+ if (insmod(path))
+ return 1;
+ }
+
+ /* mount the RW jffs2 partition, which contains the squashfs image (in /squashfs) and the deltas (in /delta) */
+ printf("mounting mtd...\n");
+ res = mount("/dev/mtdblock/3", PREFIX"/flash", "jffs2", 0, 0);
+
+ if (res)
+ {
+ perror("mounting /flash");
+ return res;
+ }
+
+ /* loop-mount the squashfs, by first connecting the file to loop0 ... */
+ printf("opening squashfs...\n");
+ int squashfs_fd = open(SQUASHFS_FILENAME, O_RDONLY);
+ if (squashfs_fd < 0)
+ {
+ perror(SQUASHFS_FILENAME);
+ return 1;
+ }
+
+ printf("setup loop\n");
+ int loop_fd = open("/dev/loop/0", O_RDONLY);
+
+ if (loop_fd < 0)
+ {
+ perror("/dev/loop/0");
+ return 1;
+ }
+
+ struct loop_info loopinfo;
+
+ memset(&loopinfo, 0, sizeof(loopinfo));
+ strncpy(loopinfo.lo_name, SQUASHFS_FILENAME, LO_NAME_SIZE);
+ loopinfo.lo_offset = 0;
+ loopinfo.lo_encrypt_key_size = 0;
+ if (ioctl(loop_fd, LOOP_SET_FD, (void*)squashfs_fd) < 0) {
+ perror("LOOP_SET_FD");
+ return 1;
+ }
+ if (ioctl(loop_fd, LOOP_SET_STATUS, &loopinfo) < 0) {
+ perror("LOOP_SET_STATUS");
+ return 1;
+ }
+ close(loop_fd);
+ close(squashfs_fd);
+
+ printf("mounting squashfs..\n");
+
+ /* and then mounting the loop device. */
+ if (mount("/dev/loop/0", PREFIX"/squashfs", "squashfs", MS_MGC_VAL|MS_RDONLY, "") < 0)
+ {
+ perror("mounting squashfs");
+ return 1;
+ }
+
+ /* now the situation is:
+
+ / - our boot jffs2 partition
+ /flash - our RW jffs2 partition
+ /flash/squashfs - our loop-mounted squashfs file,
+ /flash/delta - the delta for the root
+ /squashfs - RO root
+ /root - yet empty, but we will populate it using unionfs
+ */
+
+
+ printf("mounting unionfs..\n");
+ res = mount("none", PREFIX"/root", "unionfs", MS_MGC_VAL, "dirs="PREFIX"/flash/delta=rw:"PREFIX"/squashfs=ro");
+ if (res < 0)
+ {
+ perror("mounting unionfs");
+ return 1;
+ }
+
+ printf("chroot\n");
+ if (chroot(PREFIX"/root") < 0)
+ {
+ perror("chroot");
+ return 1;
+ }
+
+ printf("mouting devfs..\n");
+ res = mount("none", "/dev", "devfs", 0, 0);
+ if (res)
+ {
+ perror("mounting /dev");
+ return res;
+ }
+
+ printf("call init!\n");
+
+ sleep(1);
+
+ execve("/sbin/init", argv, envp);
+ perror("/sbin/init");
+
+ return 1;
+}
============================================================
--- packages/dreambox/dreambox-boottool.bb 4d9403f3ccead849401848aec98b861f3d842354
+++ packages/dreambox/dreambox-boottool.bb 4d9403f3ccead849401848aec98b861f3d842354
@@ -0,0 +1,26 @@
+DESCRIPTION = "Squashfs jffs2 unionfs mount tool"
+SECTION = "base"
+PRIORITY = "required"
+LICENSE = "proprietary"
+MAINTAINER = "Felix Domke <tmbinc at elitedvb.net>"
+
+PV = "1.0"
+PR = "r0"
+DEPENDS = "klibc"
+
+SRC_URI = "file://boottool-${MACHINE}.c"
+
+S = "${WORKDIR}/"
+
+do_install_append() {
+ install -d ${D}/boot
+ install ${S}/boottool ${D}/boot/boottool
+}
+
+do_compile_append() {
+ ${STAGING_BINDIR}/${TARGET_ARCH}-linux-klcc ${S}/boottool-${MACHINE}.c -o ${S}/boottool
+ ${STRIP} --remove-section=.comment --remove-section=.note --strip-unneeded ${S}/boottool
+}
+
+PACKAGE_ARCH := "${MACHINE_ARCH}"
+FILES_${PN} = "/boot/boottool"
More information about the Openembedded-commits
mailing list