158
162
if self.tempdir is not None and os.path.exists(self.tempdir):
159
163
shutil.rmtree(self.tempdir)
161
def get_field(self, section, field):
165
def get_field(self, field):
163
167
hwpack_with_data = None
164
168
for hwpack_tarfile in self.hwpack_tarfiles:
165
169
metadata = hwpack_tarfile.extractfile(self.metadata_filename)
166
# Use RawConfigParser which does not support the magical
167
# interpolation behavior of ConfigParser so we don't mess up
168
# metadata accidentally.
169
parser = ConfigParser.RawConfigParser()
170
parser.readfp(self.FakeSecHead(metadata))
170
lines = metadata.readlines()
171
if re.search("=", lines[0]) and not re.search(":", lines[0]):
172
# Probably V2 hardware pack without [hwpack] on the first line
173
lines = ["[hwpack]\n"] + lines
174
parser = Config(StringIO("".join(lines)), self.bootloader,
172
new_data = parser.get(section, field)
177
new_data = parser.get_option(field)
173
178
if new_data is not None:
174
179
assert data is None, "The metadata field '%s' is set to " \
175
180
"'%s' and new value '%s' is found" % (field, data,
178
183
hwpack_with_data = hwpack_tarfile
179
184
except ConfigParser.NoOptionError:
181
187
return data, hwpack_with_data
183
189
def get_format(self):
185
supported_formats = [self.FORMAT_1, self.FORMAT_2]
191
supported_formats = [self.FORMAT_1, self.FORMAT_2, self.FORMAT_3]
186
192
for hwpack_tarfile in self.hwpack_tarfiles:
187
193
format_file = hwpack_tarfile.extractfile(self.format_filename)
188
194
format_string = format_file.read().strip()
198
204
def get_file(self, file_alias):
199
file_name, hwpack_tarfile = self.get_field(self.main_section,
205
file_name, hwpack_tarfile = self.get_field(file_alias)
201
206
if file_name is not None:
202
207
hwpack_tarfile.extract(file_name, self.tempdir)
203
208
file_name = os.path.join(self.tempdir, file_name)
298
302
cls.board = board
301
def set_metadata(cls, hwpacks):
302
cls.hardwarepack_handler = HardwarepackHandler(hwpacks)
305
def set_metadata(cls, hwpacks, bootloader=None, board=None):
306
cls.hardwarepack_handler = HardwarepackHandler(hwpacks, bootloader,
303
308
with cls.hardwarepack_handler:
304
309
cls.hwpack_format = cls.hardwarepack_handler.get_format()
305
310
if (cls.hwpack_format == cls.hardwarepack_handler.FORMAT_1):
308
if (cls.hwpack_format == cls.hardwarepack_handler.FORMAT_2):
313
if (cls.hwpack_format != cls.hardwarepack_handler.FORMAT_1):
309
314
# Clear V1 defaults.
310
315
cls.kernel_addr = None
311
316
cls.initrd_addr = None
334
339
cls.serial_tty = cls.get_metadata_field('serial_tty')
335
340
wired_interfaces = cls.get_metadata_field('wired_interfaces')
336
341
if wired_interfaces is not None:
337
cls.wired_interfaces = wired_interfaces.split(' ')
342
cls.wired_interfaces = wired_interfaces
338
343
wireless_interfaces = cls.get_metadata_field(
339
344
'wireless_interfaces')
340
345
if wireless_interfaces is not None:
341
cls.wireless_interfaces = wireless_interfaces.split(' ')
342
cls.vmlinuz = cls.get_metadata_field('kernel_file')
343
cls.initrd = cls.get_metadata_field('initrd_file')
346
cls.wireless_interfaces = wireless_interfaces
347
cls.vmlinuz = cls.get_metadata_field('vmlinuz')
348
cls.initrd = cls.get_metadata_field('initrd')
344
349
cls.dtb_file = cls.get_metadata_field('dtb_file')
345
350
cls.extra_boot_args_options = cls.get_metadata_field(
346
351
'extra_boot_options')
347
352
cls.boot_script = cls.get_metadata_field('boot_script')
348
353
cls.extra_serial_opts = cls.get_metadata_field(
349
'extra_serial_options')
350
355
cls.snowball_startup_files_config = cls.get_metadata_field(
351
356
'snowball_startup_files_config')
379
384
align_up(int(loader_min_size) * 1024 ** 2,
380
385
SECTOR_SIZE) / SECTOR_SIZE)
382
uboot_in_boot_part = cls.get_metadata_field('u_boot_in_boot_part')
383
if uboot_in_boot_part is None:
384
cls.uboot_in_boot_part = False
385
elif string.lower(uboot_in_boot_part) == 'yes':
386
cls.uboot_in_boot_part = True
387
elif string.lower(uboot_in_boot_part) == 'no':
388
cls.uboot_in_boot_part = False
387
bootloader_file_in_boot_part = cls.get_metadata_field(
388
'bootloader_file_in_boot_part')
389
if bootloader_file_in_boot_part is None:
390
cls.bootloader_file_in_boot_part = False
391
elif string.lower(bootloader_file_in_boot_part) == 'yes':
392
cls.bootloader_file_in_boot_part = True
393
elif string.lower(bootloader_file_in_boot_part) == 'no':
394
cls.bootloader_file_in_boot_part = False
389
395
spl_in_boot_part = cls.get_metadata_field('spl_in_boot_part')
390
396
if spl_in_boot_part is None:
391
397
cls.spl_in_boot_part = False
401
407
elif string.lower(env_dd) == 'no':
402
408
cls.env_dd = False
404
uboot_dd = cls.get_metadata_field('u_boot_dd')
405
# Either uboot_dd is not specified, or it contains the dd offset.
410
bootloader_dd = cls.get_metadata_field('bootloader_dd')
411
# Either bootloader_dd is not specified, or it contains the dd
413
if bootloader_dd is None:
414
cls.bootloader_dd = False
409
cls.uboot_dd = int(uboot_dd)
416
cls.bootloader_dd = int(bootloader_dd)
410
417
spl_dd = cls.get_metadata_field('spl_dd')
411
418
# Either spl_dd is not specified, or it contains the dd offset.
412
419
if spl_dd is None:
580
587
initrd_addr=cls.initrd_addr, dtb_addr=cls.dtb_addr)
582
589
("%(fatload_command)s mmc %(mmc_option)s %(kernel_addr)s " +
583
"%(uimage_path)suImage; ") +
590
"%(uimage_path)suImage; ")) % replacements
591
if i_img_data is not None:
584
593
("%(fatload_command)s mmc %(mmc_option)s %(initrd_addr)s " +
585
594
"%(uimage_path)suInitrd; ")) % replacements
586
if d_img_data is not None:
587
assert cls.dtb_addr is not None, (
588
"Need a dtb_addr when passing d_img_data")
590
("%(fatload_command)s mmc %(mmc_option)s %(dtb_addr)s " +
592
"bootm %(kernel_addr)s %(initrd_addr)s %(dtb_addr)s"
596
"bootm %(kernel_addr)s %(initrd_addr)s" % replacements)
595
if d_img_data is not None:
596
assert cls.dtb_addr is not None, (
597
"Need a dtb_addr when passing d_img_data")
599
("%(fatload_command)s mmc %(mmc_option)s %(dtb_addr)s " +
600
"board.dtb; ")) % replacements
601
boot_script += (("bootm %(kernel_addr)s")) % replacements
602
if i_img_data is not None:
603
boot_script += ((" %(initrd_addr)s")) % replacements
604
if d_img_data is not None:
605
boot_script += ((" %(dtb_addr)s")) % replacements
597
606
return boot_script
611
620
cls.add_boot_args(boot_args_file.read().strip())
614
def _get_bootargs(cls, is_live, is_lowmem, consoles, rootfs_uuid):
623
def _get_bootargs(cls, is_live, is_lowmem, consoles, rootfs_id):
615
624
"""Get the bootargs for this board.
617
626
In general subclasses should not have to override this.
644
def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_uuid,
653
def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_id,
654
i_img_data, d_img_data):
646
655
"""Get the boot environment for this board.
648
657
In general subclasses should not have to override this.
651
660
boot_env["bootargs"] = cls._get_bootargs(
652
is_live, is_lowmem, consoles, rootfs_uuid)
653
boot_env["bootcmd"] = cls._get_bootcmd(d_img_data)
661
is_live, is_lowmem, consoles, rootfs_id)
662
boot_env["bootcmd"] = cls._get_bootcmd(i_img_data, d_img_data)
657
def make_boot_files(cls, uboot_parts_dir, is_live, is_lowmem, consoles,
658
chroot_dir, rootfs_uuid, boot_dir,
666
def make_boot_files(cls, bootloader_parts_dir, is_live, is_lowmem,
667
consoles, chroot_dir, rootfs_id, boot_dir,
659
668
boot_device_or_file):
660
669
if cls.hwpack_format == HardwarepackHandler.FORMAT_1:
661
parts_dir = uboot_parts_dir
670
parts_dir = bootloader_parts_dir
663
672
parts_dir = chroot_dir
664
673
(k_img_data, i_img_data, d_img_data) = cls._get_kflavor_files(
666
boot_env = cls._get_boot_env(is_live, is_lowmem, consoles, rootfs_uuid,
675
boot_env = cls._get_boot_env(is_live, is_lowmem, consoles, rootfs_id,
676
i_img_data, d_img_data)
669
678
if cls.hwpack_format == HardwarepackHandler.FORMAT_1:
670
679
cls._make_boot_files(
686
695
_dd(from_file, to_file, seek=seek)
689
def install_samsung_boot_loader(cls, samsung_spl_file, uboot_file,
698
def install_samsung_boot_loader(cls, samsung_spl_file, bootloader_file,
690
699
boot_device_or_file):
691
700
cls._dd_file(samsung_spl_file, boot_device_or_file,
692
701
cls.SAMSUNG_V310_BL1_START,
693
702
cls.SAMSUNG_V310_BL1_LEN * SECTOR_SIZE)
694
cls._dd_file(uboot_file, boot_device_or_file,
703
cls._dd_file(bootloader_file, boot_device_or_file,
695
704
cls.SAMSUNG_V310_BL2_START,
696
705
cls.SAMSUNG_V310_BL2_LEN * SECTOR_SIZE)
716
725
cls._dd_file(spl_file, boot_device_or_file, cls.spl_dd)
718
uboot_file = cls.get_file('u_boot')
720
cls._dd_file(uboot_file, boot_device_or_file, cls.uboot_dd)
727
bootloader_file = cls.get_file('bootloader_file')
728
if cls.bootloader_dd:
729
cls._dd_file(bootloader_file, boot_device_or_file,
722
732
make_uImage(cls.load_addr, k_img_data, boot_dir)
723
make_uInitrd(i_img_data, boot_dir)
734
if i_img_data is not None:
735
make_uInitrd(i_img_data, boot_dir)
725
737
if d_img_data is not None:
726
738
make_dtb(d_img_data, boot_dir)
758
770
raise NotImplementedError()
761
def populate_boot(cls, chroot_dir, rootfs_uuid, boot_partition, boot_disk,
773
def populate_boot(cls, chroot_dir, rootfs_id, boot_partition, boot_disk,
762
774
boot_device_or_file, is_live, is_lowmem, consoles):
763
775
parts_dir = 'boot'
765
777
parts_dir = 'casper'
766
uboot_parts_dir = os.path.join(chroot_dir, parts_dir)
778
bootloader_parts_dir = os.path.join(chroot_dir, parts_dir)
768
779
cmd_runner.run(['mkdir', '-p', boot_disk]).wait()
769
780
with partition_mounted(boot_partition, boot_disk):
770
if cls.uboot_in_boot_part:
781
if cls.bootloader_file_in_boot_part:
771
782
with cls.hardwarepack_handler:
772
783
# <legacy v1 support>
773
if cls.uboot_flavor is not None:
784
if cls.bootloader_flavor is not None:
774
785
default = os.path.join(
775
786
chroot_dir, 'usr', 'lib', 'u-boot',
776
cls.uboot_flavor, 'u-boot.img')
787
cls.bootloader_flavor, 'u-boot.img')
777
788
if not os.path.exists(default):
778
789
default = os.path.join(
779
790
chroot_dir, 'usr', 'lib', 'u-boot',
780
cls.uboot_flavor, 'u-boot.bin')
791
cls.bootloader_flavor, 'u-boot.bin')
783
794
# </legacy v1 support>
784
uboot_bin = cls.get_file('u_boot', default=default)
785
assert uboot_bin is not None, (
786
"uboot binary could not be found")
795
bootloader_bin = cls.get_file('bootloader_file',
797
assert bootloader_bin is not None, (
798
"bootloader binary could not be found")
788
800
proc = cmd_runner.run(
789
['cp', '-v', uboot_bin, boot_disk], as_root=True)
801
['cp', '-v', bootloader_bin, boot_disk], as_root=True)
792
804
cls.make_boot_files(
793
uboot_parts_dir, is_live, is_lowmem, consoles, chroot_dir,
794
rootfs_uuid, boot_disk, boot_device_or_file)
805
bootloader_parts_dir, is_live, is_lowmem, consoles, chroot_dir,
806
rootfs_id, boot_disk, boot_device_or_file)
797
809
def _get_kflavor_files(cls, path):
825
837
def _get_kflavor_files_v2(cls, path):
826
838
kernel = _get_file_matching(os.path.join(path, cls.vmlinuz))
827
839
if kernel is not None:
840
logger = logging.getLogger("linaro_image_tools")
828
841
initrd = _get_file_matching(os.path.join(path, cls.initrd))
829
if initrd is not None:
831
if cls.dtb_file is not None:
832
dtb = _get_file_matching(os.path.join(path, cls.dtb_file))
833
logger = logging.getLogger("linaro_image_tools")
834
logger.info("Will use kernel=%s, initrd=%s, dtb=%s." % \
835
(kernel, initrd, dtb))
836
return (kernel, initrd, dtb)
838
"Found kernel matching %s but no initrd matching %s" % (
839
cls.vmlinuz, cls.initrd))
844
"Could not find a valid initrd, skipping uInitd.")
845
dtb = _get_file_matching(os.path.join(path, cls.dtb_file))
846
if dtb is None and cls.dtb_file is not None:
848
"Could not find a valid dtb file, skipping it.")
849
logger.info("Will use kernel=%s, initrd=%s, dtb=%s." % \
850
(kernel, initrd, dtb))
851
return (kernel, initrd, dtb)
840
852
raise ValueError(
841
853
"No kernel found matching %s." % (cls.vmlinuz))
903
915
cls.serial_tty = classproperty(lambda cls: 'ttyS2')
906
def make_boot_files(cls, uboot_parts_dir, is_live, is_lowmem, consoles,
907
chroot_dir, rootfs_uuid, boot_dir,
918
def make_boot_files(cls, bootloader_parts_dir, is_live, is_lowmem,
919
consoles, chroot_dir, rootfs_id, boot_dir,
908
920
boot_device_or_file):
909
921
# XXX: This is also part of our temporary hack to fix bug 697824; we
910
922
# need to call set_appropriate_serial_tty() before doing anything that
912
924
if cls.hwpack_format == HardwarepackHandler.FORMAT_1:
913
925
cls.set_appropriate_serial_tty(chroot_dir)
914
926
super(OmapConfig, cls).make_boot_files(
915
uboot_parts_dir, is_live, is_lowmem, consoles, chroot_dir,
916
rootfs_uuid, boot_dir, boot_device_or_file)
927
bootloader_parts_dir, is_live, is_lowmem, consoles, chroot_dir,
928
rootfs_id, boot_dir, boot_device_or_file)
919
931
def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
1277
1289
# XXX: delete this method when hwpacks V1 can die
1278
1290
assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1279
1291
with cls.hardwarepack_handler:
1280
uboot_file = cls.get_file('u_boot', default=os.path.join(
1281
chroot_dir, 'usr', 'lib', 'u-boot', cls.uboot_flavor,
1292
bootloader_file = cls.get_file('bootloader_file',
1293
default=os.path.join(
1294
chroot_dir, 'usr', 'lib', 'u-boot', cls.bootloader_flavor,
1283
install_mx5_boot_loader(uboot_file, boot_device_or_file,
1296
install_mx5_boot_loader(bootloader_file, boot_device_or_file,
1284
1297
cls.LOADER_MIN_SIZE_S)
1285
1298
make_uImage(cls.load_addr, k_img_data, boot_dir)
1286
1299
make_uInitrd(i_img_data, boot_dir)
1308
1321
class EfikamxConfig(Mx51Config):
1309
uboot_flavor = 'efikamx'
1322
bootloader_flavor = 'efikamx'
1310
1323
dtb_name = 'genesi-efikamx.dtb'
1313
1326
class EfikasbConfig(Mx51Config):
1314
uboot_flavor = 'efikasb'
1327
bootloader_flavor = 'efikasb'
1315
1328
dtb_name = 'genesi-efikasb.dtb'
1318
1331
class Mx51evkConfig(Mx51Config):
1319
uboot_flavor = 'mx51evk'
1332
bootloader_flavor = 'mx51evk'
1320
1333
dtb_name = 'mx51-babbage.dtb'
1323
1336
class Mx53LoCoConfig(Mx53Config):
1324
uboot_flavor = 'mx53loco'
1337
bootloader_flavor = 'mx53loco'
1325
1338
dtb_name = 'mx53-loco.dtb'
1328
1341
class VexpressConfig(BoardConfig):
1329
uboot_flavor = 'ca9x4_ct_vxp'
1330
uboot_in_boot_part = True
1342
bootloader_flavor = 'ca9x4_ct_vxp'
1343
bootloader_file_in_boot_part = True
1331
1344
serial_tty = 'ttyAMA0'
1332
1345
_extra_serial_opts = 'console=tty0 console=%s,38400n8'
1333
1346
_live_serial_opts = 'serialtty=%s'
1424
1437
# XXX: delete this method when hwpacks V1 can die
1425
1438
assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1426
1439
cls.install_samsung_boot_loader(cls._get_samsung_spl(chroot_dir),
1427
cls._get_samsung_uboot(chroot_dir),
1428
boot_device_or_file)
1440
cls._get_samsung_bootloader(chroot_dir), boot_device_or_file)
1429
1441
env_size = cls.SAMSUNG_V310_ENV_LEN * SECTOR_SIZE
1430
1442
env_file = make_flashable_env(boot_env, env_size)
1431
1443
_dd(env_file, boot_device_or_file, seek=cls.SAMSUNG_V310_ENV_START)
1443
1455
# XXX: delete this method when hwpacks V1 can die
1444
1456
assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1445
1457
spl_dir = os.path.join(
1446
chroot_dir, 'usr', 'lib', 'u-boot', cls.uboot_flavor)
1458
chroot_dir, 'usr', 'lib', 'u-boot', cls.bootloader_flavor)
1447
1459
old_spl_path = os.path.join(spl_dir, 'v310_mmc_spl.bin')
1448
1460
new_spl_path = os.path.join(spl_dir, 'u-boot-mmc-spl.bin')
1449
1461
new_new_spl_path = os.path.join(spl_dir, 'origen-spl.bin')
1464
1476
return spl_file
1467
def _get_samsung_uboot(cls, chroot_dir):
1479
def _get_samsung_bootloader(cls, chroot_dir):
1468
1480
# XXX: delete this method when hwpacks V1 can die
1469
1481
assert cls.hwpack_format == HardwarepackHandler.FORMAT_1
1470
uboot_file = os.path.join(
1471
chroot_dir, 'usr', 'lib', 'u-boot', cls.uboot_flavor,
1482
bootloader_file = os.path.join(
1483
chroot_dir, 'usr', 'lib', 'u-boot', cls.bootloader_flavor,
1485
return bootloader_file
1476
1488
def populate_raw_partition(cls, boot_device_or_file, chroot_dir):
1503
1515
mmc_option = '0:2'
1506
def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_uuid,
1518
def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_id,
1519
i_img_data, d_img_data):
1508
1520
boot_env = super(SamsungConfig, cls)._get_boot_env(
1509
is_live, is_lowmem, consoles, rootfs_uuid, d_img_data)
1521
is_live, is_lowmem, consoles, rootfs_id, i_img_data, d_img_data)
1511
1523
boot_env["ethact"] = "smc911x-0"
1512
1524
boot_env["ethaddr"] = "00:40:5c:26:0a:5b"
1778
1790
default = _get_mlo_file(chroot_dir)
1779
1791
except AssertionError:
1781
mlo_file = cls.get_file('spl', default=default)
1793
mlo_file = cls.get_file('spl_file', default=default)
1782
1794
cmd_runner.run(["cp", "-v", mlo_file, boot_disk], as_root=True).wait()
1783
1795
# XXX: Is this really needed?
1784
1796
cmd_runner.run(["sync"]).wait()