gnomeos: Starting to get something bootable with yocto

This commit is contained in:
Colin Walters 2011-11-15 10:44:03 -05:00
parent 18f0b537a4
commit 5b70db8d60
8 changed files with 279 additions and 26 deletions

View File

@ -0,0 +1,32 @@
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
#
set -e
set -x
if test $(id -u) = 0; then
cat <<EOF
This script should not be run as root.
EOF
exit 1
fi
usage () {
echo "$0 OSTREE_REPO_PATH BINARY_TAR"
exit 1
}
OSTREE_REPO=$1
test -n "$OSTREE_REPO" || usage
shift
BUILD_TAR=$1
test -n "$BUILD_TAR" || usage
shift
tempdir=`mktemp -d tmp-commit-yocto-build.XXXXXXXXXX`
cd $tempdir
mkdir fs
cd fs
fakeroot -s ../fakeroot.db tar xf $BUILD_TAR
fakeroot -i ../fakeroot.db ostree --repo=${OSTREE_REPO} commit -s "Build (need ostree git version here)" -b gnomeos-base
rm -rf $tempdir

88
gnomeos/yocto/gnomeos-run.sh Executable file
View File

@ -0,0 +1,88 @@
#!/bin/sh
# -*- indent-tabs-mode: nil; -*-
# Run built image in QEMU
#
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
set -e
set -x
SRCDIR=`dirname $0`
WORKDIR=`pwd`
if test $(id -u) != 0; then
cat <<EOF
This script should be run as root.
EOF
exit 1
fi
usage () {
echo "$0 OSTREE_REPO_PATH"
exit 1
}
OSTREE_REPO=$1
shift
test -n "$OSTREE_REPO" || usage
OBJ=gnomeos-fs.img
if (! test -f ${OBJ}); then
rm -f ${OBJ}.tmp
qemu-img create ${OBJ}.tmp 2G
mkfs.ext3 -q -F ${OBJ}.tmp
mkdir -p fs
umount fs || true
mount -o loop ${OBJ}.tmp fs
cd fs
TOPROOT_BIND_MOUNTS="home root tmp"
for d in $TOPROOT_BIND_MOUNTS; do
mkdir -m 0755 $d
done
chmod a=rwxt tmp
mkdir ostree
mkdir -p -m 0755 ./ostree/var/{log,run,tmp,spool}
cd ostree
mkdir repo
rev=$(ostree --repo=${OSTREE_REPO} rev-parse gnomeos-base);
ostree --repo=${OSTREE_REPO} checkout ${rev} gnomeos-base-${rev}
ln -s gnomeos-base-${rev} current
cd ..
mkdir proc # needed for ostree-init
cp -a ./ostree/current/usr/sbin/ostree-init .
cd ${WORKDIR}
umount fs
mv ${OBJ}.tmp ${OBJ}
fi
ARGS="$@"
if ! [ echo $ARGS | grep -q 'init=']; then
ARGS="init=/ostree-init $ARGS"
fi
if ! [ echo $ARGS | grep -q 'root=']; then
ARGS="root=/dev/hda $ARGS"
fi
exec qemu-kvm -kernel ./tmp/deploy/images/bzImage-qemux86.bin -hda gnomeos-fs.img -append "$ARGS"

View File

@ -0,0 +1,17 @@
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
#
set -e
set -x
if test $(id -u) = 0; then
cat <<EOF
This script should not be run as root.
EOF
exit 1
fi
mkdir gnomeos-fs
cd gnomeos-fs

View File

@ -0,0 +1,11 @@
LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://COPYING-DOCS;md5=18ba770020b624031bc7c8a7b055d776"
DEPENDS = "perl-native"
SRC_URI = "git://git.gnome.org/gtk-doc;tag=GTK_DOC_1_18"
S = "${WORKDIR}/git"
inherit autotools gettext
BBCLASSEXTEND = "native"

View File

