diff options
Diffstat (limited to 'scripts/lib/wic')
29 files changed, 1230 insertions, 497 deletions
diff --git a/scripts/lib/wic/canned-wks/common.wks.inc b/scripts/lib/wic/canned-wks/common.wks.inc index 89880b417b..4a440ddafe 100644 --- a/scripts/lib/wic/canned-wks/common.wks.inc +++ b/scripts/lib/wic/canned-wks/common.wks.inc | |||
| @@ -1,3 +1,3 @@ | |||
| 1 | # This file is included into 3 canned wks files from this directory | 1 | # This file is included into 3 canned wks files from this directory |
| 2 | part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024 | 2 | part /boot --source bootimg_pcbios --ondisk sda --label boot --active --align 1024 |
| 3 | part / --source rootfs --use-uuid --fstype=ext4 --label platform --align 1024 | 3 | part / --source rootfs --use-uuid --fstype=ext4 --label platform --align 1024 |
diff --git a/scripts/lib/wic/canned-wks/directdisk-gpt.wks b/scripts/lib/wic/canned-wks/directdisk-gpt.wks index 8d7d8de6ea..cb640056f1 100644 --- a/scripts/lib/wic/canned-wks/directdisk-gpt.wks +++ b/scripts/lib/wic/canned-wks/directdisk-gpt.wks | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | # can directly dd to boot media. | 3 | # can directly dd to boot media. |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024 | 6 | part /boot --source bootimg_pcbios --ondisk sda --label boot --active --align 1024 |
| 7 | part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid | 7 | part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid |
| 8 | 8 | ||
| 9 | bootloader --ptable gpt --timeout=0 --append="rootwait rootfstype=ext4 video=vesafb vga=0x318 console=tty0 console=ttyS0,115200n8" | 9 | bootloader --ptable gpt --timeout=0 --append="rootwait rootfstype=ext4 video=vesafb vga=0x318 console=tty0 console=ttyS0,115200n8" |
diff --git a/scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks b/scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks index f61d941d6d..4fd1999ffb 100644 --- a/scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks +++ b/scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks | |||
| @@ -15,7 +15,7 @@ | |||
| 15 | # | 15 | # |
| 16 | # - or any combinations of -r and --rootfs command line options | 16 | # - or any combinations of -r and --rootfs command line options |
| 17 | 17 | ||
| 18 | part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024 | 18 | part /boot --source bootimg_pcbios --ondisk sda --label boot --active --align 1024 |
| 19 | part / --source rootfs --rootfs-dir=rootfs1 --ondisk sda --fstype=ext4 --label platform --align 1024 | 19 | part / --source rootfs --rootfs-dir=rootfs1 --ondisk sda --fstype=ext4 --label platform --align 1024 |
| 20 | part /rescue --source rootfs --rootfs-dir=rootfs2 --ondisk sda --fstype=ext4 --label secondary --align 1024 | 20 | part /rescue --source rootfs --rootfs-dir=rootfs2 --ondisk sda --fstype=ext4 --label secondary --align 1024 |
| 21 | 21 | ||
diff --git a/scripts/lib/wic/canned-wks/efi-bootdisk.wks.in b/scripts/lib/wic/canned-wks/efi-bootdisk.wks.in index 7300e65e32..5211972955 100644 --- a/scripts/lib/wic/canned-wks/efi-bootdisk.wks.in +++ b/scripts/lib/wic/canned-wks/efi-bootdisk.wks.in | |||
| @@ -1,3 +1,3 @@ | |||
| 1 | bootloader --ptable gpt | 1 | bootloader --ptable gpt |
| 2 | part /boot --source rootfs --rootfs-dir=${IMAGE_ROOTFS}/boot --fstype=vfat --label boot --active --align 1024 --use-uuid --overhead-factor 1.0 | 2 | part /boot --source rootfs --rootfs-dir=${IMAGE_ROOTFS}/boot --fstype=vfat --label boot --active --align 1024 --use-uuid --overhead-factor 1.2 |
| 3 | part / --source rootfs --fstype=ext4 --label root --align 1024 --exclude-path boot/ | 3 | part / --source rootfs --fstype=ext4 --label root --align 1024 --exclude-path boot/ |
diff --git a/scripts/lib/wic/canned-wks/efi-uki-bootdisk.wks.in b/scripts/lib/wic/canned-wks/efi-uki-bootdisk.wks.in new file mode 100644 index 0000000000..cac0fa32cd --- /dev/null +++ b/scripts/lib/wic/canned-wks/efi-uki-bootdisk.wks.in | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | bootloader --ptable gpt --timeout=5 | ||
| 2 | part /boot --source bootimg_efi --sourceparams="loader=${EFI_PROVIDER}" --label boot --active --align 1024 --use-uuid --part-name="ESP" --part-type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B --overhead-factor=1 | ||
| 3 | part / --source rootfs --fstype=ext4 --label root --align 1024 --exclude-path boot/ | ||
diff --git a/scripts/lib/wic/canned-wks/mkefidisk.wks b/scripts/lib/wic/canned-wks/mkefidisk.wks index 9f534fe184..16dfe76dfe 100644 --- a/scripts/lib/wic/canned-wks/mkefidisk.wks +++ b/scripts/lib/wic/canned-wks/mkefidisk.wks | |||
| @@ -2,10 +2,10 @@ | |||
| 2 | # long-description: Creates a partitioned EFI disk image that the user | 2 | # long-description: Creates a partitioned EFI disk image that the user |
| 3 | # can directly dd to boot media. | 3 | # can directly dd to boot media. |
| 4 | 4 | ||
| 5 | part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024 | 5 | part /boot --source bootimg_efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024 |
| 6 | 6 | ||
| 7 | part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid | 7 | part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid |
| 8 | 8 | ||
| 9 | part swap --ondisk sda --size 44 --label swap1 --fstype=swap | 9 | part swap --ondisk sda --size 44 --label swap1 --fstype=swap |
| 10 | 10 | ||
| 11 | bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0" | 11 | bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=${KERNEL_CONSOLE} console=tty0" |
diff --git a/scripts/lib/wic/canned-wks/mkhybridiso.wks b/scripts/lib/wic/canned-wks/mkhybridiso.wks index 48c5ac4791..c3a030e5b4 100644 --- a/scripts/lib/wic/canned-wks/mkhybridiso.wks +++ b/scripts/lib/wic/canned-wks/mkhybridiso.wks | |||
| @@ -2,6 +2,6 @@ | |||
| 2 | # long-description: Creates an EFI and legacy bootable hybrid ISO image | 2 | # long-description: Creates an EFI and legacy bootable hybrid ISO image |
| 3 | # which can be used on optical media as well as USB media. | 3 | # which can be used on optical media as well as USB media. |
| 4 | 4 | ||
| 5 | part /boot --source isoimage-isohybrid --sourceparams="loader=grub-efi,image_name=HYBRID_ISO_IMG" --ondisk cd --label HYBRIDISO | 5 | part /boot --source isoimage_isohybrid --sourceparams="loader=grub-efi,image_name=HYBRID_ISO_IMG" --ondisk cd --label HYBRIDISO |
| 6 | 6 | ||
| 7 | bootloader --timeout=15 --append="" | 7 | bootloader --timeout=15 --append="" |
diff --git a/scripts/lib/wic/canned-wks/qemuloongarch.wks b/scripts/lib/wic/canned-wks/qemuloongarch.wks new file mode 100644 index 0000000000..8465c7a8c0 --- /dev/null +++ b/scripts/lib/wic/canned-wks/qemuloongarch.wks | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | # short-description: Create qcow2 image for LoongArch QEMU machines | ||
| 2 | |||
| 3 | part / --source rootfs --fstype=ext4 --label root --align 4096 --size 5G | ||
diff --git a/scripts/lib/wic/canned-wks/qemux86-directdisk.wks b/scripts/lib/wic/canned-wks/qemux86-directdisk.wks index 22b45217f1..808997611a 100644 --- a/scripts/lib/wic/canned-wks/qemux86-directdisk.wks +++ b/scripts/lib/wic/canned-wks/qemux86-directdisk.wks | |||
| @@ -4,5 +4,5 @@ | |||
| 4 | 4 | ||
| 5 | include common.wks.inc | 5 | include common.wks.inc |
| 6 | 6 | ||
| 7 | bootloader --timeout=0 --append="rw oprofile.timer=1 rootfstype=ext4 " | 7 | bootloader --timeout=0 --append="rw oprofile.timer=1 rootfstype=ext4 console=tty console=ttyS0 " |
| 8 | 8 | ||
diff --git a/scripts/lib/wic/canned-wks/sdimage-bootpart.wks b/scripts/lib/wic/canned-wks/sdimage-bootpart.wks index 63bc4dab6a..f9f8044f7d 100644 --- a/scripts/lib/wic/canned-wks/sdimage-bootpart.wks +++ b/scripts/lib/wic/canned-wks/sdimage-bootpart.wks | |||
| @@ -2,5 +2,5 @@ | |||
| 2 | # long-description: Creates a partitioned SD card image. Boot files | 2 | # long-description: Creates a partitioned SD card image. Boot files |
| 3 | # are located in the first vfat partition. | 3 | # are located in the first vfat partition. |
| 4 | 4 | ||
| 5 | part /boot --source bootimg-partition --ondisk mmcblk0 --fstype=vfat --label boot --active --align 4 --size 16 | 5 | part /boot --source bootimg_partition --ondisk mmcblk0 --fstype=vfat --label boot --active --align 4 --size 16 |
| 6 | part / --source rootfs --ondisk mmcblk0 --fstype=ext4 --label root --align 4 | 6 | part / --source rootfs --ondisk mmcblk0 --fstype=ext4 --label root --align 4 |
diff --git a/scripts/lib/wic/canned-wks/systemd-bootdisk.wks b/scripts/lib/wic/canned-wks/systemd-bootdisk.wks index 95d7b97a60..3fb2c0e35f 100644 --- a/scripts/lib/wic/canned-wks/systemd-bootdisk.wks +++ b/scripts/lib/wic/canned-wks/systemd-bootdisk.wks | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | # long-description: Creates a partitioned EFI disk image that the user | 2 | # long-description: Creates a partitioned EFI disk image that the user |
| 3 | # can directly dd to boot media. The selected bootloader is systemd-boot. | 3 | # can directly dd to boot media. The selected bootloader is systemd-boot. |
| 4 | 4 | ||
| 5 | part /boot --source bootimg-efi --sourceparams="loader=systemd-boot" --ondisk sda --label msdos --active --align 1024 --use-uuid | 5 | part /boot --source bootimg_efi --sourceparams="loader=systemd-boot" --ondisk sda --label msdos --active --align 1024 --use-uuid |
| 6 | 6 | ||
| 7 | part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid | 7 | part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid |
| 8 | 8 | ||
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py index 674ccfc244..b9e60cbe4e 100644 --- a/scripts/lib/wic/engine.py +++ b/scripts/lib/wic/engine.py | |||
| @@ -180,6 +180,8 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir, | |||
| 180 | os.makedirs(options.outdir) | 180 | os.makedirs(options.outdir) |
| 181 | 181 | ||
| 182 | pname = options.imager | 182 | pname = options.imager |
| 183 | # Don't support '-' in plugin names | ||
| 184 | pname = pname.replace("-", "_") | ||
| 183 | plugin_class = PluginMgr.get_plugins('imager').get(pname) | 185 | plugin_class = PluginMgr.get_plugins('imager').get(pname) |
| 184 | if not plugin_class: | 186 | if not plugin_class: |
| 185 | raise WicError('Unknown plugin: %s' % pname) | 187 | raise WicError('Unknown plugin: %s' % pname) |
| @@ -232,6 +234,16 @@ class Disk: | |||
| 232 | self._psector_size = None | 234 | self._psector_size = None |
| 233 | self._ptable_format = None | 235 | self._ptable_format = None |
| 234 | 236 | ||
| 237 | # define sector size | ||
| 238 | sector_size_str = get_bitbake_var('WIC_SECTOR_SIZE') | ||
| 239 | if sector_size_str is not None: | ||
| 240 | try: | ||
| 241 | self.sector_size = int(sector_size_str) | ||
| 242 | except ValueError: | ||
| 243 | self.sector_size = None | ||
| 244 | else: | ||
| 245 | self.sector_size = None | ||
| 246 | |||
| 235 | # find parted | 247 | # find parted |
| 236 | # read paths from $PATH environment variable | 248 | # read paths from $PATH environment variable |
| 237 | # if it fails, use hardcoded paths | 249 | # if it fails, use hardcoded paths |
| @@ -258,7 +270,13 @@ class Disk: | |||
| 258 | def get_partitions(self): | 270 | def get_partitions(self): |
| 259 | if self._partitions is None: | 271 | if self._partitions is None: |
| 260 | self._partitions = OrderedDict() | 272 | self._partitions = OrderedDict() |
| 261 | out = exec_cmd("%s -sm %s unit B print" % (self.parted, self.imagepath)) | 273 | |
| 274 | if self.sector_size is not None: | ||
| 275 | out = exec_cmd("export PARTED_SECTOR_SIZE=%d; %s -sm %s unit B print" % \ | ||
| 276 | (self.sector_size, self.parted, self.imagepath), True) | ||
| 277 | else: | ||
| 278 | out = exec_cmd("%s -sm %s unit B print" % (self.parted, self.imagepath)) | ||
| 279 | |||
| 262 | parttype = namedtuple("Part", "pnum start end size fstype") | 280 | parttype = namedtuple("Part", "pnum start end size fstype") |
| 263 | splitted = out.splitlines() | 281 | splitted = out.splitlines() |
| 264 | # skip over possible errors in exec_cmd output | 282 | # skip over possible errors in exec_cmd output |
| @@ -359,7 +377,7 @@ class Disk: | |||
| 359 | Remove files/dirs and their contents from the partition. | 377 | Remove files/dirs and their contents from the partition. |
| 360 | This only applies to ext* partition. | 378 | This only applies to ext* partition. |
| 361 | """ | 379 | """ |
| 362 | abs_path = re.sub('\/\/+', '/', path) | 380 | abs_path = re.sub(r'\/\/+', '/', path) |
| 363 | cmd = "{} {} -wR 'rm \"{}\"'".format(self.debugfs, | 381 | cmd = "{} {} -wR 'rm \"{}\"'".format(self.debugfs, |
| 364 | self._get_part_image(pnum), | 382 | self._get_part_image(pnum), |
| 365 | abs_path) | 383 | abs_path) |
diff --git a/scripts/lib/wic/filemap.py b/scripts/lib/wic/filemap.py index 4d9da28172..85b39d5d74 100644 --- a/scripts/lib/wic/filemap.py +++ b/scripts/lib/wic/filemap.py | |||
| @@ -46,6 +46,13 @@ def get_block_size(file_obj): | |||
| 46 | bsize = stat.st_blksize | 46 | bsize = stat.st_blksize |
| 47 | else: | 47 | else: |
| 48 | raise IOError("Unable to determine block size") | 48 | raise IOError("Unable to determine block size") |
| 49 | |||
| 50 | # The logic in this script only supports a maximum of a 4KB | ||
| 51 | # block size | ||
| 52 | max_block_size = 4 * 1024 | ||
| 53 | if bsize > max_block_size: | ||
| 54 | bsize = max_block_size | ||
| 55 | |||
| 49 | return bsize | 56 | return bsize |
| 50 | 57 | ||
| 51 | class ErrorNotSupp(Exception): | 58 | class ErrorNotSupp(Exception): |
diff --git a/scripts/lib/wic/help.py b/scripts/lib/wic/help.py index 4ff7470a6a..6b49a67de9 100644 --- a/scripts/lib/wic/help.py +++ b/scripts/lib/wic/help.py | |||
| @@ -544,18 +544,18 @@ DESCRIPTION | |||
| 544 | the --source param given to that partition. For example, if the | 544 | the --source param given to that partition. For example, if the |
| 545 | partition is set up like this: | 545 | partition is set up like this: |
| 546 | 546 | ||
| 547 | part /boot --source bootimg-pcbios ... | 547 | part /boot --source bootimg_pcbios ... |
| 548 | 548 | ||
| 549 | then the methods defined as class members of the plugin having the | 549 | then the methods defined as class members of the plugin having the |
| 550 | matching bootimg-pcbios .name class member would be used. | 550 | matching bootimg_pcbios .name class member would be used. |
| 551 | 551 | ||
| 552 | To be more concrete, here's the plugin definition that would match | 552 | To be more concrete, here's the plugin definition that would match |
| 553 | a '--source bootimg-pcbios' usage, along with an example method | 553 | a '--source bootimg_pcbios' usage, along with an example method |
| 554 | that would be called by the wic implementation when it needed to | 554 | that would be called by the wic implementation when it needed to |
| 555 | invoke an implementation-specific partition-preparation function: | 555 | invoke an implementation-specific partition-preparation function: |
| 556 | 556 | ||
| 557 | class BootimgPcbiosPlugin(SourcePlugin): | 557 | class BootimgPcbiosPlugin(SourcePlugin): |
| 558 | name = 'bootimg-pcbios' | 558 | name = 'bootimg_pcbios' |
| 559 | 559 | ||
| 560 | @classmethod | 560 | @classmethod |
| 561 | def do_prepare_partition(self, part, ...) | 561 | def do_prepare_partition(self, part, ...) |
| @@ -794,7 +794,7 @@ DESCRIPTION | |||
| 794 | 794 | ||
| 795 | Here is a content of test.wks: | 795 | Here is a content of test.wks: |
| 796 | 796 | ||
| 797 | part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024 | 797 | part /boot --source bootimg_pcbios --ondisk sda --label boot --active --align 1024 |
| 798 | part / --source rootfs --ondisk sda --fstype=ext3 --label platform --align 1024 | 798 | part / --source rootfs --ondisk sda --fstype=ext3 --label platform --align 1024 |
| 799 | 799 | ||
| 800 | bootloader --timeout=0 --append="rootwait rootfstype=ext3 video=vesafb vga=0x318 console=tty0" | 800 | bootloader --timeout=0 --append="rootwait rootfstype=ext3 video=vesafb vga=0x318 console=tty0" |
| @@ -916,6 +916,10 @@ DESCRIPTION | |||
| 916 | will create empty partition. --size parameter has | 916 | will create empty partition. --size parameter has |
| 917 | to be used to specify size of empty partition. | 917 | to be used to specify size of empty partition. |
| 918 | 918 | ||
| 919 | --sourceparams: This option is specific to wic. Supply additional | ||
| 920 | parameters to the source plugin in | ||
| 921 | key1=value1,key2 format. | ||
| 922 | |||
| 919 | --ondisk or --ondrive: Forces the partition to be created on | 923 | --ondisk or --ondrive: Forces the partition to be created on |
| 920 | a particular disk. | 924 | a particular disk. |
| 921 | 925 | ||
| @@ -932,6 +936,7 @@ DESCRIPTION | |||
| 932 | squashfs | 936 | squashfs |
| 933 | erofs | 937 | erofs |
| 934 | swap | 938 | swap |
| 939 | none | ||
| 935 | 940 | ||
| 936 | --fsoptions: Specifies a free-form string of options to be | 941 | --fsoptions: Specifies a free-form string of options to be |
| 937 | used when mounting the filesystem. This string | 942 | used when mounting the filesystem. This string |
| @@ -940,6 +945,12 @@ DESCRIPTION | |||
| 940 | quotes. If not specified, the default string is | 945 | quotes. If not specified, the default string is |
| 941 | "defaults". | 946 | "defaults". |
| 942 | 947 | ||
| 948 | --fspassno: Specifies the order in which filesystem checks are done | ||
| 949 | at boot time by fsck. See fs_passno parameter of | ||
| 950 | fstab(5). This parameter will be copied into the | ||
| 951 | /etc/fstab file of the installed system. If not | ||
| 952 | specified the default value of "0" will be used. | ||
| 953 | |||
| 943 | --label label: Specifies the label to give to the filesystem | 954 | --label label: Specifies the label to give to the filesystem |
| 944 | to be made on the partition. If the given | 955 | to be made on the partition. If the given |
| 945 | label is already in use by another filesystem, | 956 | label is already in use by another filesystem, |
| @@ -959,6 +970,14 @@ DESCRIPTION | |||
| 959 | to start a partition on an x KBytes | 970 | to start a partition on an x KBytes |
| 960 | boundary. | 971 | boundary. |
| 961 | 972 | ||
| 973 | --offset: This option is specific to wic that says to place a partition | ||
| 974 | at exactly the specified offset. If the partition cannot be | ||
| 975 | placed at the specified offset, the image build will fail. | ||
| 976 | Specify as an integer value optionally followed by one of the | ||
| 977 | units s/S for 512 byte sector, k/K for kibibyte, M for | ||
| 978 | mebibyte and G for gibibyte. The default unit if none is | ||
| 979 | given is k. | ||
| 980 | |||
| 962 | --no-table: This option is specific to wic. Space will be | 981 | --no-table: This option is specific to wic. Space will be |
| 963 | reserved for the partition and it will be | 982 | reserved for the partition and it will be |
| 964 | populated but it will not be added to the | 983 | populated but it will not be added to the |
| @@ -994,12 +1013,20 @@ DESCRIPTION | |||
| 994 | --no-fstab-update: This option is specific to wic. It does not update the | 1013 | --no-fstab-update: This option is specific to wic. It does not update the |
| 995 | '/etc/fstab' stock file for the given partition. | 1014 | '/etc/fstab' stock file for the given partition. |
| 996 | 1015 | ||
| 997 | --extra-space: This option is specific to wic. It adds extra | 1016 | --extra-filesystem-space: This option is specific to wic. It adds extra |
| 998 | space after the space filled by the content | 1017 | space after the space filled by the content |
| 999 | of the partition. The final size can go | 1018 | of the partition. The final size can go |
| 1000 | beyond the size specified by --size. | 1019 | beyond the size specified by --size. |
| 1001 | By default, 10MB. This option cannot be used | 1020 | By default, 10MB. This option cannot be used |
| 1002 | with --fixed-size option. | 1021 | with --fixed-size option. |
| 1022 | |||
| 1023 | --extra-partition-space: This option is specific to wic. It adds extra | ||
| 1024 | empty space after the space filled by the | ||
| 1025 | filesystem. With --fixed-size, the extra | ||
| 1026 | partition space is removed from the filesystem | ||
| 1027 | size. Otherwise (with or without --size flag), | ||
| 1028 | the extra partition space is added to the final | ||
| 1029 | paritition size. The default value is 0MB. | ||
| 1003 | 1030 | ||
| 1004 | --overhead-factor: This option is specific to wic. The | 1031 | --overhead-factor: This option is specific to wic. The |
| 1005 | size of the partition is multiplied by | 1032 | size of the partition is multiplied by |
| @@ -1039,6 +1066,18 @@ DESCRIPTION | |||
| 1039 | not take effect when --mkfs-extraopts is used. This should be taken into | 1066 | not take effect when --mkfs-extraopts is used. This should be taken into |
| 1040 | account when using --mkfs-extraopts. | 1067 | account when using --mkfs-extraopts. |
| 1041 | 1068 | ||
| 1069 | --type: This option is specific to wic. Valid values are 'primary', | ||
| 1070 | 'logical'. For msdos partition tables, this option specifies | ||
| 1071 | the partition type. | ||
| 1072 | |||
| 1073 | --hidden: This option is specific to wic. This option sets the | ||
| 1074 | RequiredPartition bit (bit 0) on GPT partitions. | ||
| 1075 | |||
| 1076 | --mbr: This option is specific to wic. This option is used with the | ||
| 1077 | gpt-hybrid partition type that uses both a GPT partition and | ||
| 1078 | an MBR header. Partitions with this flag will be included in | ||
| 1079 | this MBR header. | ||
| 1080 | |||
| 1042 | * bootloader | 1081 | * bootloader |
| 1043 | 1082 | ||
| 1044 | This command allows the user to specify various bootloader | 1083 | This command allows the user to specify various bootloader |
| @@ -1057,6 +1096,13 @@ DESCRIPTION | |||
| 1057 | file. Using this option will override any other | 1096 | file. Using this option will override any other |
| 1058 | bootloader option. | 1097 | bootloader option. |
| 1059 | 1098 | ||
| 1099 | --ptable: Specifies the partition table format. Valid values are | ||
| 1100 | 'msdos', 'gpt', 'gpt-hybrid'. | ||
| 1101 | |||
| 1102 | --source: Specifies the source plugin. If not specified, the | ||
| 1103 | --source value will be copied from the partition that has | ||
| 1104 | /boot as mountpoint. | ||
| 1105 | |||
| 1060 | Note that bootloader functionality and boot partitions are | 1106 | Note that bootloader functionality and boot partitions are |
| 1061 | implemented by the various --source plugins that implement | 1107 | implemented by the various --source plugins that implement |
| 1062 | bootloader functionality; the bootloader command essentially | 1108 | bootloader functionality; the bootloader command essentially |
| @@ -1112,7 +1158,7 @@ COMMAND: | |||
| 1112 | TOPIC: | 1158 | TOPIC: |
| 1113 | overview - Presents an overall overview of Wic | 1159 | overview - Presents an overall overview of Wic |
| 1114 | plugins - Presents an overview and API for Wic plugins | 1160 | plugins - Presents an overview and API for Wic plugins |
| 1115 | kickstart - Presents a Wic kicstart file reference | 1161 | kickstart - Presents a Wic kickstart file reference |
| 1116 | 1162 | ||
| 1117 | 1163 | ||
| 1118 | Examples: | 1164 | Examples: |
diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py index 0df9eb0d05..48b5b09ddd 100644 --- a/scripts/lib/wic/ksparser.py +++ b/scripts/lib/wic/ksparser.py | |||
| @@ -132,7 +132,7 @@ def systemidtype(arg): | |||
| 132 | class KickStart(): | 132 | class KickStart(): |
| 133 | """Kickstart parser implementation.""" | 133 | """Kickstart parser implementation.""" |
| 134 | 134 | ||
| 135 | DEFAULT_EXTRA_SPACE = 10*1024 | 135 | DEFAULT_EXTRA_FILESYSTEM_SPACE = 10*1024 |
| 136 | DEFAULT_OVERHEAD_FACTOR = 1.3 | 136 | DEFAULT_OVERHEAD_FACTOR = 1.3 |
| 137 | 137 | ||
| 138 | def __init__(self, confpath): | 138 | def __init__(self, confpath): |
| @@ -153,12 +153,14 @@ class KickStart(): | |||
| 153 | part.add_argument('--exclude-path', nargs='+') | 153 | part.add_argument('--exclude-path', nargs='+') |
| 154 | part.add_argument('--include-path', nargs='+', action='append') | 154 | part.add_argument('--include-path', nargs='+', action='append') |
| 155 | part.add_argument('--change-directory') | 155 | part.add_argument('--change-directory') |
| 156 | part.add_argument("--extra-space", type=sizetype("M")) | 156 | part.add_argument('--extra-filesystem-space', '--extra-space', type=sizetype("M")) |
| 157 | part.add_argument('--extra-partition-space', type=sizetype("M")) | ||
| 157 | part.add_argument('--fsoptions', dest='fsopts') | 158 | part.add_argument('--fsoptions', dest='fsopts') |
| 159 | part.add_argument('--fspassno', dest='fspassno') | ||
| 158 | part.add_argument('--fstype', default='vfat', | 160 | part.add_argument('--fstype', default='vfat', |
| 159 | choices=('ext2', 'ext3', 'ext4', 'btrfs', | 161 | choices=('ext2', 'ext3', 'ext4', 'btrfs', |
| 160 | 'squashfs', 'vfat', 'msdos', 'erofs', | 162 | 'squashfs', 'vfat', 'msdos', 'erofs', |
| 161 | 'swap')) | 163 | 'swap', 'none')) |
| 162 | part.add_argument('--mkfs-extraopts', default='') | 164 | part.add_argument('--mkfs-extraopts', default='') |
| 163 | part.add_argument('--label') | 165 | part.add_argument('--label') |
| 164 | part.add_argument('--use-label', action='store_true') | 166 | part.add_argument('--use-label', action='store_true') |
| @@ -170,11 +172,12 @@ class KickStart(): | |||
| 170 | part.add_argument('--rootfs-dir') | 172 | part.add_argument('--rootfs-dir') |
| 171 | part.add_argument('--type', default='primary', | 173 | part.add_argument('--type', default='primary', |
| 172 | choices = ('primary', 'logical')) | 174 | choices = ('primary', 'logical')) |
| 175 | part.add_argument('--hidden', action='store_true') | ||
| 173 | 176 | ||
| 174 | # --size and --fixed-size cannot be specified together; options | 177 | # --size and --fixed-size cannot be specified together; options |
| 175 | # ----extra-space and --overhead-factor should also raise a parser | 178 | # ----extra-filesystem-space and --overhead-factor should also raise a |
| 176 | # --error, but since nesting mutually exclusive groups does not work, | 179 | # parser error, but since nesting mutually exclusive groups does not work, |
| 177 | # ----extra-space/--overhead-factor are handled later | 180 | # ----extra-filesystem-space/--overhead-factor are handled later |
| 178 | sizeexcl = part.add_mutually_exclusive_group() | 181 | sizeexcl = part.add_mutually_exclusive_group() |
| 179 | sizeexcl.add_argument('--size', type=sizetype("M"), default=0) | 182 | sizeexcl.add_argument('--size', type=sizetype("M"), default=0) |
| 180 | sizeexcl.add_argument('--fixed-size', type=sizetype("M"), default=0) | 183 | sizeexcl.add_argument('--fixed-size', type=sizetype("M"), default=0) |
| @@ -186,12 +189,14 @@ class KickStart(): | |||
| 186 | part.add_argument('--uuid') | 189 | part.add_argument('--uuid') |
| 187 | part.add_argument('--fsuuid') | 190 | part.add_argument('--fsuuid') |
| 188 | part.add_argument('--no-fstab-update', action='store_true') | 191 | part.add_argument('--no-fstab-update', action='store_true') |
| 192 | part.add_argument('--mbr', action='store_true') | ||
| 189 | 193 | ||
| 190 | bootloader = subparsers.add_parser('bootloader') | 194 | bootloader = subparsers.add_parser('bootloader') |
| 191 | bootloader.add_argument('--append') | 195 | bootloader.add_argument('--append') |
| 192 | bootloader.add_argument('--configfile') | 196 | bootloader.add_argument('--configfile') |
| 193 | bootloader.add_argument('--ptable', choices=('msdos', 'gpt'), | 197 | bootloader.add_argument('--ptable', choices=('msdos', 'gpt', 'gpt-hybrid'), |
| 194 | default='msdos') | 198 | default='msdos') |
| 199 | bootloader.add_argument('--diskid', type=lambda x: int(x, 0)) | ||
| 195 | bootloader.add_argument('--timeout', type=int) | 200 | bootloader.add_argument('--timeout', type=int) |
| 196 | bootloader.add_argument('--source') | 201 | bootloader.add_argument('--source') |
| 197 | 202 | ||
| @@ -256,14 +261,17 @@ class KickStart(): | |||
| 256 | err = "%s:%d: Must set the label with --label" \ | 261 | err = "%s:%d: Must set the label with --label" \ |
| 257 | % (confpath, lineno) | 262 | % (confpath, lineno) |
| 258 | raise KickStartError(err) | 263 | raise KickStartError(err) |
| 264 | if not parsed.extra_partition_space: | ||
| 265 | parsed.extra_partition_space = 0 | ||
| 259 | # using ArgumentParser one cannot easily tell if option | 266 | # using ArgumentParser one cannot easily tell if option |
| 260 | # was passed as argument, if said option has a default | 267 | # was passed as argument, if said option has a default |
| 261 | # value; --overhead-factor/--extra-space cannot be used | 268 | # value; --overhead-factor/--extra-filesystem-space |
| 262 | # with --fixed-size, so at least detect when these were | 269 | # cannot be used with --fixed-size, so at least detect |
| 263 | # passed with non-0 values ... | 270 | # when these were passed with non-0 values ... |
| 264 | if parsed.fixed_size: | 271 | if parsed.fixed_size: |
| 265 | if parsed.overhead_factor or parsed.extra_space: | 272 | if parsed.overhead_factor or parsed.extra_filesystem_space: |
| 266 | err = "%s:%d: arguments --overhead-factor and --extra-space not "\ | 273 | err = "%s:%d: arguments --overhead-factor and "\ |
| 274 | "--extra-filesystem-space not "\ | ||
| 267 | "allowed with argument --fixed-size" \ | 275 | "allowed with argument --fixed-size" \ |
| 268 | % (confpath, lineno) | 276 | % (confpath, lineno) |
| 269 | raise KickStartError(err) | 277 | raise KickStartError(err) |
| @@ -272,10 +280,10 @@ class KickStart(): | |||
| 272 | # --fixed-size iff given option was not used | 280 | # --fixed-size iff given option was not used |
| 273 | # (again, one cannot tell if option was passed but | 281 | # (again, one cannot tell if option was passed but |
| 274 | # with value equal to 0) | 282 | # with value equal to 0) |
| 275 | if '--overhead-factor' not in line_args: | 283 | if not parsed.overhead_factor: |
| 276 | parsed.overhead_factor = self.DEFAULT_OVERHEAD_FACTOR | 284 | parsed.overhead_factor = self.DEFAULT_OVERHEAD_FACTOR |
| 277 | if '--extra-space' not in line_args: | 285 | if not parsed.extra_filesystem_space: |
| 278 | parsed.extra_space = self.DEFAULT_EXTRA_SPACE | 286 | parsed.extra_filesystem_space = self.DEFAULT_EXTRA_FILESYSTEM_SPACE |
| 279 | 287 | ||
| 280 | self.partnum += 1 | 288 | self.partnum += 1 |
| 281 | self.partitions.append(Partition(parsed, self.partnum)) | 289 | self.partitions.append(Partition(parsed, self.partnum)) |
diff --git a/scripts/lib/wic/misc.py b/scripts/lib/wic/misc.py index 3e11822996..1a7c140fa6 100644 --- a/scripts/lib/wic/misc.py +++ b/scripts/lib/wic/misc.py | |||
| @@ -25,7 +25,7 @@ from wic import WicError | |||
| 25 | logger = logging.getLogger('wic') | 25 | logger = logging.getLogger('wic') |
| 26 | 26 | ||
| 27 | # executable -> recipe pairs for exec_native_cmd | 27 | # executable -> recipe pairs for exec_native_cmd |
| 28 | NATIVE_RECIPES = {"bmaptool": "bmap-tools", | 28 | NATIVE_RECIPES = {"bmaptool": "bmaptool", |
| 29 | "dumpe2fs": "e2fsprogs", | 29 | "dumpe2fs": "e2fsprogs", |
| 30 | "grub-mkimage": "grub-efi", | 30 | "grub-mkimage": "grub-efi", |
| 31 | "isohybrid": "syslinux", | 31 | "isohybrid": "syslinux", |
| @@ -36,6 +36,7 @@ NATIVE_RECIPES = {"bmaptool": "bmap-tools", | |||
| 36 | "mkdosfs": "dosfstools", | 36 | "mkdosfs": "dosfstools", |
| 37 | "mkisofs": "cdrtools", | 37 | "mkisofs": "cdrtools", |
| 38 | "mkfs.btrfs": "btrfs-tools", | 38 | "mkfs.btrfs": "btrfs-tools", |
| 39 | "mkfs.erofs": "erofs-utils", | ||
| 39 | "mkfs.ext2": "e2fsprogs", | 40 | "mkfs.ext2": "e2fsprogs", |
| 40 | "mkfs.ext3": "e2fsprogs", | 41 | "mkfs.ext3": "e2fsprogs", |
| 41 | "mkfs.ext4": "e2fsprogs", | 42 | "mkfs.ext4": "e2fsprogs", |
| @@ -140,11 +141,12 @@ def exec_native_cmd(cmd_and_args, native_sysroot, pseudo=""): | |||
| 140 | cmd_and_args = pseudo + cmd_and_args | 141 | cmd_and_args = pseudo + cmd_and_args |
| 141 | 142 | ||
| 142 | hosttools_dir = get_bitbake_var("HOSTTOOLS_DIR") | 143 | hosttools_dir = get_bitbake_var("HOSTTOOLS_DIR") |
| 144 | target_sys = get_bitbake_var("TARGET_SYS") | ||
| 143 | 145 | ||
| 144 | native_paths = "%s/sbin:%s/usr/sbin:%s/usr/bin:%s/bin:%s" % \ | 146 | native_paths = "%s/sbin:%s/usr/sbin:%s/usr/bin:%s/usr/bin/%s:%s/bin:%s" % \ |
| 145 | (native_sysroot, native_sysroot, | 147 | (native_sysroot, native_sysroot, |
| 146 | native_sysroot, native_sysroot, | 148 | native_sysroot, native_sysroot, target_sys, |
| 147 | hosttools_dir) | 149 | native_sysroot, hosttools_dir) |
| 148 | 150 | ||
| 149 | native_cmd_and_args = "export PATH=%s:$PATH;%s" % \ | 151 | native_cmd_and_args = "export PATH=%s:$PATH;%s" % \ |
| 150 | (native_paths, cmd_and_args) | 152 | (native_paths, cmd_and_args) |
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py index a25834048e..531ac6eb3d 100644 --- a/scripts/lib/wic/partition.py +++ b/scripts/lib/wic/partition.py | |||
| @@ -28,11 +28,13 @@ class Partition(): | |||
| 28 | self.align = args.align | 28 | self.align = args.align |
| 29 | self.disk = args.disk | 29 | self.disk = args.disk |
| 30 | self.device = None | 30 | self.device = None |
| 31 | self.extra_space = args.extra_space | 31 | self.extra_filesystem_space = args.extra_filesystem_space |
| 32 | self.extra_partition_space = args.extra_partition_space | ||
| 32 | self.exclude_path = args.exclude_path | 33 | self.exclude_path = args.exclude_path |
| 33 | self.include_path = args.include_path | 34 | self.include_path = args.include_path |
| 34 | self.change_directory = args.change_directory | 35 | self.change_directory = args.change_directory |
| 35 | self.fsopts = args.fsopts | 36 | self.fsopts = args.fsopts |
| 37 | self.fspassno = args.fspassno | ||
| 36 | self.fstype = args.fstype | 38 | self.fstype = args.fstype |
| 37 | self.label = args.label | 39 | self.label = args.label |
| 38 | self.use_label = args.use_label | 40 | self.use_label = args.use_label |
| @@ -58,6 +60,8 @@ class Partition(): | |||
| 58 | self.updated_fstab_path = None | 60 | self.updated_fstab_path = None |
| 59 | self.has_fstab = False | 61 | self.has_fstab = False |
| 60 | self.update_fstab_in_rootfs = False | 62 | self.update_fstab_in_rootfs = False |
| 63 | self.hidden = args.hidden | ||
| 64 | self.mbr = args.mbr | ||
| 61 | 65 | ||
| 62 | self.lineno = lineno | 66 | self.lineno = lineno |
| 63 | self.source_file = "" | 67 | self.source_file = "" |
| @@ -88,21 +92,20 @@ class Partition(): | |||
| 88 | def get_rootfs_size(self, actual_rootfs_size=0): | 92 | def get_rootfs_size(self, actual_rootfs_size=0): |
| 89 | """ | 93 | """ |
| 90 | Calculate the required size of rootfs taking into consideration | 94 | Calculate the required size of rootfs taking into consideration |
| 91 | --size/--fixed-size flags as well as overhead and extra space, as | 95 | --size/--fixed-size and --extra-partition-space flags as well as overhead |
| 92 | specified in kickstart file. Raises an error if the | 96 | and extra space, as specified in kickstart file. Raises an error |
| 93 | `actual_rootfs_size` is larger than fixed-size rootfs. | 97 | if the `actual_rootfs_size` is larger than fixed-size rootfs. |
| 94 | |||
| 95 | """ | 98 | """ |
| 96 | if self.fixed_size: | 99 | if self.fixed_size: |
| 97 | rootfs_size = self.fixed_size | 100 | rootfs_size = self.fixed_size - self.extra_partition_space |
| 98 | if actual_rootfs_size > rootfs_size: | 101 | if actual_rootfs_size > rootfs_size: |
| 99 | raise WicError("Actual rootfs size (%d kB) is larger than " | 102 | raise WicError("Actual rootfs size (%d kB) is larger than " |
| 100 | "allowed size %d kB" % | 103 | "allowed size %d kB" % |
| 101 | (actual_rootfs_size, rootfs_size)) | 104 | (actual_rootfs_size, rootfs_size)) |
| 102 | else: | 105 | else: |
| 103 | extra_blocks = self.get_extra_block_count(actual_rootfs_size) | 106 | extra_blocks = self.get_extra_block_count(actual_rootfs_size) |
| 104 | if extra_blocks < self.extra_space: | 107 | if extra_blocks < self.extra_filesystem_space: |
| 105 | extra_blocks = self.extra_space | 108 | extra_blocks = self.extra_filesystem_space |
| 106 | 109 | ||
| 107 | rootfs_size = actual_rootfs_size + extra_blocks | 110 | rootfs_size = actual_rootfs_size + extra_blocks |
| 108 | rootfs_size = int(rootfs_size * self.overhead_factor) | 111 | rootfs_size = int(rootfs_size * self.overhead_factor) |
| @@ -116,10 +119,18 @@ class Partition(): | |||
| 116 | def disk_size(self): | 119 | def disk_size(self): |
| 117 | """ | 120 | """ |
| 118 | Obtain on-disk size of partition taking into consideration | 121 | Obtain on-disk size of partition taking into consideration |
| 119 | --size/--fixed-size options. | 122 | --size/--fixed-size and --extra-partition-space options. |
| 123 | |||
| 124 | """ | ||
| 125 | return self.fixed_size if self.fixed_size else self.size + self.extra_partition_space | ||
| 120 | 126 | ||
| 127 | @property | ||
| 128 | def fs_size(self): | ||
| 129 | """ | ||
| 130 | Obtain on-disk size of filesystem inside the partition taking into | ||
| 131 | consideration --size/--fixed-size and --extra-partition-space options. | ||
| 121 | """ | 132 | """ |
| 122 | return self.fixed_size if self.fixed_size else self.size | 133 | return self.fixed_size - self.extra_partition_space if self.fixed_size else self.size |
| 123 | 134 | ||
| 124 | def prepare(self, creator, cr_workdir, oe_builddir, rootfs_dir, | 135 | def prepare(self, creator, cr_workdir, oe_builddir, rootfs_dir, |
| 125 | bootimg_dir, kernel_dir, native_sysroot, updated_fstab_path): | 136 | bootimg_dir, kernel_dir, native_sysroot, updated_fstab_path): |
| @@ -132,6 +143,8 @@ class Partition(): | |||
| 132 | self.update_fstab_in_rootfs = True | 143 | self.update_fstab_in_rootfs = True |
| 133 | 144 | ||
| 134 | if not self.source: | 145 | if not self.source: |
| 146 | if self.fstype == "none" or self.no_table: | ||
| 147 | return | ||
| 135 | if not self.size and not self.fixed_size: | 148 | if not self.size and not self.fixed_size: |
| 136 | raise WicError("The %s partition has a size of zero. Please " | 149 | raise WicError("The %s partition has a size of zero. Please " |
| 137 | "specify a non-zero --size/--fixed-size for that " | 150 | "specify a non-zero --size/--fixed-size for that " |
| @@ -159,10 +172,13 @@ class Partition(): | |||
| 159 | 172 | ||
| 160 | plugins = PluginMgr.get_plugins('source') | 173 | plugins = PluginMgr.get_plugins('source') |
| 161 | 174 | ||
| 175 | # Don't support '-' in plugin names | ||
| 176 | self.source = self.source.replace("-", "_") | ||
| 177 | |||
| 162 | if self.source not in plugins: | 178 | if self.source not in plugins: |
| 163 | raise WicError("The '%s' --source specified for %s doesn't exist.\n\t" | 179 | raise WicError("The '%s' --source specified for %s doesn't exist.\n\t" |
| 164 | "See 'wic list source-plugins' for a list of available" | 180 | "See 'wic list source-plugins' for a list of available" |
| 165 | " --sources.\n\tSee 'wic help source-plugins' for " | 181 | " --sources.\n\tSee 'wic help plugins' for " |
| 166 | "details on adding a new source plugin." % | 182 | "details on adding a new source plugin." % |
| 167 | (self.source, self.mountpoint)) | 183 | (self.source, self.mountpoint)) |
| 168 | 184 | ||
| @@ -171,9 +187,9 @@ class Partition(): | |||
| 171 | # Split sourceparams string of the form key1=val1[,key2=val2,...] | 187 | # Split sourceparams string of the form key1=val1[,key2=val2,...] |
| 172 | # into a dict. Also accepts valueless keys i.e. without = | 188 | # into a dict. Also accepts valueless keys i.e. without = |
| 173 | splitted = self.sourceparams.split(',') | 189 | splitted = self.sourceparams.split(',') |
| 174 | srcparams_dict = dict(par.split('=', 1) for par in splitted if par) | 190 | srcparams_dict = dict((par.split('=', 1) + [None])[:2] for par in splitted if par) |
| 175 | 191 | ||
| 176 | plugin = PluginMgr.get_plugins('source')[self.source] | 192 | plugin = plugins[self.source] |
| 177 | plugin.do_configure_partition(self, srcparams_dict, creator, | 193 | plugin.do_configure_partition(self, srcparams_dict, creator, |
| 178 | cr_workdir, oe_builddir, bootimg_dir, | 194 | cr_workdir, oe_builddir, bootimg_dir, |
| 179 | kernel_dir, native_sysroot) | 195 | kernel_dir, native_sysroot) |
| @@ -194,10 +210,10 @@ class Partition(): | |||
| 194 | "This a bug in source plugin %s and needs to be fixed." % | 210 | "This a bug in source plugin %s and needs to be fixed." % |
| 195 | (self.mountpoint, self.source)) | 211 | (self.mountpoint, self.source)) |
| 196 | 212 | ||
| 197 | if self.fixed_size and self.size > self.fixed_size: | 213 | if self.fixed_size and self.size + self.extra_partition_space > self.fixed_size: |
| 198 | raise WicError("File system image of partition %s is " | 214 | raise WicError("File system image of partition %s is " |
| 199 | "larger (%d kB) than its allowed size %d kB" % | 215 | "larger (%d kB + %d kB extra part space) than its allowed size %d kB" % |
| 200 | (self.mountpoint, self.size, self.fixed_size)) | 216 | (self.mountpoint, self.size, self.extra_partition_space, self.fixed_size)) |
| 201 | 217 | ||
| 202 | def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir, | 218 | def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir, |
| 203 | native_sysroot, real_rootfs = True, pseudo_dir = None): | 219 | native_sysroot, real_rootfs = True, pseudo_dir = None): |
| @@ -217,19 +233,19 @@ class Partition(): | |||
| 217 | if (pseudo_dir): | 233 | if (pseudo_dir): |
| 218 | # Canonicalize the ignore paths. This corresponds to | 234 | # Canonicalize the ignore paths. This corresponds to |
| 219 | # calling oe.path.canonicalize(), which is used in bitbake.conf. | 235 | # calling oe.path.canonicalize(), which is used in bitbake.conf. |
| 220 | ignore_paths = [rootfs] + (get_bitbake_var("PSEUDO_IGNORE_PATHS") or "").split(",") | 236 | include_paths = [rootfs_dir] + (get_bitbake_var("PSEUDO_INCLUDE_PATHS") or "").split(",") |
| 221 | canonical_paths = [] | 237 | canonical_paths = [] |
| 222 | for path in ignore_paths: | 238 | for path in include_paths: |
| 223 | if "$" not in path: | 239 | if "$" not in path: |
| 224 | trailing_slash = path.endswith("/") and "/" or "" | 240 | trailing_slash = path.endswith("/") and "/" or "" |
| 225 | canonical_paths.append(os.path.realpath(path) + trailing_slash) | 241 | canonical_paths.append(os.path.realpath(path) + trailing_slash) |
| 226 | ignore_paths = ",".join(canonical_paths) | 242 | include_paths = ",".join(canonical_paths) |
| 227 | 243 | ||
| 228 | pseudo = "export PSEUDO_PREFIX=%s;" % p_prefix | 244 | pseudo = "export PSEUDO_PREFIX=%s;" % p_prefix |
| 229 | pseudo += "export PSEUDO_LOCALSTATEDIR=%s;" % pseudo_dir | 245 | pseudo += "export PSEUDO_LOCALSTATEDIR=%s;" % pseudo_dir |
| 230 | pseudo += "export PSEUDO_PASSWD=%s;" % rootfs_dir | 246 | pseudo += "export PSEUDO_PASSWD=%s;" % rootfs_dir |
| 231 | pseudo += "export PSEUDO_NOSYMLINKEXP=1;" | 247 | pseudo += "export PSEUDO_NOSYMLINKEXP=1;" |
| 232 | pseudo += "export PSEUDO_IGNORE_PATHS=%s;" % ignore_paths | 248 | pseudo += "export PSEUDO_INCLUDE_PATHS=%s;" % include_paths |
| 233 | pseudo += "%s " % get_bitbake_var("FAKEROOTCMD") | 249 | pseudo += "%s " % get_bitbake_var("FAKEROOTCMD") |
| 234 | else: | 250 | else: |
| 235 | pseudo = None | 251 | pseudo = None |
| @@ -239,7 +255,7 @@ class Partition(): | |||
| 239 | # from bitbake variable | 255 | # from bitbake variable |
| 240 | rsize_bb = get_bitbake_var('ROOTFS_SIZE') | 256 | rsize_bb = get_bitbake_var('ROOTFS_SIZE') |
| 241 | rdir = get_bitbake_var('IMAGE_ROOTFS') | 257 | rdir = get_bitbake_var('IMAGE_ROOTFS') |
| 242 | if rsize_bb and rdir == rootfs_dir: | 258 | if rsize_bb and (rdir == rootfs_dir or (rootfs_dir.split('/')[-2] == "tmp-wic" and rootfs_dir.split('/')[-1][:6] == "rootfs")): |
| 243 | # Bitbake variable ROOTFS_SIZE is calculated in | 259 | # Bitbake variable ROOTFS_SIZE is calculated in |
| 244 | # Image._get_rootfs_size method from meta/lib/oe/image.py | 260 | # Image._get_rootfs_size method from meta/lib/oe/image.py |
| 245 | # using IMAGE_ROOTFS_SIZE, IMAGE_ROOTFS_ALIGNMENT, | 261 | # using IMAGE_ROOTFS_SIZE, IMAGE_ROOTFS_ALIGNMENT, |
| @@ -279,6 +295,9 @@ class Partition(): | |||
| 279 | 295 | ||
| 280 | extraopts = self.mkfs_extraopts or "-F -i 8192" | 296 | extraopts = self.mkfs_extraopts or "-F -i 8192" |
| 281 | 297 | ||
| 298 | # use hash_seed to generate reproducible ext4 images | ||
| 299 | (extraopts, pseudo) = self.get_hash_seed_ext4(extraopts, pseudo) | ||
| 300 | |||
| 282 | label_str = "" | 301 | label_str = "" |
| 283 | if self.label: | 302 | if self.label: |
| 284 | label_str = "-L %s" % self.label | 303 | label_str = "-L %s" % self.label |
| @@ -299,8 +318,49 @@ class Partition(): | |||
| 299 | mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs) | 318 | mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs) |
| 300 | exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) | 319 | exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) |
| 301 | 320 | ||
| 321 | if os.getenv('SOURCE_DATE_EPOCH'): | ||
| 322 | sde_time = hex(int(os.getenv('SOURCE_DATE_EPOCH'))) | ||
| 323 | debugfs_script_path = os.path.join(cr_workdir, "debugfs_script") | ||
| 324 | files = [] | ||
| 325 | for root, dirs, others in os.walk(rootfs_dir): | ||
| 326 | base = root.replace(rootfs_dir, "").rstrip(os.sep) | ||
| 327 | files += [ "/" if base == "" else base ] | ||
| 328 | files += [ base + "/" + n for n in dirs + others ] | ||
| 329 | with open(debugfs_script_path, "w") as f: | ||
| 330 | f.write("set_current_time %s\n" % (sde_time)) | ||
| 331 | if self.updated_fstab_path and self.has_fstab and not self.no_fstab_update: | ||
| 332 | f.write("set_inode_field /etc/fstab mtime %s\n" % (sde_time)) | ||
| 333 | f.write("set_inode_field /etc/fstab mtime_extra 0\n") | ||
| 334 | for file in set(files): | ||
| 335 | for time in ["atime", "ctime", "crtime"]: | ||
| 336 | f.write("set_inode_field \"%s\" %s %s\n" % (file, time, sde_time)) | ||
| 337 | f.write("set_inode_field \"%s\" %s_extra 0\n" % (file, time)) | ||
| 338 | for time in ["wtime", "mkfs_time", "lastcheck"]: | ||
| 339 | f.write("set_super_value %s %s\n" % (time, sde_time)) | ||
| 340 | for time in ["mtime", "first_error_time", "last_error_time"]: | ||
| 341 | f.write("set_super_value %s 0\n" % (time)) | ||
| 342 | debugfs_cmd = "debugfs -w -f %s %s" % (debugfs_script_path, rootfs) | ||
| 343 | exec_native_cmd(debugfs_cmd, native_sysroot) | ||
| 344 | |||
| 302 | self.check_for_Y2038_problem(rootfs, native_sysroot) | 345 | self.check_for_Y2038_problem(rootfs, native_sysroot) |
| 303 | 346 | ||
| 347 | def get_hash_seed_ext4(self, extraopts, pseudo): | ||
| 348 | if os.getenv('SOURCE_DATE_EPOCH'): | ||
| 349 | sde_time = int(os.getenv('SOURCE_DATE_EPOCH')) | ||
| 350 | if pseudo: | ||
| 351 | pseudo = "export E2FSPROGS_FAKE_TIME=%s;%s " % (sde_time, pseudo) | ||
| 352 | else: | ||
| 353 | pseudo = "export E2FSPROGS_FAKE_TIME=%s; " % sde_time | ||
| 354 | |||
| 355 | # Set hash_seed to generate deterministic directory indexes | ||
| 356 | namespace = uuid.UUID("e7429877-e7b3-4a68-a5c9-2f2fdf33d460") | ||
| 357 | if self.fsuuid: | ||
| 358 | namespace = uuid.UUID(self.fsuuid) | ||
| 359 | hash_seed = str(uuid.uuid5(namespace, str(sde_time))) | ||
| 360 | extraopts += " -E hash_seed=%s" % hash_seed | ||
| 361 | |||
| 362 | return (extraopts, pseudo) | ||
| 363 | |||
| 304 | def prepare_rootfs_btrfs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir, | 364 | def prepare_rootfs_btrfs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir, |
| 305 | native_sysroot, pseudo): | 365 | native_sysroot, pseudo): |
| 306 | """ | 366 | """ |
| @@ -352,7 +412,7 @@ class Partition(): | |||
| 352 | exec_native_cmd(mcopy_cmd, native_sysroot) | 412 | exec_native_cmd(mcopy_cmd, native_sysroot) |
| 353 | 413 | ||
| 354 | if self.updated_fstab_path and self.has_fstab and not self.no_fstab_update: | 414 | if self.updated_fstab_path and self.has_fstab and not self.no_fstab_update: |
| 355 | mcopy_cmd = "mcopy -i %s %s ::/etc/fstab" % (rootfs, self.updated_fstab_path) | 415 | mcopy_cmd = "mcopy -m -i %s %s ::/etc/fstab" % (rootfs, self.updated_fstab_path) |
| 356 | exec_native_cmd(mcopy_cmd, native_sysroot) | 416 | exec_native_cmd(mcopy_cmd, native_sysroot) |
| 357 | 417 | ||
| 358 | chmod_cmd = "chmod 644 %s" % rootfs | 418 | chmod_cmd = "chmod 644 %s" % rootfs |
| @@ -380,24 +440,30 @@ class Partition(): | |||
| 380 | (extraopts, self.fsuuid, rootfs, rootfs_dir) | 440 | (extraopts, self.fsuuid, rootfs, rootfs_dir) |
| 381 | exec_native_cmd(erofs_cmd, native_sysroot, pseudo=pseudo) | 441 | exec_native_cmd(erofs_cmd, native_sysroot, pseudo=pseudo) |
| 382 | 442 | ||
| 443 | def prepare_empty_partition_none(self, rootfs, oe_builddir, native_sysroot): | ||
| 444 | pass | ||
| 445 | |||
| 383 | def prepare_empty_partition_ext(self, rootfs, oe_builddir, | 446 | def prepare_empty_partition_ext(self, rootfs, oe_builddir, |
| 384 | native_sysroot): | 447 | native_sysroot): |
| 385 | """ | 448 | """ |
| 386 | Prepare an empty ext2/3/4 partition. | 449 | Prepare an empty ext2/3/4 partition. |
| 387 | """ | 450 | """ |
| 388 | size = self.disk_size | 451 | size = self.fs_size |
| 389 | with open(rootfs, 'w') as sparse: | 452 | with open(rootfs, 'w') as sparse: |
| 390 | os.ftruncate(sparse.fileno(), size * 1024) | 453 | os.ftruncate(sparse.fileno(), size * 1024) |
| 391 | 454 | ||
| 392 | extraopts = self.mkfs_extraopts or "-i 8192" | 455 | extraopts = self.mkfs_extraopts or "-i 8192" |
| 393 | 456 | ||
| 457 | # use hash_seed to generate reproducible ext4 images | ||
| 458 | (extraopts, pseudo) = self.get_hash_seed_ext4(extraopts, None) | ||
| 459 | |||
| 394 | label_str = "" | 460 | label_str = "" |
| 395 | if self.label: | 461 | if self.label: |
| 396 | label_str = "-L %s" % self.label | 462 | label_str = "-L %s" % self.label |
| 397 | 463 | ||
| 398 | mkfs_cmd = "mkfs.%s -F %s %s -U %s %s" % \ | 464 | mkfs_cmd = "mkfs.%s -F %s %s -U %s %s" % \ |
| 399 | (self.fstype, extraopts, label_str, self.fsuuid, rootfs) | 465 | (self.fstype, extraopts, label_str, self.fsuuid, rootfs) |
| 400 | exec_native_cmd(mkfs_cmd, native_sysroot) | 466 | exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) |
| 401 | 467 | ||
| 402 | self.check_for_Y2038_problem(rootfs, native_sysroot) | 468 | self.check_for_Y2038_problem(rootfs, native_sysroot) |
| 403 | 469 | ||
| @@ -406,7 +472,7 @@ class Partition(): | |||
| 406 | """ | 472 | """ |
| 407 | Prepare an empty btrfs partition. | 473 | Prepare an empty btrfs partition. |
| 408 | """ | 474 | """ |
| 409 | size = self.disk_size | 475 | size = self.fs_size |
| 410 | with open(rootfs, 'w') as sparse: | 476 | with open(rootfs, 'w') as sparse: |
| 411 | os.ftruncate(sparse.fileno(), size * 1024) | 477 | os.ftruncate(sparse.fileno(), size * 1024) |
| 412 | 478 | ||
| @@ -424,7 +490,7 @@ class Partition(): | |||
| 424 | """ | 490 | """ |
| 425 | Prepare an empty vfat partition. | 491 | Prepare an empty vfat partition. |
| 426 | """ | 492 | """ |
| 427 | blocks = self.disk_size | 493 | blocks = self.fs_size |
| 428 | 494 | ||
| 429 | label_str = "-n boot" | 495 | label_str = "-n boot" |
| 430 | if self.label: | 496 | if self.label: |
diff --git a/scripts/lib/wic/pluginbase.py b/scripts/lib/wic/pluginbase.py index d9b4e57747..640da292d3 100644 --- a/scripts/lib/wic/pluginbase.py +++ b/scripts/lib/wic/pluginbase.py | |||
| @@ -9,9 +9,11 @@ __all__ = ['ImagerPlugin', 'SourcePlugin'] | |||
| 9 | 9 | ||
| 10 | import os | 10 | import os |
| 11 | import logging | 11 | import logging |
| 12 | import types | ||
| 12 | 13 | ||
| 13 | from collections import defaultdict | 14 | from collections import defaultdict |
| 14 | from importlib.machinery import SourceFileLoader | 15 | import importlib |
| 16 | import importlib.util | ||
| 15 | 17 | ||
| 16 | from wic import WicError | 18 | from wic import WicError |
| 17 | from wic.misc import get_bitbake_var | 19 | from wic.misc import get_bitbake_var |
| @@ -42,7 +44,7 @@ class PluginMgr: | |||
| 42 | path = os.path.join(layer_path, script_plugin_dir) | 44 | path = os.path.join(layer_path, script_plugin_dir) |
| 43 | path = os.path.abspath(os.path.expanduser(path)) | 45 | path = os.path.abspath(os.path.expanduser(path)) |
| 44 | if path not in cls._plugin_dirs and os.path.isdir(path): | 46 | if path not in cls._plugin_dirs and os.path.isdir(path): |
| 45 | cls._plugin_dirs.insert(0, path) | 47 | cls._plugin_dirs.append(path) |
| 46 | 48 | ||
| 47 | if ptype not in PLUGINS: | 49 | if ptype not in PLUGINS: |
| 48 | # load all ptype plugins | 50 | # load all ptype plugins |
| @@ -54,7 +56,9 @@ class PluginMgr: | |||
| 54 | mname = fname[:-3] | 56 | mname = fname[:-3] |
| 55 | mpath = os.path.join(ppath, fname) | 57 | mpath = os.path.join(ppath, fname) |
| 56 | logger.debug("loading plugin module %s", mpath) | 58 | logger.debug("loading plugin module %s", mpath) |
| 57 | SourceFileLoader(mname, mpath).load_module() | 59 | spec = importlib.util.spec_from_file_location(mname, mpath) |
| 60 | module = importlib.util.module_from_spec(spec) | ||
| 61 | spec.loader.exec_module(module) | ||
| 58 | 62 | ||
| 59 | return PLUGINS.get(ptype) | 63 | return PLUGINS.get(ptype) |
| 60 | 64 | ||
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py index 35fff7c102..f40f033a3d 100644 --- a/scripts/lib/wic/plugins/imager/direct.py +++ b/scripts/lib/wic/plugins/imager/direct.py | |||
| @@ -76,7 +76,7 @@ class DirectPlugin(ImagerPlugin): | |||
| 76 | break | 76 | break |
| 77 | 77 | ||
| 78 | image_path = self._full_path(self.workdir, self.parts[0].disk, "direct") | 78 | image_path = self._full_path(self.workdir, self.parts[0].disk, "direct") |
| 79 | self._image = PartitionedImage(image_path, self.ptable_format, | 79 | self._image = PartitionedImage(image_path, self.ptable_format, self.ks.bootloader.diskid, |
| 80 | self.parts, self.native_sysroot, | 80 | self.parts, self.native_sysroot, |
| 81 | options.extra_space) | 81 | options.extra_space) |
| 82 | 82 | ||
| @@ -117,7 +117,7 @@ class DirectPlugin(ImagerPlugin): | |||
| 117 | updated = False | 117 | updated = False |
| 118 | for part in self.parts: | 118 | for part in self.parts: |
| 119 | if not part.realnum or not part.mountpoint \ | 119 | if not part.realnum or not part.mountpoint \ |
| 120 | or part.mountpoint == "/" or not part.mountpoint.startswith('/'): | 120 | or part.mountpoint == "/" or not (part.mountpoint.startswith('/') or part.mountpoint == "swap"): |
| 121 | continue | 121 | continue |
| 122 | 122 | ||
| 123 | if part.use_uuid: | 123 | if part.use_uuid: |
| @@ -138,8 +138,9 @@ class DirectPlugin(ImagerPlugin): | |||
| 138 | device_name = "/dev/%s%s%d" % (part.disk, prefix, part.realnum) | 138 | device_name = "/dev/%s%s%d" % (part.disk, prefix, part.realnum) |
| 139 | 139 | ||
| 140 | opts = part.fsopts if part.fsopts else "defaults" | 140 | opts = part.fsopts if part.fsopts else "defaults" |
| 141 | passno = part.fspassno if part.fspassno else "0" | ||
| 141 | line = "\t".join([device_name, part.mountpoint, part.fstype, | 142 | line = "\t".join([device_name, part.mountpoint, part.fstype, |
| 142 | opts, "0", "0"]) + "\n" | 143 | opts, "0", passno]) + "\n" |
| 143 | 144 | ||
| 144 | fstab_lines.append(line) | 145 | fstab_lines.append(line) |
| 145 | updated = True | 146 | updated = True |
| @@ -148,6 +149,9 @@ class DirectPlugin(ImagerPlugin): | |||
| 148 | self.updated_fstab_path = os.path.join(self.workdir, "fstab") | 149 | self.updated_fstab_path = os.path.join(self.workdir, "fstab") |
| 149 | with open(self.updated_fstab_path, "w") as f: | 150 | with open(self.updated_fstab_path, "w") as f: |
| 150 | f.writelines(fstab_lines) | 151 | f.writelines(fstab_lines) |
| 152 | if os.getenv('SOURCE_DATE_EPOCH'): | ||
| 153 | fstab_time = int(os.getenv('SOURCE_DATE_EPOCH')) | ||
| 154 | os.utime(self.updated_fstab_path, (fstab_time, fstab_time)) | ||
| 151 | 155 | ||
| 152 | def _full_path(self, path, name, extention): | 156 | def _full_path(self, path, name, extention): |
| 153 | """ Construct full file path to a file we generate. """ | 157 | """ Construct full file path to a file we generate. """ |
| @@ -199,6 +203,8 @@ class DirectPlugin(ImagerPlugin): | |||
| 199 | source_plugin = self.ks.bootloader.source | 203 | source_plugin = self.ks.bootloader.source |
| 200 | disk_name = self.parts[0].disk | 204 | disk_name = self.parts[0].disk |
| 201 | if source_plugin: | 205 | if source_plugin: |
| 206 | # Don't support '-' in plugin names | ||
| 207 | source_plugin = source_plugin.replace("-", "_") | ||
| 202 | plugin = PluginMgr.get_plugins('source')[source_plugin] | 208 | plugin = PluginMgr.get_plugins('source')[source_plugin] |
| 203 | plugin.do_install_disk(self._image, disk_name, self, self.workdir, | 209 | plugin.do_install_disk(self._image, disk_name, self, self.workdir, |
| 204 | self.oe_builddir, self.bootimg_dir, | 210 | self.oe_builddir, self.bootimg_dir, |
| @@ -259,7 +265,7 @@ class DirectPlugin(ImagerPlugin): | |||
| 259 | if part.mountpoint == "/": | 265 | if part.mountpoint == "/": |
| 260 | if part.uuid: | 266 | if part.uuid: |
| 261 | return "PARTUUID=%s" % part.uuid | 267 | return "PARTUUID=%s" % part.uuid |
| 262 | elif part.label: | 268 | elif part.label and self.ptable_format != 'msdos': |
| 263 | return "PARTLABEL=%s" % part.label | 269 | return "PARTLABEL=%s" % part.label |
| 264 | else: | 270 | else: |
| 265 | suffix = 'p' if part.disk.startswith('mmcblk') else '' | 271 | suffix = 'p' if part.disk.startswith('mmcblk') else '' |
| @@ -296,7 +302,7 @@ class PartitionedImage(): | |||
| 296 | Partitioned image in a file. | 302 | Partitioned image in a file. |
| 297 | """ | 303 | """ |
| 298 | 304 | ||
| 299 | def __init__(self, path, ptable_format, partitions, native_sysroot=None, extra_space=0): | 305 | def __init__(self, path, ptable_format, disk_id, partitions, native_sysroot=None, extra_space=0): |
| 300 | self.path = path # Path to the image file | 306 | self.path = path # Path to the image file |
| 301 | self.numpart = 0 # Number of allocated partitions | 307 | self.numpart = 0 # Number of allocated partitions |
| 302 | self.realpart = 0 # Number of partitions in the partition table | 308 | self.realpart = 0 # Number of partitions in the partition table |
| @@ -309,12 +315,25 @@ class PartitionedImage(): | |||
| 309 | # all partitions (in bytes) | 315 | # all partitions (in bytes) |
| 310 | self.ptable_format = ptable_format # Partition table format | 316 | self.ptable_format = ptable_format # Partition table format |
| 311 | # Disk system identifier | 317 | # Disk system identifier |
| 312 | self.identifier = random.SystemRandom().randint(1, 0xffffffff) | 318 | if disk_id: |
| 319 | self.identifier = disk_id | ||
| 320 | elif os.getenv('SOURCE_DATE_EPOCH'): | ||
| 321 | self.identifier = random.Random(int(os.getenv('SOURCE_DATE_EPOCH'))).randint(1, 0xffffffff) | ||
| 322 | else: | ||
| 323 | self.identifier = random.SystemRandom().randint(1, 0xffffffff) | ||
| 313 | 324 | ||
| 314 | self.partitions = partitions | 325 | self.partitions = partitions |
| 315 | self.partimages = [] | 326 | self.partimages = [] |
| 316 | # Size of a sector used in calculations | 327 | # Size of a sector used in calculations |
| 317 | self.sector_size = SECTOR_SIZE | 328 | sector_size_str = get_bitbake_var('WIC_SECTOR_SIZE') |
| 329 | if sector_size_str is not None: | ||
| 330 | try: | ||
| 331 | self.sector_size = int(sector_size_str) | ||
| 332 | except ValueError: | ||
| 333 | self.sector_size = SECTOR_SIZE | ||
| 334 | else: | ||
| 335 | self.sector_size = SECTOR_SIZE | ||
| 336 | |||
| 318 | self.native_sysroot = native_sysroot | 337 | self.native_sysroot = native_sysroot |
| 319 | num_real_partitions = len([p for p in self.partitions if not p.no_table]) | 338 | num_real_partitions = len([p for p in self.partitions if not p.no_table]) |
| 320 | self.extra_space = extra_space | 339 | self.extra_space = extra_space |
| @@ -335,7 +354,7 @@ class PartitionedImage(): | |||
| 335 | # generate parition and filesystem UUIDs | 354 | # generate parition and filesystem UUIDs |
| 336 | for part in self.partitions: | 355 | for part in self.partitions: |
| 337 | if not part.uuid and part.use_uuid: | 356 | if not part.uuid and part.use_uuid: |
| 338 | if self.ptable_format == 'gpt': | 357 | if self.ptable_format in ('gpt', 'gpt-hybrid'): |
| 339 | part.uuid = str(uuid.uuid4()) | 358 | part.uuid = str(uuid.uuid4()) |
| 340 | else: # msdos partition table | 359 | else: # msdos partition table |
| 341 | part.uuid = '%08x-%02d' % (self.identifier, part.realnum) | 360 | part.uuid = '%08x-%02d' % (self.identifier, part.realnum) |
| @@ -391,6 +410,10 @@ class PartitionedImage(): | |||
| 391 | raise WicError("setting custom partition type is not " \ | 410 | raise WicError("setting custom partition type is not " \ |
| 392 | "implemented for msdos partitions") | 411 | "implemented for msdos partitions") |
| 393 | 412 | ||
| 413 | if part.mbr and self.ptable_format != 'gpt-hybrid': | ||
| 414 | raise WicError("Partition may only be included in MBR with " \ | ||
| 415 | "a gpt-hybrid partition table") | ||
| 416 | |||
| 394 | # Get the disk where the partition is located | 417 | # Get the disk where the partition is located |
| 395 | self.numpart += 1 | 418 | self.numpart += 1 |
| 396 | if not part.no_table: | 419 | if not part.no_table: |
| @@ -399,7 +422,7 @@ class PartitionedImage(): | |||
| 399 | if self.numpart == 1: | 422 | if self.numpart == 1: |
| 400 | if self.ptable_format == "msdos": | 423 | if self.ptable_format == "msdos": |
| 401 | overhead = MBR_OVERHEAD | 424 | overhead = MBR_OVERHEAD |
| 402 | elif self.ptable_format == "gpt": | 425 | elif self.ptable_format in ("gpt", "gpt-hybrid"): |
| 403 | overhead = GPT_OVERHEAD | 426 | overhead = GPT_OVERHEAD |
| 404 | 427 | ||
| 405 | # Skip one sector required for the partitioning scheme overhead | 428 | # Skip one sector required for the partitioning scheme overhead |
| @@ -483,7 +506,7 @@ class PartitionedImage(): | |||
| 483 | # Once all the partitions have been layed out, we can calculate the | 506 | # Once all the partitions have been layed out, we can calculate the |
| 484 | # minumim disk size | 507 | # minumim disk size |
| 485 | self.min_size = self.offset | 508 | self.min_size = self.offset |
| 486 | if self.ptable_format == "gpt": | 509 | if self.ptable_format in ("gpt", "gpt-hybrid"): |
| 487 | self.min_size += GPT_OVERHEAD | 510 | self.min_size += GPT_OVERHEAD |
| 488 | 511 | ||
| 489 | self.min_size *= self.sector_size | 512 | self.min_size *= self.sector_size |
| @@ -497,29 +520,58 @@ class PartitionedImage(): | |||
| 497 | logger.debug("Added '%s' partition, sectors %d-%d, size %d sectors", | 520 | logger.debug("Added '%s' partition, sectors %d-%d, size %d sectors", |
| 498 | parttype, start, end, size) | 521 | parttype, start, end, size) |
| 499 | 522 | ||
| 500 | cmd = "parted -s %s unit s mkpart %s" % (device, parttype) | 523 | cmd = "export PARTED_SECTOR_SIZE=%d; parted -s %s unit s mkpart %s" % \ |
| 524 | (self.sector_size, device, parttype) | ||
| 501 | if fstype: | 525 | if fstype: |
| 502 | cmd += " %s" % fstype | 526 | cmd += " %s" % fstype |
| 503 | cmd += " %d %d" % (start, end) | 527 | cmd += " %d %d" % (start, end) |
| 504 | 528 | ||
| 505 | return exec_native_cmd(cmd, self.native_sysroot) | 529 | return exec_native_cmd(cmd, self.native_sysroot) |
| 506 | 530 | ||
| 531 | def _write_identifier(self, device, identifier): | ||
| 532 | logger.debug("Set disk identifier %x", identifier) | ||
| 533 | with open(device, 'r+b') as img: | ||
| 534 | img.seek(0x1B8) | ||
| 535 | img.write(identifier.to_bytes(4, 'little')) | ||
| 536 | |||
| 537 | def _make_disk(self, device, ptable_format, min_size): | ||
| 538 | logger.debug("Creating sparse file %s", device) | ||
| 539 | with open(device, 'w') as sparse: | ||
| 540 | os.ftruncate(sparse.fileno(), min_size) | ||
| 541 | |||
| 542 | logger.debug("Initializing partition table for %s", device) | ||
| 543 | exec_native_cmd("export PARTED_SECTOR_SIZE=%d; parted -s %s mklabel %s" % | ||
| 544 | (self.sector_size, device, ptable_format), self.native_sysroot) | ||
| 545 | |||
| 546 | def _write_disk_guid(self): | ||
| 547 | if self.ptable_format in ('gpt', 'gpt-hybrid'): | ||
| 548 | if os.getenv('SOURCE_DATE_EPOCH'): | ||
| 549 | self.disk_guid = uuid.UUID(int=int(os.getenv('SOURCE_DATE_EPOCH'))) | ||
| 550 | else: | ||
| 551 | self.disk_guid = uuid.uuid4() | ||
| 552 | |||
| 553 | logger.debug("Set disk guid %s", self.disk_guid) | ||
| 554 | sfdisk_cmd = "sfdisk --sector-size %s --disk-id %s %s" % \ | ||
| 555 | (self.sector_size, self.path, self.disk_guid) | ||
| 556 | exec_native_cmd(sfdisk_cmd, self.native_sysroot) | ||
| 557 | |||
| 507 | def create(self): | 558 | def create(self): |
| 508 | logger.debug("Creating sparse file %s", self.path) | 559 | self._make_disk(self.path, |
| 509 | with open(self.path, 'w') as sparse: | 560 | "gpt" if self.ptable_format == "gpt-hybrid" else self.ptable_format, |
| 510 | os.ftruncate(sparse.fileno(), self.min_size) | 561 | self.min_size) |
| 511 | 562 | ||
| 512 | logger.debug("Initializing partition table for %s", self.path) | 563 | self._write_identifier(self.path, self.identifier) |
| 513 | exec_native_cmd("parted -s %s mklabel %s" % | 564 | self._write_disk_guid() |
| 514 | (self.path, self.ptable_format), self.native_sysroot) | ||
| 515 | 565 | ||
| 516 | logger.debug("Set disk identifier %x", self.identifier) | 566 | if self.ptable_format == "gpt-hybrid": |
| 517 | with open(self.path, 'r+b') as img: | 567 | mbr_path = self.path + ".mbr" |
| 518 | img.seek(0x1B8) | 568 | self._make_disk(mbr_path, "msdos", self.min_size) |
| 519 | img.write(self.identifier.to_bytes(4, 'little')) | 569 | self._write_identifier(mbr_path, self.identifier) |
| 520 | 570 | ||
| 521 | logger.debug("Creating partitions") | 571 | logger.debug("Creating partitions") |
| 522 | 572 | ||
| 573 | hybrid_mbr_part_num = 0 | ||
| 574 | |||
| 523 | for part in self.partitions: | 575 | for part in self.partitions: |
| 524 | if part.num == 0: | 576 | if part.num == 0: |
| 525 | continue | 577 | continue |
| @@ -564,46 +616,77 @@ class PartitionedImage(): | |||
| 564 | self._create_partition(self.path, part.type, | 616 | self._create_partition(self.path, part.type, |
| 565 | parted_fs_type, part.start, part.size_sec) | 617 | parted_fs_type, part.start, part.size_sec) |
| 566 | 618 | ||
| 567 | if part.part_name: | 619 | if self.ptable_format == "gpt-hybrid" and part.mbr: |
| 568 | logger.debug("partition %d: set name to %s", | 620 | hybrid_mbr_part_num += 1 |
| 569 | part.num, part.part_name) | 621 | if hybrid_mbr_part_num > 4: |
| 570 | exec_native_cmd("sgdisk --change-name=%d:%s %s" % \ | 622 | raise WicError("Extended MBR partitions are not supported in hybrid MBR") |
| 571 | (part.num, part.part_name, | 623 | self._create_partition(mbr_path, "primary", |
| 572 | self.path), self.native_sysroot) | 624 | parted_fs_type, part.start, part.size_sec) |
| 573 | 625 | ||
| 626 | if self.ptable_format in ("gpt", "gpt-hybrid") and (part.part_name or part.label): | ||
| 627 | partition_label = part.part_name if part.part_name else part.label | ||
| 628 | logger.debug("partition %d: set name to %s", | ||
| 629 | part.num, partition_label) | ||
| 630 | exec_native_cmd("sfdisk --sector-size %s --part-label %s %d %s" % \ | ||
| 631 | (self.sector_size, self.path, part.num, | ||
| 632 | partition_label), self.native_sysroot) | ||
| 574 | if part.part_type: | 633 | if part.part_type: |
| 575 | logger.debug("partition %d: set type UID to %s", | 634 | logger.debug("partition %d: set type UID to %s", |
| 576 | part.num, part.part_type) | 635 | part.num, part.part_type) |
| 577 | exec_native_cmd("sgdisk --typecode=%d:%s %s" % \ | 636 | exec_native_cmd("sfdisk --sector-size %s --part-type %s %d %s" % \ |
| 578 | (part.num, part.part_type, | 637 | (self.sector_size, self.path, part.num, |
| 579 | self.path), self.native_sysroot) | 638 | part.part_type), self.native_sysroot) |
| 580 | 639 | ||
| 581 | if part.uuid and self.ptable_format == "gpt": | 640 | if part.uuid and self.ptable_format in ("gpt", "gpt-hybrid"): |
| 582 | logger.debug("partition %d: set UUID to %s", | 641 | logger.debug("partition %d: set UUID to %s", |
| 583 | part.num, part.uuid) | 642 | part.num, part.uuid) |
| 584 | exec_native_cmd("sgdisk --partition-guid=%d:%s %s" % \ | 643 | exec_native_cmd("sfdisk --sector-size %s --part-uuid %s %d %s" % \ |
| 585 | (part.num, part.uuid, self.path), | 644 | (self.sector_size, self.path, part.num, part.uuid), |
| 586 | self.native_sysroot) | ||
| 587 | |||
| 588 | if part.label and self.ptable_format == "gpt": | ||
| 589 | logger.debug("partition %d: set name to %s", | ||
| 590 | part.num, part.label) | ||
| 591 | exec_native_cmd("parted -s %s name %d %s" % \ | ||
| 592 | (self.path, part.num, part.label), | ||
| 593 | self.native_sysroot) | 645 | self.native_sysroot) |
| 594 | 646 | ||
| 595 | if part.active: | 647 | if part.active: |
| 596 | flag_name = "legacy_boot" if self.ptable_format == 'gpt' else "boot" | 648 | flag_name = "legacy_boot" if self.ptable_format in ('gpt', 'gpt-hybrid') else "boot" |
| 597 | logger.debug("Set '%s' flag for partition '%s' on disk '%s'", | 649 | logger.debug("Set '%s' flag for partition '%s' on disk '%s'", |
| 598 | flag_name, part.num, self.path) | 650 | flag_name, part.num, self.path) |
| 599 | exec_native_cmd("parted -s %s set %d %s on" % \ | 651 | exec_native_cmd("export PARTED_SECTOR_SIZE=%d; parted -s %s set %d %s on" % \ |
| 600 | (self.path, part.num, flag_name), | 652 | (self.sector_size, self.path, part.num, flag_name), |
| 601 | self.native_sysroot) | 653 | self.native_sysroot) |
| 654 | if self.ptable_format == 'gpt-hybrid' and part.mbr: | ||
| 655 | exec_native_cmd("export PARTED_SECTOR_SIZE=%d; parted -s %s set %d %s on" % \ | ||
| 656 | (self.sector_size, mbr_path, hybrid_mbr_part_num, "boot"), | ||
| 657 | self.native_sysroot) | ||
| 602 | if part.system_id: | 658 | if part.system_id: |
| 603 | exec_native_cmd("sfdisk --part-type %s %s %s" % \ | 659 | exec_native_cmd("sfdisk --sector-size %s --part-type %s %s %s" % \ |
| 604 | (self.path, part.num, part.system_id), | 660 | (self.sector_size, self.path, part.num, part.system_id), |
| 605 | self.native_sysroot) | 661 | self.native_sysroot) |
| 606 | 662 | ||
| 663 | if part.hidden and self.ptable_format == "gpt": | ||
| 664 | logger.debug("Set hidden attribute for partition '%s' on disk '%s'", | ||
| 665 | part.num, self.path) | ||
| 666 | exec_native_cmd("sfdisk --sector-size %s --part-attrs %s %s RequiredPartition" % \ | ||
| 667 | (self.sector_size, self.path, part.num), | ||
| 668 | self.native_sysroot) | ||
| 669 | |||
| 670 | if self.ptable_format == "gpt-hybrid": | ||
| 671 | # Write a protective GPT partition | ||
| 672 | hybrid_mbr_part_num += 1 | ||
| 673 | if hybrid_mbr_part_num > 4: | ||
| 674 | raise WicError("Extended MBR partitions are not supported in hybrid MBR") | ||
| 675 | |||
| 676 | # parted cannot directly create a protective GPT partition, so | ||
| 677 | # create with an arbitrary type, then change it to the correct type | ||
| 678 | # with sfdisk | ||
| 679 | self._create_partition(mbr_path, "primary", "fat32", 1, GPT_OVERHEAD) | ||
| 680 | exec_native_cmd("sfdisk --sector-size %s --part-type %s %d 0xee" % \ | ||
| 681 | (self.sector_size, mbr_path, hybrid_mbr_part_num), | ||
| 682 | self.native_sysroot) | ||
| 683 | |||
| 684 | # Copy hybrid MBR | ||
| 685 | with open(mbr_path, "rb") as mbr_file: | ||
| 686 | with open(self.path, "r+b") as image_file: | ||
| 687 | mbr = mbr_file.read(512) | ||
| 688 | image_file.write(mbr) | ||
| 689 | |||
| 607 | def cleanup(self): | 690 | def cleanup(self): |
| 608 | pass | 691 | pass |
| 609 | 692 | ||
diff --git a/scripts/lib/wic/plugins/source/bootimg-pcbios.py b/scripts/lib/wic/plugins/source/bootimg-pcbios.py deleted file mode 100644 index 32e47f1831..0000000000 --- a/scripts/lib/wic/plugins/source/bootimg-pcbios.py +++ /dev/null | |||
| @@ -1,209 +0,0 @@ | |||
| 1 | # | ||
| 2 | # Copyright (c) 2014, Intel Corporation. | ||
| 3 | # | ||
| 4 | # SPDX-License-Identifier: GPL-2.0-only | ||
| 5 | # | ||
| 6 | # DESCRIPTION | ||
| 7 | # This implements the 'bootimg-pcbios' source plugin class for 'wic' | ||
| 8 | # | ||
| 9 | # AUTHORS | ||
| 10 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> | ||
| 11 | # | ||
| 12 | |||
| 13 | import logging | ||
| 14 | import os | ||
| 15 | import re | ||
| 16 | |||
| 17 | from wic import WicError | ||
| 18 | from wic.engine import get_custom_config | ||
| 19 | from wic.pluginbase import SourcePlugin | ||
| 20 | from wic.misc import (exec_cmd, exec_native_cmd, | ||
| 21 | get_bitbake_var, BOOTDD_EXTRA_SPACE) | ||
| 22 | |||
| 23 | logger = logging.getLogger('wic') | ||
| 24 | |||
| 25 | class BootimgPcbiosPlugin(SourcePlugin): | ||
| 26 | """ | ||
| 27 | Create MBR boot partition and install syslinux on it. | ||
| 28 | """ | ||
| 29 | |||
| 30 | name = 'bootimg-pcbios' | ||
| 31 | |||
| 32 | @classmethod | ||
| 33 | def _get_bootimg_dir(cls, bootimg_dir, dirname): | ||
| 34 | """ | ||
| 35 | Check if dirname exists in default bootimg_dir or in STAGING_DIR. | ||
| 36 | """ | ||
| 37 | staging_datadir = get_bitbake_var("STAGING_DATADIR") | ||
| 38 | for result in (bootimg_dir, staging_datadir): | ||
| 39 | if os.path.exists("%s/%s" % (result, dirname)): | ||
| 40 | return result | ||
| 41 | |||
| 42 | # STAGING_DATADIR is expanded with MLPREFIX if multilib is enabled | ||
| 43 | # but dependency syslinux is still populated to original STAGING_DATADIR | ||
| 44 | nonarch_datadir = re.sub('/[^/]*recipe-sysroot', '/recipe-sysroot', staging_datadir) | ||
| 45 | if os.path.exists(os.path.join(nonarch_datadir, dirname)): | ||
| 46 | return nonarch_datadir | ||
| 47 | |||
| 48 | raise WicError("Couldn't find correct bootimg_dir, exiting") | ||
| 49 | |||
| 50 | @classmethod | ||
| 51 | def do_install_disk(cls, disk, disk_name, creator, workdir, oe_builddir, | ||
| 52 | bootimg_dir, kernel_dir, native_sysroot): | ||
| 53 | """ | ||
| 54 | Called after all partitions have been prepared and assembled into a | ||
| 55 | disk image. In this case, we install the MBR. | ||
| 56 | """ | ||
| 57 | bootimg_dir = cls._get_bootimg_dir(bootimg_dir, 'syslinux') | ||
| 58 | mbrfile = "%s/syslinux/" % bootimg_dir | ||
| 59 | if creator.ptable_format == 'msdos': | ||
| 60 | mbrfile += "mbr.bin" | ||
| 61 | elif creator.ptable_format == 'gpt': | ||
| 62 | mbrfile += "gptmbr.bin" | ||
| 63 | else: | ||
| 64 | raise WicError("Unsupported partition table: %s" % | ||
| 65 | creator.ptable_format) | ||
| 66 | |||
| 67 | if not os.path.exists(mbrfile): | ||
| 68 | raise WicError("Couldn't find %s. If using the -e option, do you " | ||
| 69 | "have the right MACHINE set in local.conf? If not, " | ||
| 70 | "is the bootimg_dir path correct?" % mbrfile) | ||
| 71 | |||
| 72 | full_path = creator._full_path(workdir, disk_name, "direct") | ||
| 73 | logger.debug("Installing MBR on disk %s as %s with size %s bytes", | ||
| 74 | disk_name, full_path, disk.min_size) | ||
| 75 | |||
| 76 | dd_cmd = "dd if=%s of=%s conv=notrunc" % (mbrfile, full_path) | ||
| 77 | exec_cmd(dd_cmd, native_sysroot) | ||
| 78 | |||
| 79 | @classmethod | ||
| 80 | def do_configure_partition(cls, part, source_params, creator, cr_workdir, | ||
| 81 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 82 | native_sysroot): | ||
| 83 | """ | ||
| 84 | Called before do_prepare_partition(), creates syslinux config | ||
| 85 | """ | ||
| 86 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 87 | |||
| 88 | install_cmd = "install -d %s" % hdddir | ||
| 89 | exec_cmd(install_cmd) | ||
| 90 | |||
| 91 | bootloader = creator.ks.bootloader | ||
| 92 | |||
| 93 | custom_cfg = None | ||
| 94 | if bootloader.configfile: | ||
| 95 | custom_cfg = get_custom_config(bootloader.configfile) | ||
| 96 | if custom_cfg: | ||
| 97 | # Use a custom configuration for grub | ||
| 98 | syslinux_conf = custom_cfg | ||
| 99 | logger.debug("Using custom configuration file %s " | ||
| 100 | "for syslinux.cfg", bootloader.configfile) | ||
| 101 | else: | ||
| 102 | raise WicError("configfile is specified but failed to " | ||
| 103 | "get it from %s." % bootloader.configfile) | ||
| 104 | |||
| 105 | if not custom_cfg: | ||
| 106 | # Create syslinux configuration using parameters from wks file | ||
| 107 | splash = os.path.join(cr_workdir, "/hdd/boot/splash.jpg") | ||
| 108 | if os.path.exists(splash): | ||
| 109 | splashline = "menu background splash.jpg" | ||
| 110 | else: | ||
| 111 | splashline = "" | ||
| 112 | |||
| 113 | syslinux_conf = "" | ||
| 114 | syslinux_conf += "PROMPT 0\n" | ||
| 115 | syslinux_conf += "TIMEOUT " + str(bootloader.timeout) + "\n" | ||
| 116 | syslinux_conf += "\n" | ||
| 117 | syslinux_conf += "ALLOWOPTIONS 1\n" | ||
| 118 | syslinux_conf += "SERIAL 0 115200\n" | ||
| 119 | syslinux_conf += "\n" | ||
| 120 | if splashline: | ||
| 121 | syslinux_conf += "%s\n" % splashline | ||
| 122 | syslinux_conf += "DEFAULT boot\n" | ||
| 123 | syslinux_conf += "LABEL boot\n" | ||
| 124 | |||
| 125 | kernel = "/vmlinuz" | ||
| 126 | syslinux_conf += "KERNEL " + kernel + "\n" | ||
| 127 | |||
| 128 | syslinux_conf += "APPEND label=boot root=%s %s\n" % \ | ||
| 129 | (creator.rootdev, bootloader.append) | ||
| 130 | |||
| 131 | logger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg", | ||
| 132 | cr_workdir) | ||
| 133 | cfg = open("%s/hdd/boot/syslinux.cfg" % cr_workdir, "w") | ||
| 134 | cfg.write(syslinux_conf) | ||
| 135 | cfg.close() | ||
| 136 | |||
| 137 | @classmethod | ||
| 138 | def do_prepare_partition(cls, part, source_params, creator, cr_workdir, | ||
| 139 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 140 | rootfs_dir, native_sysroot): | ||
| 141 | """ | ||
| 142 | Called to do the actual content population for a partition i.e. it | ||
| 143 | 'prepares' the partition to be incorporated into the image. | ||
| 144 | In this case, prepare content for legacy bios boot partition. | ||
| 145 | """ | ||
| 146 | bootimg_dir = cls._get_bootimg_dir(bootimg_dir, 'syslinux') | ||
| 147 | |||
| 148 | staging_kernel_dir = kernel_dir | ||
| 149 | |||
| 150 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 151 | |||
| 152 | kernel = get_bitbake_var("KERNEL_IMAGETYPE") | ||
| 153 | if get_bitbake_var("INITRAMFS_IMAGE_BUNDLE") == "1": | ||
| 154 | if get_bitbake_var("INITRAMFS_IMAGE"): | ||
| 155 | kernel = "%s-%s.bin" % \ | ||
| 156 | (get_bitbake_var("KERNEL_IMAGETYPE"), get_bitbake_var("INITRAMFS_LINK_NAME")) | ||
| 157 | |||
| 158 | cmds = ("install -m 0644 %s/%s %s/vmlinuz" % | ||
| 159 | (staging_kernel_dir, kernel, hdddir), | ||
| 160 | "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" % | ||
| 161 | (bootimg_dir, hdddir), | ||
| 162 | "install -m 0644 %s/syslinux/vesamenu.c32 %s/vesamenu.c32" % | ||
| 163 | (bootimg_dir, hdddir), | ||
| 164 | "install -m 444 %s/syslinux/libcom32.c32 %s/libcom32.c32" % | ||
| 165 | (bootimg_dir, hdddir), | ||
| 166 | "install -m 444 %s/syslinux/libutil.c32 %s/libutil.c32" % | ||
| 167 | (bootimg_dir, hdddir)) | ||
| 168 | |||
| 169 | for install_cmd in cmds: | ||
| 170 | exec_cmd(install_cmd) | ||
| 171 | |||
| 172 | du_cmd = "du -bks %s" % hdddir | ||
| 173 | out = exec_cmd(du_cmd) | ||
| 174 | blocks = int(out.split()[0]) | ||
| 175 | |||
| 176 | extra_blocks = part.get_extra_block_count(blocks) | ||
| 177 | |||
| 178 | if extra_blocks < BOOTDD_EXTRA_SPACE: | ||
| 179 | extra_blocks = BOOTDD_EXTRA_SPACE | ||
| 180 | |||
| 181 | blocks += extra_blocks | ||
| 182 | |||
| 183 | logger.debug("Added %d extra blocks to %s to get to %d total blocks", | ||
| 184 | extra_blocks, part.mountpoint, blocks) | ||
| 185 | |||
| 186 | # dosfs image, created by mkdosfs | ||
| 187 | bootimg = "%s/boot%s.img" % (cr_workdir, part.lineno) | ||
| 188 | |||
| 189 | label = part.label if part.label else "boot" | ||
| 190 | |||
| 191 | dosfs_cmd = "mkdosfs -n %s -i %s -S 512 -C %s %d" % \ | ||
| 192 | (label, part.fsuuid, bootimg, blocks) | ||
| 193 | exec_native_cmd(dosfs_cmd, native_sysroot) | ||
| 194 | |||
| 195 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) | ||
| 196 | exec_native_cmd(mcopy_cmd, native_sysroot) | ||
| 197 | |||
| 198 | syslinux_cmd = "syslinux %s" % bootimg | ||
| 199 | exec_native_cmd(syslinux_cmd, native_sysroot) | ||
| 200 | |||
| 201 | chmod_cmd = "chmod 644 %s" % bootimg | ||
| 202 | exec_cmd(chmod_cmd) | ||
| 203 | |||
| 204 | du_cmd = "du -Lbks %s" % bootimg | ||
| 205 | out = exec_cmd(du_cmd) | ||
| 206 | bootimg_size = out.split()[0] | ||
| 207 | |||
| 208 | part.size = int(bootimg_size) | ||
| 209 | part.source_file = bootimg | ||
diff --git a/scripts/lib/wic/plugins/source/bootimg-biosplusefi.py b/scripts/lib/wic/plugins/source/bootimg_biosplusefi.py index 5bd7390680..4279ddded8 100644 --- a/scripts/lib/wic/plugins/source/bootimg-biosplusefi.py +++ b/scripts/lib/wic/plugins/source/bootimg_biosplusefi.py | |||
| @@ -13,7 +13,7 @@ | |||
| 13 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 13 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 14 | # | 14 | # |
| 15 | # DESCRIPTION | 15 | # DESCRIPTION |
| 16 | # This implements the 'bootimg-biosplusefi' source plugin class for 'wic' | 16 | # This implements the 'bootimg_biosplusefi' source plugin class for 'wic' |
| 17 | # | 17 | # |
| 18 | # AUTHORS | 18 | # AUTHORS |
| 19 | # William Bourque <wbourque [at) gmail.com> | 19 | # William Bourque <wbourque [at) gmail.com> |
| @@ -34,7 +34,7 @@ class BootimgBiosPlusEFIPlugin(SourcePlugin): | |||
| 34 | 34 | ||
| 35 | Note it is possible to create an image that can boot from both | 35 | Note it is possible to create an image that can boot from both |
| 36 | legacy BIOS and EFI by defining two partitions : one with arg | 36 | legacy BIOS and EFI by defining two partitions : one with arg |
| 37 | --source bootimg-efi and another one with --source bootimg-pcbios. | 37 | --source bootimg_efi and another one with --source bootimg_pcbios. |
| 38 | However, this method has the obvious downside that it requires TWO | 38 | However, this method has the obvious downside that it requires TWO |
| 39 | partitions to be created on the storage device. | 39 | partitions to be created on the storage device. |
| 40 | Both partitions will also be marked as "bootable" which does not work on | 40 | Both partitions will also be marked as "bootable" which does not work on |
| @@ -45,7 +45,7 @@ class BootimgBiosPlusEFIPlugin(SourcePlugin): | |||
| 45 | the first partition will be duplicated into the second, even though it | 45 | the first partition will be duplicated into the second, even though it |
| 46 | will not be used at all. | 46 | will not be used at all. |
| 47 | 47 | ||
| 48 | Also, unlike "isoimage-isohybrid" that also does BIOS and EFI, this plugin | 48 | Also, unlike "isoimage_isohybrid" that also does BIOS and EFI, this plugin |
| 49 | allows you to have more than only a single rootfs partitions and does | 49 | allows you to have more than only a single rootfs partitions and does |
| 50 | not turn the rootfs into an initramfs RAM image. | 50 | not turn the rootfs into an initramfs RAM image. |
| 51 | 51 | ||
| @@ -53,32 +53,32 @@ class BootimgBiosPlusEFIPlugin(SourcePlugin): | |||
| 53 | does not have the limitations listed above. | 53 | does not have the limitations listed above. |
| 54 | 54 | ||
| 55 | The plugin is made so it does tries not to reimplement what's already | 55 | The plugin is made so it does tries not to reimplement what's already |
| 56 | been done in other plugins; as such it imports "bootimg-pcbios" | 56 | been done in other plugins; as such it imports "bootimg_pcbios" |
| 57 | and "bootimg-efi". | 57 | and "bootimg_efi". |
| 58 | Plugin "bootimg-pcbios" is used to generate legacy BIOS boot. | 58 | Plugin "bootimg_pcbios" is used to generate legacy BIOS boot. |
| 59 | Plugin "bootimg-efi" is used to generate the UEFI boot. Note that it | 59 | Plugin "bootimg_efi" is used to generate the UEFI boot. Note that it |
| 60 | requires a --sourceparams argument to know which loader to use; refer | 60 | requires a --sourceparams argument to know which loader to use; refer |
| 61 | to "bootimg-efi" code/documentation for the list of loader. | 61 | to "bootimg_efi" code/documentation for the list of loader. |
| 62 | 62 | ||
| 63 | Imports are handled with "SourceFileLoader" from importlib as it is | 63 | Imports are handled with "SourceFileLoader" from importlib as it is |
| 64 | otherwise very difficult to import module that has hyphen "-" in their | 64 | otherwise very difficult to import module that has hyphen "-" in their |
| 65 | filename. | 65 | filename. |
| 66 | The SourcePlugin() methods used in the plugins (do_install_disk, | 66 | The SourcePlugin() methods used in the plugins (do_install_disk, |
| 67 | do_configure_partition, do_prepare_partition) are then called on both, | 67 | do_configure_partition, do_prepare_partition) are then called on both, |
| 68 | beginning by "bootimg-efi". | 68 | beginning by "bootimg_efi". |
| 69 | 69 | ||
| 70 | Plugin options, such as "--sourceparams" can still be passed to a | 70 | Plugin options, such as "--sourceparams" can still be passed to a |
| 71 | plugin, as long they does not cause issue in the other plugin. | 71 | plugin, as long they does not cause issue in the other plugin. |
| 72 | 72 | ||
| 73 | Example wic configuration: | 73 | Example wic configuration: |
| 74 | part /boot --source bootimg-biosplusefi --sourceparams="loader=grub-efi"\\ | 74 | part /boot --source bootimg_biosplusefi --sourceparams="loader=grub-efi"\\ |
| 75 | --ondisk sda --label os_boot --active --align 1024 --use-uuid | 75 | --ondisk sda --label os_boot --active --align 1024 --use-uuid |
| 76 | """ | 76 | """ |
| 77 | 77 | ||
| 78 | name = 'bootimg-biosplusefi' | 78 | name = 'bootimg_biosplusefi' |
| 79 | 79 | ||
| 80 | __PCBIOS_MODULE_NAME = "bootimg-pcbios" | 80 | __PCBIOS_MODULE_NAME = "bootimg_pcbios" |
| 81 | __EFI_MODULE_NAME = "bootimg-efi" | 81 | __EFI_MODULE_NAME = "bootimg_efi" |
| 82 | 82 | ||
| 83 | __imgEFIObj = None | 83 | __imgEFIObj = None |
| 84 | __imgBiosObj = None | 84 | __imgBiosObj = None |
| @@ -100,7 +100,7 @@ class BootimgBiosPlusEFIPlugin(SourcePlugin): | |||
| 100 | 100 | ||
| 101 | """ | 101 | """ |
| 102 | 102 | ||
| 103 | # Import bootimg-pcbios (class name "BootimgPcbiosPlugin") | 103 | # Import bootimg_pcbios (class name "BootimgPcbiosPlugin") |
| 104 | modulePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), | 104 | modulePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), |
| 105 | cls.__PCBIOS_MODULE_NAME + ".py") | 105 | cls.__PCBIOS_MODULE_NAME + ".py") |
| 106 | loader = SourceFileLoader(cls.__PCBIOS_MODULE_NAME, modulePath) | 106 | loader = SourceFileLoader(cls.__PCBIOS_MODULE_NAME, modulePath) |
| @@ -108,7 +108,7 @@ class BootimgBiosPlusEFIPlugin(SourcePlugin): | |||
| 108 | loader.exec_module(mod) | 108 | loader.exec_module(mod) |
| 109 | cls.__imgBiosObj = mod.BootimgPcbiosPlugin() | 109 | cls.__imgBiosObj = mod.BootimgPcbiosPlugin() |
| 110 | 110 | ||
| 111 | # Import bootimg-efi (class name "BootimgEFIPlugin") | 111 | # Import bootimg_efi (class name "BootimgEFIPlugin") |
| 112 | modulePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), | 112 | modulePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), |
| 113 | cls.__EFI_MODULE_NAME + ".py") | 113 | cls.__EFI_MODULE_NAME + ".py") |
| 114 | loader = SourceFileLoader(cls.__EFI_MODULE_NAME, modulePath) | 114 | loader = SourceFileLoader(cls.__EFI_MODULE_NAME, modulePath) |
diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py b/scripts/lib/wic/plugins/source/bootimg_efi.py index 0391aebdc8..cf16705a28 100644 --- a/scripts/lib/wic/plugins/source/bootimg-efi.py +++ b/scripts/lib/wic/plugins/source/bootimg_efi.py | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | # SPDX-License-Identifier: GPL-2.0-only | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # | 5 | # |
| 6 | # DESCRIPTION | 6 | # DESCRIPTION |
| 7 | # This implements the 'bootimg-efi' source plugin class for 'wic' | 7 | # This implements the 'bootimg_efi' source plugin class for 'wic' |
| 8 | # | 8 | # |
| 9 | # AUTHORS | 9 | # AUTHORS |
| 10 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> | 10 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> |
| @@ -32,7 +32,29 @@ class BootimgEFIPlugin(SourcePlugin): | |||
| 32 | This plugin supports GRUB 2 and systemd-boot bootloaders. | 32 | This plugin supports GRUB 2 and systemd-boot bootloaders. |
| 33 | """ | 33 | """ |
| 34 | 34 | ||
| 35 | name = 'bootimg-efi' | 35 | name = 'bootimg_efi' |
| 36 | |||
| 37 | @classmethod | ||
| 38 | def _copy_additional_files(cls, hdddir, initrd, dtb): | ||
| 39 | bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") | ||
| 40 | if not bootimg_dir: | ||
| 41 | raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting") | ||
| 42 | |||
| 43 | if initrd: | ||
| 44 | initrds = initrd.split(';') | ||
| 45 | for rd in initrds: | ||
| 46 | cp_cmd = "cp -v -p %s/%s %s" % (bootimg_dir, rd, hdddir) | ||
| 47 | out = exec_cmd(cp_cmd, True) | ||
| 48 | logger.debug("initrd files:\n%s" % (out)) | ||
| 49 | else: | ||
| 50 | logger.debug("Ignoring missing initrd") | ||
| 51 | |||
| 52 | if dtb: | ||
| 53 | if ';' in dtb: | ||
| 54 | raise WicError("Only one DTB supported, exiting") | ||
| 55 | cp_cmd = "cp -v -p %s/%s %s" % (bootimg_dir, dtb, hdddir) | ||
| 56 | out = exec_cmd(cp_cmd, True) | ||
| 57 | logger.debug("dtb files:\n%s" % (out)) | ||
| 36 | 58 | ||
| 37 | @classmethod | 59 | @classmethod |
| 38 | def do_configure_grubefi(cls, hdddir, creator, cr_workdir, source_params): | 60 | def do_configure_grubefi(cls, hdddir, creator, cr_workdir, source_params): |
| @@ -53,18 +75,9 @@ class BootimgEFIPlugin(SourcePlugin): | |||
| 53 | "get it from %s." % configfile) | 75 | "get it from %s." % configfile) |
| 54 | 76 | ||
| 55 | initrd = source_params.get('initrd') | 77 | initrd = source_params.get('initrd') |
| 78 | dtb = source_params.get('dtb') | ||
| 56 | 79 | ||
| 57 | if initrd: | 80 | cls._copy_additional_files(hdddir, initrd, dtb) |
| 58 | bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") | ||
| 59 | if not bootimg_dir: | ||
| 60 | raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting") | ||
| 61 | |||
| 62 | initrds = initrd.split(';') | ||
| 63 | for rd in initrds: | ||
| 64 | cp_cmd = "cp %s/%s %s" % (bootimg_dir, rd, hdddir) | ||
| 65 | exec_cmd(cp_cmd, True) | ||
| 66 | else: | ||
| 67 | logger.debug("Ignoring missing initrd") | ||
| 68 | 81 | ||
| 69 | if not custom_cfg: | 82 | if not custom_cfg: |
| 70 | # Create grub configuration using parameters from wks file | 83 | # Create grub configuration using parameters from wks file |
| @@ -98,6 +111,9 @@ class BootimgEFIPlugin(SourcePlugin): | |||
| 98 | grubefi_conf += " /%s" % rd | 111 | grubefi_conf += " /%s" % rd |
| 99 | grubefi_conf += "\n" | 112 | grubefi_conf += "\n" |
| 100 | 113 | ||
| 114 | if dtb: | ||
| 115 | grubefi_conf += "devicetree /%s\n" % dtb | ||
| 116 | |||
| 101 | grubefi_conf += "}\n" | 117 | grubefi_conf += "}\n" |
| 102 | 118 | ||
| 103 | logger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg", | 119 | logger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg", |
| @@ -109,8 +125,16 @@ class BootimgEFIPlugin(SourcePlugin): | |||
| 109 | @classmethod | 125 | @classmethod |
| 110 | def do_configure_systemdboot(cls, hdddir, creator, cr_workdir, source_params): | 126 | def do_configure_systemdboot(cls, hdddir, creator, cr_workdir, source_params): |
| 111 | """ | 127 | """ |
| 112 | Create loader-specific systemd-boot/gummiboot config | 128 | Create loader-specific systemd-boot/gummiboot config. Unified Kernel Image (uki) |
| 129 | support is done in image recipe with uki.bbclass and only systemd-boot loader config | ||
| 130 | and ESP partition structure is created here. | ||
| 113 | """ | 131 | """ |
| 132 | # detect uki.bbclass usage | ||
| 133 | image_classes = get_bitbake_var("IMAGE_CLASSES").split() | ||
| 134 | unified_image = False | ||
| 135 | if "uki" in image_classes: | ||
| 136 | unified_image = True | ||
| 137 | |||
| 114 | install_cmd = "install -d %s/loader" % hdddir | 138 | install_cmd = "install -d %s/loader" % hdddir |
| 115 | exec_cmd(install_cmd) | 139 | exec_cmd(install_cmd) |
| 116 | 140 | ||
| @@ -118,35 +142,26 @@ class BootimgEFIPlugin(SourcePlugin): | |||
| 118 | exec_cmd(install_cmd) | 142 | exec_cmd(install_cmd) |
| 119 | 143 | ||
| 120 | bootloader = creator.ks.bootloader | 144 | bootloader = creator.ks.bootloader |
| 121 | |||
| 122 | loader_conf = "" | 145 | loader_conf = "" |
| 123 | if source_params.get('create-unified-kernel-image') != "true": | ||
| 124 | loader_conf += "default boot\n" | ||
| 125 | loader_conf += "timeout %d\n" % bootloader.timeout | ||
| 126 | 146 | ||
| 127 | initrd = source_params.get('initrd') | 147 | # 5 seconds is a sensible default timeout |
| 128 | 148 | loader_conf += "timeout %d\n" % (bootloader.timeout or 5) | |
| 129 | if initrd and source_params.get('create-unified-kernel-image') != "true": | ||
| 130 | # obviously we need to have a common common deploy var | ||
| 131 | bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") | ||
| 132 | if not bootimg_dir: | ||
| 133 | raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting") | ||
| 134 | |||
| 135 | initrds = initrd.split(';') | ||
| 136 | for rd in initrds: | ||
| 137 | cp_cmd = "cp %s/%s %s" % (bootimg_dir, rd, hdddir) | ||
| 138 | exec_cmd(cp_cmd, True) | ||
| 139 | else: | ||
| 140 | logger.debug("Ignoring missing initrd") | ||
| 141 | 149 | ||
| 142 | logger.debug("Writing systemd-boot config " | 150 | logger.debug("Writing systemd-boot config " |
| 143 | "%s/hdd/boot/loader/loader.conf", cr_workdir) | 151 | "%s/hdd/boot/loader/loader.conf", cr_workdir) |
| 144 | cfg = open("%s/hdd/boot/loader/loader.conf" % cr_workdir, "w") | 152 | cfg = open("%s/hdd/boot/loader/loader.conf" % cr_workdir, "w") |
| 145 | cfg.write(loader_conf) | 153 | cfg.write(loader_conf) |
| 154 | logger.debug("loader.conf:\n%s" % (loader_conf)) | ||
| 146 | cfg.close() | 155 | cfg.close() |
| 147 | 156 | ||
| 157 | initrd = source_params.get('initrd') | ||
| 158 | dtb = source_params.get('dtb') | ||
| 159 | if not unified_image: | ||
| 160 | cls._copy_additional_files(hdddir, initrd, dtb) | ||
| 161 | |||
| 148 | configfile = creator.ks.bootloader.configfile | 162 | configfile = creator.ks.bootloader.configfile |
| 149 | custom_cfg = None | 163 | custom_cfg = None |
| 164 | boot_conf = "" | ||
| 150 | if configfile: | 165 | if configfile: |
| 151 | custom_cfg = get_custom_config(configfile) | 166 | custom_cfg = get_custom_config(configfile) |
| 152 | if custom_cfg: | 167 | if custom_cfg: |
| @@ -157,8 +172,7 @@ class BootimgEFIPlugin(SourcePlugin): | |||
| 157 | else: | 172 | else: |
| 158 | raise WicError("configfile is specified but failed to " | 173 | raise WicError("configfile is specified but failed to " |
| 159 | "get it from %s.", configfile) | 174 | "get it from %s.", configfile) |
| 160 | 175 | else: | |
| 161 | if not custom_cfg: | ||
| 162 | # Create systemd-boot configuration using parameters from wks file | 176 | # Create systemd-boot configuration using parameters from wks file |
| 163 | kernel = get_bitbake_var("KERNEL_IMAGETYPE") | 177 | kernel = get_bitbake_var("KERNEL_IMAGETYPE") |
| 164 | if get_bitbake_var("INITRAMFS_IMAGE_BUNDLE") == "1": | 178 | if get_bitbake_var("INITRAMFS_IMAGE_BUNDLE") == "1": |
| @@ -168,7 +182,6 @@ class BootimgEFIPlugin(SourcePlugin): | |||
| 168 | 182 | ||
| 169 | title = source_params.get('title') | 183 | title = source_params.get('title') |
| 170 | 184 | ||
| 171 | boot_conf = "" | ||
| 172 | boot_conf += "title %s\n" % (title if title else "boot") | 185 | boot_conf += "title %s\n" % (title if title else "boot") |
| 173 | boot_conf += "linux /%s\n" % kernel | 186 | boot_conf += "linux /%s\n" % kernel |
| 174 | 187 | ||
| @@ -185,11 +198,15 @@ class BootimgEFIPlugin(SourcePlugin): | |||
| 185 | for rd in initrds: | 198 | for rd in initrds: |
| 186 | boot_conf += "initrd /%s\n" % rd | 199 | boot_conf += "initrd /%s\n" % rd |
| 187 | 200 | ||
| 188 | if source_params.get('create-unified-kernel-image') != "true": | 201 | if dtb: |
| 202 | boot_conf += "devicetree /%s\n" % dtb | ||
| 203 | |||
| 204 | if not unified_image: | ||
| 189 | logger.debug("Writing systemd-boot config " | 205 | logger.debug("Writing systemd-boot config " |
| 190 | "%s/hdd/boot/loader/entries/boot.conf", cr_workdir) | 206 | "%s/hdd/boot/loader/entries/boot.conf", cr_workdir) |
| 191 | cfg = open("%s/hdd/boot/loader/entries/boot.conf" % cr_workdir, "w") | 207 | cfg = open("%s/hdd/boot/loader/entries/boot.conf" % cr_workdir, "w") |
| 192 | cfg.write(boot_conf) | 208 | cfg.write(boot_conf) |
| 209 | logger.debug("boot.conf:\n%s" % (boot_conf)) | ||
| 193 | cfg.close() | 210 | cfg.close() |
| 194 | 211 | ||
| 195 | 212 | ||
| @@ -210,10 +227,12 @@ class BootimgEFIPlugin(SourcePlugin): | |||
| 210 | cls.do_configure_grubefi(hdddir, creator, cr_workdir, source_params) | 227 | cls.do_configure_grubefi(hdddir, creator, cr_workdir, source_params) |
| 211 | elif source_params['loader'] == 'systemd-boot': | 228 | elif source_params['loader'] == 'systemd-boot': |
| 212 | cls.do_configure_systemdboot(hdddir, creator, cr_workdir, source_params) | 229 | cls.do_configure_systemdboot(hdddir, creator, cr_workdir, source_params) |
| 230 | elif source_params['loader'] == 'uefi-kernel': | ||
| 231 | pass | ||
| 213 | else: | 232 | else: |
| 214 | raise WicError("unrecognized bootimg-efi loader: %s" % source_params['loader']) | 233 | raise WicError("unrecognized bootimg_efi loader: %s" % source_params['loader']) |
| 215 | except KeyError: | 234 | except KeyError: |
| 216 | raise WicError("bootimg-efi requires a loader, none specified") | 235 | raise WicError("bootimg_efi requires a loader, none specified") |
| 217 | 236 | ||
| 218 | if get_bitbake_var("IMAGE_EFI_BOOT_FILES") is None: | 237 | if get_bitbake_var("IMAGE_EFI_BOOT_FILES") is None: |
| 219 | logger.debug('No boot files defined in IMAGE_EFI_BOOT_FILES') | 238 | logger.debug('No boot files defined in IMAGE_EFI_BOOT_FILES') |
| @@ -233,7 +252,7 @@ class BootimgEFIPlugin(SourcePlugin): | |||
| 233 | 252 | ||
| 234 | # list of tuples (src_name, dst_name) | 253 | # list of tuples (src_name, dst_name) |
| 235 | deploy_files = [] | 254 | deploy_files = [] |
| 236 | for src_entry in re.findall(r'[\w;\-\./\*]+', boot_files): | 255 | for src_entry in re.findall(r'[\w;\-\.\+/\*]+', boot_files): |
| 237 | if ';' in src_entry: | 256 | if ';' in src_entry: |
| 238 | dst_entry = tuple(src_entry.split(';')) | 257 | dst_entry = tuple(src_entry.split(';')) |
| 239 | if not dst_entry[0] or not dst_entry[1]: | 258 | if not dst_entry[0] or not dst_entry[1]: |
| @@ -292,90 +311,83 @@ class BootimgEFIPlugin(SourcePlugin): | |||
| 292 | (get_bitbake_var("KERNEL_IMAGETYPE"), get_bitbake_var("INITRAMFS_LINK_NAME")) | 311 | (get_bitbake_var("KERNEL_IMAGETYPE"), get_bitbake_var("INITRAMFS_LINK_NAME")) |
| 293 | 312 | ||
| 294 | if source_params.get('create-unified-kernel-image') == "true": | 313 | if source_params.get('create-unified-kernel-image') == "true": |
| 295 | initrd = source_params.get('initrd') | 314 | raise WicError("create-unified-kernel-image is no longer supported. Please use uki.bbclass.") |
| 296 | if not initrd: | ||
| 297 | raise WicError("initrd= must be specified when create-unified-kernel-image=true, exiting") | ||
| 298 | |||
| 299 | deploy_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") | ||
| 300 | efi_stub = glob("%s/%s" % (deploy_dir, "linux*.efi.stub")) | ||
| 301 | if len(efi_stub) == 0: | ||
| 302 | raise WicError("Unified Kernel Image EFI stub not found, exiting") | ||
| 303 | efi_stub = efi_stub[0] | ||
| 304 | |||
| 305 | with tempfile.TemporaryDirectory() as tmp_dir: | ||
| 306 | label = source_params.get('label') | ||
| 307 | label_conf = "root=%s" % creator.rootdev | ||
| 308 | if label: | ||
| 309 | label_conf = "LABEL=%s" % label | ||
| 310 | |||
| 311 | bootloader = creator.ks.bootloader | ||
| 312 | cmdline = open("%s/cmdline" % tmp_dir, "w") | ||
| 313 | cmdline.write("%s %s" % (label_conf, bootloader.append)) | ||
| 314 | cmdline.close() | ||
| 315 | 315 | ||
| 316 | initrds = initrd.split(';') | 316 | if source_params.get('install-kernel-into-boot-dir') != 'false': |
| 317 | initrd = open("%s/initrd" % tmp_dir, "wb") | 317 | install_cmd = "install -v -p -m 0644 %s/%s %s/%s" % \ |
| 318 | for f in initrds: | ||
| 319 | with open("%s/%s" % (deploy_dir, f), 'rb') as in_file: | ||
| 320 | shutil.copyfileobj(in_file, initrd) | ||
| 321 | initrd.close() | ||
| 322 | |||
| 323 | # Searched by systemd-boot: | ||
| 324 | # https://systemd.io/BOOT_LOADER_SPECIFICATION/#type-2-efi-unified-kernel-images | ||
| 325 | install_cmd = "install -d %s/EFI/Linux" % hdddir | ||
| 326 | exec_cmd(install_cmd) | ||
| 327 | |||
| 328 | staging_dir_host = get_bitbake_var("STAGING_DIR_HOST") | ||
| 329 | |||
| 330 | # https://www.freedesktop.org/software/systemd/man/systemd-stub.html | ||
| 331 | objcopy_cmd = "objcopy \ | ||
| 332 | --add-section .osrel=%s --change-section-vma .osrel=0x20000 \ | ||
| 333 | --add-section .cmdline=%s --change-section-vma .cmdline=0x30000 \ | ||
| 334 | --add-section .linux=%s --change-section-vma .linux=0x2000000 \ | ||
| 335 | --add-section .initrd=%s --change-section-vma .initrd=0x3000000 \ | ||
| 336 | %s %s" % \ | ||
| 337 | ("%s/usr/lib/os-release" % staging_dir_host, | ||
| 338 | cmdline.name, | ||
| 339 | "%s/%s" % (staging_kernel_dir, kernel), | ||
| 340 | initrd.name, | ||
| 341 | efi_stub, | ||
| 342 | "%s/EFI/Linux/linux.efi" % hdddir) | ||
| 343 | exec_cmd(objcopy_cmd) | ||
| 344 | else: | ||
| 345 | install_cmd = "install -m 0644 %s/%s %s/%s" % \ | ||
| 346 | (staging_kernel_dir, kernel, hdddir, kernel) | 318 | (staging_kernel_dir, kernel, hdddir, kernel) |
| 347 | exec_cmd(install_cmd) | 319 | out = exec_cmd(install_cmd) |
| 320 | logger.debug("Installed kernel files:\n%s" % out) | ||
| 348 | 321 | ||
| 349 | if get_bitbake_var("IMAGE_EFI_BOOT_FILES"): | 322 | if get_bitbake_var("IMAGE_EFI_BOOT_FILES"): |
| 350 | for src_path, dst_path in cls.install_task: | 323 | for src_path, dst_path in cls.install_task: |
| 351 | install_cmd = "install -m 0644 -D %s %s" \ | 324 | install_cmd = "install -v -p -m 0644 -D %s %s" \ |
| 352 | % (os.path.join(kernel_dir, src_path), | 325 | % (os.path.join(kernel_dir, src_path), |
| 353 | os.path.join(hdddir, dst_path)) | 326 | os.path.join(hdddir, dst_path)) |
| 354 | exec_cmd(install_cmd) | 327 | out = exec_cmd(install_cmd) |
| 328 | logger.debug("Installed IMAGE_EFI_BOOT_FILES:\n%s" % out) | ||
| 355 | 329 | ||
| 356 | try: | 330 | try: |
| 357 | if source_params['loader'] == 'grub-efi': | 331 | if source_params['loader'] == 'grub-efi': |
| 358 | shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, | 332 | shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, |
| 359 | "%s/grub.cfg" % cr_workdir) | 333 | "%s/grub.cfg" % cr_workdir) |
| 360 | for mod in [x for x in os.listdir(kernel_dir) if x.startswith("grub-efi-")]: | 334 | for mod in [x for x in os.listdir(kernel_dir) if x.startswith("grub-efi-")]: |
| 361 | cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir, mod, hdddir, mod[9:]) | 335 | cp_cmd = "cp -v -p %s/%s %s/EFI/BOOT/%s" % (kernel_dir, mod, hdddir, mod[9:]) |
| 362 | exec_cmd(cp_cmd, True) | 336 | exec_cmd(cp_cmd, True) |
| 363 | shutil.move("%s/grub.cfg" % cr_workdir, | 337 | shutil.move("%s/grub.cfg" % cr_workdir, |
| 364 | "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir) | 338 | "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir) |
| 365 | elif source_params['loader'] == 'systemd-boot': | 339 | elif source_params['loader'] == 'systemd-boot': |
| 366 | for mod in [x for x in os.listdir(kernel_dir) if x.startswith("systemd-")]: | 340 | for mod in [x for x in os.listdir(kernel_dir) if x.startswith("systemd-")]: |
| 367 | cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir, mod, hdddir, mod[8:]) | 341 | cp_cmd = "cp -v -p %s/%s %s/EFI/BOOT/%s" % (kernel_dir, mod, hdddir, mod[8:]) |
| 368 | exec_cmd(cp_cmd, True) | 342 | out = exec_cmd(cp_cmd, True) |
| 343 | logger.debug("systemd-boot files:\n%s" % out) | ||
| 344 | elif source_params['loader'] == 'uefi-kernel': | ||
| 345 | kernel = get_bitbake_var("KERNEL_IMAGETYPE") | ||
| 346 | if not kernel: | ||
| 347 | raise WicError("Empty KERNEL_IMAGETYPE") | ||
| 348 | target = get_bitbake_var("TARGET_SYS") | ||
| 349 | if not target: | ||
| 350 | raise WicError("Empty TARGET_SYS") | ||
| 351 | |||
| 352 | if re.match("x86_64", target): | ||
| 353 | kernel_efi_image = "bootx64.efi" | ||
| 354 | elif re.match('i.86', target): | ||
| 355 | kernel_efi_image = "bootia32.efi" | ||
| 356 | elif re.match('aarch64', target): | ||
| 357 | kernel_efi_image = "bootaa64.efi" | ||
| 358 | elif re.match('arm', target): | ||
| 359 | kernel_efi_image = "bootarm.efi" | ||
| 360 | else: | ||
| 361 | raise WicError("UEFI stub kernel is incompatible with target %s" % target) | ||
| 362 | |||
| 363 | for mod in [x for x in os.listdir(kernel_dir) if x.startswith(kernel)]: | ||
| 364 | cp_cmd = "cp -v -p %s/%s %s/EFI/BOOT/%s" % (kernel_dir, mod, hdddir, kernel_efi_image) | ||
| 365 | out = exec_cmd(cp_cmd, True) | ||
| 366 | logger.debug("uefi-kernel files:\n%s" % out) | ||
| 369 | else: | 367 | else: |
| 370 | raise WicError("unrecognized bootimg-efi loader: %s" % | 368 | raise WicError("unrecognized bootimg_efi loader: %s" % |
| 371 | source_params['loader']) | 369 | source_params['loader']) |
| 370 | |||
| 371 | # must have installed at least one EFI bootloader | ||
| 372 | out = glob(os.path.join(hdddir, 'EFI', 'BOOT', 'boot*.efi')) | ||
| 373 | logger.debug("Installed EFI loader files:\n%s" % out) | ||
| 374 | if not out: | ||
| 375 | raise WicError("No EFI loaders installed to ESP partition. Check that grub-efi, systemd-boot or similar is installed.") | ||
| 376 | |||
| 372 | except KeyError: | 377 | except KeyError: |
| 373 | raise WicError("bootimg-efi requires a loader, none specified") | 378 | raise WicError("bootimg_efi requires a loader, none specified") |
| 374 | 379 | ||
| 375 | startup = os.path.join(kernel_dir, "startup.nsh") | 380 | startup = os.path.join(kernel_dir, "startup.nsh") |
| 376 | if os.path.exists(startup): | 381 | if os.path.exists(startup): |
| 377 | cp_cmd = "cp %s %s/" % (startup, hdddir) | 382 | cp_cmd = "cp -v -p %s %s/" % (startup, hdddir) |
| 378 | exec_cmd(cp_cmd, True) | 383 | out = exec_cmd(cp_cmd, True) |
| 384 | logger.debug("startup files:\n%s" % out) | ||
| 385 | |||
| 386 | for paths in part.include_path or []: | ||
| 387 | for path in paths: | ||
| 388 | cp_cmd = "cp -v -p -r %s %s/" % (path, hdddir) | ||
| 389 | exec_cmd(cp_cmd, True) | ||
| 390 | logger.debug("include_path files:\n%s" % out) | ||
| 379 | 391 | ||
| 380 | du_cmd = "du -bks %s" % hdddir | 392 | du_cmd = "du -bks %s" % hdddir |
| 381 | out = exec_cmd(du_cmd) | 393 | out = exec_cmd(du_cmd) |
| @@ -391,17 +403,26 @@ class BootimgEFIPlugin(SourcePlugin): | |||
| 391 | logger.debug("Added %d extra blocks to %s to get to %d total blocks", | 403 | logger.debug("Added %d extra blocks to %s to get to %d total blocks", |
| 392 | extra_blocks, part.mountpoint, blocks) | 404 | extra_blocks, part.mountpoint, blocks) |
| 393 | 405 | ||
| 406 | # required for compatibility with certain devices expecting file system | ||
| 407 | # block count to be equal to partition block count | ||
| 408 | if blocks < part.fixed_size: | ||
| 409 | blocks = part.fixed_size | ||
| 410 | logger.debug("Overriding %s to %d total blocks for compatibility", | ||
| 411 | part.mountpoint, blocks) | ||
| 412 | |||
| 394 | # dosfs image, created by mkdosfs | 413 | # dosfs image, created by mkdosfs |
| 395 | bootimg = "%s/boot.img" % cr_workdir | 414 | bootimg = "%s/boot.img" % cr_workdir |
| 396 | 415 | ||
| 397 | label = part.label if part.label else "ESP" | 416 | label = part.label if part.label else "ESP" |
| 398 | 417 | ||
| 399 | dosfs_cmd = "mkdosfs -n %s -i %s -C %s %d" % \ | 418 | dosfs_cmd = "mkdosfs -v -n %s -i %s -C %s %d" % \ |
| 400 | (label, part.fsuuid, bootimg, blocks) | 419 | (label, part.fsuuid, bootimg, blocks) |
| 401 | exec_native_cmd(dosfs_cmd, native_sysroot) | 420 | exec_native_cmd(dosfs_cmd, native_sysroot) |
| 421 | logger.debug("mkdosfs:\n%s" % (str(out))) | ||
| 402 | 422 | ||
| 403 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) | 423 | mcopy_cmd = "mcopy -v -p -i %s -s %s/* ::/" % (bootimg, hdddir) |
| 404 | exec_native_cmd(mcopy_cmd, native_sysroot) | 424 | out = exec_native_cmd(mcopy_cmd, native_sysroot) |
| 425 | logger.debug("mcopy:\n%s" % (str(out))) | ||
| 405 | 426 | ||
| 406 | chmod_cmd = "chmod 644 %s" % bootimg | 427 | chmod_cmd = "chmod 644 %s" % bootimg |
| 407 | exec_cmd(chmod_cmd) | 428 | exec_cmd(chmod_cmd) |
diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg_partition.py index 5dbe2558d2..cc121a78f0 100644 --- a/scripts/lib/wic/plugins/source/bootimg-partition.py +++ b/scripts/lib/wic/plugins/source/bootimg_partition.py | |||
| @@ -1,8 +1,10 @@ | |||
| 1 | # | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors | ||
| 3 | # | ||
| 2 | # SPDX-License-Identifier: GPL-2.0-only | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 3 | # | 5 | # |
| 4 | # DESCRIPTION | 6 | # DESCRIPTION |
| 5 | # This implements the 'bootimg-partition' source plugin class for | 7 | # This implements the 'bootimg_partition' source plugin class for |
| 6 | # 'wic'. The plugin creates an image of boot partition, copying over | 8 | # 'wic'. The plugin creates an image of boot partition, copying over |
| 7 | # files listed in IMAGE_BOOT_FILES bitbake variable. | 9 | # files listed in IMAGE_BOOT_FILES bitbake variable. |
| 8 | # | 10 | # |
| @@ -14,7 +16,7 @@ import logging | |||
| 14 | import os | 16 | import os |
| 15 | import re | 17 | import re |
| 16 | 18 | ||
| 17 | from glob import glob | 19 | from oe.bootfiles import get_boot_files |
| 18 | 20 | ||
| 19 | from wic import WicError | 21 | from wic import WicError |
| 20 | from wic.engine import get_custom_config | 22 | from wic.engine import get_custom_config |
| @@ -29,7 +31,8 @@ class BootimgPartitionPlugin(SourcePlugin): | |||
| 29 | listed in IMAGE_BOOT_FILES bitbake variable. | 31 | listed in IMAGE_BOOT_FILES bitbake variable. |
| 30 | """ | 32 | """ |
| 31 | 33 | ||
| 32 | name = 'bootimg-partition' | 34 | name = 'bootimg_partition' |
| 35 | image_boot_files_var_name = 'IMAGE_BOOT_FILES' | ||
| 33 | 36 | ||
| 34 | @classmethod | 37 | @classmethod |
| 35 | def do_configure_partition(cls, part, source_params, cr, cr_workdir, | 38 | def do_configure_partition(cls, part, source_params, cr, cr_workdir, |
| @@ -54,51 +57,16 @@ class BootimgPartitionPlugin(SourcePlugin): | |||
| 54 | else: | 57 | else: |
| 55 | var = "" | 58 | var = "" |
| 56 | 59 | ||
| 57 | boot_files = get_bitbake_var("IMAGE_BOOT_FILES" + var) | 60 | boot_files = get_bitbake_var(cls.image_boot_files_var_name + var) |
| 58 | if boot_files is not None: | 61 | if boot_files is not None: |
| 59 | break | 62 | break |
| 60 | 63 | ||
| 61 | if boot_files is None: | 64 | if boot_files is None: |
| 62 | raise WicError('No boot files defined, IMAGE_BOOT_FILES unset for entry #%d' % part.lineno) | 65 | raise WicError('No boot files defined, %s unset for entry #%d' % (cls.image_boot_files_var_name, part.lineno)) |
| 63 | 66 | ||
| 64 | logger.debug('Boot files: %s', boot_files) | 67 | logger.debug('Boot files: %s', boot_files) |
| 65 | 68 | ||
| 66 | # list of tuples (src_name, dst_name) | 69 | cls.install_task = get_boot_files(kernel_dir, boot_files) |
| 67 | deploy_files = [] | ||
| 68 | for src_entry in re.findall(r'[\w;\-\./\*]+', boot_files): | ||
| 69 | if ';' in src_entry: | ||
| 70 | dst_entry = tuple(src_entry.split(';')) | ||
| 71 | if not dst_entry[0] or not dst_entry[1]: | ||
| 72 | raise WicError('Malformed boot file entry: %s' % src_entry) | ||
| 73 | else: | ||
| 74 | dst_entry = (src_entry, src_entry) | ||
| 75 | |||
| 76 | logger.debug('Destination entry: %r', dst_entry) | ||
| 77 | deploy_files.append(dst_entry) | ||
| 78 | |||
| 79 | cls.install_task = []; | ||
| 80 | for deploy_entry in deploy_files: | ||
| 81 | src, dst = deploy_entry | ||
| 82 | if '*' in src: | ||
| 83 | # by default install files under their basename | ||
| 84 | entry_name_fn = os.path.basename | ||
| 85 | if dst != src: | ||
| 86 | # unless a target name was given, then treat name | ||
| 87 | # as a directory and append a basename | ||
| 88 | entry_name_fn = lambda name: \ | ||
| 89 | os.path.join(dst, | ||
| 90 | os.path.basename(name)) | ||
| 91 | |||
| 92 | srcs = glob(os.path.join(kernel_dir, src)) | ||
| 93 | |||
| 94 | logger.debug('Globbed sources: %s', ', '.join(srcs)) | ||
| 95 | for entry in srcs: | ||
| 96 | src = os.path.relpath(entry, kernel_dir) | ||
| 97 | entry_dst_name = entry_name_fn(entry) | ||
| 98 | cls.install_task.append((src, entry_dst_name)) | ||
| 99 | else: | ||
| 100 | cls.install_task.append((src, dst)) | ||
| 101 | |||
| 102 | if source_params.get('loader') != "u-boot": | 70 | if source_params.get('loader') != "u-boot": |
| 103 | return | 71 | return |
| 104 | 72 | ||
| @@ -110,7 +78,7 @@ class BootimgPartitionPlugin(SourcePlugin): | |||
| 110 | # Use a custom configuration for extlinux.conf | 78 | # Use a custom configuration for extlinux.conf |
| 111 | extlinux_conf = custom_cfg | 79 | extlinux_conf = custom_cfg |
| 112 | logger.debug("Using custom configuration file " | 80 | logger.debug("Using custom configuration file " |
| 113 | "%s for extlinux.cfg", configfile) | 81 | "%s for extlinux.conf", configfile) |
| 114 | else: | 82 | else: |
| 115 | raise WicError("configfile is specified but failed to " | 83 | raise WicError("configfile is specified but failed to " |
| 116 | "get it from %s." % configfile) | 84 | "get it from %s." % configfile) |
diff --git a/scripts/lib/wic/plugins/source/bootimg_pcbios.py b/scripts/lib/wic/plugins/source/bootimg_pcbios.py new file mode 100644 index 0000000000..caabda6318 --- /dev/null +++ b/scripts/lib/wic/plugins/source/bootimg_pcbios.py | |||
| @@ -0,0 +1,483 @@ | |||
| 1 | # | ||
| 2 | # Copyright (c) 2014, Intel Corporation. | ||
| 3 | # | ||
| 4 | # SPDX-License-Identifier: GPL-2.0-only | ||
| 5 | # | ||
| 6 | # DESCRIPTION | ||
| 7 | # This implements the 'bootimg_pcbios' source plugin class for 'wic' | ||
| 8 | # | ||
| 9 | # AUTHORS | ||
| 10 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> | ||
| 11 | # | ||
| 12 | |||
| 13 | import logging | ||
| 14 | import os | ||
| 15 | import re | ||
| 16 | import shutil | ||
| 17 | |||
| 18 | from glob import glob | ||
| 19 | from wic import WicError | ||
| 20 | from wic.engine import get_custom_config | ||
| 21 | from wic.pluginbase import SourcePlugin | ||
| 22 | from wic.misc import (exec_cmd, exec_native_cmd, | ||
| 23 | get_bitbake_var, BOOTDD_EXTRA_SPACE) | ||
| 24 | |||
| 25 | logger = logging.getLogger('wic') | ||
| 26 | |||
| 27 | class BootimgPcbiosPlugin(SourcePlugin): | ||
| 28 | """ | ||
| 29 | Creates boot partition that is legacy BIOS firmare bootable with | ||
| 30 | MBR/MSDOS as partition table format. Plugin will install caller | ||
| 31 | selected bootloader directly to resulting wic image. | ||
| 32 | |||
| 33 | Supported Bootloaders: | ||
| 34 | * syslinux (default) | ||
| 35 | * grub | ||
| 36 | |||
| 37 | ****************** Wic Plugin Depends/Vars ****************** | ||
| 38 | WKS_FILE_DEPENDS = "grub-native grub" | ||
| 39 | WKS_FILE_DEPENDS = "syslinux-native syslinux" | ||
| 40 | |||
| 41 | # Optional variables | ||
| 42 | # GRUB_MKIMAGE_FORMAT_PC - Used to define target platform. | ||
| 43 | # GRUB_PREFIX_PATH - Used to define which directory | ||
| 44 | # grub config and modules are going | ||
| 45 | # to reside in. | ||
| 46 | GRUB_PREFIX_PATH = '/boot/grub2' # Default: /boot/grub | ||
| 47 | GRUB_MKIMAGE_FORMAT_PC = 'i386-pc' # Default: i386-pc | ||
| 48 | |||
| 49 | WICVARS:append = "\ | ||
| 50 | GRUB_PREFIX_PATH \ | ||
| 51 | GRUB_MKIMAGE_FORMAT_PC \ | ||
| 52 | " | ||
| 53 | ****************** Wic Plugin Depends/Vars ****************** | ||
| 54 | |||
| 55 | |||
| 56 | **************** Example kickstart Legacy Bios Grub Boot **************** | ||
| 57 | part boot --label bios_boot --fstype ext4 --offset 1024 --fixed-size 78M | ||
| 58 | --source bootimg_pcbios --sourceparams="loader-bios=grub" --active | ||
| 59 | |||
| 60 | part roots --label rootfs --fstype ext4 --source rootfs --use-uuid | ||
| 61 | bootloader --ptable msdos --source bootimg_pcbios | ||
| 62 | **************** Example kickstart Legacy Bios Grub Boot **************** | ||
| 63 | |||
| 64 | |||
| 65 | *************** Example kickstart Legacy Bios Syslinux Boot **************** | ||
| 66 | part /boot --source bootimg_pcbios --sourceparams="loader-bios=syslinux" | ||
| 67 | --ondisk sda --label boot --fstype vfat --align 1024 --active | ||
| 68 | |||
| 69 | part roots --label rootfs --fstype ext4 --source rootfs --use-uuid | ||
| 70 | bootloader --ptable msdos --source bootimg_pcbios | ||
| 71 | """ | ||
| 72 | |||
| 73 | name = 'bootimg_pcbios' | ||
| 74 | |||
| 75 | # Variable required for do_install_disk | ||
| 76 | loader = '' | ||
| 77 | |||
| 78 | @classmethod | ||
| 79 | def _get_bootimg_dir(cls, bootimg_dir, dirname): | ||
| 80 | """ | ||
| 81 | Check if dirname exists in default bootimg_dir or in STAGING_DIR. | ||
| 82 | """ | ||
| 83 | staging_datadir = get_bitbake_var("STAGING_DATADIR") | ||
| 84 | for result in (bootimg_dir, staging_datadir): | ||
| 85 | if os.path.exists("%s/%s" % (result, dirname)): | ||
| 86 | return result | ||
| 87 | |||
| 88 | # STAGING_DATADIR is expanded with MLPREFIX if multilib is enabled | ||
| 89 | # but dependency syslinux is still populated to original STAGING_DATADIR | ||
| 90 | nonarch_datadir = re.sub('/[^/]*recipe-sysroot', '/recipe-sysroot', staging_datadir) | ||
| 91 | if os.path.exists(os.path.join(nonarch_datadir, dirname)): | ||
| 92 | return nonarch_datadir | ||
| 93 | |||
| 94 | raise WicError("Couldn't find correct bootimg_dir, exiting") | ||
| 95 | |||
| 96 | @classmethod | ||
| 97 | def do_install_disk(cls, disk, disk_name, creator, workdir, oe_builddir, | ||
| 98 | bootimg_dir, kernel_dir, native_sysroot): | ||
| 99 | full_path = creator._full_path(workdir, disk_name, "direct") | ||
| 100 | logger.debug("Installing MBR on disk %s as %s with size %s bytes", | ||
| 101 | disk_name, full_path, disk.min_size) | ||
| 102 | |||
| 103 | if cls.loader == 'grub': | ||
| 104 | cls._do_install_grub(creator, kernel_dir, | ||
| 105 | native_sysroot, full_path) | ||
| 106 | elif cls.loader == 'syslinux': | ||
| 107 | cls._do_install_syslinux(creator, bootimg_dir, | ||
| 108 | native_sysroot, full_path) | ||
| 109 | else: | ||
| 110 | raise WicError("boot loader some how not specified check do_prepare_partition") | ||
| 111 | |||
| 112 | @classmethod | ||
| 113 | def do_configure_partition(cls, part, source_params, creator, cr_workdir, | ||
| 114 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 115 | native_sysroot): | ||
| 116 | try: | ||
| 117 | if source_params['loader-bios'] == 'grub': | ||
| 118 | cls._do_configure_grub(part, creator, cr_workdir) | ||
| 119 | elif source_params['loader-bios'] == 'syslinux': | ||
| 120 | cls._do_configure_syslinux(part, creator, cr_workdir) | ||
| 121 | else: | ||
| 122 | raise WicError("unrecognized bootimg_pcbios loader: %s" % source_params['loader-bios']) | ||
| 123 | except KeyError: | ||
| 124 | cls._do_configure_syslinux(part, creator, cr_workdir) | ||
| 125 | |||
| 126 | @classmethod | ||
| 127 | def do_prepare_partition(cls, part, source_params, creator, cr_workdir, | ||
| 128 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 129 | rootfs_dir, native_sysroot): | ||
| 130 | try: | ||
| 131 | if source_params['loader-bios'] == 'grub': | ||
| 132 | cls._do_prepare_grub(part, cr_workdir, oe_builddir, | ||
| 133 | kernel_dir, rootfs_dir, native_sysroot) | ||
| 134 | elif source_params['loader-bios'] == 'syslinux': | ||
| 135 | cls._do_prepare_syslinux(part, cr_workdir, bootimg_dir, | ||
| 136 | kernel_dir, native_sysroot) | ||
| 137 | else: | ||
| 138 | raise WicError("unrecognized bootimg_pcbios loader: %s" % source_params['loader-bios']) | ||
| 139 | |||
| 140 | # Required by do_install_disk | ||
| 141 | cls.loader = source_params['loader-bios'] | ||
| 142 | except KeyError: | ||
| 143 | # Required by do_install_disk | ||
| 144 | cls.loader = 'syslinux' | ||
| 145 | cls._do_prepare_syslinux(part, cr_workdir, bootimg_dir, | ||
| 146 | kernel_dir, native_sysroot) | ||
| 147 | |||
| 148 | @classmethod | ||
| 149 | def _get_staging_libdir(cls): | ||
| 150 | """ | ||
| 151 | For unknown reasons when running test with poky | ||
| 152 | STAGING_LIBDIR gets unset when wic create is executed. | ||
| 153 | Bellow is a hack to determine what STAGING_LIBDIR should | ||
| 154 | be if not specified. | ||
| 155 | """ | ||
| 156 | |||
| 157 | staging_libdir = get_bitbake_var('STAGING_LIBDIR') | ||
| 158 | staging_dir_target = get_bitbake_var('STAGING_DIR_TARGET') | ||
| 159 | |||
| 160 | if not staging_libdir: | ||
| 161 | staging_libdir = '%s/usr/lib64' % staging_dir_target | ||
| 162 | if not os.path.isdir(staging_libdir): | ||
| 163 | staging_libdir = '%s/usr/lib32' % staging_dir_target | ||
| 164 | if not os.path.isdir(staging_libdir): | ||
| 165 | staging_libdir = '%s/usr/lib' % staging_dir_target | ||
| 166 | |||
| 167 | return staging_libdir | ||
| 168 | |||
| 169 | @classmethod | ||
| 170 | def _get_bootloader_config(cls, bootloader, loader): | ||
| 171 | custom_cfg = None | ||
| 172 | |||
| 173 | if bootloader.configfile: | ||
| 174 | custom_cfg = get_custom_config(bootloader.configfile) | ||
| 175 | if custom_cfg: | ||
| 176 | logger.debug("Using custom configuration file %s " | ||
| 177 | "for %s.cfg", bootloader.configfile, | ||
| 178 | loader) | ||
| 179 | return custom_cfg | ||
| 180 | else: | ||
| 181 | raise WicError("configfile is specified but failed to " | ||
| 182 | "get it from %s." % bootloader.configfile) | ||
| 183 | return custom_cfg | ||
| 184 | |||
| 185 | @classmethod | ||
| 186 | def _do_configure_syslinux(cls, part, creator, cr_workdir): | ||
| 187 | """ | ||
| 188 | Called before do_prepare_partition(), creates syslinux config | ||
| 189 | """ | ||
| 190 | |||
| 191 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 192 | |||
| 193 | install_cmd = "install -d %s" % hdddir | ||
| 194 | exec_cmd(install_cmd) | ||
| 195 | |||
| 196 | bootloader = creator.ks.bootloader | ||
| 197 | syslinux_conf = cls._get_bootloader_config(bootloader, 'syslinux') | ||
| 198 | |||
| 199 | if not syslinux_conf: | ||
| 200 | # Create syslinux configuration using parameters from wks file | ||
| 201 | splash = os.path.join(hdddir, "/splash.jpg") | ||
| 202 | if os.path.exists(splash): | ||
| 203 | splashline = "menu background splash.jpg" | ||
| 204 | else: | ||
| 205 | splashline = "" | ||
| 206 | |||
| 207 | # Set a default timeout if none specified to avoid | ||
| 208 | # 'None' being the value placed within the configuration | ||
| 209 | # file. | ||
| 210 | if not bootloader.timeout: | ||
| 211 | bootloader.timeout = 500 | ||
| 212 | |||
| 213 | # Set a default kernel params string if none specified | ||
| 214 | # to avoid 'None' being the value placed within the | ||
| 215 | # configuration file. | ||
| 216 | if not bootloader.append: | ||
| 217 | bootloader.append = "rootwait console=ttyS0,115200 console=tty0" | ||
| 218 | |||
| 219 | syslinux_conf = "" | ||
| 220 | syslinux_conf += "PROMPT 0\n" | ||
| 221 | syslinux_conf += "TIMEOUT " + str(bootloader.timeout) + "\n" | ||
| 222 | syslinux_conf += "\n" | ||
| 223 | syslinux_conf += "ALLOWOPTIONS 1\n" | ||
| 224 | syslinux_conf += "SERIAL 0 115200\n" | ||
| 225 | syslinux_conf += "\n" | ||
| 226 | if splashline: | ||
| 227 | syslinux_conf += "%s\n" % splashline | ||
| 228 | syslinux_conf += "DEFAULT boot\n" | ||
| 229 | syslinux_conf += "LABEL boot\n" | ||
| 230 | |||
| 231 | kernel = "/" + get_bitbake_var("KERNEL_IMAGETYPE") | ||
| 232 | syslinux_conf += "KERNEL " + kernel + "\n" | ||
| 233 | |||
| 234 | syslinux_conf += "APPEND label=boot root=%s %s\n" % \ | ||
| 235 | (creator.rootdev, bootloader.append) | ||
| 236 | |||
| 237 | logger.debug("Writing syslinux config %s/syslinux.cfg", hdddir) | ||
| 238 | cfg = open("%s/hdd/boot/syslinux.cfg" % cr_workdir, "w") | ||
| 239 | cfg.write(syslinux_conf) | ||
| 240 | cfg.close() | ||
| 241 | |||
| 242 | @classmethod | ||
| 243 | def _do_prepare_syslinux(cls, part, cr_workdir, bootimg_dir, | ||
| 244 | kernel_dir, native_sysroot): | ||
| 245 | """ | ||
| 246 | Called to do the actual content population for a partition i.e. it | ||
| 247 | 'prepares' the partition to be incorporated into the image. | ||
| 248 | In this case, prepare content for legacy bios boot partition. | ||
| 249 | """ | ||
| 250 | bootimg_dir = cls._get_bootimg_dir(bootimg_dir, 'syslinux') | ||
| 251 | |||
| 252 | staging_kernel_dir = kernel_dir | ||
| 253 | |||
| 254 | hdddir = "%s/hdd/boot" % cr_workdir | ||
| 255 | |||
| 256 | kernel = get_bitbake_var("KERNEL_IMAGETYPE") | ||
| 257 | if get_bitbake_var("INITRAMFS_IMAGE_BUNDLE") == "1": | ||
| 258 | if get_bitbake_var("INITRAMFS_IMAGE"): | ||
| 259 | kernel = "%s-%s.bin" % \ | ||
| 260 | (get_bitbake_var("KERNEL_IMAGETYPE"), get_bitbake_var("INITRAMFS_LINK_NAME")) | ||
| 261 | |||
| 262 | cmds = ("install -m 0644 %s/%s %s/%s" % | ||
| 263 | (staging_kernel_dir, kernel, hdddir, get_bitbake_var("KERNEL_IMAGETYPE")), | ||
| 264 | "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" % | ||
| 265 | (bootimg_dir, hdddir), | ||
| 266 | "install -m 0644 %s/syslinux/vesamenu.c32 %s/vesamenu.c32" % | ||
| 267 | (bootimg_dir, hdddir), | ||
| 268 | "install -m 444 %s/syslinux/libcom32.c32 %s/libcom32.c32" % | ||
| 269 | (bootimg_dir, hdddir), | ||
| 270 | "install -m 444 %s/syslinux/libutil.c32 %s/libutil.c32" % | ||
| 271 | (bootimg_dir, hdddir)) | ||
| 272 | |||
| 273 | for install_cmd in cmds: | ||
| 274 | exec_cmd(install_cmd) | ||
| 275 | |||
| 276 | du_cmd = "du -bks %s" % hdddir | ||
| 277 | out = exec_cmd(du_cmd) | ||
| 278 | blocks = int(out.split()[0]) | ||
| 279 | |||
| 280 | extra_blocks = part.get_extra_block_count(blocks) | ||
| 281 | |||
| 282 | if extra_blocks < BOOTDD_EXTRA_SPACE: | ||
| 283 | extra_blocks = BOOTDD_EXTRA_SPACE | ||
| 284 | |||
| 285 | blocks += extra_blocks | ||
| 286 | |||
| 287 | logger.debug("Added %d extra blocks to %s to get to %d total blocks", | ||
| 288 | extra_blocks, part.mountpoint, blocks) | ||
| 289 | |||
| 290 | # dosfs image, created by mkdosfs | ||
| 291 | bootimg = "%s/boot%s.img" % (cr_workdir, part.lineno) | ||
| 292 | |||
| 293 | label = part.label if part.label else "boot" | ||
| 294 | |||
| 295 | dosfs_cmd = "mkdosfs -n %s -i %s -S 512 -C %s %d" % \ | ||
| 296 | (label, part.fsuuid, bootimg, blocks) | ||
| 297 | exec_native_cmd(dosfs_cmd, native_sysroot) | ||
| 298 | |||
| 299 | mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) | ||
| 300 | exec_native_cmd(mcopy_cmd, native_sysroot) | ||
| 301 | |||
| 302 | syslinux_cmd = "syslinux %s" % bootimg | ||
| 303 | exec_native_cmd(syslinux_cmd, native_sysroot) | ||
| 304 | |||
| 305 | chmod_cmd = "chmod 644 %s" % bootimg | ||
| 306 | exec_cmd(chmod_cmd) | ||
| 307 | |||
| 308 | du_cmd = "du -Lbks %s" % bootimg | ||
| 309 | out = exec_cmd(du_cmd) | ||
| 310 | bootimg_size = out.split()[0] | ||
| 311 | |||
| 312 | part.size = int(bootimg_size) | ||
| 313 | part.source_file = bootimg | ||
| 314 | |||
| 315 | @classmethod | ||
| 316 | def _do_install_syslinux(cls, creator, bootimg_dir, | ||
| 317 | native_sysroot, full_path): | ||
| 318 | """ | ||
| 319 | Called after all partitions have been prepared and assembled into a | ||
| 320 | disk image. In this case, we install the MBR. | ||
| 321 | """ | ||
| 322 | |||
| 323 | bootimg_dir = cls._get_bootimg_dir(bootimg_dir, 'syslinux') | ||
| 324 | mbrfile = "%s/syslinux/" % bootimg_dir | ||
| 325 | if creator.ptable_format == 'msdos': | ||
| 326 | mbrfile += "mbr.bin" | ||
| 327 | elif creator.ptable_format == 'gpt': | ||
| 328 | mbrfile += "gptmbr.bin" | ||
| 329 | else: | ||
| 330 | raise WicError("Unsupported partition table: %s" % | ||
| 331 | creator.ptable_format) | ||
| 332 | |||
| 333 | if not os.path.exists(mbrfile): | ||
| 334 | raise WicError("Couldn't find %s. If using the -e option, do you " | ||
| 335 | "have the right MACHINE set in local.conf? If not, " | ||
| 336 | "is the bootimg_dir path correct?" % mbrfile) | ||
| 337 | |||
| 338 | dd_cmd = "dd if=%s of=%s conv=notrunc" % (mbrfile, full_path) | ||
| 339 | exec_cmd(dd_cmd, native_sysroot) | ||
| 340 | |||
| 341 | @classmethod | ||
| 342 | def _do_configure_grub(cls, part, creator, cr_workdir): | ||
| 343 | hdddir = "%s/hdd" % cr_workdir | ||
| 344 | bootloader = creator.ks.bootloader | ||
| 345 | |||
| 346 | grub_conf = cls._get_bootloader_config(bootloader, 'grub') | ||
| 347 | |||
| 348 | grub_prefix_path = get_bitbake_var('GRUB_PREFIX_PATH') | ||
| 349 | if not grub_prefix_path: | ||
| 350 | grub_prefix_path = '/boot/grub' | ||
| 351 | |||
| 352 | grub_path = "%s/%s" %(hdddir, grub_prefix_path) | ||
| 353 | install_cmd = "install -d %s" % grub_path | ||
| 354 | exec_cmd(install_cmd) | ||
| 355 | |||
| 356 | if not grub_conf: | ||
| 357 | # Set a default timeout if none specified to avoid | ||
| 358 | # 'None' being the value placed within the configuration | ||
| 359 | # file. | ||
| 360 | if not bootloader.timeout: | ||
| 361 | bootloader.timeout = 500 | ||
| 362 | |||
| 363 | # Set a default kernel params string if none specified | ||
| 364 | # to avoid 'None' being the value placed within the | ||
| 365 | # configuration file. | ||
| 366 | if not bootloader.append: | ||
| 367 | bootloader.append = "rootwait rootfstype=%s " % (part.fstype) | ||
| 368 | bootloader.append += "console=ttyS0,115200 console=tty0" | ||
| 369 | |||
| 370 | kernel = "/boot/" + get_bitbake_var("KERNEL_IMAGETYPE") | ||
| 371 | |||
| 372 | grub_conf = 'serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n' | ||
| 373 | grub_conf += 'set gfxmode=auto\n' | ||
| 374 | grub_conf += 'set gfxpayload=keep\n\n' | ||
| 375 | grub_conf += 'set default=0\n\n' | ||
| 376 | grub_conf += '# Boot automatically after %d secs.\n' % (bootloader.timeout) | ||
| 377 | grub_conf += 'set timeout=%d\n\n' % (bootloader.timeout) | ||
| 378 | grub_conf += 'menuentry \'default\' {\n' | ||
| 379 | grub_conf += '\tsearch --no-floppy --set=root --file %s\n' % (kernel) | ||
| 380 | grub_conf += '\tprobe --set partuuid --part-uuid ($root)\n' | ||
| 381 | grub_conf += '\tlinux %s root=PARTUUID=$partuuid %s\n}\n' % \ | ||
| 382 | (kernel, bootloader.append) | ||
| 383 | |||
| 384 | logger.debug("Writing grub config %s/grub.cfg", grub_path) | ||
| 385 | cfg = open("%s/grub.cfg" % grub_path, "w") | ||
| 386 | cfg.write(grub_conf) | ||
| 387 | cfg.close() | ||
| 388 | |||
| 389 | @classmethod | ||
| 390 | def _do_prepare_grub(cls, part, cr_workdir, oe_builddir, | ||
| 391 | kernel_dir, rootfs_dir, native_sysroot): | ||
| 392 | """ | ||
| 393 | 1. Generate embed.cfg that'll later be embedded into core.img. | ||
| 394 | So, that core.img knows where to search for grub.cfg. | ||
| 395 | 2. Generate core.img or grub stage 1.5. | ||
| 396 | 3. Copy modules into partition. | ||
| 397 | 4. Create partition rootfs file. | ||
| 398 | """ | ||
| 399 | |||
| 400 | hdddir = "%s/hdd" % cr_workdir | ||
| 401 | |||
| 402 | copy_types = [ '*.mod', '*.o', '*.lst' ] | ||
| 403 | |||
| 404 | builtin_modules = 'boot linux ext2 fat serial part_msdos part_gpt \ | ||
| 405 | normal multiboot probe biosdisk msdospart configfile search loadenv test' | ||
| 406 | |||
| 407 | staging_libdir = cls._get_staging_libdir() | ||
| 408 | |||
| 409 | grub_format = get_bitbake_var('GRUB_MKIMAGE_FORMAT_PC') | ||
| 410 | if not grub_format: | ||
| 411 | grub_format = 'i386-pc' | ||
| 412 | |||
| 413 | grub_prefix_path = get_bitbake_var('GRUB_PREFIX_PATH') | ||
| 414 | if not grub_prefix_path: | ||
| 415 | grub_prefix_path = '/boot/grub' | ||
| 416 | |||
| 417 | grub_path = "%s/%s" %(hdddir, grub_prefix_path) | ||
| 418 | core_img = '%s/grub-bios-core.img' % (kernel_dir) | ||
| 419 | grub_mods_path = '%s/grub/%s' % (staging_libdir, grub_format) | ||
| 420 | |||
| 421 | # Generate embedded grub config | ||
| 422 | embed_cfg_str = 'search.file %s/grub.cfg root\n' % (grub_prefix_path) | ||
| 423 | embed_cfg_str += 'set prefix=($root)%s\n' % (grub_prefix_path) | ||
| 424 | embed_cfg_str += 'configfile ($root)%s/grub.cfg\n' % (grub_prefix_path) | ||
| 425 | cfg = open('%s/embed.cfg' % (kernel_dir), 'w+') | ||
| 426 | cfg.write(embed_cfg_str) | ||
| 427 | cfg.close() | ||
| 428 | |||
| 429 | # core.img doesn't get included into boot partition | ||
| 430 | # it's later dd onto the resulting wic image. | ||
| 431 | grub_mkimage = 'grub-mkimage \ | ||
| 432 | --prefix=%s \ | ||
| 433 | --format=%s \ | ||
| 434 | --config=%s/embed.cfg \ | ||
| 435 | --directory=%s \ | ||
| 436 | --output=%s %s' % \ | ||
| 437 | (grub_prefix_path, grub_format, kernel_dir, | ||
| 438 | grub_mods_path, core_img, builtin_modules) | ||
| 439 | exec_native_cmd(grub_mkimage, native_sysroot) | ||
| 440 | |||
| 441 | # Copy grub modules | ||
| 442 | install_dir = '%s/%s/%s' % (hdddir, grub_prefix_path, grub_format) | ||
| 443 | os.makedirs(install_dir, exist_ok=True) | ||
| 444 | |||
| 445 | for ctype in copy_types: | ||
| 446 | files = glob('%s/grub/%s/%s' % \ | ||
| 447 | (staging_libdir, grub_format, ctype)) | ||
| 448 | for file in files: | ||
| 449 | shutil.copy2(file, install_dir, follow_symlinks=True) | ||
| 450 | |||
| 451 | # Create boot partition | ||
| 452 | logger.debug('Prepare partition using rootfs in %s', hdddir) | ||
| 453 | part.prepare_rootfs(cr_workdir, oe_builddir, hdddir, | ||
| 454 | native_sysroot, False) | ||
| 455 | |||
| 456 | @classmethod | ||
| 457 | def _do_install_grub(cls, creator, kernel_dir, | ||
| 458 | native_sysroot, full_path): | ||
| 459 | core_img = '%s/grub-bios-core.img' % (kernel_dir) | ||
| 460 | |||
| 461 | staging_libdir = cls._get_staging_libdir() | ||
| 462 | |||
| 463 | grub_format = get_bitbake_var('GRUB_MKIMAGE_FORMAT_PC') | ||
| 464 | if not grub_format: | ||
| 465 | grub_format = 'i386-pc' | ||
| 466 | |||
| 467 | boot_img = '%s/grub/%s/boot.img' % (staging_libdir, grub_format) | ||
| 468 | if not os.path.exists(boot_img): | ||
| 469 | raise WicError("Couldn't find %s. Did you include " | ||
| 470 | "do_image_wic[depends] += \"grub:do_populate_sysroot\" " | ||
| 471 | "in your image recipe" % boot_img) | ||
| 472 | |||
| 473 | # Install boot.img or grub stage 1 | ||
| 474 | dd_cmd = "dd if=%s of=%s conv=notrunc bs=1 seek=0 count=440" % (boot_img, full_path) | ||
| 475 | exec_cmd(dd_cmd, native_sysroot) | ||
| 476 | |||
| 477 | if creator.ptable_format == 'msdos': | ||
| 478 | # Install core.img or grub stage 1.5 | ||
| 479 | dd_cmd = "dd if=%s of=%s conv=notrunc bs=1 seek=512" % (core_img, full_path) | ||
| 480 | exec_cmd(dd_cmd, native_sysroot) | ||
| 481 | else: | ||
| 482 | raise WicError("Unsupported partition table: %s" % | ||
| 483 | creator.ptable_format) | ||
diff --git a/scripts/lib/wic/plugins/source/empty.py b/scripts/lib/wic/plugins/source/empty.py index 041617d648..4178912377 100644 --- a/scripts/lib/wic/plugins/source/empty.py +++ b/scripts/lib/wic/plugins/source/empty.py | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | # | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors | ||
| 3 | # | ||
| 2 | # SPDX-License-Identifier: MIT | 4 | # SPDX-License-Identifier: MIT |
| 3 | # | 5 | # |
| 4 | 6 | ||
| @@ -7,9 +9,19 @@ | |||
| 7 | # To use it you must pass "empty" as argument for the "--source" parameter in | 9 | # To use it you must pass "empty" as argument for the "--source" parameter in |
| 8 | # the wks file. For example: | 10 | # the wks file. For example: |
| 9 | # part foo --source empty --ondisk sda --size="1024" --align 1024 | 11 | # part foo --source empty --ondisk sda --size="1024" --align 1024 |
| 12 | # | ||
| 13 | # The plugin supports writing zeros to the start of the | ||
| 14 | # partition. This is useful to overwrite old content like | ||
| 15 | # filesystem signatures which may be re-recognized otherwise. | ||
| 16 | # This feature can be enabled with | ||
| 17 | # '--sourceparams="[fill|size=<N>[S|s|K|k|M|G]][,][bs=<N>[S|s|K|k|M|G]]"' | ||
| 18 | # Conflicting or missing options throw errors. | ||
| 10 | 19 | ||
| 11 | import logging | 20 | import logging |
| 21 | import os | ||
| 12 | 22 | ||
| 23 | from wic import WicError | ||
| 24 | from wic.ksparser import sizetype | ||
| 13 | from wic.pluginbase import SourcePlugin | 25 | from wic.pluginbase import SourcePlugin |
| 14 | 26 | ||
| 15 | logger = logging.getLogger('wic') | 27 | logger = logging.getLogger('wic') |
| @@ -17,6 +29,16 @@ logger = logging.getLogger('wic') | |||
| 17 | class EmptyPartitionPlugin(SourcePlugin): | 29 | class EmptyPartitionPlugin(SourcePlugin): |
| 18 | """ | 30 | """ |
| 19 | Populate unformatted empty partition. | 31 | Populate unformatted empty partition. |
| 32 | |||
| 33 | The following sourceparams are supported: | ||
| 34 | - fill | ||
| 35 | Fill the entire partition with zeros. Requires '--fixed-size' option | ||
| 36 | to be set. | ||
| 37 | - size=<N>[S|s|K|k|M|G] | ||
| 38 | Set the first N bytes of the partition to zero. Default unit is 'K'. | ||
| 39 | - bs=<N>[S|s|K|k|M|G] | ||
| 40 | Write at most N bytes at a time during source file creation. | ||
| 41 | Defaults to '1M'. Default unit is 'K'. | ||
| 20 | """ | 42 | """ |
| 21 | 43 | ||
| 22 | name = 'empty' | 44 | name = 'empty' |
| @@ -29,4 +51,39 @@ class EmptyPartitionPlugin(SourcePlugin): | |||
| 29 | Called to do the actual content population for a partition i.e. it | 51 | Called to do the actual content population for a partition i.e. it |
| 30 | 'prepares' the partition to be incorporated into the image. | 52 | 'prepares' the partition to be incorporated into the image. |
| 31 | """ | 53 | """ |
| 32 | return | 54 | get_byte_count = sizetype('K', True) |
| 55 | size = 0 | ||
| 56 | |||
| 57 | if 'fill' in source_params and 'size' in source_params: | ||
| 58 | raise WicError("Conflicting source parameters 'fill' and 'size' specified, exiting.") | ||
| 59 | |||
| 60 | # Set the size of the zeros to be written to the partition | ||
| 61 | if 'fill' in source_params: | ||
| 62 | if part.fixed_size == 0: | ||
| 63 | raise WicError("Source parameter 'fill' only works with the '--fixed-size' option, exiting.") | ||
| 64 | size = get_byte_count(part.fixed_size) | ||
| 65 | elif 'size' in source_params: | ||
| 66 | size = get_byte_count(source_params['size']) | ||
| 67 | |||
| 68 | if size == 0: | ||
| 69 | # Nothing to do, create empty partition | ||
| 70 | return | ||
| 71 | |||
| 72 | if 'bs' in source_params: | ||
| 73 | bs = get_byte_count(source_params['bs']) | ||
| 74 | else: | ||
| 75 | bs = get_byte_count('1M') | ||
| 76 | |||
| 77 | # Create a binary file of the requested size filled with zeros | ||
| 78 | source_file = os.path.join(cr_workdir, 'empty-plugin-zeros%s.bin' % part.lineno) | ||
| 79 | if not os.path.exists(os.path.dirname(source_file)): | ||
| 80 | os.makedirs(os.path.dirname(source_file)) | ||
| 81 | |||
| 82 | quotient, remainder = divmod(size, bs) | ||
| 83 | with open(source_file, 'wb') as file: | ||
| 84 | for _ in range(quotient): | ||
| 85 | file.write(bytearray(bs)) | ||
| 86 | file.write(bytearray(remainder)) | ||
| 87 | |||
| 88 | part.size = (size + 1024 - 1) // 1024 # size in KB rounded up | ||
| 89 | part.source_file = source_file | ||
diff --git a/scripts/lib/wic/plugins/source/extra_partition.py b/scripts/lib/wic/plugins/source/extra_partition.py new file mode 100644 index 0000000000..d370b0107e --- /dev/null +++ b/scripts/lib/wic/plugins/source/extra_partition.py | |||
| @@ -0,0 +1,134 @@ | |||
| 1 | import logging | ||
| 2 | import os | ||
| 3 | import re | ||
| 4 | |||
| 5 | from glob import glob | ||
| 6 | |||
| 7 | from wic import WicError | ||
| 8 | from wic.pluginbase import SourcePlugin | ||
| 9 | from wic.misc import exec_cmd, get_bitbake_var | ||
| 10 | |||
| 11 | logger = logging.getLogger('wic') | ||
| 12 | |||
| 13 | class ExtraPartitionPlugin(SourcePlugin): | ||
| 14 | """ | ||
| 15 | Populates an extra partition with files listed in the IMAGE_EXTRA_PARTITION_FILES | ||
| 16 | BitBake variable. Files should be deployed to the DEPLOY_DIR_IMAGE directory. | ||
| 17 | |||
| 18 | The plugin supports: | ||
| 19 | - Glob pattern matching for file selection. | ||
| 20 | - File renaming. | ||
| 21 | - Suffixes to specify the target partition (by label, UUID, or partname), | ||
| 22 | enabling multiple extra partitions to coexist. | ||
| 23 | |||
| 24 | For example: | ||
| 25 | |||
| 26 | IMAGE_EXTRA_PARTITION_FILES_label-foo = "bar.conf;foo.conf" | ||
| 27 | IMAGE_EXTRA_PARTITION_FILES_uuid-e7d0824e-cda3-4bed-9f54-9ef5312d105d = "bar.conf;foobar.conf" | ||
| 28 | IMAGE_EXTRA_PARTITION_FILES = "foo/*" | ||
| 29 | WICVARS:append = "\ | ||
| 30 | IMAGE_EXTRA_PARTITION_FILES_label-foo \ | ||
| 31 | IMAGE_EXTRA_PARTITION_FILES_uuid-e7d0824e-cda3-4bed-9f54-9ef5312d105d \ | ||
| 32 | " | ||
| 33 | |||
| 34 | """ | ||
| 35 | |||
| 36 | name = 'extra_partition' | ||
| 37 | image_extra_partition_files_var_name = 'IMAGE_EXTRA_PARTITION_FILES' | ||
| 38 | |||
| 39 | @classmethod | ||
| 40 | def do_configure_partition(cls, part, source_params, cr, cr_workdir, | ||
| 41 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 42 | native_sysroot): | ||
| 43 | """ | ||
| 44 | Called before do_prepare_partition(), list the files to copy | ||
| 45 | """ | ||
| 46 | extradir = "%s/extra.%d" % (cr_workdir, part.lineno) | ||
| 47 | install_cmd = "install -d %s" % extradir | ||
| 48 | exec_cmd(install_cmd) | ||
| 49 | |||
| 50 | if not kernel_dir: | ||
| 51 | kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") | ||
| 52 | if not kernel_dir: | ||
| 53 | raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting") | ||
| 54 | |||
| 55 | extra_files = None | ||
| 56 | for (fmt, id) in (("_uuid-%s", part.uuid), ("_label-%s", part.label), ("_part-name-%s", part.part_name), (None, None)): | ||
| 57 | if fmt: | ||
| 58 | var = fmt % id | ||
| 59 | else: | ||
| 60 | var = "" | ||
| 61 | extra_files = get_bitbake_var(cls.image_extra_partition_files_var_name + var) | ||
| 62 | if extra_files is not None: | ||
| 63 | break | ||
| 64 | |||
| 65 | if extra_files is None: | ||
| 66 | raise WicError('No extra files defined, %s unset for entry #%d' % (cls.image_extra_partition_files_var_name, part.lineno)) | ||
| 67 | |||
| 68 | logger.info('Extra files: %s', extra_files) | ||
| 69 | |||
| 70 | # list of tuples (src_name, dst_name) | ||
| 71 | deploy_files = [] | ||
| 72 | for src_entry in re.findall(r'[\w;\-\./\*]+', extra_files): | ||
| 73 | if ';' in src_entry: | ||
| 74 | dst_entry = tuple(src_entry.split(';')) | ||
| 75 | if not dst_entry[0] or not dst_entry[1]: | ||
| 76 | raise WicError('Malformed extra file entry: %s' % src_entry) | ||
| 77 | else: | ||
| 78 | dst_entry = (src_entry, src_entry) | ||
| 79 | |||
| 80 | logger.debug('Destination entry: %r', dst_entry) | ||
| 81 | deploy_files.append(dst_entry) | ||
| 82 | |||
| 83 | cls.install_task = []; | ||
| 84 | for deploy_entry in deploy_files: | ||
| 85 | src, dst = deploy_entry | ||
| 86 | if '*' in src: | ||
| 87 | # by default install files under their basename | ||
| 88 | entry_name_fn = os.path.basename | ||
| 89 | if dst != src: | ||
| 90 | # unless a target name was given, then treat name | ||
| 91 | # as a directory and append a basename | ||
| 92 | entry_name_fn = lambda name: \ | ||
| 93 | os.path.join(dst, | ||
| 94 | os.path.basename(name)) | ||
| 95 | |||
| 96 | srcs = glob(os.path.join(kernel_dir, src)) | ||
| 97 | |||
| 98 | logger.debug('Globbed sources: %s', ', '.join(srcs)) | ||
| 99 | for entry in srcs: | ||
| 100 | src = os.path.relpath(entry, kernel_dir) | ||
| 101 | entry_dst_name = entry_name_fn(entry) | ||
| 102 | cls.install_task.append((src, entry_dst_name)) | ||
| 103 | else: | ||
| 104 | cls.install_task.append((src, dst)) | ||
| 105 | |||
| 106 | |||
| 107 | @classmethod | ||
| 108 | def do_prepare_partition(cls, part, source_params, cr, cr_workdir, | ||
| 109 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 110 | rootfs_dir, native_sysroot): | ||
| 111 | """ | ||
| 112 | Called to do the actual content population for a partition i.e. it | ||
| 113 | 'prepares' the partition to be incorporated into the image. | ||
| 114 | In this case, we copies all files listed in IMAGE_EXTRA_PARTITION_FILES variable. | ||
| 115 | """ | ||
| 116 | extradir = "%s/extra.%d" % (cr_workdir, part.lineno) | ||
| 117 | |||
| 118 | if not kernel_dir: | ||
| 119 | kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") | ||
| 120 | if not kernel_dir: | ||
| 121 | raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting") | ||
| 122 | |||
| 123 | for task in cls.install_task: | ||
| 124 | src_path, dst_path = task | ||
| 125 | logger.debug('Install %s as %s', src_path, dst_path) | ||
| 126 | install_cmd = "install -m 0644 -D %s %s" \ | ||
| 127 | % (os.path.join(kernel_dir, src_path), | ||
| 128 | os.path.join(extradir, dst_path)) | ||
| 129 | exec_cmd(install_cmd) | ||
| 130 | |||
| 131 | logger.debug('Prepare extra partition using rootfs in %s', extradir) | ||
| 132 | part.prepare_rootfs(cr_workdir, oe_builddir, extradir, | ||
| 133 | native_sysroot, False) | ||
| 134 | |||
diff --git a/scripts/lib/wic/plugins/source/isoimage-isohybrid.py b/scripts/lib/wic/plugins/source/isoimage_isohybrid.py index afc9ea0f8f..5d42eb5d3e 100644 --- a/scripts/lib/wic/plugins/source/isoimage-isohybrid.py +++ b/scripts/lib/wic/plugins/source/isoimage_isohybrid.py | |||
| @@ -1,8 +1,10 @@ | |||
| 1 | # | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors | ||
| 3 | # | ||
| 2 | # SPDX-License-Identifier: GPL-2.0-only | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 3 | # | 5 | # |
| 4 | # DESCRIPTION | 6 | # DESCRIPTION |
| 5 | # This implements the 'isoimage-isohybrid' source plugin class for 'wic' | 7 | # This implements the 'isoimage_isohybrid' source plugin class for 'wic' |
| 6 | # | 8 | # |
| 7 | # AUTHORS | 9 | # AUTHORS |
| 8 | # Mihaly Varga <mihaly.varga (at] ni.com> | 10 | # Mihaly Varga <mihaly.varga (at] ni.com> |
| @@ -33,7 +35,7 @@ class IsoImagePlugin(SourcePlugin): | |||
| 33 | bootloader files. | 35 | bootloader files. |
| 34 | 36 | ||
| 35 | Example kickstart file: | 37 | Example kickstart file: |
| 36 | part /boot --source isoimage-isohybrid --sourceparams="loader=grub-efi, \\ | 38 | part /boot --source isoimage_isohybrid --sourceparams="loader=grub-efi, \\ |
| 37 | image_name= IsoImage" --ondisk cd --label LIVECD | 39 | image_name= IsoImage" --ondisk cd --label LIVECD |
| 38 | bootloader --timeout=10 --append=" " | 40 | bootloader --timeout=10 --append=" " |
| 39 | 41 | ||
| @@ -43,7 +45,7 @@ class IsoImagePlugin(SourcePlugin): | |||
| 43 | extension added by direct imeger plugin) and a file named IsoImage-cd.iso | 45 | extension added by direct imeger plugin) and a file named IsoImage-cd.iso |
| 44 | """ | 46 | """ |
| 45 | 47 | ||
| 46 | name = 'isoimage-isohybrid' | 48 | name = 'isoimage_isohybrid' |
| 47 | 49 | ||
| 48 | @classmethod | 50 | @classmethod |
| 49 | def do_configure_syslinux(cls, creator, cr_workdir): | 51 | def do_configure_syslinux(cls, creator, cr_workdir): |
| @@ -338,10 +340,10 @@ class IsoImagePlugin(SourcePlugin): | |||
| 338 | cls.do_configure_grubefi(part, creator, target_dir) | 340 | cls.do_configure_grubefi(part, creator, target_dir) |
| 339 | 341 | ||
| 340 | else: | 342 | else: |
| 341 | raise WicError("unrecognized bootimg-efi loader: %s" % | 343 | raise WicError("unrecognized bootimg_efi loader: %s" % |
| 342 | source_params['loader']) | 344 | source_params['loader']) |
| 343 | except KeyError: | 345 | except KeyError: |
| 344 | raise WicError("bootimg-efi requires a loader, none specified") | 346 | raise WicError("bootimg_efi requires a loader, none specified") |
| 345 | 347 | ||
| 346 | # Create efi.img that contains bootloader files for EFI booting | 348 | # Create efi.img that contains bootloader files for EFI booting |
| 347 | # if ISODIR didn't exist or didn't contains it | 349 | # if ISODIR didn't exist or didn't contains it |
diff --git a/scripts/lib/wic/plugins/source/rawcopy.py b/scripts/lib/wic/plugins/source/rawcopy.py index fa7b1eb8ac..21903c2f23 100644 --- a/scripts/lib/wic/plugins/source/rawcopy.py +++ b/scripts/lib/wic/plugins/source/rawcopy.py | |||
| @@ -1,9 +1,13 @@ | |||
| 1 | # | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors | ||
| 3 | # | ||
| 2 | # SPDX-License-Identifier: GPL-2.0-only | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 3 | # | 5 | # |
| 4 | 6 | ||
| 5 | import logging | 7 | import logging |
| 6 | import os | 8 | import os |
| 9 | import signal | ||
| 10 | import subprocess | ||
| 7 | 11 | ||
| 8 | from wic import WicError | 12 | from wic import WicError |
| 9 | from wic.pluginbase import SourcePlugin | 13 | from wic.pluginbase import SourcePlugin |
| @@ -21,6 +25,10 @@ class RawCopyPlugin(SourcePlugin): | |||
| 21 | 25 | ||
| 22 | @staticmethod | 26 | @staticmethod |
| 23 | def do_image_label(fstype, dst, label): | 27 | def do_image_label(fstype, dst, label): |
| 28 | # don't create label when fstype is none | ||
| 29 | if fstype == 'none': | ||
| 30 | return | ||
| 31 | |||
| 24 | if fstype.startswith('ext'): | 32 | if fstype.startswith('ext'): |
| 25 | cmd = 'tune2fs -L %s %s' % (label, dst) | 33 | cmd = 'tune2fs -L %s %s' % (label, dst) |
| 26 | elif fstype in ('msdos', 'vfat'): | 34 | elif fstype in ('msdos', 'vfat'): |
| @@ -38,6 +46,26 @@ class RawCopyPlugin(SourcePlugin): | |||
| 38 | 46 | ||
| 39 | exec_cmd(cmd) | 47 | exec_cmd(cmd) |
| 40 | 48 | ||
| 49 | @staticmethod | ||
| 50 | def do_image_uncompression(src, dst, workdir): | ||
| 51 | def subprocess_setup(): | ||
| 52 | # Python installs a SIGPIPE handler by default. This is usually not what | ||
| 53 | # non-Python subprocesses expect. | ||
| 54 | # SIGPIPE errors are known issues with gzip/bash | ||
| 55 | signal.signal(signal.SIGPIPE, signal.SIG_DFL) | ||
| 56 | |||
| 57 | extension = os.path.splitext(src)[1] | ||
| 58 | decompressor = { | ||
| 59 | ".bz2": "bzip2", | ||
| 60 | ".gz": "gzip", | ||
| 61 | ".xz": "xz", | ||
| 62 | ".zst": "zstd -f", | ||
| 63 | }.get(extension) | ||
| 64 | if not decompressor: | ||
| 65 | raise WicError("Not supported compressor filename extension: %s" % extension) | ||
| 66 | cmd = "%s -dc %s > %s" % (decompressor, src, dst) | ||
| 67 | subprocess.call(cmd, preexec_fn=subprocess_setup, shell=True, cwd=workdir) | ||
| 68 | |||
| 41 | @classmethod | 69 | @classmethod |
| 42 | def do_prepare_partition(cls, part, source_params, cr, cr_workdir, | 70 | def do_prepare_partition(cls, part, source_params, cr, cr_workdir, |
| 43 | oe_builddir, bootimg_dir, kernel_dir, | 71 | oe_builddir, bootimg_dir, kernel_dir, |
| @@ -56,7 +84,13 @@ class RawCopyPlugin(SourcePlugin): | |||
| 56 | if 'file' not in source_params: | 84 | if 'file' not in source_params: |
| 57 | raise WicError("No file specified") | 85 | raise WicError("No file specified") |
| 58 | 86 | ||
| 59 | src = os.path.join(kernel_dir, source_params['file']) | 87 | if 'unpack' in source_params: |
| 88 | img = os.path.join(kernel_dir, source_params['file']) | ||
| 89 | src = os.path.join(cr_workdir, os.path.splitext(source_params['file'])[0]) | ||
| 90 | RawCopyPlugin.do_image_uncompression(img, src, cr_workdir) | ||
| 91 | else: | ||
| 92 | src = os.path.join(kernel_dir, source_params['file']) | ||
| 93 | |||
| 60 | dst = os.path.join(cr_workdir, "%s.%s" % (os.path.basename(source_params['file']), part.lineno)) | 94 | dst = os.path.join(cr_workdir, "%s.%s" % (os.path.basename(source_params['file']), part.lineno)) |
| 61 | 95 | ||
| 62 | if not os.path.exists(os.path.dirname(dst)): | 96 | if not os.path.exists(os.path.dirname(dst)): |
diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py index 2e34e715ca..06fce06bb1 100644 --- a/scripts/lib/wic/plugins/source/rootfs.py +++ b/scripts/lib/wic/plugins/source/rootfs.py | |||
| @@ -35,22 +35,22 @@ class RootfsPlugin(SourcePlugin): | |||
| 35 | @staticmethod | 35 | @staticmethod |
| 36 | def __validate_path(cmd, rootfs_dir, path): | 36 | def __validate_path(cmd, rootfs_dir, path): |
| 37 | if os.path.isabs(path): | 37 | if os.path.isabs(path): |
| 38 | logger.error("%s: Must be relative: %s" % (cmd, orig_path)) | 38 | logger.error("%s: Must be relative: %s" % (cmd, path)) |
| 39 | sys.exit(1) | 39 | sys.exit(1) |
| 40 | 40 | ||
| 41 | # Disallow climbing outside of parent directory using '..', | 41 | # Disallow climbing outside of parent directory using '..', |
| 42 | # because doing so could be quite disastrous (we will delete the | 42 | # because doing so could be quite disastrous (we will delete the |
| 43 | # directory, or modify a directory outside OpenEmbedded). | 43 | # directory, or modify a directory outside OpenEmbedded). |
| 44 | full_path = os.path.realpath(os.path.join(rootfs_dir, path)) | 44 | full_path = os.path.abspath(os.path.join(rootfs_dir, path)) |
| 45 | if not full_path.startswith(os.path.realpath(rootfs_dir)): | 45 | if not full_path.startswith(os.path.realpath(rootfs_dir)): |
| 46 | logger.error("%s: Must point inside the rootfs:" % (cmd, path)) | 46 | logger.error("%s: Must point inside the rootfs: %s" % (cmd, path)) |
| 47 | sys.exit(1) | 47 | sys.exit(1) |
| 48 | 48 | ||
| 49 | return full_path | 49 | return full_path |
| 50 | 50 | ||
| 51 | @staticmethod | 51 | @staticmethod |
| 52 | def __get_rootfs_dir(rootfs_dir): | 52 | def __get_rootfs_dir(rootfs_dir): |
| 53 | if os.path.isdir(rootfs_dir): | 53 | if rootfs_dir and os.path.isdir(rootfs_dir): |
| 54 | return os.path.realpath(rootfs_dir) | 54 | return os.path.realpath(rootfs_dir) |
| 55 | 55 | ||
| 56 | image_rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", rootfs_dir) | 56 | image_rootfs_dir = get_bitbake_var("IMAGE_ROOTFS", rootfs_dir) |
| @@ -97,6 +97,9 @@ class RootfsPlugin(SourcePlugin): | |||
| 97 | part.has_fstab = os.path.exists(os.path.join(part.rootfs_dir, "etc/fstab")) | 97 | part.has_fstab = os.path.exists(os.path.join(part.rootfs_dir, "etc/fstab")) |
| 98 | pseudo_dir = os.path.join(part.rootfs_dir, "../pseudo") | 98 | pseudo_dir = os.path.join(part.rootfs_dir, "../pseudo") |
| 99 | if not os.path.lexists(pseudo_dir): | 99 | if not os.path.lexists(pseudo_dir): |
| 100 | pseudo_dir = os.path.join(cls.__get_rootfs_dir(None), '../pseudo') | ||
| 101 | |||
| 102 | if not os.path.lexists(pseudo_dir): | ||
| 100 | logger.warn("%s folder does not exist. " | 103 | logger.warn("%s folder does not exist. " |
| 101 | "Usernames and permissions will be invalid " % pseudo_dir) | 104 | "Usernames and permissions will be invalid " % pseudo_dir) |
| 102 | pseudo_dir = None | 105 | pseudo_dir = None |
| @@ -221,7 +224,7 @@ class RootfsPlugin(SourcePlugin): | |||
| 221 | if part.update_fstab_in_rootfs and part.has_fstab and not part.no_fstab_update: | 224 | if part.update_fstab_in_rootfs and part.has_fstab and not part.no_fstab_update: |
| 222 | fstab_path = os.path.join(new_rootfs, "etc/fstab") | 225 | fstab_path = os.path.join(new_rootfs, "etc/fstab") |
| 223 | # Assume that fstab should always be owned by root with fixed permissions | 226 | # Assume that fstab should always be owned by root with fixed permissions |
| 224 | install_cmd = "install -m 0644 %s %s" % (part.updated_fstab_path, fstab_path) | 227 | install_cmd = "install -m 0644 -p %s %s" % (part.updated_fstab_path, fstab_path) |
| 225 | if new_pseudo: | 228 | if new_pseudo: |
| 226 | pseudo = cls.__get_pseudo(native_sysroot, new_rootfs, new_pseudo) | 229 | pseudo = cls.__get_pseudo(native_sysroot, new_rootfs, new_pseudo) |
| 227 | else: | 230 | else: |
