2017-07-04 21:03:51 +00:00
|
|
|
"""
|
2018-01-04 03:53:35 +00:00
|
|
|
Copyright 2018 Oliver Smith
|
2017-07-04 21:03:51 +00:00
|
|
|
|
|
|
|
This file is part of pmbootstrap.
|
|
|
|
|
|
|
|
pmbootstrap is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
pmbootstrap is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
import logging
|
2018-01-22 22:35:07 +00:00
|
|
|
import os
|
2017-07-04 21:03:51 +00:00
|
|
|
|
|
|
|
import pmb.build
|
|
|
|
import pmb.chroot.apk
|
|
|
|
import pmb.config
|
|
|
|
import pmb.flasher
|
2017-07-30 21:15:59 +00:00
|
|
|
import pmb.helpers.file
|
2017-07-04 21:03:51 +00:00
|
|
|
|
|
|
|
|
2017-09-06 20:14:03 +00:00
|
|
|
def odin(args, flavor, folder):
|
2017-07-30 21:15:59 +00:00
|
|
|
"""
|
|
|
|
Create Odin flashable tar file with kernel and initramfs for devices configured with
|
|
|
|
the flasher method 'heimdall-isorec' and with boot.img for devices with 'heimdall-bootimg'
|
|
|
|
"""
|
|
|
|
pmb.flasher.init(args)
|
|
|
|
suffix = "rootfs_" + args.device
|
|
|
|
|
|
|
|
# Validate method
|
2017-12-21 22:12:52 +00:00
|
|
|
method = args.deviceinfo["flash_method"]
|
2017-07-30 21:15:59 +00:00
|
|
|
if not method.startswith("heimdall-"):
|
|
|
|
raise RuntimeError("An odin flashable tar is not supported for the flash"
|
|
|
|
" method '" + method + "' specified in the current configuration."
|
|
|
|
" Only 'heimdall' methods are supported.")
|
|
|
|
|
|
|
|
# Partitions
|
2018-02-28 01:28:36 +00:00
|
|
|
partition_kernel = args.deviceinfo["flash_heimdall_partition_kernel"] or "KERNEL"
|
|
|
|
partition_initfs = args.deviceinfo["flash_heimdall_partition_initfs"] or "RECOVERY"
|
2017-07-30 21:15:59 +00:00
|
|
|
|
|
|
|
# Temporary folder
|
|
|
|
temp_folder = "/tmp/odin-flashable-tar"
|
2018-01-22 22:35:07 +00:00
|
|
|
if os.path.exists(args.work + "/chroot_native" + temp_folder):
|
|
|
|
pmb.chroot.root(args, ["rm", "-rf", temp_folder])
|
2017-07-30 21:15:59 +00:00
|
|
|
|
|
|
|
# Odin flashable tar generation script (because redirecting stdin/stdout is not allowed
|
|
|
|
# in pmbootstrap's chroot/shell functions for security reasons)
|
|
|
|
with open(args.work + "/chroot_rootfs_" + args.device + "/tmp/_odin.sh", "w") as handle:
|
|
|
|
odin_kernel_md5 = partition_kernel + ".bin.md5"
|
|
|
|
odin_initfs_md5 = partition_initfs + ".bin.md5"
|
|
|
|
odin_device_tar = args.device + ".tar"
|
|
|
|
odin_device_tar_md5 = args.device + ".tar.md5"
|
|
|
|
|
|
|
|
handle.write(
|
|
|
|
"#!/bin/sh\n"
|
|
|
|
"cd " + temp_folder + "\n")
|
|
|
|
if method == "heimdall-isorec":
|
|
|
|
handle.write(
|
|
|
|
# Kernel: copy and append md5
|
|
|
|
"cp /boot/vmlinuz-" + flavor + " " + odin_kernel_md5 + "\n"
|
|
|
|
"md5sum -t " + odin_kernel_md5 + " >> " + odin_kernel_md5 + "\n"
|
|
|
|
# Initramfs: recompress with lzop, append md5
|
|
|
|
"gunzip -c /boot/initramfs-" + flavor + " | lzop > " + odin_initfs_md5 + "\n"
|
|
|
|
"md5sum -t " + odin_initfs_md5 + " >> " + odin_initfs_md5 + "\n")
|
|
|
|
elif method == "heimdall-bootimg":
|
|
|
|
handle.write(
|
|
|
|
# boot.img: copy and append md5
|
|
|
|
"cp /boot/boot.img-" + flavor + " " + odin_kernel_md5 + "\n"
|
|
|
|
"md5sum -t " + odin_kernel_md5 + " >> " + odin_kernel_md5 + "\n")
|
|
|
|
handle.write(
|
|
|
|
# Create tar, remove included files and append md5
|
|
|
|
"tar -c -f " + odin_device_tar + " *.bin.md5\n"
|
|
|
|
"rm *.bin.md5\n"
|
|
|
|
"md5sum -t " + odin_device_tar + " >> " + odin_device_tar + "\n"
|
|
|
|
"mv " + odin_device_tar + " " + odin_device_tar_md5 + "\n")
|
|
|
|
|
|
|
|
commands = [["mkdir", "-p", temp_folder],
|
|
|
|
["cat", "/tmp/_odin.sh"], # for the log
|
|
|
|
["sh", "/tmp/_odin.sh"],
|
|
|
|
["rm", "/tmp/_odin.sh"]
|
|
|
|
]
|
|
|
|
for command in commands:
|
|
|
|
pmb.chroot.root(args, command, suffix)
|
|
|
|
|
|
|
|
# Move Odin flashable tar to native chroot and cleanup temp folder
|
2017-10-12 20:08:10 +00:00
|
|
|
pmb.chroot.user(args, ["mkdir", "-p", "/home/pmos/rootfs"])
|
2017-07-30 21:15:59 +00:00
|
|
|
pmb.chroot.root(args, ["mv", "/mnt/rootfs_" + args.device + temp_folder +
|
2017-10-12 20:08:10 +00:00
|
|
|
"/" + odin_device_tar_md5, "/home/pmos/rootfs/"]),
|
|
|
|
pmb.chroot.root(args, ["chown", "pmos:pmos",
|
|
|
|
"/home/pmos/rootfs/" + odin_device_tar_md5])
|
2017-07-30 21:15:59 +00:00
|
|
|
pmb.chroot.root(args, ["rmdir", temp_folder], suffix)
|
|
|
|
|
|
|
|
# Create the symlink
|
2017-10-12 20:08:10 +00:00
|
|
|
file = args.work + "/chroot_native/home/pmos/rootfs/" + odin_device_tar_md5
|
2017-07-30 21:15:59 +00:00
|
|
|
link = folder + "/" + odin_device_tar_md5
|
|
|
|
pmb.helpers.file.symlink(args, file, link)
|
2017-07-04 21:03:51 +00:00
|
|
|
|
2017-07-30 21:15:59 +00:00
|
|
|
# Display a readable message
|
|
|
|
msg = " * " + odin_device_tar_md5
|
|
|
|
if method == "heimdall-isorec":
|
|
|
|
msg += " (Odin flashable file, contains initramfs and kernel)"
|
|
|
|
elif method == "heimdall-bootimg":
|
|
|
|
msg += " (Odin flashable file, contains boot.img)"
|
|
|
|
logging.info(msg)
|