@ -0,0 +1,80 @@
#
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
#
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58 \
file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
inherit rootfs_${IMAGE_PKGTYPE}
PACKAGE_INSTALL = "task-core-boot task-base-extended \
ostree ostree-init"
RDEPENDS += "${PACKAGE_INSTALL}"
DEPENDS += "virtual/fakeroot-native"
EXCLUDE_FROM_WORLD = "1"
do_rootfs[nostamp] = "1"
do_rootfs[dirs] = "${TOPDIR}"
do_rootfs[lockfiles] += "${IMAGE_ROOTFS}.lock"
do_build[nostamp] = "1"
do_rootfs[umask] = 022
# Must call real_do_rootfs() from inside here, rather than as a separate
# task, so that we have a single fakeroot context for the whole process.
fakeroot do_rootfs () {
set -x
rm -rf ${IMAGE_ROOTFS}
rm -rf ${MULTILIB_TEMP_ROOTFS}
mkdir -p ${IMAGE_ROOTFS}
mkdir -p ${DEPLOY_DIR_IMAGE}
rootfs_${IMAGE_PKGTYPE}_do_rootfs
echo "GNOME OS Unix login" > ${IMAGE_ROOTFS}/etc/issue
TOPROOT_BIND_MOUNTS="home root tmp"
OSTREE_BIND_MOUNTS="var"
OSDIRS="dev proc mnt media sys sysroot"
READONLY_BIND_MOUNTS="bin etc lib sbin usr"
rm -rf ${WORKDIR}/gnomeos-contents
mkdir ${WORKDIR}/gnomeos-contents
cd ${WORKDIR}/gnomeos-contents
for d in $TOPROOT_BIND_MOUNTS $OSTREE_BIND_MOUNTS $OSDIRS; do
mkdir $d
done
chmod a=rwxt tmp
for d in $READONLY_BIND_MOUNTS; do
mv ${IMAGE_ROOTFS}/$d .
done
rm -rf ${IMAGE_ROOTFS}
mv ${WORKDIR}/gnomeos-contents ${IMAGE_ROOTFS}
DEST=${IMAGE_NAME}.rootfs.tar.gz
(cd ${IMAGE_ROOTFS} && tar -zcv -f ${WORKDIR}/$DEST .)
echo "Created $DEST"
mv ${WORKDIR}/$DEST ${DEPLOY_DIR_IMAGE}/
cd ${DEPLOY_DIR_IMAGE}/
rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.tar.gz
ln -s ${IMAGE_NAME}.rootfs.tar.gz ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.tar.gz
echo "Created ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.tar.gz"
}
log_check() {
true
}
do_fetch[noexec] = "1"
do_unpack[noexec] = "1"
do_patch[noexec] = "1"
do_configure[noexec] = "1"
do_compile[noexec] = "1"
do_install[noexec] = "1"
do_populate_sysroot[noexec] = "1"
do_package[noexec] = "1"
do_package_write_ipk[noexec] = "1"
do_package_write_deb[noexec] = "1"
do_package_write_rpm[noexec] = "1"
addtask rootfs before do_build

View File

@ -1,19 +0,0 @@
#
# Copyright (C) 2011 Red Hat, Inc.
#
IMAGE_LINGUAS = " "
LICENSE = "LGPL2"
inherit core-image
IMAGE_INSTALL += "ostree-init"
# remove not needed ipkg informations
ROOTFS_POSTPROCESS_COMMAND += "remove_packaging_data_files ; "
gnomeos_rootfs_postinst() {
echo "GNOME OS Unix login" > ${IMAGE_ROOTFS}/etc/issue
}
ROOTFS_POSTPROCESS_COMMAND += " gnomeos_rootfs_postinst ; "

View File

