From patchwork Sat Aug 2 22:02:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Davis Jr X-Patchwork-Id: 67990 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FCA8C87FD2 for ; Sat, 2 Aug 2025 22:02:53 +0000 (UTC) Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by mx.groups.io with SMTP id smtpd.web11.6833.1754172168094912601 for ; Sat, 02 Aug 2025 15:02:48 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@underview.tech header.s=google header.b=dFG30hH4; spf=pass (domain: underview.tech, ip: 209.85.222.174, mailfrom: vince@underview.tech) Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7e34493ecb4so236322485a.1 for ; Sat, 02 Aug 2025 15:02:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=underview.tech; s=google; t=1754172167; x=1754776967; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1ZejjFbOhTYPl17Yvjar/b3x4tbM3Xyp7IYidkmutcQ=; b=dFG30hH4TAchA2cIFO/stVb4vw/yQzTAR3zG/vn6Db9A+71LkZ0jXuEvL9DJM0tyUZ c0dFyeHs2bY5cjn6HeoukqSUxrtWO1zNOTj2eKW0MV+5Eu8iTPZyKZcRFxu5hxsxXZE/ Z1DWOoGI33u7SD9aogDBvyWZMQwoKjIafVdqxva0LEaM25LpJYE+XMcX8490ofu3aRvp PZq5JLSetXhVDtpPyq34Wfb5gFrJ47Kt5Bz0708MuR0gMPAwDriiVxcyymNFd05P/15F LzuVKTP0za5DsyTTDtYLSeyjkcllqQaVCdaAw46tCZ3/rBqe3Mj0uEEmjn6s53pS8ijw e4Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754172167; x=1754776967; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1ZejjFbOhTYPl17Yvjar/b3x4tbM3Xyp7IYidkmutcQ=; b=JFiBqz29iUXYiGUxio7doNGItEZuUF+IoCD17gmMeFXQ7ZB/v6jJNyZ2QA7L/ruZ4x gcNU1T5oQQW2zw6f1759sWSyywMQ156hXQWmR6jfIa2JRyMlMKRsXwC61kykAXHFmpZ7 R+sjcw03zsabddFgQUn9Npj/Q0Weqozss3Hx7eGgazNNDu8zPnmhbwxode6t4IWmz4Ad D63bsBjEzAyf8BUeItl0WrKndkNbseS6KbEM/8EYMdgiF7zjAmHeyynNp7sjPPIqeJrM jOFRGbO07WyAJawHMtHIRFycLkPizKkm/oPLYbiMgv1ES641sWDHA0sRMGc3uPcovJ8F u+eQ== X-Gm-Message-State: AOJu0YwIx2DYpxE6dJ0evc0ezEt9UlVgaoUhKyJx8GquNVbJ67+qSZjY oRs1drxnxWCz6zdH58cYW/a6y/t3irznruVTklT7/9N008RR4StKo8yyfU9GYeYL8b3U0YfzNLt Jcqhc X-Gm-Gg: ASbGnctgb4Xptdh4fY0mUC2JKSUT3M3qJjdIzGtE2kg0Lng3lU6uudg992dCJhSJYRb HLDLVJcl33UO85au6xWGrh+OSWA1HGgCw+gKukw8mDXXFTZb5hpzhrrd2G8eoeqxo/hZZ3eiDQY f+AtMgrggdOYGTcFa3GxjnuOJZK8kGYkje8RBx3/54cwI0VR9pXcfrDfvaPaVpqM0D8qbcnY+fM RCN6SRarG72UJ0h6fNYRYlKYKsqt5c3+4wjvOR4LHO8NZtKg57eWugWzvBcsJ+QblRdovffjF8+ NKu8dkP06EYZcQBJrUOmFyUssZr7upsFCnWqR21hoU8CYx0df7I0zZeDItgRjZEHF1yL6oFspLK kRjH1kWRlg4k= X-Google-Smtp-Source: AGHT+IFrf/W84sMGJb4nFYndCJ2yS1AnH7O5vGcAABfcroRslv+91kwaXzAttYLO4tKdTGqwtFu6hg== X-Received: by 2002:a05:620a:19:b0:7e0:9f9b:c1f9 with SMTP id af79cd13be357-7e69626833amr572950385a.3.1754172166558; Sat, 02 Aug 2025 15:02:46 -0700 (PDT) Received: from vince-server.. ([2601:406:4d01:1820::71f9]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7e67f706406sm373028385a.49.2025.08.02.15.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Aug 2025 15:02:46 -0700 (PDT) From: Vincent Davis Jr To: openembedded-core@lists.openembedded.org Cc: Vincent Davis Jr Subject: [PATCH v6 1/3] bootimg_pcbios: initial import of grub legacy bios boot Date: Sat, 2 Aug 2025 18:02:28 -0400 Message-ID: <20250802220229.2826203-2-vince@underview.tech> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Sat, 02 Aug 2025 22:02:53 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/221392 Moves syslinux config file creation, partition prepare, and mbr install tasks into there own seperate functions before removal from SourcePlugin class functions. Add 3 new functions for creation of grub config, preparing boot partition to contain grub config and modules, and install grub boot.img to resulting wic image. Signed-off-by: Vincent Davis Jr --- .../lib/wic/plugins/source/bootimg_pcbios.py | 351 +++++++++++++++++- 1 file changed, 350 insertions(+), 1 deletion(-) diff --git a/scripts/lib/wic/plugins/source/bootimg_pcbios.py b/scripts/lib/wic/plugins/source/bootimg_pcbios.py index 21f41e00bb..5138b680c9 100644 --- a/scripts/lib/wic/plugins/source/bootimg_pcbios.py +++ b/scripts/lib/wic/plugins/source/bootimg_pcbios.py @@ -13,7 +13,9 @@ import logging import os import re +import shutil +from glob import glob from wic import WicError from wic.engine import get_custom_config from wic.pluginbase import SourcePlugin @@ -24,11 +26,51 @@ logger = logging.getLogger('wic') class BootimgPcbiosPlugin(SourcePlugin): """ - Create MBR boot partition and install syslinux on it. + Creates boot partition that is legacy BIOS firmare bootable with + MBR/MSDOS as partition table format. Plugin will install caller + selected bootloader directly to resulting wic image. + + Supported Bootloaders: + * syslinux (default) + * grub + + ****************** Wic Plugin Depends/Vars ****************** + WKS_FILE_DEPENDS = "grub-native grub" + WKS_FILE_DEPENDS = "syslinux-native syslinux" + + # Optional variables + GRUB_PREFIX_PATH = '/boot/grub2' # Default: /boot/grub + GRUB_MKIMAGE_FORMAT_PC = 'i386-pc' # Default: i386-pc + + WICVARS:append = "\ + GRUB_PREFIX_PATH \ + GRUB_MKIMAGE_FORMAT_PC \ + " + ****************** Wic Plugin Depends/Vars ****************** + + + **************** Example kickstart Legacy Bios Grub Boot **************** + part boot --label bios_boot --fstype ext4 --offset 1024 --fixed-size 78M + --source bootimg_pcbios --sourceparams="loader-bios=grub" --active + + part roots --label rootfs --fstype ext4 --source rootfs --use-uuid + bootloader --ptable msdos --source bootimg_pcbios + **************** Example kickstart Legacy Bios Grub Boot **************** + + + *************** Example kickstart Legacy Bios Syslinux Boot **************** + part /boot --source bootimg_pcbios --sourceparams="loader-bios=syslinux" + --ondisk sda --label boot --fstype vfat --align 1024 --active + + part roots --label rootfs --fstype ext4 --source rootfs --use-uuid + bootloader --ptable msdos --source bootimg_pcbios """ name = 'bootimg_pcbios' + # Variable required for do_install_disk + loader = '' + @classmethod def _get_bootimg_dir(cls, bootimg_dir, dirname): """ @@ -207,3 +249,310 @@ class BootimgPcbiosPlugin(SourcePlugin): part.size = int(bootimg_size) part.source_file = bootimg + + @classmethod + def _get_staging_libdir(cls): + """ + For unknown reasons when running test with poky + STAGING_LIBDIR gets unset when wic create is executed. + Bellow is a hack to determine what STAGING_LIBDIR should + be if not specified. + """ + + staging_libdir = get_bitbake_var('STAGING_LIBDIR') + staging_dir_target = get_bitbake_var('STAGING_DIR_TARGET') + + if not staging_libdir: + staging_libdir = '%s/usr/lib64' % staging_dir_target + if not os.path.isdir(staging_libdir): + staging_libdir = '%s/usr/lib32' % staging_dir_target + if not os.path.isdir(staging_libdir): + staging_libdir = '%s/usr/lib' % staging_dir_target + + return staging_libdir + + @classmethod + def _get_bootloader_config(cls, bootloader, loader): + custom_cfg = None + + if bootloader.configfile: + custom_cfg = get_custom_config(bootloader.configfile) + if custom_cfg: + logger.debug("Using custom configuration file %s " + "for %s.cfg", bootloader.configfile, + loader) + return custom_cfg + else: + raise WicError("configfile is specified but failed to " + "get it from %s." % bootloader.configfile) + return custom_cfg + + @classmethod + def _do_configure_syslinux_cfg(cls, creator, cr_workdir, bootimg_dir): + hdddir = "%s/hdd/boot" % cr_workdir + bootloader = creator.ks.bootloader + + syslinux_conf = cls._get_bootloader_config(bootloader, 'syslinux') + + install_cmd = "install -d %s" % hdddir + exec_cmd(install_cmd) + + bootloader.timeout = (bootloader.timeout if bootloader.timeout else 500) + + if not syslinux_conf: + # Create syslinux configuration using parameters from wks file + splash = os.path.join(hdddir, "/splash.jpg") + if os.path.exists(splash): + splashline = "menu background splash.jpg" + else: + splashline = "" + + syslinux_conf = "" + syslinux_conf += "PROMPT 0\n" + syslinux_conf += "TIMEOUT %s\n" % (bootloader.timeout) + syslinux_conf += "\n" + syslinux_conf += "ALLOWOPTIONS 1\n" + syslinux_conf += "SERIAL 0 115200\n" + syslinux_conf += "\n" + if splashline: + syslinux_conf += "%s\n" % splashline + syslinux_conf += "DEFAULT boot\n" + syslinux_conf += "LABEL boot\n" + + kernel = "/" + get_bitbake_var("KERNEL_IMAGETYPE") + syslinux_conf += "KERNEL " + kernel + "\n" + + syslinux_conf += "APPEND label=boot root=%s %s\n" % \ + (creator.rootdev, bootloader.append or '') + + logger.debug("Writing syslinux config %s/syslinux.cfg", hdddir) + cfg = open("%s/syslinux.cfg" % hdddir, "w") + cfg.write(syslinux_conf) + cfg.close() + + @classmethod + def _do_prepare_syslinux(cls, part, cr_workdir, oe_builddir, + bootimg_dir, kernel_dir, native_sysroot): + + bootimg_dir = cls._get_bootimg_dir(bootimg_dir, 'syslinux') + + staging_kernel_dir = kernel_dir + + hdddir = "%s/hdd/boot" % cr_workdir + + kernel = get_bitbake_var("KERNEL_IMAGETYPE") + if get_bitbake_var("INITRAMFS_IMAGE_BUNDLE") == "1": + if get_bitbake_var("INITRAMFS_IMAGE"): + kernel = "%s-%s.bin" % \ + (get_bitbake_var("KERNEL_IMAGETYPE"), get_bitbake_var("INITRAMFS_LINK_NAME")) + + cmds = ("install -m 0644 %s/%s %s/%s" % + (staging_kernel_dir, kernel, hdddir, get_bitbake_var("KERNEL_IMAGETYPE")), + "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" % + (bootimg_dir, hdddir), + "install -m 0644 %s/syslinux/vesamenu.c32 %s/vesamenu.c32" % + (bootimg_dir, hdddir), + "install -m 444 %s/syslinux/libcom32.c32 %s/libcom32.c32" % + (bootimg_dir, hdddir), + "install -m 444 %s/syslinux/libutil.c32 %s/libutil.c32" % + (bootimg_dir, hdddir)) + + for install_cmd in cmds: + exec_cmd(install_cmd) + + du_cmd = "du -bks %s" % hdddir + out = exec_cmd(du_cmd) + blocks = int(out.split()[0]) + + extra_blocks = part.get_extra_block_count(blocks) + + if extra_blocks < BOOTDD_EXTRA_SPACE: + extra_blocks = BOOTDD_EXTRA_SPACE + + blocks += extra_blocks + + logger.debug("Added %d extra blocks to %s to get to %d total blocks", + extra_blocks, part.mountpoint, blocks) + + # dosfs image, created by mkdosfs + bootimg = "%s/boot%s.img" % (cr_workdir, part.lineno) + + label = part.label if part.label else "boot" + + dosfs_cmd = "mkdosfs -n %s -i %s -S 512 -C %s %d" % \ + (label, part.fsuuid, bootimg, blocks) + exec_native_cmd(dosfs_cmd, native_sysroot) + + mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) + exec_native_cmd(mcopy_cmd, native_sysroot) + + syslinux_cmd = "syslinux %s" % bootimg + exec_native_cmd(syslinux_cmd, native_sysroot) + + chmod_cmd = "chmod 644 %s" % bootimg + exec_cmd(chmod_cmd) + + du_cmd = "du -Lbks %s" % bootimg + out = exec_cmd(du_cmd) + bootimg_size = out.split()[0] + + part.size = int(bootimg_size) + part.source_file = bootimg + + @classmethod + def _do_install_syslinux(cls, creator, bootimg_dir, + native_sysroot, full_path): + + bootimg_dir = cls._get_bootimg_dir(bootimg_dir, 'syslinux') + + mbrfile = "%s/syslinux/" % bootimg_dir + if creator.ptable_format == 'msdos': + mbrfile += "mbr.bin" + elif creator.ptable_format == 'gpt': + mbrfile += "gptmbr.bin" + else: + raise WicError("Unsupported partition table: %s" % + creator.ptable_format) + + if not os.path.exists(mbrfile): + raise WicError("Couldn't find %s. If using the -e option, do you " + "have the right MACHINE set in local.conf? If not, " + "is the bootimg_dir path correct?" % mbrfile) + + dd_cmd = "dd if=%s of=%s conv=notrunc" % (mbrfile, full_path) + exec_cmd(dd_cmd, native_sysroot) + + @classmethod + def _do_configure_grub_cfg(cls, creator, cr_workdir): + hdddir = "%s/hdd" % cr_workdir + bootloader = creator.ks.bootloader + + grub_conf = cls._get_bootloader_config(bootloader, 'grub') + + grub_prefix_path = get_bitbake_var('GRUB_PREFIX_PATH') + if not grub_prefix_path: + grub_prefix_path = '/boot/grub' + + grub_path = "%s/%s" %(hdddir, grub_prefix_path) + install_cmd = "install -d %s" % grub_path + exec_cmd(install_cmd) + + bootloader.timeout = (bootloader.timeout if bootloader.timeout else 500) + + if not grub_conf: + grub_conf = 'serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n' + grub_conf += 'set gfxmode=auto\n' + grub_conf += 'set gfxpayload=keep\n\n' + grub_conf += 'set default=0\n\n' + grub_conf += '# Boot automatically after %d secs.\n' % (bootloader.timeout) + grub_conf += 'set timeout=%d\n\n' % (bootloader.timeout) + grub_conf += 'menuentry \'rootfs\' {\n' + grub_conf += '\tsearch --no-floppy --set=root --label rootfs\n' + grub_conf += '\tprobe --set partuuid --part-uuid ($root)\n' + + kernel = "/boot/" + get_bitbake_var("KERNEL_IMAGETYPE") + grub_conf += '\tlinux %s root=PARTUUID=$partuuid %s\n}\n' % \ + (kernel, bootloader.append if bootloader.append else '') + + logger.debug("Writing grub config %s/grub.cfg", grub_path) + cfg = open("%s/grub.cfg" % grub_path, "w") + cfg.write(grub_conf) + cfg.close() + + @classmethod + def _do_prepare_grub(cls, part, cr_workdir, oe_builddir, + kernel_dir, rootfs_dir, native_sysroot): + """ + 1. Generate embed.cfg that'll later be embedded into core.img. + So, that core.img knows where to search for grub.cfg. + 2. Generate core.img or grub stage 1.5. + 3. Copy modules into partition. + 4. Create partition rootfs file. + """ + + hdddir = "%s/hdd" % cr_workdir + + copy_types = [ '*.mod', '*.o', '*.lst' ] + + builtin_modules = 'boot linux ext2 fat serial part_msdos part_gpt \ + normal multiboot probe biosdisk msdospart configfile search loadenv test' + + staging_libdir = cls._get_staging_libdir() + + grub_format = get_bitbake_var('GRUB_MKIMAGE_FORMAT_PC') + if not grub_format: + grub_format = 'i386-pc' + + grub_prefix_path = get_bitbake_var('GRUB_PREFIX_PATH') + if not grub_prefix_path: + grub_prefix_path = '/boot/grub' + + grub_path = "%s/%s" %(hdddir, grub_prefix_path) + core_img = '%s/grub-bios-core.img' % (kernel_dir) + grub_mods_path = '%s/grub/%s' % (staging_libdir, grub_format) + + # Generate embedded grub config + embed_cfg_str = 'search.file %s/grub.cfg root\n' % (grub_prefix_path) + embed_cfg_str += 'set prefix=($root)%s\n' % (grub_prefix_path) + embed_cfg_str += 'configfile ($root)%s/grub.cfg\n' % (grub_prefix_path) + cfg = open('%s/embed.cfg' % (kernel_dir), 'w+') + cfg.write(embed_cfg_str) + cfg.close() + + # core.img doesn't get included into boot partition + # it's later dd onto the resulting wic image. + grub_mkimage = 'grub-mkimage \ + --prefix=%s \ + --format=%s \ + --config=%s/embed.cfg \ + --directory=%s \ + --output=%s %s' % \ + (grub_prefix_path, grub_format, kernel_dir, + grub_mods_path, core_img, builtin_modules) + exec_native_cmd(grub_mkimage, native_sysroot) + + # Copy grub modules + install_dir = '%s/%s/%s' % (hdddir, grub_prefix_path, grub_format) + os.makedirs(install_dir, exist_ok=True) + + for ctype in copy_types: + files = glob('%s/grub/%s/%s' % \ + (staging_libdir, grub_format, ctype)) + for file in files: + shutil.copy2(file, install_dir, follow_symlinks=True) + + # Create boot partition + logger.debug('Prepare partition using rootfs in %s', hdddir) + part.prepare_rootfs(cr_workdir, oe_builddir, hdddir, + native_sysroot, False) + + @classmethod + def _do_install_grub(cls, creator, kernel_dir, + native_sysroot, full_path): + core_img = '%s/grub-bios-core.img' % (kernel_dir) + + staging_libdir = cls._get_staging_libdir() + + grub_format = get_bitbake_var('GRUB_MKIMAGE_FORMAT_PC') + if not grub_format: + grub_format = 'i386-pc' + + boot_img = '%s/grub/%s/boot.img' %(staging_libdir, grub_format) + if not os.path.exists(boot_img): + raise WicError("Couldn't find %s. Did you include " + "do_image_wic[depends] += \"grub:do_populate_sysroot\" " + "in your image recipe" % boot_img) + + # Install boot.img or grub stage 1 + dd_cmd = "dd if=%s of=%s conv=notrunc bs=1 seek=0 count=440" % (boot_img, full_path) + exec_cmd(dd_cmd, native_sysroot) + + if creator.ptable_format == 'msdos': + # Install core.img or grub stage 1.5 + dd_cmd = "dd if=%s of=%s conv=notrunc bs=1 seek=512" % (core_img, full_path) + exec_cmd(dd_cmd, native_sysroot) + elif creator.ptable_format == 'gpt': + logger.debug('Update core.img stored on bios boot partition') + else: + raise WicError("Unsupported partition table: %s" % + creator.ptable_format) From patchwork Sat Aug 2 22:02:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Davis Jr X-Patchwork-Id: 67991 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12419C87FD2 for ; Sat, 2 Aug 2025 22:05:03 +0000 (UTC) Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by mx.groups.io with SMTP id smtpd.web10.6925.1754172296170975370 for ; Sat, 02 Aug 2025 15:04:56 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@underview.tech header.s=google header.b=Yhuwz+AV; spf=pass (domain: underview.tech, ip: 209.85.222.177, mailfrom: vince@underview.tech) Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-7e699d1179cso99015585a.2 for ; Sat, 02 Aug 2025 15:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=underview.tech; s=google; t=1754172295; x=1754777095; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QaOAG5PlHsZOLXXACUh4LeF2FLe7m+DFvUJOS1CTZBo=; b=Yhuwz+AVlSQznf5WWPuKi4FQyn4liLKr5wflJGt0AU4Hen2G93CEWrUDKlSUySBF4A +jRLA6ph29i1iteB5GvBM62F7QUfgs02MTWgLVFitK+oO9t1/wzftiFfTYmLGRqU5nWY hyLW/ZWPr5yw+RCliqPM8hlAvqtGF+qJZT63/77mF/3Vzb27WNdAsU+B3pwvugLhyQHp rEZSHRUapw1VSW8iIEIu5BHJaibc+rvYzVq7Y3uqYhQrD/Oqnm7o6HyjuP4TcoVTYSNr deaKf/AcSTR/pidJLhxZWv86KpuPiB53GBcqDYZFsYY3xHuhNj3kucUhktvQwPdSbv+p W96Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754172295; x=1754777095; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QaOAG5PlHsZOLXXACUh4LeF2FLe7m+DFvUJOS1CTZBo=; b=iHkWp3Gx6abkmrQ4Aemp451kQkiw/sYFQ+tF9obE8JjG1Uev03ZPokWpAqW0fV3yAu /Q3X9QJiUuK1s1pK3BbjzdtEc+T0xpJgLh60GezIB27PwPufkGvkwWzQtaWseIPpsQd0 wOOr8dBQs+Z/4vYDnesQmAMBWgG0YrdssObe+5l8DBHsF/Kp/e2uch5Whol2zAyAwch+ gk8rdAuHHzSAY80tkUcbO/AjfyoWbr/TaRU3lAcG5tXYKems921N/1ImY1wmCM8Rui0G 6pDciF5FcDroA71hWvtzzMDWPtWowiS9KkliIDhCUcLUbk3BO49Ifkxx6S6DTIDyEMnw 8hOA== X-Gm-Message-State: AOJu0Yz9Ej3sQDDjvuKJ2MtJU6keTKRZNI+46GY0s5O7gjXdfHbtA8hg fE5nwMB6KM/5d7XA05+S7QYUPa5QSmzW+A94L24AYIVw8mg11dy92p7KcVe27ebPNmGZjKxXR4i f5l5S X-Gm-Gg: ASbGncuZ3vGAKvdFXKrfm1rD/bWKyxrbqFm0bTlIW1rBSQ3f+rZTlRVSy8gwwtiUSSj Gh5ifo1BOLOCVIrgAe9VqezSjrMBUF6YsBB5ZNuIi+6TP/u0iX/LQri56CXyr3PSTX+gV8uB8Wf pdex1zU3QaCZZyt72IM+3ltTdycwWcE7RmrWKdlUfbv8wD4z5NG0KEmMktqihEsPeAh9CR8vn22 jIeYk3UTenL1YbSC7e4tU6pHt4WSGp3iNNF7UD755nnO5J/UlummJ466nBh6a00FSGTd89LS/rE QzAnpjHDu7Pkp0chY94oaAc4kEVs6ZZfr4QD9bMtwTlYrq666UURQg6gbVe5oe+4/YG37v99cvb 2Pjfioj0+dIAFxRr3b6YHog== X-Google-Smtp-Source: AGHT+IE5ddXQcKT8gCr7uapjyeHvLWG9/OuFVQf2LdZVTLmQW4KSY7mnobIgmzshY8fRmUXyxht2Rg== X-Received: by 2002:a05:620a:46a6:b0:7e3:35dd:4829 with SMTP id af79cd13be357-7e69636879amr587563885a.46.1754172294769; Sat, 02 Aug 2025 15:04:54 -0700 (PDT) Received: from vince-server.. ([2601:406:4d01:1820::71f9]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7e67f706406sm373028385a.49.2025.08.02.15.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Aug 2025 15:04:53 -0700 (PDT) From: Vincent Davis Jr To: openembedded-core@lists.openembedded.org Cc: Vincent Davis Jr Subject: [PATCH v6 2/3] bootimg_pcbios: final import of grub legacy bios boot Date: Sat, 2 Aug 2025 18:02:30 -0400 Message-ID: <20250802220229.2826203-4-vince@underview.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250802220229.2826203-2-vince@underview.tech> References: <20250802220229.2826203-2-vince@underview.tech> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Sat, 02 Aug 2025 22:05:03 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/221393 Due to the bootimg_biosplusefi source_params['loader'] had to be named source_params['loader-bios'] so not to create conflict in the wics plugin Removes old syslinux implementation as it was copied into seperate functions and adds ability to set and or not set source_params. If source_params set check for both * syslinux * grub if not set default to using syslinux Signed-off-by: Vincent Davis Jr --- .../lib/wic/plugins/source/bootimg_pcbios.py | 160 ++++-------------- 1 file changed, 33 insertions(+), 127 deletions(-) diff --git a/scripts/lib/wic/plugins/source/bootimg_pcbios.py b/scripts/lib/wic/plugins/source/bootimg_pcbios.py index 5138b680c9..27d7963389 100644 --- a/scripts/lib/wic/plugins/source/bootimg_pcbios.py +++ b/scripts/lib/wic/plugins/source/bootimg_pcbios.py @@ -96,27 +96,19 @@ class BootimgPcbiosPlugin(SourcePlugin): Called after all partitions have been prepared and assembled into a disk image. In this case, we install the MBR. """ - bootimg_dir = cls._get_bootimg_dir(bootimg_dir, 'syslinux') - mbrfile = "%s/syslinux/" % bootimg_dir - if creator.ptable_format == 'msdos': - mbrfile += "mbr.bin" - elif creator.ptable_format == 'gpt': - mbrfile += "gptmbr.bin" - else: - raise WicError("Unsupported partition table: %s" % - creator.ptable_format) - - if not os.path.exists(mbrfile): - raise WicError("Couldn't find %s. If using the -e option, do you " - "have the right MACHINE set in local.conf? If not, " - "is the bootimg_dir path correct?" % mbrfile) full_path = creator._full_path(workdir, disk_name, "direct") logger.debug("Installing MBR on disk %s as %s with size %s bytes", disk_name, full_path, disk.min_size) - dd_cmd = "dd if=%s of=%s conv=notrunc" % (mbrfile, full_path) - exec_cmd(dd_cmd, native_sysroot) + if cls.loader == 'grub': + cls._do_install_grub(creator, kernel_dir, + native_sysroot, full_path) + elif cls.loader == 'syslinux': + cls._do_install_syslinux(creator, bootimg_dir, + native_sysroot, full_path) + else: + raise WicError("boot loader some how not specified check do_prepare_partition") @classmethod def do_configure_partition(cls, part, source_params, creator, cr_workdir, @@ -125,56 +117,16 @@ class BootimgPcbiosPlugin(SourcePlugin): """ Called before do_prepare_partition(), creates syslinux config """ - hdddir = "%s/hdd/boot" % cr_workdir - - install_cmd = "install -d %s" % hdddir - exec_cmd(install_cmd) - - bootloader = creator.ks.bootloader - - custom_cfg = None - if bootloader.configfile: - custom_cfg = get_custom_config(bootloader.configfile) - if custom_cfg: - # Use a custom configuration for grub - syslinux_conf = custom_cfg - logger.debug("Using custom configuration file %s " - "for syslinux.cfg", bootloader.configfile) - else: - raise WicError("configfile is specified but failed to " - "get it from %s." % bootloader.configfile) - if not custom_cfg: - # Create syslinux configuration using parameters from wks file - splash = os.path.join(cr_workdir, "/hdd/boot/splash.jpg") - if os.path.exists(splash): - splashline = "menu background splash.jpg" + try: + if source_params['loader-bios'] == 'grub': + cls._do_configure_grub_cfg(creator, cr_workdir) + elif source_params['loader-bios'] == 'syslinux': + cls._do_configure_syslinux_cfg(creator, cr_workdir, bootimg_dir) else: - splashline = "" - - syslinux_conf = "" - syslinux_conf += "PROMPT 0\n" - syslinux_conf += "TIMEOUT " + str(bootloader.timeout) + "\n" - syslinux_conf += "\n" - syslinux_conf += "ALLOWOPTIONS 1\n" - syslinux_conf += "SERIAL 0 115200\n" - syslinux_conf += "\n" - if splashline: - syslinux_conf += "%s\n" % splashline - syslinux_conf += "DEFAULT boot\n" - syslinux_conf += "LABEL boot\n" - - kernel = "/" + get_bitbake_var("KERNEL_IMAGETYPE") - syslinux_conf += "KERNEL " + kernel + "\n" - - syslinux_conf += "APPEND label=boot root=%s %s\n" % \ - (creator.rootdev, bootloader.append) - - logger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg", - cr_workdir) - cfg = open("%s/hdd/boot/syslinux.cfg" % cr_workdir, "w") - cfg.write(syslinux_conf) - cfg.close() + raise WicError("unrecognized bootimg_pcbios loader: %s" % source_params['loader-bios']) + except KeyError: + cls._do_configure_syslinux_cfg(creator, cr_workdir, bootimg_dir) @classmethod def do_prepare_partition(cls, part, source_params, creator, cr_workdir, @@ -185,70 +137,24 @@ class BootimgPcbiosPlugin(SourcePlugin): 'prepares' the partition to be incorporated into the image. In this case, prepare content for legacy bios boot partition. """ - bootimg_dir = cls._get_bootimg_dir(bootimg_dir, 'syslinux') - - staging_kernel_dir = kernel_dir - - hdddir = "%s/hdd/boot" % cr_workdir - kernel = get_bitbake_var("KERNEL_IMAGETYPE") - if get_bitbake_var("INITRAMFS_IMAGE_BUNDLE") == "1": - if get_bitbake_var("INITRAMFS_IMAGE"): - kernel = "%s-%s.bin" % \ - (get_bitbake_var("KERNEL_IMAGETYPE"), get_bitbake_var("INITRAMFS_LINK_NAME")) - - cmds = ("install -m 0644 %s/%s %s/%s" % - (staging_kernel_dir, kernel, hdddir, get_bitbake_var("KERNEL_IMAGETYPE")), - "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" % - (bootimg_dir, hdddir), - "install -m 0644 %s/syslinux/vesamenu.c32 %s/vesamenu.c32" % - (bootimg_dir, hdddir), - "install -m 444 %s/syslinux/libcom32.c32 %s/libcom32.c32" % - (bootimg_dir, hdddir), - "install -m 444 %s/syslinux/libutil.c32 %s/libutil.c32" % - (bootimg_dir, hdddir)) - - for install_cmd in cmds: - exec_cmd(install_cmd) - - du_cmd = "du -bks %s" % hdddir - out = exec_cmd(du_cmd) - blocks = int(out.split()[0]) - - extra_blocks = part.get_extra_block_count(blocks) - - if extra_blocks < BOOTDD_EXTRA_SPACE: - extra_blocks = BOOTDD_EXTRA_SPACE - - blocks += extra_blocks - - logger.debug("Added %d extra blocks to %s to get to %d total blocks", - extra_blocks, part.mountpoint, blocks) - - # dosfs image, created by mkdosfs - bootimg = "%s/boot%s.img" % (cr_workdir, part.lineno) - - label = part.label if part.label else "boot" - - dosfs_cmd = "mkdosfs -n %s -i %s -S 512 -C %s %d" % \ - (label, part.fsuuid, bootimg, blocks) - exec_native_cmd(dosfs_cmd, native_sysroot) - - mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) - exec_native_cmd(mcopy_cmd, native_sysroot) - - syslinux_cmd = "syslinux %s" % bootimg - exec_native_cmd(syslinux_cmd, native_sysroot) - - chmod_cmd = "chmod 644 %s" % bootimg - exec_cmd(chmod_cmd) - - du_cmd = "du -Lbks %s" % bootimg - out = exec_cmd(du_cmd) - bootimg_size = out.split()[0] - - part.size = int(bootimg_size) - part.source_file = bootimg + try: + if source_params['loader-bios'] == 'grub': + cls._do_prepare_grub(part, cr_workdir, oe_builddir, + kernel_dir, rootfs_dir, native_sysroot) + elif source_params['loader-bios'] == 'syslinux': + cls._do_prepare_syslinux(part, cr_workdir, oe_builddir, + bootimg_dir, kernel_dir, native_sysroot) + else: + raise WicError("unrecognized bootimg_pcbios loader: %s" % source_params['loader-bios']) + + # Required by do_install_disk + cls.loader = source_params['loader-bios'] + except KeyError: + # Required by do_install_disk + cls.loader = 'syslinux' + cls._do_prepare_syslinux(part, cr_workdir, oe_builddir, + bootimg_dir, kernel_dir, native_sysroot) @classmethod def _get_staging_libdir(cls): From patchwork Sat Aug 2 22:02:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Davis Jr X-Patchwork-Id: 67992 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC873C87FD2 for ; Sat, 2 Aug 2025 22:05:22 +0000 (UTC) Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by mx.groups.io with SMTP id smtpd.web10.6932.1754172312722346491 for ; Sat, 02 Aug 2025 15:05:12 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@underview.tech header.s=google header.b=Uq4a0M+/; spf=pass (domain: underview.tech, ip: 209.85.222.176, mailfrom: vince@underview.tech) Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7e34493ecb4so236474785a.1 for ; Sat, 02 Aug 2025 15:05:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=underview.tech; s=google; t=1754172311; x=1754777111; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bGLy1iMR67fvn+6SuMga8KLU1s1FK38i/nCe0V5V9Y8=; b=Uq4a0M+/Xrd3CoKkLVVipzTWR4NBa4x6MSG5OuFaYEJdOT2q3FuM8dPLy7uTaIDwWf MkxIRYQJYMbaOJJb/sSL3AINzspe50cyzykr2dW/45cla0xWgtrAxYA567FnKJFJtath rwI0b3M+cwVWjWA5rHV94A7k8gpM8q66eR1ETBPb0lKMbeercyvWvHrc6Ss+RACsm/xG LYXIJziH6YdObkDD/wLTCHIkvr4633pZ0J4isYTW9wywj2eSc2JEzG2dQNqt9w80bF4t IbJ2gdN0n/Yf25FEcotrpFzccPQtobeNlS9B+se9slecWCk12RHp6IR1EXebaLM+GddP /Xvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754172311; x=1754777111; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bGLy1iMR67fvn+6SuMga8KLU1s1FK38i/nCe0V5V9Y8=; b=Q5/6xP7DjLaxPt6qqF79YZ6VhnehXNdSohdSMKiTNJNRvuNYz64QHeU9hprI8f/ELq Pcm+G/9uqk4DL/gJEZMco7KOhiGQupzdfB6nrP31l/UfjlV8+kve1wWQ1M7lXZndiDbu kQ8ne6NQ1EC+YVOPKQ1oWc2VsB5Jyn7doHxPPDaW3ARRJ7XKXGCFJ8SOTJni0kfST6x2 6mbgBAwzTcebfvdLpTR5UNYv+9UXO+PHDIM2b754cig7tfAF+oGQY5V1RRyjGbcYCzhT XnwTW2Zrt90xNfHngMyjSXvcCBFY83IuU5KF/lRchvStT3h/etRdK0sUuShAo5SXfjaC M4pw== X-Gm-Message-State: AOJu0Yw8Sr49EdO+upAQzBF5h+b0iGXlANH4OSPcnc+IBoHAInC+14+2 iXEJNwE+LtNfuDWGYDfpcl/LT8FgqQdXSR1gDcYbpInvyapwvp9lExAO9jQnXWwoF1ivMw+kk3k e0ntF X-Gm-Gg: ASbGnctbObRiA1L2IWAMroDrj73BCtO+49zfnVhNGMMh+0yqGAqo3jEl7/hlFp6Wcq9 aIgknQ7jRozvl10IsMVSyVIZSCDr7DvKuixIEc9ZGjeMADxgVmOuIMjwgoplS5jBKy4zRzU31qv atzouOheNE9YFOYwPx8KtfZxkIBVbI1Nab+KhVGqMDjFR8L5wqRdVYTR2tgqgvNZFzvsIaesgtM qri2LiCW+kum2hVCZggqLAzPY8aBJQ9si1Y9bEnbcdh/0IULNlqIojC6fe1qCQVdBRgdf7jBrN3 ueovu9Ll1QB2OauC2MTtgjgsVdLJzHsB0CMvR3HLKvE2zZQyPyGan4KGOxOA5oLz40+XTdkO7I7 9iacAO44lMGk= X-Google-Smtp-Source: AGHT+IEowuWfpeKvgWx7okJd+IfBPK4rJMDHgcuvqsd+KSibpgV3wmRT867xRE8dZdtbPs4rHNnF6w== X-Received: by 2002:a05:620a:7005:b0:7e7:f84c:9d6a with SMTP id af79cd13be357-7e7f84ca068mr21074185a.32.1754172311164; Sat, 02 Aug 2025 15:05:11 -0700 (PDT) Received: from vince-server.. ([2601:406:4d01:1820::71f9]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7e67f706406sm373028385a.49.2025.08.02.15.05.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Aug 2025 15:05:10 -0700 (PDT) From: Vincent Davis Jr To: openembedded-core@lists.openembedded.org Cc: Vincent Davis Jr Subject: [PATCH v6 3/3] oe-selftest: add wic.Wic.test_grub_install_pcbios Date: Sat, 2 Aug 2025 18:02:32 -0400 Message-ID: <20250802220229.2826203-6-vince@underview.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250802220229.2826203-2-vince@underview.tech> References: <20250802220229.2826203-2-vince@underview.tech> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Sat, 02 Aug 2025 22:05:22 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/221394 wic.Wic.test_grub_install_pcbios test Test updates to the bootimg_pcbios plugin that enables support for installing grub directly to the resulting wic image. The test checks to see if the wics plugin generates a wic image. Then see's if normal.mod and grub.cfg are located in the boot partition. Signed-off-by: Vincent Davis Jr --- meta/lib/oeqa/selftest/cases/wic.py | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py index 680f99d381..44442e402d 100644 --- a/meta/lib/oeqa/selftest/cases/wic.py +++ b/meta/lib/oeqa/selftest/cases/wic.py @@ -215,6 +215,47 @@ class Wic(WicTestCase): found, "The kernel image '{}' was not found in the boot partition".format(kimgtype) ) + @skipIfNotArch(['x86_64']) + def test_grub_install_pcbios(self): + """ + Test the installation of the grub modules + config + into the boot directory in the resulting wic image. + """ + + # create a temporary file for the WKS content + with NamedTemporaryFile("w", suffix=".wks") as wks: + wks.write( + 'part --source bootimg_pcbios --sourceparams="loader-bios=grub" ' + '--offset 1024 --fixed-size 78M --label boot --active\n' + 'bootloader --ptable msdos --source bootimg_pcbios\n' + ) + wks.flush() + # create a temporary directory to extract the disk image to + with TemporaryDirectory() as tmpdir: + img = "core-image-minimal" + config = 'DEPENDS:pn-%s += "grub-native grub"' % (img) + + self.append_config(config) + bitbake(img) + self.remove_config(config) + + cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir) + runCmd(cmd) + + wksname = os.path.splitext(os.path.basename(wks.name))[0] + out = glob(os.path.join(self.resultdir, "%s-*.direct" % wksname)) + self.assertEqual(1, len(out)) + + sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') + + # Check if grub.cfg is installed + result = runCmd("wic ls %s:1/boot/grub -n %s" % (out[0], sysroot)) + self.assertIn('grub', result.output) + + # Check if normal.mod is installed + result = runCmd("wic ls %s:1/boot/grub/i386-pc -n %s" % (out[0], sysroot)) + self.assertIn('normal', result.output) + def test_build_image_name(self): """Test wic create wictestdisk --image-name=core-image-minimal""" cmd = "wic create wictestdisk --image-name=core-image-minimal -o %s" % self.resultdir