Skip to contentSkip to conversation

poky-tiny improvements

PATCH Superseded Alejandro Hernandez 4 participants 14 messages Jan 3, 2017 – Jan 4, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover poky-tiny improvements

This is the first set of patches meant to improve some of the characteristics of poky-tiny, these patches are from or based on Tom Zanussi's work; includes a new image recipe to be able to boot poky-tiny from initrd, along with changes to be able to create it using bootimg-efi, make it compatible with systemd-boot, and scripts to measure size of the image, kernel and modules.

The following changes since commit ce6e0c09723b4894beef32bba02785afdaff868b:

bitbake: fetch2/wget: fixup case with no useful netrc data (2016-12-21 23:05:25 +0000)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib hsalejandro/tinymaster2
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=hsalejandro/tinymaster2

Alejandro Hernandez (1):
core-image-tiny-initramfs: Fix error message shown after a successful
initrd boot

Tom Zanussi (5):
image-live-artifacts: Add support for creating image artifacts only
core-image-tiny-initramfs: Add and image creating image artifacts only ksize.py: Python 3 fixes
scripts/tiny/ksum.py: New tool
bootimg-efi: Look for image artifacts in a common location

 meta/classes/image-live-artifacts.bbclass          |  64 ++++++++
 meta/classes/image.bbclass                         |   4 +
 .../images/core-image-tiny-initramfs.bb            |  43 ++++++
 scripts/lib/wic/plugins/source/bootimg-efi.py      |  28 +++-
 scripts/tiny/ksize.py                              |  17 ++-
 scripts/tiny/ksum.py                               | 168 +++++++++++++++++++++
 6 files changed, 313 insertions(+), 11 deletions(-)
 create mode 100644 meta/classes/image-live-artifacts.bbclass
 create mode 100644 meta/recipes-core/images/core-image-tiny-initramfs.bb
 create mode 100755 scripts/tiny/ksum.py
Signature · 1 line
2.6.6
#1 lore raw

PATCH 1/6 image-live-artifacts: Add support for creating image artifacts only

From: Tom Zanussi <[email protected]>

Rather than create an actual image, just put the image artifacts in an 'artifacts' directory that can then be picked up by wic.

---
 meta/classes/image-live-artifacts.bbclass | 64 +++++++++++++++++++++++++++++++
 meta/classes/image.bbclass                |  4 ++
 2 files changed, 68 insertions(+)
 create mode 100644 meta/classes/image-live-artifacts.bbclass
meta/classes/image-live-artifacts.bbclass new file +64 -0
new file mode 100644
index 0000000..e056336
@@ -0,0 +1,64 @@
+# Copyright (C) 2004, Advanced Micro Devices, Inc.  All Rights Reserved
+# Released under the MIT license (see packages/COPYING)
+
+# Creates a bootable image using syslinux, your kernel and an optional
+# initrd
+
+#
+# End result is two things:
+#
+# 1. A .hddimg file which is an msdos filesystem containing syslinux, a kernel,
+# an initrd and a rootfs image. These can be written to harddisks directly and
+# also booted on USB flash disks (write them there with dd).
+#
+# 2. A CD .iso image
+
+# Boot process is that the initrd will boot and process which label was selected
+# in syslinux. Actions based on the label are then performed (e.g. installing to
+# an hdd)
+
+# External variables (also used by syslinux.bbclass)
+# ${INITRD} - indicates a list of filesystem images to concatenate and use as an initrd (optional)
+# ${COMPRESSISO} - Transparent compress ISO, reduce size ~40% if set to 1
+# ${NOISO}  - skip building the ISO image if set to 1
+# ${NOHDD}  - skip building the HDD image if set to 1
+# ${HDDIMG_ID} - FAT image volume-id
+# ${ROOTFS} - indicates a filesystem image to include as the root filesystem (optional)
+
+inherit live-vm-common
+
+do_bootimg[depends] += "dosfstools-native:do_populate_sysroot \
+                        mtools-native:do_populate_sysroot \
+                        cdrtools-native:do_populate_sysroot \
+                        virtual/kernel:do_deploy \
+                        ${MLPREFIX}syslinux:do_populate_sysroot \
+                        syslinux-native:do_populate_sysroot \
+                        ${@oe.utils.ifelse(d.getVar('COMPRESSISO', False),'zisofs-tools-native:do_populate_sysroot','')} \
+                        "
+
+
+LABELS_LIVE ?= "boot install"
+
+ARTIFACTS_DIR = "${DEPLOY_DIR_IMAGE}/artifacts"
+
+populate_bootloader() {
+	populate_kernel ${ARTIFACTS_DIR}
+
+	if [ "${PCBIOS}" = "1" ]; then
+		syslinux_hddimg_populate ${ARTIFACTS_DIR}
+	fi
+	if [ "${EFI}" = "1" ]; then
+		efi_hddimg_populate ${ARTIFACTS_DIR}
+	fi
+}
+
+python do_bootimg() {
+    set_live_vm_vars(d, 'LIVE')
+    if d.getVar("PCBIOS", True) == "1":
+        bb.build.exec_func('build_syslinux_cfg', d)
+    if d.getVar("EFI", True) == "1":
+        bb.build.exec_func('build_efi_cfg', d)
+    bb.build.exec_func('populate_bootloader', d)
+}
+
+addtask bootimg before do_image_complete
meta/classes/image.bbclass +4 -0
index 04fd5f9..c3f5f2e 100644
@@ -130,6 +130,10 @@ do_rootfs[vardeps] += "${@rootfs_variables(d)}"
 do_build[depends] += "virtual/kernel:do_deploy"
 
 def build_live(d):