@ -62,7 +62,7 @@ perrorv (const char *format, ...)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
FILE *cmdline_f = NULL; FILE *cmdline_f = NULL;
const char *ostree_root = NULL; char *ostree_root = NULL;
const char *p = NULL; const char *p = NULL;
size_t bytes_read; size_t bytes_read;
size_t buf_size; size_t buf_size;
@ -72,12 +72,23 @@ int main(int argc, char *argv[])
struct stat stbuf; struct stat stbuf;
char **init_argv = NULL; char **init_argv = NULL;
int i; int i;
int mounted_proc = 0;
cmdline_f = fopen ("/proc/cmdline", "r"); cmdline_f = fopen ("/proc/cmdline", "r");
if (!cmdline_f) if (!cmdline_f)
{ {
perrorv ("Failed to open /proc/cmdline"); if (mount ("procs", "/proc", "proc", 0, NULL) < 0)
return 1; {
perrorv ("Failed to mount /proc");
return 1;
}
mounted_proc = 1;
cmdline_f = fopen ("/proc/cmdline", "r");
if (!cmdline_f)
{
perrorv ("Failed to open /proc/cmdline (after mounting)");
return 1;
}
} }
buf_size = 8; buf_size = 8;
@ -101,13 +112,22 @@ int main(int argc, char *argv[])
exit (1); exit (1);
} }
for (p = buf; *p; p += strlen (p) + 1) p = buf;
while (p != NULL)
{ {
if (!strcmp (p, "ostree=")) if (!strncmp (p, "ostree=", strlen ("ostree=")))
{ {
ostree_root = p + strlen ("ostree="); const char *start = p + strlen ("ostree=");
const char *end = strchr (start, ' ');
if (end)
ostree_root = strndup (start, end - start);
else
ostree_root = strdup (start);
break; break;
} }
p = strchr (p, ' ');
if (p)
p += 1;
} }
if (ostree_root) if (ostree_root)
@ -119,6 +139,13 @@ int main(int argc, char *argv[])
exit (1); exit (1);
} }
snprintf (destpath, sizeof(destpath), "/ostree/%s/var", ostree_root);
if (mount ("/ostree/var", destpath, NULL, MS_BIND, NULL) < 0)
{
perrorv ("Failed to bind mount /ostree/var to '%s'", destpath);
exit (1);
}
snprintf (destpath, sizeof(destpath), "/ostree/%s/sysroot", ostree_root); snprintf (destpath, sizeof(destpath), "/ostree/%s/sysroot", ostree_root);
if (mount ("/", destpath, NULL, MS_BIND, NULL) < 0) if (mount ("/", destpath, NULL, MS_BIND, NULL) < 0)
{ {
@ -138,7 +165,6 @@ int main(int argc, char *argv[])
perrorv ("failed to chdir to subroot"); perrorv ("failed to chdir to subroot");
exit (1); exit (1);
} }
} }
else else
{ {
@ -146,12 +172,17 @@ int main(int argc, char *argv[])
exit (1); exit (1);
} }
if (mounted_proc)
(void)umount ("/proc");
init_argv = malloc (sizeof (char*)*(argc+1)); init_argv = malloc (sizeof (char*)*(argc+1));
init_argv[0] = INIT_PATH; init_argv[0] = INIT_PATH;
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
init_argv[i] = argv[i]; init_argv[i] = argv[i];
init_argv[i] = NULL; init_argv[i] = NULL;
fprintf (stderr, "ostree-init: Running real init\n");
fflush (stderr);
execv (INIT_PATH, init_argv); execv (INIT_PATH, init_argv);
perrorv ("Failed to exec init '%s'", INIT_PATH); perrorv ("Failed to exec init '%s'", INIT_PATH);
exit (1); exit (1);

View File

@ -0,0 +1,13 @@
SUMMARY = "GNOME OS management tool"
LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://COPYING;md5=97285cb818cf231e6a36f72c82592235"
SRC_URI = "git://git.gnome.org/ostree;tag=18f0b537a45f12852e4ec6b174440cbfe7702e4d"
S = "${WORKDIR}/git"
inherit autotools
EXTRA_OECONF = "--without-soup-gnome"
BBCLASSEXTEND = "native"