5
4
from linaro_media_create import cmd_runner
8
def _run_mkimage(img_type, load_addr, entry_point, name, img_data, img,
9
stdout=None, as_root=True):
20
proc = cmd_runner.run(cmd, as_root=as_root, stdout=stdout)
22
return proc.returncode
25
def _get_file_matching(regex):
26
"""Return a file whose path matches the given regex.
28
If zero or more than one files match, raise a ValueError.
30
files = glob.glob(regex)
35
"No files found matching '%s'; can't continue" % regex)
37
# TODO: Could ask the user to chosse which file to use instead of
38
# raising an exception.
39
raise ValueError("Too many files matching '%s' found." % regex)
42
def make_uImage(load_addr, uboot_parts_dir, sub_arch, boot_disk):
43
img_data = _get_file_matching(
44
'%s/vmlinuz-*-%s' % (uboot_parts_dir, sub_arch))
45
img = '%s/uImage' % boot_disk
47
'kernel', load_addr, load_addr, 'Linux', img_data, img)
50
def make_uInitrd(uboot_parts_dir, sub_arch, boot_disk):
51
img_data = _get_file_matching(
52
'%s/initrd.img-*-%s' % (uboot_parts_dir, sub_arch))
53
img = '%s/uInitrd' % boot_disk
54
return _run_mkimage('ramdisk', '0', '0', 'initramfs', img_data, img)
57
def make_boot_script(boot_script_data, tmp_dir, boot_script):
58
# Need to save the boot script data into a file that will be passed to
60
data_file = '%s/boot.cmd' % tmp_dir
61
with open(data_file, 'w') as fd:
62
fd.write(boot_script_data)
64
'script', '0', '0', 'boot script', data_file, boot_script)
67
def install_mx51evk_boot_loader(imx_file, boot_device_or_file):
68
proc = cmd_runner.run([
71
"of=%s" % boot_device_or_file,
74
"conv=notrunc"], as_root=True)
78
def install_omap_boot_loader(mlo_file, boot_disk):
79
cmd_runner.run(["cp", "-v", mlo_file, boot_disk], as_root=True).wait()
80
# XXX: Is this really needed?
81
cmd_runner.run(["sync"]).wait()
84
def make_boot_ini(boot_script, boot_disk):
85
proc = cmd_runner.run(
86
["cp", "-v", boot_script, "%s/boot.ini" % boot_disk], as_root=True)
90
def populate_boot(board, board_config, chroot_dir, boot_partition, boot_disk,
91
boot_device_or_file, tmp_dir, is_live, is_lowmem, consoles):
7
def populate_boot(board_config, chroot_dir, boot_partition, boot_disk,
8
boot_device_or_file, is_live, is_lowmem, consoles):
115
32
dict(boot_disk=boot_disk,
116
33
boot_script_name=board_config.boot_script))
118
load_addr = board_config.load_addr
119
sub_arch = board_config.sub_arch
120
boot_cmd = board_config.get_boot_cmd(is_live, is_lowmem, consoles)
122
# TODO: Once linaro-media-create is fully ported to python, we should
123
# split this into several board-specific functions that are defined
124
# somewhere else and just called here.
125
if board in ["beagle", "panda"]:
126
xloader_dir = 'x-loader-omap'
128
xloader_dir = 'x-loader-omap4'
129
mlo_file = os.path.join(
130
chroot_dir, 'usr', 'lib', xloader_dir, 'MLO')
131
install_omap_boot_loader(mlo_file, boot_disk)
132
make_uImage(load_addr, uboot_parts_dir, sub_arch, boot_disk)
133
make_uInitrd(uboot_parts_dir, sub_arch, boot_disk)
134
make_boot_script(boot_cmd, tmp_dir, boot_script)
135
make_boot_ini(boot_script, boot_disk)
137
elif board == "igep":
138
make_uImage(load_addr, uboot_parts_dir, sub_arch, boot_disk)
139
make_uInitrd(uboot_parts_dir, sub_arch, boot_disk)
140
make_boot_script(boot_cmd, tmp_dir, boot_script)
141
make_boot_ini(boot_script, boot_disk)
143
elif board == "ux500":
144
make_uImage(load_addr, uboot_parts_dir, sub_arch, boot_disk)
145
make_uInitrd(uboot_parts_dir, sub_arch, boot_disk)
146
make_boot_script(boot_cmd, tmp_dir, boot_script)
148
elif board == "vexpress":
149
make_uImage(load_addr, uboot_parts_dir, sub_arch, boot_disk)
150
make_uInitrd(uboot_parts_dir, sub_arch, boot_disk)
152
elif board == "mx51evk":
153
install_mx51evk_boot_loader(
154
"binary/usr/lib/u-boot/mx51evk/u-boot.imx", boot_device_or_file)
155
make_uImage(load_addr, uboot_parts_dir, sub_arch, boot_disk)
156
make_uInitrd(uboot_parts_dir, sub_arch, boot_disk)
157
make_boot_script(boot_cmd, tmp_dir, boot_script)
160
raise AssertionError(
161
"Internal error; missing support for board: %s" % board)
35
board_config.make_boot_files(
36
uboot_parts_dir, is_live, is_lowmem, consoles, chroot_dir, boot_disk,
37
boot_script, boot_device_or_file)
163
39
cmd_runner.run(['sync']).wait()