+    artifacts_only = d.getVar("ARTIFACTS_ONLY", True)
+    if artifacts_only:
+         return "image-live-artifacts"
+
     if bb.utils.contains("IMAGE_FSTYPES", "live", "live", "0", d) == "0": # live is not set but hob might set iso or hddimg
         d.setVar('NOISO', bb.utils.contains('IMAGE_FSTYPES', "iso", "0", "1", d))
         d.setVar('NOHDD', bb.utils.contains('IMAGE_FSTYPES', "hddimg", "0", "1", d))
Signature · 1 line
2.6.6
#3 lore raw

PATCH 2/6 core-image-tiny-initramfs: Add and image creating image artifacts only

In reply to Alejandro Hernandez

From: Tom Zanussi <[email protected]>

Add an image that simply creates image artifacts using image-live-artifacts support instead of creating an actual image.

The image artifacts can then be subsequently assembled by an external tool such as wic to create an actual image.

This eliminates redundant image creation when using such tools.

---
 .../images/core-image-tiny-initramfs.bb            | 31 ++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 meta/recipes-core/images/core-image-tiny-initramfs.bb
meta/recipes-core/images/core-image-tiny-initramfs.bb new file +31 -0
new file mode 100644
index 0000000..216f3e0
@@ -0,0 +1,31 @@
+# Simple initramfs image artifact generation for tiny images.
+DESCRIPTION = "Tiny image capable of booting a device. The kernel includes \
+the Minimal RAM-based Initial Root Filesystem (initramfs), which finds the \
+first 'init' program more efficiently.  core-image-tiny-initramfs doesn't \
+actually generate an image but rather generates boot and rootfs artifacts \
+into a common location that can subsequently be picked up by external image \
+generation tools such as wic."
+
+PACKAGE_INSTALL = "initramfs-live-boot packagegroup-core-boot dropbear ${VIRTUAL-RUNTIME_base-utils} udev base-passwd ${ROOTFS_BOOTSTRAP_INSTALL}"
+
+# Do not pollute the initrd image with rootfs features
+IMAGE_FEATURES = ""
+
+export IMAGE_BASENAME = "core-image-tiny-initramfs"
+IMAGE_LINGUAS = ""
+
+LICENSE = "MIT"
+
+# don't actually generate an image, just the artifacts needed for one
+ARTIFACTS_ONLY ?= "1"
+
+IMAGE_FSTYPES = "${INITRAMFS_FSTYPES}"
+inherit core-image
+
+IMAGE_ROOTFS_SIZE = "8192"
+IMAGE_ROOTFS_EXTRA_SPACE = "0"
+
+BAD_RECOMMENDATIONS += "busybox-syslog"
+
+# Use the same restriction as initramfs-live-install
+COMPATIBLE_HOST = "(i.86|x86_64).*-linux"
Signature · 1 line
2.6.6
#5 lore raw

PATCH 3/6 ksize.py: Python 3 fixes

In reply to Alejandro Hernandez

From: Tom Zanussi <[email protected]>

String errors and partial __cmp__ fix.

---
 scripts/tiny/ksize.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
scripts/tiny/ksize.py +12 -5
index b9d2b19..ea1ca7f 100755
@@ -41,7 +41,7 @@ def usage():
 class Sizes:
     def __init__(self, glob):
         self.title = glob
-        p = Popen("size -t " + glob, shell=True, stdout=PIPE, stderr=PIPE)
+        p = Popen("size -t " + str(glob), shell=True, stdout=PIPE, stderr=PIPE)
         output = p.communicate()[0].splitlines()
         if len(output) > 2:
             sizes = output[-1].split()[0:4]
@@ -62,18 +62,18 @@ class Report:
         r = Report(filename, title)
         path = os.path.dirname(filename)
 
-        p = Popen("ls " + path + "/*.o | grep -v built-in.o",
+        p = Popen("ls " + str(path) + "/*.o | grep -v built-in.o",
                   shell=True, stdout=PIPE, stderr=PIPE)
         glob = ' '.join(p.communicate()[0].splitlines())
-        oreport = Report(glob, path + "/*.o")
-        oreport.sizes.title = path + "/*.o"
+        oreport = Report(glob, str(path) + "/*.o")
+        oreport.sizes.title = str(path) + "/*.o"
         r.parts.append(oreport)
 
         if subglob:
             p = Popen("ls " + subglob, shell=True, stdout=PIPE, stderr=PIPE)
             for f in p.communicate()[0].splitlines():
                 path = os.path.dirname(f)
-                r.parts.append(Report.create(f, path, path + "/*/built-in.o"))
+                r.parts.append(Report.create(f, path, str(path) + "/*/built-in.o"))
             r.parts.sort(reverse=True)
 
         for b in r.parts:
@@ -116,6 +116,13 @@ class Report:
                self.deltas["data"], self.deltas["bss"]))
         print("\n")
 
+    def __lt__(this, that):
+        if that is None:
+            return 1
+        if not isinstance(that, Report):
+            raise TypeError
+        return this.sizes.total < that.sizes.total
+
     def __cmp__(this, that):
         if that is None:
             return 1
Signature · 1 line
2.6.6
#10 lore raw

