diff options
author | Fathi Boudra <fathi.boudra@linaro.org> | 2013-08-08 10:44:38 +0300 |
---|---|---|
committer | Fathi Boudra <fathi.boudra@linaro.org> | 2013-08-08 10:44:38 +0300 |
commit | a854bc17e2fff247974cb999a66b9edb0b6dd6c2 (patch) | |
tree | c9ccada57a81bb432cd49fde47c272ab45c9c5a1 | |
parent | c0a67563872b9c7d796c8fc901c0d1a2f3f61c35 (diff) |
Initial support for Fedora rootfs
-rwxr-xr-x | linaro-hwpack-install | 49 | ||||
-rwxr-xr-x | linaro-media-create | 26 | ||||
-rw-r--r-- | linaro_image_tools/media_create/chroot_utils.py | 2 | ||||
-rw-r--r-- | linaro_image_tools/media_create/rootfs.py | 19 | ||||
-rw-r--r-- | linaro_image_tools/media_create/unpack_binary_tarball.py | 5 | ||||
-rw-r--r-- | linaro_image_tools/utils.py | 12 |
6 files changed, 88 insertions, 25 deletions
diff --git a/linaro-hwpack-install b/linaro-hwpack-install index a6e0e96..a6c3d9c 100755 --- a/linaro-hwpack-install +++ b/linaro-hwpack-install @@ -1,8 +1,7 @@ #!/bin/sh # linaro-hwpack-install - Install a Linaro Hardware Pack. -# This script is meant to run inside a chroot containing nothing other than -# ubuntu-minimal, so it must not depend on anything that's not in -# there. +# This script is meant to run inside a chroot. It must not depend on anything +# that's not in there. # TODO: When upgrading to a newer hwpack, make sure packages and apt sources # that are no longer needed are removed. @@ -44,6 +43,7 @@ APT_GET_OPTIONS="Dir::Etc::SourceList=${SOURCES_LIST_FILE}" SUPPORTED_FORMATS="1.0 2.0 3.0" # A space-separated list of hwpack formats. FLASH_KERNEL_SKIP="true" export FLASH_KERNEL_SKIP # skip attempting to run flash-kernel-hooks +DISTRIBUTION=`grep '^ID=' /etc/os-release | sed 's/ID=//'` sudo="sudo" if [ $(id -u) -eq 0 ]; then @@ -129,7 +129,7 @@ setup_hwpack() { "Try using a newer version of $(basename $0)." # Check the architecture of the hwpack matches that of the host system. - if [ "x$EXTRACT_KERNEL_ONLY" = "xno" ]; then + if [ "x$EXTRACT_KERNEL_ONLY" = "xno" -a "$DISTRIBUTION" = "ubuntu" ]; then # TODO: create a generic way to identify the architecture, without depending on dpkg [ "$HWPACK_ARCH" = `dpkg --print-architecture` ] || \ die "Hardware pack architecture ($HWPACK_ARCH) does not match the host's architecture" @@ -269,14 +269,49 @@ extract_kernel_packages() { # We assume the hwpack is always available at the rootfs ROOTFS_DIR=$(dirname $HWPACK_TARBALL) + DEB_DIR="${TEMP_DIR}/extracted" + mkdir -p ${DEB_DIR} + ls ${HWPACK_DIR}/pkgs/linux-[ih]*.deb | while read pkg; do echo "Extracting package `basename $pkg`" - dpkg-deb -x ${pkg} $ROOTFS_DIR + if [ "$DISTRIBUTION" = "ubuntu" ]; then + dpkg-deb -x ${pkg} $ROOTFS_DIR + elif [ "$DISTRIBUTION" = "fedora" ]; then + ar x ${pkg} + tar -xf data.tar.* -C ${DEB_DIR} + rm -f debian-binary control.tar.gz data.tar.* + fi + done + + ls ${HWPACK_DIR}/pkgs/arndale-pre-boot_*.deb | while read pkg; do + echo "Extracting package `basename $pkg`" + if [ "$DISTRIBUTION" = "ubuntu" ]; then + dpkg-deb -x ${pkg} $ROOTFS_DIR + elif [ "$DISTRIBUTION" = "fedora" ]; then + ar x ${pkg} + tar -xf data.tar.* -C ${DEB_DIR} + rm -f debian-binary control.tar.gz data.tar.* + fi done + if [ "$DISTRIBUTION" = "fedora" ]; then + cp -a ${DEB_DIR}/boot/* /boot/ + cp -a ${DEB_DIR}/lib/modules/* /usr/lib/modules/ + cp -a ${DEB_DIR}/lib/firmware/* /usr/lib/firmware/ + fi + + if [ -d "${HWPACK_DIR}/u_boot" ]; then + cp -a ${HWPACK_DIR}/u_boot/usr/lib/* /usr/lib + fi + + if [ -d "${HWPACK_DIR}/uefi" ]; then + cp -a ${HWPACK_DIR}/uefi/usr/lib/* /usr/lib + fi + # manually generate modules.dep ls $ROOTFS_DIR/lib/modules | while read kernel; do depmod -b $ROOTFS_DIR ${kernel} || true + [ "$DISTRIBUTION" = "fedora" ] && dracut /boot/initrd.img-${kernel} ${kernel} done; } @@ -284,7 +319,7 @@ cleanup() { # Ensure our temp dir and apt sources are removed. echo -n "Cleaning up ..." rm -rf $TEMP_DIR - if [ "x$EXTRACT_KERNEL_ONLY" = "xno" ]; then + if [ "x$EXTRACT_KERNEL_ONLY" = "xno" -a "$DISTRIBUTION" = "ubuntu" ]; then rm -f /usr/sbin/policy-rc.d mv -f /sbin/start-stop-daemon.REAL /sbin/start-stop-daemon if [ -x /sbin/initctl.REAL ]; then @@ -318,7 +353,7 @@ trap cleanup EXIT setup_hwpack # In case we only care about the kernel, don't mess up with the system -if [ "x$EXTRACT_KERNEL_ONLY" = "xno" ]; then +if [ "x$EXTRACT_KERNEL_ONLY" = "xno" -a "$DISTRIBUTION" = "ubuntu" ]; then setup_apt_sources setup_ubuntu_rootfs install_deb_packages diff --git a/linaro-media-create b/linaro-media-create index 8feb4ed..599bbb1 100755 --- a/linaro-media-create +++ b/linaro-media-create @@ -181,12 +181,6 @@ if __name__ == '__main__': # The binary image is in the new live format. filesystem_dir = 'binary/boot/filesystem.dir' - # if not a debian compatible system, just extract the kernel packages - extract_kpkgs = False - if not path_in_tarfile_exists( - os.path.join(filesystem_dir, 'etc', 'debian_version'), args.binary): - extract_kpkgs = True - ROOTFS_DIR = os.path.join(BIN_DIR, filesystem_dir) try: @@ -209,6 +203,24 @@ if __name__ == '__main__': unpack_binary_tarball(args.binary, BIN_DIR) + # if compatible system, extract all packages + os_release_id = 'linux' + os_release_file = '%s/etc/os-release' % ROOTFS_DIR + if os.path.exists(os_release_file): + for line in open(os_release_file): + if line.startswith('ID='): + os_release_id = line[(len('ID=')):] + os_release_id = os_release_id.strip('\"\n') + break + + if os_release_id == 'debian' or os_release_id == 'ubuntu' or \ + os.path.exists('%s/etc/debian_version' % ROOTFS_DIR): + extract_kpkgs = False + elif os_release_id == 'fedora': + extract_kpkgs = False + else: + extract_kpkgs = True + hwpacks = args.hwpacks lmc_dir = os.path.dirname(__file__) if lmc_dir == '': @@ -252,6 +264,6 @@ if __name__ == '__main__': populate_rootfs(ROOTFS_DIR, ROOT_DISK, root_partition, args.rootfs, rootfs_id, create_swap, str(args.swap_file), board_config.mmc_device_id, board_config.mmc_part_offset, - board_config) + os_release_id, board_config) logger.info("Done creating Linaro image on %s" % media.path) diff --git a/linaro_image_tools/media_create/chroot_utils.py b/linaro_image_tools/media_create/chroot_utils.py index 83b0f6d..6776c4c 100644 --- a/linaro_image_tools/media_create/chroot_utils.py +++ b/linaro_image_tools/media_create/chroot_utils.py @@ -105,7 +105,7 @@ def install_hwpack(rootfs_dir, hwpack_file, extract_kpkgs, hwpack_force_yes): print "Installing (linaro-hwpack-install) %s in target rootfs." % ( hwpack_basename) - # Get infromation required by linaro-hwpack-install + # Get information required by linaro-hwpack-install with HardwarepackHandler([hwpack_file]) as hwpack: version, _ = hwpack.get_field("version") architecture, _ = hwpack.get_field("architecture") diff --git a/linaro_image_tools/media_create/rootfs.py b/linaro_image_tools/media_create/rootfs.py index 73bc8eb..765cc99 100644 --- a/linaro_image_tools/media_create/rootfs.py +++ b/linaro_image_tools/media_create/rootfs.py @@ -43,7 +43,8 @@ def rootfs_mount_options(rootfs_type): def populate_rootfs(content_dir, root_disk, partition, rootfs_type, rootfs_id, should_create_swap, swap_size, - mmc_device_id, partition_offset, board_config=None): + mmc_device_id, partition_offset, os_release_id, + board_config=None): """Populate the rootfs and make the necessary tweaks to make it usable. This consists of: @@ -86,13 +87,14 @@ def populate_rootfs(content_dir, root_disk, partition, rootfs_type, append_to_fstab(root_disk, fstab_additions) - print "\nCreating /etc/flash-kernel.conf\n" - create_flash_kernel_config( - root_disk, mmc_device_id, 1 + partition_offset) + if os_release_id == 'debian' or os_release_id == 'ubuntu': + print "\nCreating /etc/flash-kernel.conf\n" + create_flash_kernel_config( + root_disk, mmc_device_id, 1 + partition_offset) - if board_config is not None: - print "\nUpdating /etc/network/interfaces\n" - update_network_interfaces(root_disk, board_config) + if board_config is not None: + print "\nUpdating /etc/network/interfaces\n" + update_network_interfaces(root_disk, board_config) def update_network_interfaces(root_disk, board_config): @@ -136,7 +138,8 @@ def _list_files(directory): not be world-readable. """ p = cmd_runner.run( - ['find', directory, '-maxdepth', '1', '-mindepth', '1'], + ['find', directory, '-maxdepth', '1', '-mindepth', '1', + '!', '-name', 'lost+found'], stdout=subprocess.PIPE, as_root=True) stdout, _ = p.communicate() return stdout.split() diff --git a/linaro_image_tools/media_create/unpack_binary_tarball.py b/linaro_image_tools/media_create/unpack_binary_tarball.py index ba00261..8dcdef8 100644 --- a/linaro_image_tools/media_create/unpack_binary_tarball.py +++ b/linaro_image_tools/media_create/unpack_binary_tarball.py @@ -29,8 +29,11 @@ def unpack_android_binary_tarball(tarball, unpack_dir, as_root=True): def unpack_binary_tarball(tarball, unpack_dir, as_root=True): + extract_opt = '-xf' + if tarball.endswith('.xz'): + extract_opt = '-Jxf' proc = cmd_runner.run( - ['tar', '--numeric-owner', '-C', unpack_dir, '-xf', tarball], + ['tar', '--numeric-owner', '-C', unpack_dir, extract_opt, tarball], as_root=as_root) proc.wait() return proc.returncode diff --git a/linaro_image_tools/utils.py b/linaro_image_tools/utils.py index c8d9682..2710c02 100644 --- a/linaro_image_tools/utils.py +++ b/linaro_image_tools/utils.py @@ -89,11 +89,21 @@ CommandNotFound = try_import('CommandNotFound.CommandNotFound') def path_in_tarfile_exists(path, tar_file): exists = True try: - tarinfo = tarfile.open(tar_file, 'r:gz') + tarinfo = tarfile.open(tar_file, 'r:*') tarinfo.getmember(path) tarinfo.close() except KeyError: exists = False + except (tarfile.ReadError, tarfile.CompressionError): + exists = False + # Fallback to tar command + cmd = ['tar', '-tf', tar_file, '--wildcards', '*' + path] + proc = cmd_runner.run(cmd, + stdout=open('/dev/null', 'w'), + stderr=open('/dev/null', 'w')) + proc.wait() + if proc.returncode == 0: + exists = True finally: return exists |