PATCH 4/6 scripts/tiny/ksum.py: New tool

In reply to Alejandro Hernandez

From: Tom Zanussi <[email protected]>

'ksum.py' generates a combined summary of vmlinux and module sizes for a built kernel, as a quick tool for comparing the overall effects of systemic tinification changes. Execute from the base directory of the kernel build you want to summarize. Setting the 'verbose' flag will display the sizes for each file included in the summary.

---
 scripts/tiny/ksum.py | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 168 insertions(+)
 create mode 100755 scripts/tiny/ksum.py
scripts/tiny/ksum.py new file +168 -0
new file mode 100755
index 0000000..d4f3892
@@ -0,0 +1,168 @@
+#!/usr/bin/env python
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# Copyright (c) 2016, Intel Corporation.
+# All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# DESCRIPTION 'ksum.py' generates a combined summary of vmlinux and
+# module sizes for a built kernel, as a quick tool for comparing the
+# overall effects of systemic tinification changes.  Execute from the
+# base directory of the kernel build you want to summarize.  Setting
+# the 'verbose' flag will display the sizes for each file included in
+# the summary.
+#
+# AUTHORS
+# Tom Zanussi <tom.zanussi (at] linux.intel.com>
+#
+
+__version__ = "0.1.0"
+
+# Python Standard Library modules
+import os
+import sys
+import getopt
+from subprocess import *
+
+def usage():
+    prog = os.path.basename(sys.argv[0])
+    print('Usage: %s [OPTION]...' % prog)
+    print('  -v,                 display sizes for each file')
+    print('  -h, --help          display this help and exit')
+    print('')
+    print('Run %s from the top-level Linux kernel build directory.' % prog)
+
+verbose = False
+
+n_ko_files = 0
+ko_file_list = []
+
+ko_text = 0
+ko_data = 0
+ko_bss = 0
+ko_total = 0
+
+vmlinux_file = ""
+vmlinux_level = 0
+
+vmlinux_text = 0
+vmlinux_data = 0
+vmlinux_bss = 0
+vmlinux_total = 0
+
+def is_vmlinux_file(filename):
+    global vmlinux_level
+    if filename == ("vmlinux") and vmlinux_level == 0:
+        vmlinux_level += 1
+        return True
+    return False
+
+def is_ko_file(filename):
+    if filename.endswith(".ko"):
+        return True
+    return False
+
+def collect_object_files():
+    print "Collecting object files recursively from %s..." % os.getcwd()
+    for dirpath, dirs, files in os.walk(os.getcwd()):
+        for filename in files:
+            if is_ko_file(filename):
+                ko_file_list.append(os.path.join(dirpath, filename))
+            elif is_vmlinux_file(filename):
+                global vmlinux_file
+                vmlinux_file = os.path.join(dirpath, filename)
+    print "Collecting object files [DONE]"
+
+def add_ko_file(filename):
+        p = Popen("size -t " + filename, shell=True, stdout=PIPE, stderr=PIPE)
+        output = p.communicate()[0].splitlines()
+        if len(output) > 2:
+            sizes = output[-1].split()[0:4]
+            if verbose:
+                print "     %10d %10d %10d %10d\t" % \
+                    (int(sizes[0]), int(sizes[1]), int(sizes[2]), int(sizes[3])),
+                print "%s" % filename[len(os.getcwd()) + 1:]
+            global n_ko_files, ko_text, ko_data, ko_bss, ko_total
+            ko_text += int(sizes[0])
+            ko_data += int(sizes[1])
+            ko_bss += int(sizes[2])
+            ko_total += int(sizes[3])
+            n_ko_files += 1
+
+def get_vmlinux_totals():
+        p = Popen("size -t " + vmlinux_file, shell=True, stdout=PIPE, stderr=PIPE)
+        output = p.communicate()[0].splitlines()
+        if len(output) > 2:
+            sizes = output[-1].split()[0:4]
+            if verbose:
+                print "     %10d %10d %10d %10d\t" % \
+                    (int(sizes[0]), int(sizes[1]), int(sizes[2]), int(sizes[3])),
+                print "%s" % vmlinux_file[len(os.getcwd()) + 1:]
+            global vmlinux_text, vmlinux_data, vmlinux_bss, vmlinux_total
+            vmlinux_text += int(sizes[0])
+            vmlinux_data += int(sizes[1])
+            vmlinux_bss += int(sizes[2])
+            vmlinux_total += int(sizes[3])
+
+def sum_ko_files():
+    for ko_file in ko_file_list:
+        add_ko_file(ko_file)
+
+def main():
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "vh", ["help"])
+    except getopt.GetoptError as err:
+        print('%s' % str(err))
+        usage()
+        sys.exit(2)
+
+    for o, a in opts:
+        if o == '-v':
+            global verbose
+            verbose = True
+        elif o in ('-h', '--help'):
+            usage()
+            sys.exit(0)
+        else:
+            assert False, "unhandled option"
+
+    collect_object_files()
+    sum_ko_files()
+    get_vmlinux_totals()
+
+    print "\nTotals:"
+    print "\nvmlinux:"
+    print "    text\tdata\t\tbss\t\ttotal"
+    print "    %-10d\t%-10d\t%-10d\t%-10d" % \
+        (vmlinux_text, vmlinux_data, vmlinux_bss, vmlinux_total)
+    print "\nmodules (%d):" % n_ko_files
+    print "    text\tdata\t\tbss\t\ttotal"
+    print "    %-10d\t%-10d\t%-10d\t%-10d" % \
+        (ko_text, ko_data, ko_bss, ko_total)
+    print "\nvmlinux + modules:"
+    print "    text\tdata\t\tbss\t\ttotal"
+    print "    %-10d\t%-10d\t%-10d\t%-10d" % \
+        (vmlinux_text + ko_text, vmlinux_data + ko_data, \
+         vmlinux_bss + ko_bss, vmlinux_total + ko_total)
+
+if __name__ == "__main__":
+    try:
+        ret = main()
+    except Exception:
+        ret = 1
+        import traceback
+        traceback.print_exc(5)
+    sys.exit(ret)
Signature · 1 line
2.6.6
#12 lore raw

PATCH 5/6 bootimg-efi: Look for image artifacts in a common location

In reply to Alejandro Hernandez

From: Tom Zanussi <[email protected]>

Rather than have each image type look for artifacts in image-specific locations, move towards having them look for artifacts in a common location, in this case DEPLOY_DIR_IMAGE/artifacts.

This currently only applies to bootimg-efi images, and only if the oe-core image classes have been modified to generate artifacts there (e.g. using image-live-artifacts).

---
 scripts/lib/wic/plugins/source/bootimg-efi.py | 28 +++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
scripts/lib/wic/plugins/source/bootimg-efi.py +22 -6
index 305e910..2c16a0f 100644
@@ -42,7 +42,7 @@ class BootimgEFIPlugin(SourcePlugin):
     name = 'bootimg-efi'
 
     @classmethod
-    def do_configure_grubefi(cls, hdddir, creator, cr_workdir):
+    def do_configure_grubefi(cls, hdddir, creator, cr_workdir, source_params):
         """
         Create loader-specific (grub-efi) config
         """
@@ -82,7 +82,7 @@ class BootimgEFIPlugin(SourcePlugin):
         cfg.close()
 
     @classmethod
-    def do_configure_systemdboot(cls, hdddir, creator, cr_workdir):
+    def do_configure_systemdboot(cls, hdddir, creator, cr_workdir, source_params):
         """
         Create loader-specific systemd-boot/gummiboot config
         """
@@ -98,6 +98,18 @@ class BootimgEFIPlugin(SourcePlugin):
         loader_conf += "default boot\n"
         loader_conf += "timeout %d\n" % bootloader.timeout
 
+        initrd = ""
+
+        if source_params['initrd']:
+	    initrd = source_params['initrd']
+            # obviously we need to have a common common deploy var
+            bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
+            if not bootimg_dir:
+                msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+
+            cp_cmd = "cp %s/%s %s" % (bootimg_dir, initrd, hdddir)
+            exec_cmd(cp_cmd, True)
+
         msger.debug("Writing systemd-boot config %s/hdd/boot/loader/loader.conf" \
                         % cr_workdir)
         cfg = open("%s/hdd/boot/loader/loader.conf" % cr_workdir, "w")
@@ -127,6 +139,9 @@ class BootimgEFIPlugin(SourcePlugin):
             boot_conf += "options LABEL=Boot root=%s %s\n" % \
                              (creator.rootdev, bootloader.append)
 
+           if initrd:
+                boot_conf += "initrd /%s\n" % initrd
+
         msger.debug("Writing systemd-boot config %s/hdd/boot/loader/entries/boot.conf" \
                         % cr_workdir)
         cfg = open("%s/hdd/boot/loader/entries/boot.conf" % cr_workdir, "w")
@@ -148,9 +163,9 @@ class BootimgEFIPlugin(SourcePlugin):
 
         try:
             if source_params['loader'] == 'grub-efi':
-                cls.do_configure_grubefi(hdddir, creator, cr_workdir)
+                cls.do_configure_grubefi(hdddir, creator, cr_workdir, source_params)
             elif source_params['loader'] == 'systemd-boot':
-                cls.do_configure_systemdboot(hdddir, creator, cr_workdir)
+                cls.do_configure_systemdboot(hdddir, creator, cr_workdir, source_params)
             else:
                 msger.error("unrecognized bootimg-efi loader: %s" % source_params['loader'])
         except KeyError:
@@ -167,9 +182,10 @@ class BootimgEFIPlugin(SourcePlugin):
         In this case, prepare content for an EFI (grub) boot partition.
         """
         if not bootimg_dir:
-            bootimg_dir = get_bitbake_var("HDDDIR")
+	    bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
             if not bootimg_dir:
-                msger.error("Couldn't find HDDDIR, exiting\n")
+                 msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
+            bootimg_dir += "/artifacts"
             # just so the result notes display it
             creator.set_bootimg_dir(bootimg_dir)
 
Signature · 1 line
2.6.6
#13 lore raw

PATCH 6/6 core-image-tiny-initramfs: Fix error message shown after a successful initrd boot

In reply to Alejandro Hernandez

When booting core-image-tiny-initramfs, since we want to live on initrd, on purpose, we never find a rootfs image to switch root to, this causes init to show an error as it would with other images, this patch replaces the message shown to the user, avoiding confusion when it was indeed a successful boot.

---
 meta/recipes-core/images/core-image-tiny-initramfs.bb | 12 ++++++++++++
 1 file changed, 12 insertions(+)
meta/recipes-core/images/core-image-tiny-initramfs.bb +12 -0
index 216f3e0..a1a4f66 100644
@@ -29,3 +29,15 @@ BAD_RECOMMENDATIONS += "busybox-syslog"
 
 # Use the same restriction as initramfs-live-install
 COMPATIBLE_HOST = "(i.86|x86_64).*-linux"
+
+python tinyinitrd () {
+  # Modify our init file so the user knows we drop to shell prompt on purpose
+  newinit = None
+  with open(d.expand('${IMAGE_ROOTFS}/init'), 'r') as init:
+    newinit = init.read()
+    newinit = newinit.replace('Cannot find $ROOT_IMAGE file in /run/media/* , dropping to a shell ', 'Poky Tiny Reference Distribution:')
+  with open(d.expand('${IMAGE_ROOTFS}/init'), 'w') as init:
+    init.write(newinit)
+}
+
+IMAGE_PREPROCESS_COMMAND += "tinyinitrd;"
Signature · 1 line
2.6.6
#2 lore raw

Re: [PATCH 1/6] image-live-artifacts: Add support for creating image artifacts only

In reply to Alejandro Hernandez
Quoted 6 lines · Alejandro Hernandez

From: Tom Zanussi <[email protected]>

Rather than create an actual image, just put the image artifacts in an 'artifacts' directory that can then be picked up by wic.

I think the idea here is good, the implementation is suboptimal though. The reason being it introduces more variables which do things outside a clear namespace (ARTIFACTS_ONLY).

I'd really like to see this code trigger off an entry in IMAGE_FSTYPES like IMAGE_FSTYPES = "live-artifacts-only" or some other such keyword. The ultimate idea is we'd get rid of all these class specific variables and you'd just set IMAGE_FSTYPES according to what you want.

The depends on COMPRESSISO also looks like a cut and paste which I'm not sure could trigger in this codepath?

Cheers,

Richard

#11 lore raw

Re: [PATCH 4/6] scripts/tiny/ksum.py: New tool

In reply to Alejandro Hernandez
Quoted 8 lines · Alejandro Hernandez

From: Tom Zanussi <[email protected]>

'ksum.py' generates a combined summary of vmlinux and module sizes for a built kernel, as a quick tool for comparing the overall effects of systemic tinification changes. Execute from the base directory of the kernel build you want to summarize. Setting the 'verbose' flag will display the sizes for each file included in the summary.

Does this work with python3 as well?

Quoted 188 lines
---
 scripts/tiny/ksum.py | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 168 insertions(+)
 create mode 100755 scripts/tiny/ksum.py
scripts/tiny/ksum.py new file +168 -1
new file mode 100755
index 0000000..d4f3892
@@ -0,0 +1,168 @@
+#!/usr/bin/env python
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# Copyright (c) 2016, Intel Corporation.
+# All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# DESCRIPTION 'ksum.py' generates a combined summary of vmlinux and
+# module sizes for a built kernel, as a quick tool for comparing the
+# overall effects of systemic tinification changes.  Execute from the
+# base directory of the kernel build you want to summarize.  Setting
+# the 'verbose' flag will display the sizes for each file included in
+# the summary.
+#
+# AUTHORS
+# Tom Zanussi <tom.zanussi (at] linux.intel.com>
+#
+
+__version__ = "0.1.0"
+
+# Python Standard Library modules
+import os
+import sys
+import getopt
+from subprocess import *
+
+def usage():
+    prog = os.path.basename(sys.argv[0])
+    print('Usage: %s [OPTION]...' % prog)
+    print('  -v,                 display sizes for each file')
+    print('  -h, --help          display this help and exit')
+    print('')
+    print('Run %s from the top-level Linux kernel build directory.' % prog)
+
+verbose = False
+
+n_ko_files = 0
+ko_file_list = []
+
+ko_text = 0
+ko_data = 0
+ko_bss = 0
+ko_total = 0
+
+vmlinux_file = ""
+vmlinux_level = 0
+
+vmlinux_text = 0
+vmlinux_data = 0
+vmlinux_bss = 0
+vmlinux_total = 0
+
+def is_vmlinux_file(filename):
+    global vmlinux_level
+    if filename == ("vmlinux") and vmlinux_level == 0:
+        vmlinux_level += 1
+        return True
+    return False
+
+def is_ko_file(filename):
+    if filename.endswith(".ko"):
+        return True
+    return False
+
+def collect_object_files():
+    print "Collecting object files recursively from %s..." % os.getcwd()
+    for dirpath, dirs, files in os.walk(os.getcwd()):
+        for filename in files:
+            if is_ko_file(filename):
+                ko_file_list.append(os.path.join(dirpath, filename))
+            elif is_vmlinux_file(filename):
+                global vmlinux_file
+                vmlinux_file = os.path.join(dirpath, filename)
+    print "Collecting object files [DONE]"
+
+def add_ko_file(filename):
+        p = Popen("size -t " + filename, shell=True, stdout=PIPE, stderr=PIPE)
+        output = p.communicate()[0].splitlines()
+        if len(output) > 2:
+            sizes = output[-1].split()[0:4]
+            if verbose:
+                print "     %10d %10d %10d %10d\t" % \
+                    (int(sizes[0]), int(sizes[1]), int(sizes[2]), int(sizes[3])),
+                print "%s" % filename[len(os.getcwd()) + 1:]
+            global n_ko_files, ko_text, ko_data, ko_bss, ko_total
+            ko_text += int(sizes[0])
+            ko_data += int(sizes[1])
+            ko_bss += int(sizes[2])
+            ko_total += int(sizes[3])
+            n_ko_files += 1
+
+def get_vmlinux_totals():
+        p = Popen("size -t " + vmlinux_file, shell=True, stdout=PIPE, stderr=PIPE)
+        output = p.communicate()[0].splitlines()
+        if len(output) > 2:
+            sizes = output[-1].split()[0:4]
+            if verbose:
+                print "     %10d %10d %10d %10d\t" % \
+                    (int(sizes[0]), int(sizes[1]), int(sizes[2]), int(sizes[3])),
+                print "%s" % vmlinux_file[len(os.getcwd()) + 1:]
+            global vmlinux_text, vmlinux_data, vmlinux_bss, vmlinux_total
+            vmlinux_text += int(sizes[0])
+            vmlinux_data += int(sizes[1])
+            vmlinux_bss += int(sizes[2])
+            vmlinux_total += int(sizes[3])
+
+def sum_ko_files():
+    for ko_file in ko_file_list:
+        add_ko_file(ko_file)
+
+def main():
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "vh", ["help"])
+    except getopt.GetoptError as err:
+        print('%s' % str(err))
+        usage()
+        sys.exit(2)
+
+    for o, a in opts:
+        if o == '-v':
+            global verbose
+            verbose = True
+        elif o in ('-h', '--help'):
+            usage()
+            sys.exit(0)
+        else:
+            assert False, "unhandled option"
+
+    collect_object_files()
+    sum_ko_files()
+    get_vmlinux_totals()
+
+    print "\nTotals:"
+    print "\nvmlinux:"
+    print "    text\tdata\t\tbss\t\ttotal"
+    print "    %-10d\t%-10d\t%-10d\t%-10d" % \
+        (vmlinux_text, vmlinux_data, vmlinux_bss, vmlinux_total)
+    print "\nmodules (%d):" % n_ko_files
+    print "    text\tdata\t\tbss\t\ttotal"
+    print "    %-10d\t%-10d\t%-10d\t%-10d" % \
+        (ko_text, ko_data, ko_bss, ko_total)
+    print "\nvmlinux + modules:"
+    print "    text\tdata\t\tbss\t\ttotal"
+    print "    %-10d\t%-10d\t%-10d\t%-10d" % \
+        (vmlinux_text + ko_text, vmlinux_data + ko_data, \
+         vmlinux_bss + ko_bss, vmlinux_total + ko_total)
+
+if __name__ == "__main__":
+    try:
+        ret = main()
+    except Exception:
+        ret = 1
+        import traceback
+        traceback.print_exc(5)
+    sys.exit(ret)
--

2.6.6

--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core

#6 lore raw

Re: [PATCH 3/6] ksize.py: Python 3 fixes

In reply to Alejandro Hernandez
Quoted 3 lines · Alejandro Hernandez

From: Tom Zanussi <[email protected]>

String errors and partial __cmp__ fix.

may be fold it into previous patch.

Quoted 64 lines
---
 scripts/tiny/ksize.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
scripts/tiny/ksize.py +12 -6
index b9d2b19..ea1ca7f 100755
@@ -41,7 +41,7 @@ def usage():
 class Sizes:
     def __init__(self, glob):
         self.title = glob
-        p = Popen("size -t " + glob, shell=True, stdout=PIPE, stderr=PIPE)
+        p = Popen("size -t " + str(glob), shell=True, stdout=PIPE, stderr=PIPE)
         output = p.communicate()[0].splitlines()
         if len(output) > 2:
             sizes = output[-1].split()[0:4]
@@ -62,18 +62,18 @@ class Report:
         r = Report(filename, title)
         path = os.path.dirname(filename)
 
-        p = Popen("ls " + path + "/*.o | grep -v built-in.o",
+        p = Popen("ls " + str(path) + "/*.o | grep -v built-in.o",
                   shell=True, stdout=PIPE, stderr=PIPE)
         glob = ' '.join(p.communicate()[0].splitlines())
-        oreport = Report(glob, path + "/*.o")
-        oreport.sizes.title = path + "/*.o"
+        oreport = Report(glob, str(path) + "/*.o")
+        oreport.sizes.title = str(path) + "/*.o"
         r.parts.append(oreport)
 
         if subglob:
             p = Popen("ls " + subglob, shell=True, stdout=PIPE, stderr=PIPE)
             for f in p.communicate()[0].splitlines():
                 path = os.path.dirname(f)
-                r.parts.append(Report.create(f, path, path + "/*/built-in.o"))
+                r.parts.append(Report.create(f, path, str(path) + "/*/built-in.o"))
             r.parts.sort(reverse=True)
 
         for b in r.parts:
@@ -116,6 +116,13 @@ class Report:
                self.deltas["data"], self.deltas["bss"]))
         print("\n")
 
+    def __lt__(this, that):
+        if that is None:
+            return 1
+        if not isinstance(that, Report):
+            raise TypeError
+        return this.sizes.total < that.sizes.total
+
     def __cmp__(this, that):
         if that is None:
             return 1
--

2.6.6

--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core

#7 lore raw

Re: [PATCH 3/6] ksize.py: Python 3 fixes

Hey Khem,

Its an old script fro Tom, but as far as I remember it worked fine on python3, although thanks for checking and sending the patch!

Cheers

Alejandro

Quoted 70 lines · Khem Raj
Quoted 3 lines · Alejandro Hernandez

From: Tom Zanussi <[email protected]>

String errors and partial __cmp__ fix.

may be fold it into previous patch.

Quoted 63 lines
---
  scripts/tiny/ksize.py | 17 ++++++++++++-----
  1 file changed, 12 insertions(+), 5 deletions(-)
scripts/tiny/ksize.py +12 -6
index b9d2b19..ea1ca7f 100755
@@ -41,7 +41,7 @@ def usage():
  class Sizes:
      def __init__(self, glob):
          self.title = glob
-        p = Popen("size -t " + glob, shell=True, stdout=PIPE, stderr=PIPE)
+        p = Popen("size -t " + str(glob), shell=True, stdout=PIPE, stderr=PIPE)
          output = p.communicate()[0].splitlines()
          if len(output) > 2:
              sizes = output[-1].split()[0:4]
@@ -62,18 +62,18 @@ class Report:
          r = Report(filename, title)
          path = os.path.dirname(filename)
 
-        p = Popen("ls " + path + "/*.o | grep -v built-in.o",
+        p = Popen("ls " + str(path) + "/*.o | grep -v built-in.o",
                    shell=True, stdout=PIPE, stderr=PIPE)
          glob = ' '.join(p.communicate()[0].splitlines())
-        oreport = Report(glob, path + "/*.o")
-        oreport.sizes.title = path + "/*.o"
+        oreport = Report(glob, str(path) + "/*.o")
+        oreport.sizes.title = str(path) + "/*.o"
          r.parts.append(oreport)
 
          if subglob:
              p = Popen("ls " + subglob, shell=True, stdout=PIPE, stderr=PIPE)
              for f in p.communicate()[0].splitlines():
                  path = os.path.dirname(f)
-                r.parts.append(Report.create(f, path, path + "/*/built-in.o"))
+                r.parts.append(Report.create(f, path, str(path) + "/*/built-in.o"))
              r.parts.sort(reverse=True)
 
          for b in r.parts:
@@ -116,6 +116,13 @@ class Report:
                 self.deltas["data"], self.deltas["bss"]))
          print("\n")
 
+    def __lt__(this, that):
+        if that is None:
+            return 1
+        if not isinstance(that, Report):
+            raise TypeError
+        return this.sizes.total < that.sizes.total
+
      def __cmp__(this, that):
          if that is None:
              return 1
--

2.6.6

--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core

#4 lore raw

Re: [PATCH 2/6] core-image-tiny-initramfs: Add and image creating image artifacts only

In reply to Alejandro Hernandez

Alex, the patch requires to be signed off.

Quoted 51 lines · Alejandro Hernandez

From: Tom Zanussi <[email protected]>

Add an image that simply creates image artifacts using image-live-artifacts support instead of creating an actual image.

The image artifacts can then be subsequently assembled by an external tool such as wic to create an actual image.

This eliminates redundant image creation when using such tools.

---
  .../images/core-image-tiny-initramfs.bb            | 31 ++++++++++++++++++++++
  1 file changed, 31 insertions(+)

create mode 100644 meta/recipes-core/images/core-image-tiny-initramfs.bb

meta/recipes-core/images/core-image-tiny-initramfs.bb new file +31 -0
new file mode 100644
index 0000000..216f3e0
@@ -0,0 +1,31 @@
+# Simple initramfs image artifact generation for tiny images.
+DESCRIPTION = "Tiny image capable of booting a device. The kernel includes \
+the Minimal RAM-based Initial Root Filesystem (initramfs), which finds the \
+first 'init' program more efficiently.  core-image-tiny-initramfs doesn't \
+actually generate an image but rather generates boot and rootfs artifacts \
+into a common location that can subsequently be picked up by external image \
+generation tools such as wic."
+
+PACKAGE_INSTALL = "initramfs-live-boot packagegroup-core-boot dropbear ${VIRTUAL-RUNTIME_base-utils} udev base-passwd ${ROOTFS_BOOTSTRAP_INSTALL}"
+
+# Do not pollute the initrd image with rootfs features
+IMAGE_FEATURES = ""
+
+export IMAGE_BASENAME = "core-image-tiny-initramfs"
+IMAGE_LINGUAS = ""
+
+LICENSE = "MIT"
+
+# don't actually generate an image, just the artifacts needed for one
+ARTIFACTS_ONLY ?= "1"
+
+IMAGE_FSTYPES = "${INITRAMFS_FSTYPES}"
+inherit core-image
+
+IMAGE_ROOTFS_SIZE = "8192"
+IMAGE_ROOTFS_EXTRA_SPACE = "0"
+
+BAD_RECOMMENDATIONS += "busybox-syslog"
+
+# Use the same restriction as initramfs-live-install
+COMPATIBLE_HOST = "(i.86|x86_64).*-linux"
#8 lore raw

Re: [PATCH 3/6] ksize.py: Python 3 fixes

In reply to Alejandro Hernandez

Hey Khem,

Ok, now I'm actually awake when reading this, are you saying these changes should go in the same patch as the one for ksum.py?

Quoted 87 lines · Alejandro Hernandez

Hey Khem,

Its an old script fro Tom, but as far as I remember it worked fine on python3, although thanks for checking and sending the patch!

Cheers

Alejandro

Quoted 75 lines · Khem Raj
Quoted 3 lines · Alejandro Hernandez

From: Tom Zanussi <[email protected]>

String errors and partial __cmp__ fix.

may be fold it into previous patch.

Quoted 68 lines
---
  scripts/tiny/ksize.py | 17 ++++++++++++-----
  1 file changed, 12 insertions(+), 5 deletions(-)
scripts/tiny/ksize.py +1 -1
index b9d2b19..ea1ca7f 100755
@@ -41,7 +41,7 @@ def usage():
  class Sizes:
      def __init__(self, glob):
          self.title = glob
-        p = Popen("size -t " + glob, shell=True, stdout=PIPE, 
 stderr=PIPE)
+        p = Popen("size -t " + str(glob), shell=True, stdout=PIPE, 
 stderr=PIPE)
          output = p.communicate()[0].splitlines()
          if len(output) > 2:
              sizes = output[-1].split()[0:4]
scripts/tiny/ksize.py +4 -4
@@ -62,18 +62,18 @@ class Report:
          r = Report(filename, title)
          path = os.path.dirname(filename)
 
-        p = Popen("ls " + path + "/*.o | grep -v built-in.o",
+        p = Popen("ls " + str(path) + "/*.o | grep -v built-in.o",
                    shell=True, stdout=PIPE, stderr=PIPE)
          glob = ' '.join(p.communicate()[0].splitlines())
-        oreport = Report(glob, path + "/*.o")
-        oreport.sizes.title = path + "/*.o"
+        oreport = Report(glob, str(path) + "/*.o")
+        oreport.sizes.title = str(path) + "/*.o"
          r.parts.append(oreport)
 
          if subglob:
              p = Popen("ls " + subglob, shell=True, stdout=PIPE, 
 stderr=PIPE)
              for f in p.communicate()[0].splitlines():
                  path = os.path.dirname(f)
-                r.parts.append(Report.create(f, path, path + 
 "/*/built-in.o"))
+                r.parts.append(Report.create(f, path, str(path) + 
 "/*/built-in.o"))

r.parts.sort(reverse=True)

for b in r.parts:

scripts/tiny/ksize.py +7 -0
@@ -116,6 +116,13 @@ class Report:
                 self.deltas["data"], self.deltas["bss"]))
          print("\n")
 
+    def __lt__(this, that):
+        if that is None:
+            return 1
+        if not isinstance(that, Report):
+            raise TypeError
+        return this.sizes.total < that.sizes.total
+
      def __cmp__(this, that):
          if that is None:
              return 1
Signature · 7 lines
2.6.6

-- 
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core
#9 lore raw

Re: [PATCH 3/6] ksize.py: Python 3 fixes

Quoted 5 lines · Alejandro Hernandez

Hey Khem,

Ok, now I'm actually awake when reading this, are you saying these changes should go in the same patch as the one for ksum.py?

yes thats right.

Quoted 97 lines · Alejandro Hernandez
Quoted 93 lines

Hey Khem,

Its an old script fro Tom, but as far as I remember it worked fine on python3, although thanks for checking and sending the patch!

Cheers

Alejandro

Quoted 78 lines · Khem Raj
Quoted 4 lines · Alejandro Hernandez

From: Tom Zanussi <[email protected]>

String errors and partial __cmp__ fix.

may be fold it into previous patch.

Quoted 68 lines
---
  scripts/tiny/ksize.py | 17 ++++++++++++-----
  1 file changed, 12 insertions(+), 5 deletions(-)
scripts/tiny/ksize.py +1 -1
index b9d2b19..ea1ca7f 100755
@@ -41,7 +41,7 @@ def usage():
  class Sizes:
      def __init__(self, glob):
          self.title = glob
-        p = Popen("size -t " + glob, shell=True, stdout=PIPE,
 stderr=PIPE)
+        p = Popen("size -t " + str(glob), shell=True, stdout=PIPE,
 stderr=PIPE)
          output = p.communicate()[0].splitlines()
          if len(output) > 2:
              sizes = output[-1].split()[0:4]
scripts/tiny/ksize.py +4 -4
@@ -62,18 +62,18 @@ class Report:
          r = Report(filename, title)
          path = os.path.dirname(filename)
 
-        p = Popen("ls " + path + "/*.o | grep -v built-in.o",
+        p = Popen("ls " + str(path) + "/*.o | grep -v built-in.o",
                    shell=True, stdout=PIPE, stderr=PIPE)
          glob = ' '.join(p.communicate()[0].splitlines())
-        oreport = Report(glob, path + "/*.o")
-        oreport.sizes.title = path + "/*.o"
+        oreport = Report(glob, str(path) + "/*.o")
+        oreport.sizes.title = str(path) + "/*.o"
          r.parts.append(oreport)
 
          if subglob:
              p = Popen("ls " + subglob, shell=True, stdout=PIPE,
 stderr=PIPE)
              for f in p.communicate()[0].splitlines():
                  path = os.path.dirname(f)
-                r.parts.append(Report.create(f, path, path +
 "/*/built-in.o"))
+                r.parts.append(Report.create(f, path, str(path) +
 "/*/built-in.o"))

r.parts.sort(reverse=True)

for b in r.parts:

scripts/tiny/ksize.py +7 -1
@@ -116,6 +116,13 @@ class Report:
                 self.deltas["data"], self.deltas["bss"]))
          print("\n")
 
+    def __lt__(this, that):
+        if that is None:
+            return 1
+        if not isinstance(that, Report):
+            raise TypeError
+        return this.sizes.total < that.sizes.total
+
      def __cmp__(this, that):
          if that is None:
              return 1
--

2.6.6

--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core