<p>nsekar@codeaurora.org has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/c/coreboot/+/29973">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">qcs405 [temp]: Combine BB with QC-Sec for ROM boot<br><br>Some of the changes in this patch are part of the SDM845 upstream<br>patches. Those will be needed until the sdm845 patches are<br>merged. After that the remaining delta would have to be patched<br>out and pushed separately.<br><br>TEST=build & run<br><br>Change-Id: Ief4d92214cdc7ec06e90b0c7e73c11b6d6deddb9<br>Signed-off-by: Sricharan R <sricharan@codeaurora.org><br>Signed-off-by: Nitheesh Sekar <nsekar@codeaurora.org><br>---<br>M src/arch/arm64/armv8/cpu.S<br>M src/soc/qualcomm/ipq40xx/Kconfig<br>M src/soc/qualcomm/ipq40xx/mbn_header.h<br>M src/soc/qualcomm/ipq806x/Makefile.inc<br>M src/soc/qualcomm/ipq806x/mbn_header.h<br>M src/soc/qualcomm/qcs405/Makefile.inc<br>M src/soc/qualcomm/sdm845/Makefile.inc<br>R util/qualcomm/createxbl.py<br>M util/qualcomm/description.md<br>R util/qualcomm/ipqheader.py<br>R util/qualcomm/mbn_tools.py<br>R util/qualcomm/mbncat.py<br>A util/qualcomm/qgpt.py<br>M util/qualcomm/scripts/cmm/debug_cb_405.cmm<br>M util/qualcomm/scripts/cmm/debug_cb_845.cmm<br>M util/qualcomm/scripts/cmm/debug_cb_common.cmm<br>M util/qualcomm/scripts/cmm/pbl32_to_bootblock64_jump.cmm<br>17 files changed, 483 insertions(+), 224 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/73/29973/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/arch/arm64/armv8/cpu.S b/src/arch/arm64/armv8/cpu.S</span><br><span>index d3fd9d3..038e711 100644</span><br><span>--- a/src/arch/arm64/armv8/cpu.S</span><br><span>+++ b/src/arch/arm64/armv8/cpu.S</span><br><span>@@ -148,7 +148,7 @@</span><br><span> 2:</span><br><span>        stp     x0, x0, [x1], #16</span><br><span>    cmp     x1, x2</span><br><span style="color: hsl(0, 100%, 40%);">-  bne     2b</span><br><span style="color: hsl(120, 100%, 40%);">+    ble     2b</span><br><span> </span><br><span>       /* Initialize stack with sentinel value to later check overflow. */</span><br><span>  ldr     x2, =0xdeadbeefdeadbeef</span><br><span>diff --git a/src/soc/qualcomm/ipq40xx/Kconfig b/src/soc/qualcomm/ipq40xx/Kconfig</span><br><span>index 2cfcd2d..849d306 100644</span><br><span>--- a/src/soc/qualcomm/ipq40xx/Kconfig</span><br><span>+++ b/src/soc/qualcomm/ipq40xx/Kconfig</span><br><span>@@ -48,7 +48,7 @@</span><br><span> config SBL_UTIL_PATH</span><br><span>     depends on USE_BLOBS</span><br><span>         string "Path for utils to combine SBL_ELF and bootblock"</span><br><span style="color: hsl(0, 100%, 40%);">-      default "util/ipqheader"</span><br><span style="color: hsl(120, 100%, 40%);">+    default "util/qualcomm"</span><br><span>    help</span><br><span>           Path for utils to combine SBL_ELF and bootblock</span><br><span> </span><br><span>diff --git a/src/soc/qualcomm/ipq40xx/mbn_header.h b/src/soc/qualcomm/ipq40xx/mbn_header.h</span><br><span>index cedcf12..a48de1c 100644</span><br><span>--- a/src/soc/qualcomm/ipq40xx/mbn_header.h</span><br><span>+++ b/src/soc/qualcomm/ipq40xx/mbn_header.h</span><br><span>@@ -18,7 +18,7 @@</span><br><span> </span><br><span> #include <types.h></span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* QCA firmware blob header gleaned from util/ipqheader/ipqheader.py */</span><br><span style="color: hsl(120, 100%, 40%);">+/* QCA firmware blob header gleaned from util/qualcomm/ipqheader.py */</span><br><span> </span><br><span> struct mbn_header {</span><br><span>     u32     mbn_type;</span><br><span>diff --git a/src/soc/qualcomm/ipq806x/Makefile.inc b/src/soc/qualcomm/ipq806x/Makefile.inc</span><br><span>index 8a428b2..1fd134a 100644</span><br><span>--- a/src/soc/qualcomm/ipq806x/Makefile.inc</span><br><span>+++ b/src/soc/qualcomm/ipq806x/Makefile.inc</span><br><span>@@ -62,14 +62,14 @@</span><br><span> # Add MBN header to allow SBL3 to start coreboot bootblock</span><br><span> $(objcbfs)/bootblock.mbn: $(objcbfs)/bootblock.raw.bin</span><br><span>     @printf "    ADD MBN    $(subst $(obj)/,,$(@))\n"</span><br><span style="color: hsl(0, 100%, 40%);">-     ./util/ipqheader/ipqheader.py $(call loadaddr,bootblock) $< $@.tmp</span><br><span style="color: hsl(120, 100%, 40%);">+ ./util/qualcomm/ipqheader.py $(call loadaddr,bootblock) $< $@.tmp</span><br><span>         @mv $@.tmp $@</span><br><span> </span><br><span> # Create a complete bootblock which will start up the system</span><br><span> $(objcbfs)/bootblock.bin: $(call strip_quotes,$(CONFIG_SBL_BLOB)) \</span><br><span>                        $(objcbfs)/bootblock.mbn</span><br><span>  @printf "    MBNCAT     $(subst $(obj)/,,$(@))\n"</span><br><span style="color: hsl(0, 100%, 40%);">-     @util/ipqheader/mbncat.py -o $@.tmp $^</span><br><span style="color: hsl(120, 100%, 40%);">+        @util/qualcomm/mbncat.py -o $@.tmp $^</span><br><span>        @mv $@.tmp $@</span><br><span> </span><br><span> endif</span><br><span>diff --git a/src/soc/qualcomm/ipq806x/mbn_header.h b/src/soc/qualcomm/ipq806x/mbn_header.h</span><br><span>index 1e6a32f..c7b38d3 100644</span><br><span>--- a/src/soc/qualcomm/ipq806x/mbn_header.h</span><br><span>+++ b/src/soc/qualcomm/ipq806x/mbn_header.h</span><br><span>@@ -18,7 +18,7 @@</span><br><span> </span><br><span> #include <types.h></span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* Qualcomm firmware blob header gleaned from util/ipqheader/ipqheader.py */</span><br><span style="color: hsl(120, 100%, 40%);">+/* Qualcomm firmware blob header gleaned from util/qualcomm/ipqheader.py */</span><br><span> </span><br><span> struct mbn_header {</span><br><span>      u32     mbn_type;</span><br><span>diff --git a/src/soc/qualcomm/qcs405/Makefile.inc b/src/soc/qualcomm/qcs405/Makefile.inc</span><br><span>index 47ec7ca..40dcb9b 100644</span><br><span>--- a/src/soc/qualcomm/qcs405/Makefile.inc</span><br><span>+++ b/src/soc/qualcomm/qcs405/Makefile.inc</span><br><span>@@ -90,7 +90,7 @@</span><br><span> qc_sec_file := $(shell ls $(QC_SEC_FILE))</span><br><span> ifneq (,$(findstring $(QC_SEC_FILE),$(qc_sec_file)))</span><br><span> $(objcbfs)/bootblock.bin: $(objcbfs)/bootblock.elf</span><br><span style="color: hsl(0, 100%, 40%);">-   @util/qualcomm/createxbl.py -f $(objcbfs)/bootblock.elf \</span><br><span style="color: hsl(120, 100%, 40%);">+     @python util/qualcomm/createxbl.py -f $(objcbfs)/bootblock.elf \</span><br><span>             -x $(QC_SEC_FILE) -o $(objcbfs)/merged_bb_qcsec.mbn \</span><br><span>                -a 64 -d 32 -c 32</span><br><span> ifeq ($(CONFIG_QC_FLASH_SIMULATE_SDCARD),y)</span><br><span>diff --git a/src/soc/qualcomm/sdm845/Makefile.inc b/src/soc/qualcomm/sdm845/Makefile.inc</span><br><span>index 507d913..6f3f3bf 100644</span><br><span>--- a/src/soc/qualcomm/sdm845/Makefile.inc</span><br><span>+++ b/src/soc/qualcomm/sdm845/Makefile.inc</span><br><span>@@ -31,8 +31,22 @@</span><br><span> </span><br><span> CPPFLAGS_common += -Isrc/soc/qualcomm/sdm845/include</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+SDM845_BLOB := $(top)/3rdparty/blobs/soc/qualcomm/sdm845</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+################################################################################</span><br><span style="color: hsl(120, 100%, 40%);">+QC_SEC_FILE := $(SDM845_BLOB)/qc_sec.mbn</span><br><span style="color: hsl(120, 100%, 40%);">+qc_sec_file := $(shell ls $(QC_SEC_FILE))</span><br><span style="color: hsl(120, 100%, 40%);">+ifneq (,$(findstring $(QC_SEC_FILE),$(qc_sec_file)))</span><br><span style="color: hsl(120, 100%, 40%);">+$(objcbfs)/bootblock.bin: $(objcbfs)/bootblock.elf</span><br><span style="color: hsl(120, 100%, 40%);">+       @util/qualcomm/createxbl.py -f $(objcbfs)/bootblock.elf \</span><br><span style="color: hsl(120, 100%, 40%);">+             -x $(QC_SEC_FILE) -o $(objcbfs)/merged_bb_qcsec.mbn \</span><br><span style="color: hsl(120, 100%, 40%);">+         -a 64 -d 64 -c 64</span><br><span style="color: hsl(120, 100%, 40%);">+     @util/qualcomm/qgpt.py $(objcbfs)/merged_bb_qcsec.mbn \</span><br><span style="color: hsl(120, 100%, 40%);">+               $(objcbfs)/bootblock.bin</span><br><span style="color: hsl(120, 100%, 40%);">+else</span><br><span> $(objcbfs)/bootblock.bin: $(objcbfs)/bootblock.raw.bin</span><br><span>     @printf "Generating: $(subst $(obj)/,,$(@))\n"</span><br><span>     cp $(objcbfs)/bootblock.raw.bin $(objcbfs)/bootblock.bin</span><br><span style="color: hsl(120, 100%, 40%);">+endif</span><br><span> </span><br><span> endif</span><br><span>diff --git a/util/ipqheader/createxbl.py b/util/qualcomm/createxbl.py</span><br><span>similarity index 87%</span><br><span>rename from util/ipqheader/createxbl.py</span><br><span>rename to util/qualcomm/createxbl.py</span><br><span>index 1efd8ba..655b0ec 100755</span><br><span>--- a/util/ipqheader/createxbl.py</span><br><span>+++ b/util/qualcomm/createxbl.py</span><br><span>@@ -1,4 +1,3 @@</span><br><span style="color: hsl(0, 100%, 40%);">-#!/usr/bin/env python2</span><br><span> #============================================================================</span><br><span> #</span><br><span> #/** @file createxbl.py</span><br><span>@@ -6,32 +5,9 @@</span><br><span> # GENERAL DESCRIPTION</span><br><span> #   Concatentates XBL segments into one ELF image</span><br><span> #</span><br><span style="color: hsl(0, 100%, 40%);">-# Copyright (c) 2016, The Linux Foundation. All rights reserved.</span><br><span style="color: hsl(0, 100%, 40%);">-#</span><br><span style="color: hsl(0, 100%, 40%);">-# Redistribution and use in source and binary forms, with or without</span><br><span style="color: hsl(0, 100%, 40%);">-# modification, are permitted provided that the following conditions are</span><br><span style="color: hsl(0, 100%, 40%);">-# met:</span><br><span style="color: hsl(0, 100%, 40%);">-#     * Redistributions of source code must retain the above copyright</span><br><span style="color: hsl(0, 100%, 40%);">-#       notice, this list of conditions and the following disclaimer.</span><br><span style="color: hsl(0, 100%, 40%);">-#     * Redistributions in binary form must reproduce the above</span><br><span style="color: hsl(0, 100%, 40%);">-#       copyright notice, this list of conditions and the following</span><br><span style="color: hsl(0, 100%, 40%);">-#       disclaimer in the documentation and/or other materials provided</span><br><span style="color: hsl(0, 100%, 40%);">-#       with the distribution.</span><br><span style="color: hsl(0, 100%, 40%);">-#     * Neither the name of The Linux Foundation nor the names of its</span><br><span style="color: hsl(0, 100%, 40%);">-#       contributors may be used to endorse or promote products derived</span><br><span style="color: hsl(0, 100%, 40%);">-#       from this software without specific prior written permission.</span><br><span style="color: hsl(0, 100%, 40%);">-#</span><br><span style="color: hsl(0, 100%, 40%);">-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED</span><br><span style="color: hsl(0, 100%, 40%);">-# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF</span><br><span style="color: hsl(0, 100%, 40%);">-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT</span><br><span style="color: hsl(0, 100%, 40%);">-# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS</span><br><span style="color: hsl(0, 100%, 40%);">-# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR</span><br><span style="color: hsl(0, 100%, 40%);">-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF</span><br><span style="color: hsl(0, 100%, 40%);">-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR</span><br><span style="color: hsl(0, 100%, 40%);">-# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,</span><br><span style="color: hsl(0, 100%, 40%);">-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE</span><br><span style="color: hsl(0, 100%, 40%);">-# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN</span><br><span style="color: hsl(0, 100%, 40%);">-# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span><br><span style="color: hsl(120, 100%, 40%);">+# Copyright 2014-2016 by QUALCOMM Technologies, Incorporated.</span><br><span style="color: hsl(120, 100%, 40%);">+# All Rights Reserved.</span><br><span style="color: hsl(120, 100%, 40%);">+# QUALCOMM Proprietary/GTDR</span><br><span> #</span><br><span> #**/</span><br><span> #</span><br><span>@@ -44,7 +20,9 @@</span><br><span> #</span><br><span> # when       who       what, where, why</span><br><span> # --------   ---       ------------------------------------------------------</span><br><span style="color: hsl(0, 100%, 40%);">-# 09/04/15   et        Added -x and -d to embed xbl_sec ELF</span><br><span style="color: hsl(120, 100%, 40%);">+# 04/16/16   et        Appended path to import correct mbn_tools</span><br><span style="color: hsl(120, 100%, 40%);">+# 11/09/15   plc       Update pflag for xblsec segment</span><br><span style="color: hsl(120, 100%, 40%);">+# 09/04/15   et        Added -x and -d to embed xbl_sec ELF </span><br><span> # 02/11/15   ck        Fixed missing elf type check in ZI OOB feature</span><br><span> # 11/04/14   ck        Updated calls to mbn_tools functions</span><br><span> # 10/22/14   ck        Added -z option to remove out of bounds ZI segments when converting from 64 to 32</span><br><span>@@ -60,15 +38,19 @@</span><br><span> import os</span><br><span> import sys</span><br><span> import shutil</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# Add path to mbn_tools</span><br><span style="color: hsl(120, 100%, 40%);">+sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)),</span><br><span style="color: hsl(120, 100%, 40%);">+                'sectools','sectools','features','isc','parsegen'))</span><br><span> import mbn_tools</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-PAGE_SIZE       = 4096</span><br><span style="color: hsl(0, 100%, 40%);">-SEGMENT_ALIGN   = 16</span><br><span style="color: hsl(0, 100%, 40%);">-ELF32_HDR_SIZE  = 52</span><br><span style="color: hsl(0, 100%, 40%);">-ELF32_PHDR_SIZE = 32</span><br><span style="color: hsl(0, 100%, 40%);">-ELF64_HDR_SIZE  = 64</span><br><span style="color: hsl(0, 100%, 40%);">-ELF64_PHDR_SIZE = 56</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+PAGE_SIZE              = 4096</span><br><span style="color: hsl(120, 100%, 40%);">+SEGMENT_ALIGN          = 16</span><br><span style="color: hsl(120, 100%, 40%);">+ELF32_HDR_SIZE         = 52</span><br><span style="color: hsl(120, 100%, 40%);">+ELF32_PHDR_SIZE        = 32</span><br><span style="color: hsl(120, 100%, 40%);">+ELF64_HDR_SIZE         = 64</span><br><span style="color: hsl(120, 100%, 40%);">+ELF64_PHDR_SIZE        = 56</span><br><span style="color: hsl(120, 100%, 40%);">+SEGMENT_ALIGN_4K       = 4096</span><br><span> </span><br><span> ##############################################################################</span><br><span> # main</span><br><span>@@ -83,7 +65,7 @@</span><br><span>   parser.add_option("-s", "--second_filepath",</span><br><span>                     action="store", type="string", dest="elf_inp_file2",</span><br><span>                     help="Second ELF file to merge.")</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+  </span><br><span>   parser.add_option("-x", "--xbl_sec_filepath",</span><br><span>                     action="store", type="string", dest="elf_inp_xbl_sec",</span><br><span>                     help="Second ELF file to merge.")</span><br><span>@@ -99,7 +81,7 @@</span><br><span>   parser.add_option("-b", "--second_elf_arch",</span><br><span>                     action="store", type="string", dest="elf_2_arch",</span><br><span>                     help="Second ELF file architecture.  '32' or '64'")</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+  </span><br><span>   parser.add_option("-d", "--xbl_sec_elf_arch",</span><br><span>                     action="store", type="string", dest="elf_xbl_sec_arch",</span><br><span>                     help="xbl_sec file architecture.  '32' or '64'")</span><br><span>@@ -118,7 +100,7 @@</span><br><span>                     help="Removes ZI segments that have addresses greater" + \</span><br><span>                          " than 32 bits when converting from a 64 to 32 bit ELF")</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+  </span><br><span>   (options, args) = parser.parse_args()</span><br><span>   if not options.elf_inp_file1:</span><br><span>     parser.error('First ELF filename not given')</span><br><span>@@ -128,7 +110,7 @@</span><br><span> </span><br><span>   if not options.elf_1_arch:</span><br><span>     parser.error('First ELF architecture not given')</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+  </span><br><span>   if (not options.elf_1_arch == '64') and (not options.elf_1_arch == '32'):</span><br><span>     parser.error('Invalid First ELF architecture given')</span><br><span> </span><br><span>@@ -136,7 +118,7 @@</span><br><span>   if options.elf_inp_file2:</span><br><span>     if (not options.elf_2_arch == '64') and (not options.elf_2_arch == '32'):</span><br><span>       parser.error('Invalid Second ELF architecture given')</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+  </span><br><span>   # Only evaluate elf_xbl_sec_arch if file is given</span><br><span>   if options.elf_inp_xbl_sec:</span><br><span>     if (not options.elf_xbl_sec_arch == '64') and (not options.elf_xbl_sec_arch == '32'):</span><br><span>@@ -159,7 +141,7 @@</span><br><span>     elf_inp_file2 = options.elf_inp_file2</span><br><span>   else:</span><br><span>     elf_inp_file2 = ""</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+    </span><br><span>   # Do same for xbl_sec</span><br><span>   elf_inp_xbl_sec = options.elf_inp_xbl_sec if options.elf_inp_xbl_sec else ""</span><br><span> </span><br><span>@@ -179,7 +161,7 @@</span><br><span>       is_elf2_64_bit = False</span><br><span>   else:</span><br><span>     is_elf2_64_bit = False</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+  </span><br><span>   if options.elf_inp_xbl_sec:</span><br><span>     if options.elf_xbl_sec_arch == '64':</span><br><span>       is_elf_xbl_sec_64_bit = True</span><br><span>@@ -187,7 +169,7 @@</span><br><span>       is_elf_xbl_sec_64_bit = False</span><br><span>   else:</span><br><span>     is_elf_xbl_sec_64_bit = False</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+  </span><br><span>   # If output ELF arch is given then set is_out_elf_64_bit accordingly.</span><br><span>   # If not then default to be input1's setting</span><br><span>   if options.elf_out_arch:</span><br><span>@@ -207,7 +189,7 @@</span><br><span> </span><br><span> </span><br><span>   mbn_type = 'elf'</span><br><span style="color: hsl(0, 100%, 40%);">-  header_format = 'reg'</span><br><span style="color: hsl(120, 100%, 40%);">+  header_format = 'reg' </span><br><span>   gen_dict['IMAGE_KEY_IMAGE_ID'] = mbn_tools.ImageType.APPSBL_IMG</span><br><span>   #gen_dict['IMAGE_KEY_IMAGE_SOURCE'] = 0</span><br><span>   #gen_dict['IMAGE_KEY_IMAGE_DEST'] = 0</span><br><span>@@ -224,9 +206,9 @@</span><br><span>   target_nonsec = target_base + "_combined_hash.mbn"</span><br><span> </span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-  #print "Input file 1:", elf_inp_file1</span><br><span style="color: hsl(0, 100%, 40%);">-  #print "Input file 2:", elf_inp_file2</span><br><span style="color: hsl(0, 100%, 40%);">-  #print "Output file:", binary_out</span><br><span style="color: hsl(120, 100%, 40%);">+  print "Input file 1:", elf_inp_file1</span><br><span style="color: hsl(120, 100%, 40%);">+  print "Input file 2:", elf_inp_file2</span><br><span style="color: hsl(120, 100%, 40%);">+  print "Output file:", binary_out</span><br><span> </span><br><span>   merge_elfs([],</span><br><span>              elf_inp_file1,</span><br><span>@@ -238,7 +220,7 @@</span><br><span>        is_elf_xbl_sec_64_bit,</span><br><span>        is_out_elf_64_bit,</span><br><span>           zi_oob_enabled)</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+  </span><br><span> </span><br><span>   # Hash the image if user did not explicitly say not to</span><br><span>   if options.hash_image:</span><br><span>@@ -246,21 +228,21 @@</span><br><span>     shutil.move(merged_elf, binary_out)</span><br><span>   else:</span><br><span>     shutil.copy(merged_elf, source_elf)</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    # Create hash table</span><br><span style="color: hsl(120, 100%, 40%);">+  </span><br><span style="color: hsl(120, 100%, 40%);">+    # Create hash table </span><br><span>     rv = mbn_tools.pboot_gen_elf([],</span><br><span>                                  source_elf,</span><br><span style="color: hsl(0, 100%, 40%);">-                               target_hash,</span><br><span style="color: hsl(120, 100%, 40%);">+                          target_hash, </span><br><span>                                  elf_out_file_name = target_phdr_elf,</span><br><span style="color: hsl(0, 100%, 40%);">-                                 secure_type = image_header_secflag)</span><br><span style="color: hsl(120, 100%, 40%);">+                                 secure_type = image_header_secflag)        </span><br><span>     if rv:</span><br><span>        raise RuntimeError, "Failed to run pboot_gen_elf"</span><br><span> </span><br><span>     # Create hash table header</span><br><span style="color: hsl(0, 100%, 40%);">-    rv = mbn_tools.image_header([],</span><br><span style="color: hsl(120, 100%, 40%);">+    rv = mbn_tools.image_header(os.environ,</span><br><span>                                 gen_dict,</span><br><span>                             target_hash,</span><br><span style="color: hsl(0, 100%, 40%);">-                            target_hash_hd,</span><br><span style="color: hsl(120, 100%, 40%);">+                               target_hash_hd, </span><br><span>                             image_header_secflag,</span><br><span>                                elf_file_name = source_elf)</span><br><span>     if rv:</span><br><span>@@ -269,7 +251,7 @@</span><br><span>     files_to_cat_in_order = [target_hash_hd, target_hash]</span><br><span>     mbn_tools.concat_files (target_nonsec, files_to_cat_in_order)</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    # Add the hash segment into the ELF</span><br><span style="color: hsl(120, 100%, 40%);">+    # Add the hash segment into the ELF </span><br><span>     mbn_tools.pboot_add_hash([],</span><br><span>                              target_phdr_elf,</span><br><span>                              target_nonsec,</span><br><span>@@ -287,7 +269,7 @@</span><br><span> ##############################################################################</span><br><span> # merge_elfs</span><br><span> ##############################################################################</span><br><span style="color: hsl(0, 100%, 40%);">-def merge_elfs(env,</span><br><span style="color: hsl(120, 100%, 40%);">+def merge_elfs(env, </span><br><span>                elf_in_file_name1,</span><br><span>                elf_in_file_name2,</span><br><span>                elf_in_file_xbl_sec,</span><br><span>@@ -299,17 +281,17 @@</span><br><span>                    zi_oob_enabled):</span><br><span> </span><br><span>   [elf_header1, phdr_table1] = \</span><br><span style="color: hsl(0, 100%, 40%);">-    mbn_tools.preprocess_elf_file(elf_in_file_name1)</span><br><span style="color: hsl(120, 100%, 40%);">+    mbn_tools.preprocess_elf_file(elf_in_file_name1) </span><br><span> </span><br><span>   # Check to make sure second file path exists before using</span><br><span>   if elf_in_file_name2 != "":</span><br><span>     [elf_header2, phdr_table2] = \</span><br><span style="color: hsl(0, 100%, 40%);">-      mbn_tools.preprocess_elf_file(elf_in_file_name2)</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+      mbn_tools.preprocess_elf_file(elf_in_file_name2) </span><br><span style="color: hsl(120, 100%, 40%);">+      </span><br><span>   # Check to make sure xbl_sec file path exists before using</span><br><span>   if elf_in_file_xbl_sec != "":</span><br><span>     [elf_headerxblsec, phdr_tablexblsec] = \</span><br><span style="color: hsl(0, 100%, 40%);">-      mbn_tools.preprocess_elf_file(elf_in_file_xbl_sec)</span><br><span style="color: hsl(120, 100%, 40%);">+      mbn_tools.preprocess_elf_file(elf_in_file_xbl_sec) </span><br><span> </span><br><span>   # Open Files</span><br><span>   elf_in_fp1 = mbn_tools.OPEN(elf_in_file_name1, "rb")</span><br><span>@@ -340,7 +322,7 @@</span><br><span>     else:</span><br><span>       phdr_total_size += elf_header2.e_phnum * ELF32_PHDR_SIZE</span><br><span>       phdr_total_count += elf_header2.e_phnum</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+  </span><br><span>   # Account for xbl_sec header if included</span><br><span>   if elf_in_file_xbl_sec != "":</span><br><span>     phdr_total_count += 1</span><br><span>@@ -379,7 +361,7 @@</span><br><span>                                  '\x00' + \</span><br><span>                                  '\x00' + \</span><br><span>                                  ('\x00' * 7))</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+   </span><br><span>     # Address needs to be verified that it is not greater than 32 bits</span><br><span>     # as it is possible to go from a 64 bit elf to 32.</span><br><span>     if (elf_header1.e_entry > 0xFFFFFFFF):</span><br><span>@@ -415,7 +397,7 @@</span><br><span>             phdr_total_count = phdr_total_count - 1</span><br><span>     # Do not include xbl_sec in above calculation</span><br><span>     # xbl_sec is to be treated as a single blob</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+    </span><br><span> </span><br><span>   # Now it is ok to populate the ELF header and write it out</span><br><span>   out_elf_header.e_phnum = phdr_total_count</span><br><span>@@ -492,9 +474,9 @@</span><br><span>         exit()</span><br><span>       new_phdr.p_align  = curr_phdr.p_align</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    #print "i=",i</span><br><span style="color: hsl(0, 100%, 40%);">-    #print "phdr_offset=", phdr_offset</span><br><span style="color: hsl(120, 100%, 40%);">+    </span><br><span style="color: hsl(120, 100%, 40%);">+    print "i=",i</span><br><span style="color: hsl(120, 100%, 40%);">+    print "phdr_offset=", phdr_offset</span><br><span> </span><br><span>     # update output file location to next phdr location</span><br><span>     elf_out_fp.seek(phdr_offset)</span><br><span>@@ -502,15 +484,12 @@</span><br><span>     phdr_offset += out_elf_header.e_phentsize</span><br><span> </span><br><span>     inp_data_offset = curr_phdr.p_offset # used to read data from input file</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#    print "inp_data_offset="</span><br><span style="color: hsl(0, 100%, 40%);">-#    print inp_data_offset</span><br><span style="color: hsl(0, 100%, 40%);">-#</span><br><span style="color: hsl(0, 100%, 40%);">-#    print "curr_phdr.p_offset="</span><br><span style="color: hsl(0, 100%, 40%);">-#    print curr_phdr.p_offset</span><br><span style="color: hsl(0, 100%, 40%);">-#</span><br><span style="color: hsl(0, 100%, 40%);">-#    print "curr_phdr.p_filesz="</span><br><span style="color: hsl(0, 100%, 40%);">-#    print curr_phdr.p_filesz</span><br><span style="color: hsl(120, 100%, 40%);">+    print "inp_data_offset="</span><br><span style="color: hsl(120, 100%, 40%);">+    print inp_data_offset</span><br><span style="color: hsl(120, 100%, 40%);">+    print "curr_phdr.p_offset="</span><br><span style="color: hsl(120, 100%, 40%);">+    print curr_phdr.p_offset</span><br><span style="color: hsl(120, 100%, 40%);">+    print "curr_phdr.p_filesz="</span><br><span style="color: hsl(120, 100%, 40%);">+    print curr_phdr.p_filesz</span><br><span> </span><br><span>     # output current phdr</span><br><span>     if is_out_elf_64_bit == False:</span><br><span>@@ -525,8 +504,14 @@</span><br><span>                  new_phdr.p_offset,</span><br><span>                                                new_phdr.p_filesz)</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    # Update segment alignment value if applicable</span><br><span style="color: hsl(120, 100%, 40%);">+    if new_phdr.p_align == SEGMENT_ALIGN_4K:</span><br><span style="color: hsl(120, 100%, 40%);">+      local_align = SEGMENT_ALIGN</span><br><span style="color: hsl(120, 100%, 40%);">+    else:</span><br><span style="color: hsl(120, 100%, 40%);">+      local_align = new_phdr.p_align</span><br><span style="color: hsl(120, 100%, 40%);">+    </span><br><span>     # update data segment offset to be aligned after previous segment</span><br><span style="color: hsl(0, 100%, 40%);">-    segment_offset += roundup(new_phdr.p_filesz, SEGMENT_ALIGN);</span><br><span style="color: hsl(120, 100%, 40%);">+    segment_offset += roundup(new_phdr.p_filesz, local_align);</span><br><span>   elf_in_fp1.close()</span><br><span> </span><br><span>   # Output second elf data if applicable</span><br><span>@@ -590,9 +575,10 @@</span><br><span>           exit()</span><br><span>         new_phdr.p_align  = curr_phdr.p_align</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#     print "i=",i</span><br><span style="color: hsl(0, 100%, 40%);">-#     print "phdr_offset=", phdr_offset</span><br><span style="color: hsl(120, 100%, 40%);">+  print "i"</span><br><span style="color: hsl(120, 100%, 40%);">+   print i</span><br><span style="color: hsl(120, 100%, 40%);">+       print "phdr_offset="</span><br><span style="color: hsl(120, 100%, 40%);">+        print phdr_offset</span><br><span> </span><br><span>       # update output file location to next phdr location</span><br><span>       elf_out_fp.seek(phdr_offset)</span><br><span>@@ -600,15 +586,12 @@</span><br><span>       phdr_offset += out_elf_header.e_phentsize</span><br><span> </span><br><span>       inp_data_offset = curr_phdr.p_offset # used to read data from input file</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#     print "inp_data_offset="</span><br><span style="color: hsl(0, 100%, 40%);">-#     print inp_data_offset</span><br><span style="color: hsl(0, 100%, 40%);">-#</span><br><span style="color: hsl(0, 100%, 40%);">-#     print "curr_phdr.p_offset="</span><br><span style="color: hsl(0, 100%, 40%);">-#     print curr_phdr.p_offset</span><br><span style="color: hsl(0, 100%, 40%);">-#</span><br><span style="color: hsl(0, 100%, 40%);">-#     print "curr_phdr.p_filesz="</span><br><span style="color: hsl(0, 100%, 40%);">-#     print curr_phdr.p_filesz</span><br><span style="color: hsl(120, 100%, 40%);">+      print "inp_data_offset="</span><br><span style="color: hsl(120, 100%, 40%);">+      print inp_data_offset</span><br><span style="color: hsl(120, 100%, 40%);">+      print "curr_phdr.p_offset="</span><br><span style="color: hsl(120, 100%, 40%);">+      print curr_phdr.p_offset</span><br><span style="color: hsl(120, 100%, 40%);">+      print "curr_phdr.p_filesz="</span><br><span style="color: hsl(120, 100%, 40%);">+      print curr_phdr.p_filesz</span><br><span> </span><br><span>       # output current phdr</span><br><span>       if is_out_elf_64_bit == False:</span><br><span>@@ -623,28 +606,38 @@</span><br><span>                                                  new_phdr.p_offset,</span><br><span>                                                  new_phdr.p_filesz)</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+      # Update segment alignment value if applicable</span><br><span style="color: hsl(120, 100%, 40%);">+      if new_phdr.p_align == SEGMENT_ALIGN_4K:</span><br><span style="color: hsl(120, 100%, 40%);">+        local_align = SEGMENT_ALIGN</span><br><span style="color: hsl(120, 100%, 40%);">+      else:</span><br><span style="color: hsl(120, 100%, 40%);">+        local_align = new_phdr.p_align</span><br><span style="color: hsl(120, 100%, 40%);">+    </span><br><span>       # update data segment offset to be aligned after previous segment</span><br><span style="color: hsl(0, 100%, 40%);">-      segment_offset += roundup(new_phdr.p_filesz, SEGMENT_ALIGN);</span><br><span style="color: hsl(120, 100%, 40%);">+      segment_offset += roundup(new_phdr.p_filesz, local_align);</span><br><span>     elf_in_fp2.close()</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+    </span><br><span>   # Embed xbl_sec image if provided</span><br><span>   if elf_in_file_xbl_sec != "":</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+    </span><br><span>     # Scan pheaders in xbl_sec for segment that contains entry point address</span><br><span>     entry_seg_offset = -1</span><br><span>     entry_addr = elf_headerxblsec.e_entry</span><br><span style="color: hsl(120, 100%, 40%);">+    start_addr = -1</span><br><span>     for i in range(elf_headerxblsec.e_phnum):</span><br><span>       phdr = phdr_tablexblsec[i]</span><br><span style="color: hsl(0, 100%, 40%);">-      max_addr = phdr.p_vaddr + phdr.p_memsz</span><br><span style="color: hsl(120, 100%, 40%);">+      max_addr = phdr.p_vaddr + phdr.p_memsz - 1</span><br><span>       if phdr.p_vaddr <= entry_addr <= max_addr:</span><br><span>         entry_seg_offset = phdr.p_offset</span><br><span style="color: hsl(120, 100%, 40%);">+ start_addr = phdr.p_vaddr</span><br><span>         break</span><br><span>     if entry_seg_offset == -1:</span><br><span>       print "Error: Failed to find entry point in any segment!"</span><br><span>       exit()</span><br><span>     # magical equation for program header's phys and virt addr</span><br><span style="color: hsl(0, 100%, 40%);">-    phys_virt_addr = entry_addr - entry_seg_offset</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+    # phys_virt_addr = entry_addr - entry_seg_offset</span><br><span style="color: hsl(120, 100%, 40%);">+    phys_virt_addr = start_addr - entry_seg_offset</span><br><span style="color: hsl(120, 100%, 40%);">+    print "entry_addr " + str(hex(entry_addr)) + "entry_seg_offset " + str(hex(start_addr)) + "phys_virt_addr " + str(hex(phys_virt_addr))</span><br><span style="color: hsl(120, 100%, 40%);">+    </span><br><span>     if is_out_elf_64_bit:</span><br><span>       # Converting from 32 to 64 elf requires no data size validation</span><br><span>       new_phdr = mbn_tools.Elf64_Phdr('\0' * ELF64_PHDR_SIZE)</span><br><span>@@ -654,7 +647,7 @@</span><br><span>       new_phdr.p_paddr  = phys_virt_addr</span><br><span>       new_phdr.p_filesz = os.path.getsize(elf_in_file_xbl_sec)</span><br><span>       new_phdr.p_memsz  = new_phdr.p_filesz</span><br><span style="color: hsl(0, 100%, 40%);">-      new_phdr.p_flags  = 0x5</span><br><span style="color: hsl(120, 100%, 40%);">+      new_phdr.p_flags  = 0x5 | (mbn_tools.MI_PBT_SWAPPED_SEGMENT << mbn_tools.MI_PBT_FLAG_SEGMENT_TYPE_SHIFT);</span><br><span>       new_phdr.p_align  = 0x1000</span><br><span>     else:</span><br><span>       # Converting from 64 to 32 elf requires data size validation</span><br><span>@@ -663,7 +656,7 @@</span><br><span>       new_phdr = mbn_tools.Elf32_Phdr('\0' * ELF32_PHDR_SIZE)</span><br><span>       new_phdr.p_type   = 0x1 #</span><br><span>       new_phdr.p_offset = segment_offset</span><br><span style="color: hsl(0, 100%, 40%);">-      new_phdr.p_flags  = 0x5</span><br><span style="color: hsl(120, 100%, 40%);">+      new_phdr.p_flags  = 0x5 | (mbn_tools.MI_PBT_SWAPPED_SEGMENT << mbn_tools.MI_PBT_FLAG_SEGMENT_TYPE_SHIFT);</span><br><span>       new_phdr.p_align  = 0x1000</span><br><span> </span><br><span>       if phys_virt_addr > 0xFFFFFFFF:</span><br><span>@@ -678,22 +671,22 @@</span><br><span>         exit()</span><br><span>       new_phdr.p_filesz = os.path.getsize(elf_in_file_xbl_sec)</span><br><span>       new_phdr.p_memsz  = new_phdr.p_filesz</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+      </span><br><span style="color: hsl(120, 100%, 40%);">+    </span><br><span>     # update output file location to next phdr location</span><br><span>     elf_out_fp.seek(phdr_offset)</span><br><span>     # increment phdr_offset to next location</span><br><span>     phdr_offset += out_elf_header.e_phentsize</span><br><span>     # Copy entire xbl_sec file, so start from byte 0</span><br><span style="color: hsl(0, 100%, 40%);">-    inp_data_offset = 0</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+    inp_data_offset = 0 </span><br><span style="color: hsl(120, 100%, 40%);">+    </span><br><span>     # Output xbl_sec's phdr</span><br><span>     elf_in_file_xbl_sec</span><br><span>     if is_out_elf_64_bit == False:</span><br><span>       elf_out_fp.write(mbn_tools.Elf32_Phdr.getPackedData(new_phdr))</span><br><span>     else:</span><br><span>       elf_out_fp.write(mbn_tools.Elf64_Phdr.getPackedData(new_phdr))</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+      </span><br><span>     # Copy the ENTIRE xbl_sec image</span><br><span>     bytes_written = mbn_tools.file_copy_offset(elf_in_fpxblsec,</span><br><span>                                                inp_data_offset,</span><br><span>@@ -702,10 +695,17 @@</span><br><span>                                                new_phdr.p_filesz)</span><br><span>     # update data segment offset to be aligned after previous segment</span><br><span>     # Not necessary, unless appending more pheaders after this point</span><br><span style="color: hsl(0, 100%, 40%);">-    segment_offset += roundup(new_phdr.p_filesz, SEGMENT_ALIGN);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    # Update segment alignment value if applicable</span><br><span style="color: hsl(120, 100%, 40%);">+    if new_phdr.p_align == SEGMENT_ALIGN_4K:</span><br><span style="color: hsl(120, 100%, 40%);">+      local_align = SEGMENT_ALIGN</span><br><span style="color: hsl(120, 100%, 40%);">+    else:</span><br><span style="color: hsl(120, 100%, 40%);">+      local_align = new_phdr.p_align</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    segment_offset += roundup(new_phdr.p_filesz, local_align);</span><br><span style="color: hsl(120, 100%, 40%);">+    </span><br><span>     elf_in_fpxblsec.close()</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+  </span><br><span>   elf_out_fp.close()</span><br><span> </span><br><span>   return 0</span><br><span>diff --git a/util/qualcomm/description.md b/util/qualcomm/description.md</span><br><span>old mode 100644</span><br><span>new mode 100755</span><br><span>diff --git a/util/ipqheader/ipqheader.py b/util/qualcomm/ipqheader.py</span><br><span>similarity index 100%</span><br><span>rename from util/ipqheader/ipqheader.py</span><br><span>rename to util/qualcomm/ipqheader.py</span><br><span>diff --git a/util/ipqheader/mbn_tools.py b/util/qualcomm/mbn_tools.py</span><br><span>similarity index 94%</span><br><span>rename from util/ipqheader/mbn_tools.py</span><br><span>rename to util/qualcomm/mbn_tools.py</span><br><span>index c66afda..a144b23 100755</span><br><span>--- a/util/ipqheader/mbn_tools.py</span><br><span>+++ b/util/qualcomm/mbn_tools.py</span><br><span>@@ -1,38 +1,15 @@</span><br><span style="color: hsl(0, 100%, 40%);">-#!/usr/bin/env python2</span><br><span style="color: hsl(120, 100%, 40%);">+#==============================================================================</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+#  Copyright (c) 2010-2013,2017 Qualcomm Technologies, Inc.</span><br><span style="color: hsl(120, 100%, 40%);">+#  All Rights Reserved.</span><br><span style="color: hsl(120, 100%, 40%);">+#  Confidential and Proprietary - Qualcomm Technologies, Inc.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span> #===============================================================================</span><br><span> #</span><br><span> # MBN TOOLS</span><br><span> #</span><br><span> # GENERAL DESCRIPTION</span><br><span> #    Contains all MBN Utilities for image generation</span><br><span style="color: hsl(0, 100%, 40%);">-#</span><br><span style="color: hsl(0, 100%, 40%);">-# Copyright (c) 2016, The Linux Foundation. All rights reserved.</span><br><span style="color: hsl(0, 100%, 40%);">-#</span><br><span style="color: hsl(0, 100%, 40%);">-# Redistribution and use in source and binary forms, with or without</span><br><span style="color: hsl(0, 100%, 40%);">-# modification, are permitted provided that the following conditions are</span><br><span style="color: hsl(0, 100%, 40%);">-# met:</span><br><span style="color: hsl(0, 100%, 40%);">-#     * Redistributions of source code must retain the above copyright</span><br><span style="color: hsl(0, 100%, 40%);">-#       notice, this list of conditions and the following disclaimer.</span><br><span style="color: hsl(0, 100%, 40%);">-#     * Redistributions in binary form must reproduce the above</span><br><span style="color: hsl(0, 100%, 40%);">-#       copyright notice, this list of conditions and the following</span><br><span style="color: hsl(0, 100%, 40%);">-#       disclaimer in the documentation and/or other materials provided</span><br><span style="color: hsl(0, 100%, 40%);">-#       with the distribution.</span><br><span style="color: hsl(0, 100%, 40%);">-#     * Neither the name of The Linux Foundation nor the names of its</span><br><span style="color: hsl(0, 100%, 40%);">-#       contributors may be used to endorse or promote products derived</span><br><span style="color: hsl(0, 100%, 40%);">-#       from this software without specific prior written permission.</span><br><span style="color: hsl(0, 100%, 40%);">-#</span><br><span style="color: hsl(0, 100%, 40%);">-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED</span><br><span style="color: hsl(0, 100%, 40%);">-# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF</span><br><span style="color: hsl(0, 100%, 40%);">-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT</span><br><span style="color: hsl(0, 100%, 40%);">-# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS</span><br><span style="color: hsl(0, 100%, 40%);">-# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR</span><br><span style="color: hsl(0, 100%, 40%);">-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF</span><br><span style="color: hsl(0, 100%, 40%);">-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR</span><br><span style="color: hsl(0, 100%, 40%);">-# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,</span><br><span style="color: hsl(0, 100%, 40%);">-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE</span><br><span style="color: hsl(0, 100%, 40%);">-# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN</span><br><span style="color: hsl(0, 100%, 40%);">-# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span><br><span style="color: hsl(0, 100%, 40%);">-#</span><br><span> #-------------------------------------------------------------------------------</span><br><span> #                      EDIT HISTORY FOR FILE</span><br><span> #</span><br><span>@@ -52,13 +29,12 @@</span><br><span> # 10/20/11   dxiang  Clean up</span><br><span> #===============================================================================</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-import stat</span><br><span style="color: hsl(0, 100%, 40%);">-import csv</span><br><span style="color: hsl(0, 100%, 40%);">-import itertools</span><br><span style="color: hsl(0, 100%, 40%);">-import struct</span><br><span style="color: hsl(0, 100%, 40%);">-import os</span><br><span style="color: hsl(0, 100%, 40%);">-import shutil</span><br><span style="color: hsl(120, 100%, 40%);">+import copy</span><br><span> import hashlib</span><br><span style="color: hsl(120, 100%, 40%);">+import os</span><br><span style="color: hsl(120, 100%, 40%);">+import re</span><br><span style="color: hsl(120, 100%, 40%);">+import shutil</span><br><span style="color: hsl(120, 100%, 40%);">+import struct</span><br><span> </span><br><span> #----------------------------------------------------------------------------</span><br><span> # GLOBAL VARIABLES BEGIN</span><br><span>@@ -311,7 +287,7 @@</span><br><span>     1) 'X's  | char *         | string      | 'X' bytes</span><br><span>     2) H     | unsigned short | integer     | 2 bytes</span><br><span>     3) I     | unsigned int   | integer     | 4 bytes</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+    4) Q     | unsigned long  | integer     | 8 bytes</span><br><span> """</span><br><span> </span><br><span> #----------------------------------------------------------------------------</span><br><span>@@ -989,6 +965,12 @@</span><br><span>       boot_header.cert_chain_ptr = image_dest + code_size + signature_size</span><br><span>       boot_header.cert_chain_size = cert_chain_size</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+      # If platform image integrity check is enabled</span><br><span style="color: hsl(120, 100%, 40%);">+      if 'USES_PLATFORM_IMAGE_INTEGRITY_CHECK' in env:</span><br><span style="color: hsl(120, 100%, 40%);">+          boot_header.flash_parti_ver = 5   # version</span><br><span style="color: hsl(120, 100%, 40%);">+          boot_header.image_src = 0         # sig_size_qti</span><br><span style="color: hsl(120, 100%, 40%);">+          boot_header.image_dest_ptr = 0    # cert_chain_size_qti</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>       # If preamble is required, output the preamble file and update the boot_header</span><br><span>       if requires_preamble is True:</span><br><span>          boot_header = image_preamble(gen_dict, preamble_file_name, boot_header, num_of_pages)</span><br><span>@@ -1005,14 +987,16 @@</span><br><span> # pboot_gen_elf</span><br><span> #----------------------------------------------------------------------------</span><br><span> def pboot_gen_elf(env, elf_in_file_name,</span><br><span style="color: hsl(0, 100%, 40%);">-                       hash_out_file_name,</span><br><span style="color: hsl(0, 100%, 40%);">-                       elf_out_file_name,</span><br><span style="color: hsl(0, 100%, 40%);">-                       secure_type = 'non_secure',</span><br><span style="color: hsl(0, 100%, 40%);">-                       hash_seg_max_size = None,</span><br><span style="color: hsl(0, 100%, 40%);">-                       last_phys_addr = None,</span><br><span style="color: hsl(0, 100%, 40%);">-                       append_xml_hdr = False,</span><br><span style="color: hsl(0, 100%, 40%);">-                       is_sha256_algo = True,</span><br><span style="color: hsl(0, 100%, 40%);">-                       cert_chain_size_in = CERT_CHAIN_ONEROOT_MAXSIZE):</span><br><span style="color: hsl(120, 100%, 40%);">+                  hash_out_file_name,</span><br><span style="color: hsl(120, 100%, 40%);">+                  elf_out_file_name,</span><br><span style="color: hsl(120, 100%, 40%);">+                  secure_type='non_secure',</span><br><span style="color: hsl(120, 100%, 40%);">+                  hash_seg_max_size=None,</span><br><span style="color: hsl(120, 100%, 40%);">+                  last_phys_addr=None,</span><br><span style="color: hsl(120, 100%, 40%);">+                  append_xml_hdr=False,</span><br><span style="color: hsl(120, 100%, 40%);">+                  is_sha256_algo=True,</span><br><span style="color: hsl(120, 100%, 40%);">+                  cert_chain_size_in=CERT_CHAIN_ONEROOT_MAXSIZE,</span><br><span style="color: hsl(120, 100%, 40%);">+                  hash_pageseg_as_segment=False):</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>    global MI_PROG_BOOT_DIGEST_SIZE</span><br><span>    if (is_sha256_algo is True):</span><br><span>       MI_PROG_BOOT_DIGEST_SIZE = 32</span><br><span>@@ -1090,26 +1074,41 @@</span><br><span> </span><br><span>          off = seg_offset + seg_size</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-         while seg_offset < off:</span><br><span style="color: hsl(120, 100%, 40%);">+         # Add a single hash table entry for pageable segment</span><br><span style="color: hsl(120, 100%, 40%);">+         if hash_pageseg_as_segment:</span><br><span style="color: hsl(120, 100%, 40%);">+             elf_in_fp.seek(seg_offset)</span><br><span style="color: hsl(120, 100%, 40%);">+             fbuf = elf_in_fp.read(seg_size)</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-            if seg_offset < ELF_BLOCK_ALIGN:</span><br><span style="color: hsl(0, 100%, 40%);">-               hash_size = seg_offset</span><br><span style="color: hsl(0, 100%, 40%);">-            else:</span><br><span style="color: hsl(0, 100%, 40%);">-               hash_size = ELF_BLOCK_ALIGN</span><br><span style="color: hsl(120, 100%, 40%);">+             if MI_PBT_CHECK_FLAG_TYPE(curr_phdr.p_flags) is True:</span><br><span style="color: hsl(120, 100%, 40%);">+                 hash = generate_hash(fbuf, is_sha256_algo)</span><br><span style="color: hsl(120, 100%, 40%);">+             else:</span><br><span style="color: hsl(120, 100%, 40%);">+                 hash = '\0' * MI_PROG_BOOT_DIGEST_SIZE</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-            elf_in_fp.seek(seg_offset)</span><br><span style="color: hsl(0, 100%, 40%);">-            fbuf = elf_in_fp.read(hash_size)</span><br><span style="color: hsl(120, 100%, 40%);">+             # Write hash to file</span><br><span style="color: hsl(120, 100%, 40%);">+             hash_out_fp.write(hash)</span><br><span style="color: hsl(120, 100%, 40%);">+             hashtable_size += MI_PROG_BOOT_DIGEST_SIZE</span><br><span style="color: hsl(120, 100%, 40%);">+         # Add a hash table entry for each block of pageable segment</span><br><span style="color: hsl(120, 100%, 40%);">+         else:</span><br><span style="color: hsl(120, 100%, 40%);">+             while seg_offset < off:</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-            if MI_PBT_CHECK_FLAG_TYPE(curr_phdr.p_flags) is True:</span><br><span style="color: hsl(0, 100%, 40%);">-               hash = generate_hash(fbuf, is_sha256_algo)</span><br><span style="color: hsl(0, 100%, 40%);">-            else:</span><br><span style="color: hsl(0, 100%, 40%);">-               hash = '\0' * MI_PROG_BOOT_DIGEST_SIZE</span><br><span style="color: hsl(120, 100%, 40%);">+                if seg_offset < ELF_BLOCK_ALIGN:</span><br><span style="color: hsl(120, 100%, 40%);">+                   hash_size = seg_offset</span><br><span style="color: hsl(120, 100%, 40%);">+                else:</span><br><span style="color: hsl(120, 100%, 40%);">+                   hash_size = ELF_BLOCK_ALIGN</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-            # Write hash to file</span><br><span style="color: hsl(0, 100%, 40%);">-            hash_out_fp.write(hash)</span><br><span style="color: hsl(120, 100%, 40%);">+                elf_in_fp.seek(seg_offset)</span><br><span style="color: hsl(120, 100%, 40%);">+                fbuf = elf_in_fp.read(hash_size)</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-            hashtable_size += MI_PROG_BOOT_DIGEST_SIZE</span><br><span style="color: hsl(0, 100%, 40%);">-            seg_offset += ELF_BLOCK_ALIGN</span><br><span style="color: hsl(120, 100%, 40%);">+                if MI_PBT_CHECK_FLAG_TYPE(curr_phdr.p_flags) is True:</span><br><span style="color: hsl(120, 100%, 40%);">+                   hash = generate_hash(fbuf, is_sha256_algo)</span><br><span style="color: hsl(120, 100%, 40%);">+                else:</span><br><span style="color: hsl(120, 100%, 40%);">+                   hash = '\0' * MI_PROG_BOOT_DIGEST_SIZE</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                # Write hash to file</span><br><span style="color: hsl(120, 100%, 40%);">+                hash_out_fp.write(hash)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                hashtable_size += MI_PROG_BOOT_DIGEST_SIZE</span><br><span style="color: hsl(120, 100%, 40%);">+                seg_offset += ELF_BLOCK_ALIGN</span><br><span> </span><br><span>       # Copy the hash entry for all that are PAGED segments and those that are not the PHDR type. This is for</span><br><span>       # backward tool compatibility where some images are generated using older exe tools.</span><br><span>@@ -1165,15 +1164,15 @@</span><br><span>      bytes_to_pad = ELF_BLOCK_ALIGN - pad_hash_segment</span><br><span>      hash_seg_end = hash_tbl_end_addr + bytes_to_pad</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-     # Check if a shifting is required to accommodate for the hash segment.</span><br><span style="color: hsl(120, 100%, 40%);">+     # Check if a shifting is required to accomodate for the hash segment.</span><br><span>      # Get the minimum offset by going through the program headers.</span><br><span>      # Note that the program headers in the input file do not contain</span><br><span>      # the dummy program header for ELF + Program header, and the</span><br><span>      # program header for the hashtable.</span><br><span style="color: hsl(0, 100%, 40%);">-     min_offset = phdr_table[0].p_offset</span><br><span style="color: hsl(120, 100%, 40%);">+     min_offset = hash_seg_end #start with the minimum needed</span><br><span>      for i in range(num_phdrs):</span><br><span>         curr_phdr = phdr_table[i]</span><br><span style="color: hsl(0, 100%, 40%);">-        if curr_phdr.p_offset < min_offset:</span><br><span style="color: hsl(120, 100%, 40%);">+        if curr_phdr.p_offset < min_offset and (curr_phdr.p_type != PHDR_TYPE): # discard entry of type PHDR which will have offset=0:</span><br><span>             min_offset = curr_phdr.p_offset</span><br><span> </span><br><span>      if min_offset < hash_seg_end:</span><br><span>@@ -1443,6 +1442,11 @@</span><br><span>    [elf_header, phdr_table] = preprocess_elf_file(elf_in_file_name)</span><br><span>    segment_list = readSCL(scl_file_name, env['GLOBAL_DICT'])</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+   if 'USES_FEATURE_DYNAMIC_LOADING' in env:</span><br><span style="color: hsl(120, 100%, 40%);">+      sub = 1</span><br><span style="color: hsl(120, 100%, 40%);">+   else:</span><br><span style="color: hsl(120, 100%, 40%);">+      sub = 0</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>    if elf_header.e_ident[ELFINFO_CLASS_INDEX] == ELFINFO_CLASS_64:</span><br><span>      curr_phdr = Elf64_Phdr('\0' * ELF64_PHDR_SIZE)</span><br><span>      # Offset into program header where the p_flags field is stored</span><br><span>@@ -1456,14 +1460,14 @@</span><br><span>    elf_in_fp = OPEN(elf_in_file_name, "r+")</span><br><span> </span><br><span>    # Check for corresponding number of segments</span><br><span style="color: hsl(0, 100%, 40%);">-   if len(segment_list) is not elf_header.e_phnum:</span><br><span style="color: hsl(120, 100%, 40%);">+   if len(segment_list) is not (elf_header.e_phnum -sub):</span><br><span>       raise RuntimeError, 'SCL file and ELF file have different number of segments!'</span><br><span> </span><br><span>    # Go to the start of the p_flag entry in the first program header</span><br><span>    file_offset = elf_header.e_phoff + phdr_flag_off</span><br><span> </span><br><span>    # Change each program header flag in the ELF file based off the SCL file</span><br><span style="color: hsl(0, 100%, 40%);">-   for i in range(elf_header.e_phnum):</span><br><span style="color: hsl(120, 100%, 40%);">+   for i in range(elf_header.e_phnum -sub):</span><br><span>       # Seek to correct location and create new p_flag value</span><br><span>       elf_in_fp.seek(file_offset)</span><br><span>       curr_phdr = phdr_table[i]</span><br><span>@@ -1810,8 +1814,8 @@</span><br><span>    # Get file names for 'cust' and 'targ' auto-generated files inside 'build/ms'</span><br><span>    cust_h = env.subst('CUST${BUILD_ID}.H').lower()</span><br><span>    targ_h = env.subst('TARG${BUILD_ID}.H').lower()</span><br><span style="color: hsl(0, 100%, 40%);">-   cust_file_name = str(env.FindFile(cust_h, "${INC_ROOT}/build/ms"))</span><br><span style="color: hsl(0, 100%, 40%);">-   targ_file_name = str(env.FindFile(targ_h, "${INC_ROOT}/build/ms"))</span><br><span style="color: hsl(120, 100%, 40%);">+   cust_file_name = str(env.FindFile(cust_h, "${INC_ROOT}/build/ms").abspath)</span><br><span style="color: hsl(120, 100%, 40%);">+   targ_file_name = str(env.FindFile(targ_h, "${INC_ROOT}/build/ms").abspath)</span><br><span> </span><br><span>    # Check that files are present</span><br><span>    if (os.path.exists(cust_file_name) is True) and \</span><br><span>@@ -1834,45 +1838,36 @@</span><br><span>       raise RuntimeError, "At least 1 file must be specified as an input"</span><br><span> </span><br><span>    global_dict = {}</span><br><span style="color: hsl(0, 100%, 40%);">-   Fields = ["Define", "Key", "Value"]</span><br><span> </span><br><span>    # For each input file</span><br><span>    for i in range(len(args)):</span><br><span style="color: hsl(120, 100%, 40%);">+      with open(args[i]) as fp:</span><br><span style="color: hsl(120, 100%, 40%);">+         for line in fp:</span><br><span style="color: hsl(120, 100%, 40%);">+            temp = re.findall('\#define[ ]+(\w+)([ ]+[^\n]+)*', line.strip())</span><br><span style="color: hsl(120, 100%, 40%);">+            if (1 == len(temp)):</span><br><span style="color: hsl(120, 100%, 40%);">+               k, v = temp[0]</span><br><span style="color: hsl(120, 100%, 40%);">+               k = k.strip()</span><br><span style="color: hsl(120, 100%, 40%);">+               v = v.strip()</span><br><span style="color: hsl(120, 100%, 40%);">+               if 0 == len(v):</span><br><span style="color: hsl(120, 100%, 40%);">+                  # If value pair is empty string, assume feature definition is true</span><br><span style="color: hsl(120, 100%, 40%);">+                  global_dict[k] = 'yes'</span><br><span style="color: hsl(120, 100%, 40%);">+                  continue</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-      template_file_path = args[i]</span><br><span style="color: hsl(0, 100%, 40%);">-      instream = OPEN(template_file_path, 'r')</span><br><span style="color: hsl(0, 100%, 40%);">-      # Tokenize each line with a white space</span><br><span style="color: hsl(0, 100%, 40%);">-      values = csv.DictReader(instream, Fields, delimiter=" ")</span><br><span style="color: hsl(120, 100%, 40%);">+               if global_dict is not None and len(global_dict.keys()) > 0:</span><br><span style="color: hsl(120, 100%, 40%);">+                  # Check for and handle text replacements as we parse</span><br><span style="color: hsl(120, 100%, 40%);">+                  all_keys = copy.copy(global_dict.keys())</span><br><span style="color: hsl(120, 100%, 40%);">+                  all_keys.sort(key=lambda x: len(x), reverse=True)</span><br><span style="color: hsl(120, 100%, 40%);">+                  for x in all_keys:</span><br><span style="color: hsl(120, 100%, 40%);">+                     v = v.replace(x, str(global_dict[x]))</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-      for values in itertools.izip(values):</span><br><span style="color: hsl(0, 100%, 40%);">-         new_entry = values[0]</span><br><span style="color: hsl(0, 100%, 40%);">-         # Verify the parsed tokens</span><br><span style="color: hsl(0, 100%, 40%);">-         if (new_entry['Define'] == '#define') and \</span><br><span style="color: hsl(0, 100%, 40%);">-            (new_entry['Key'] != None) and \</span><br><span style="color: hsl(0, 100%, 40%);">-            (new_entry['Value'] != None):</span><br><span style="color: hsl(120, 100%, 40%);">+               # Attempt to evaluate value</span><br><span style="color: hsl(120, 100%, 40%);">+               try:</span><br><span style="color: hsl(120, 100%, 40%);">+                  v = eval(v)</span><br><span style="color: hsl(120, 100%, 40%);">+               # Catch exceptions and do not evaluate</span><br><span style="color: hsl(120, 100%, 40%);">+               except:</span><br><span style="color: hsl(120, 100%, 40%);">+                  pass</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-            new_key   = new_entry['Key'].strip()</span><br><span style="color: hsl(0, 100%, 40%);">-            new_value = new_entry['Value'].strip()</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-            # If value pair is empty string, assume feature definition is true</span><br><span style="color: hsl(0, 100%, 40%);">-            if new_value == '':</span><br><span style="color: hsl(0, 100%, 40%);">-               new_value = 'yes'</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-            # Check for and handle text replacements as we parse</span><br><span style="color: hsl(0, 100%, 40%);">-            if global_dict is not None and len(global_dict.keys()) > 0:</span><br><span style="color: hsl(0, 100%, 40%);">-               for key in global_dict:</span><br><span style="color: hsl(0, 100%, 40%);">-                  new_value = new_value.replace(key, str(global_dict.get(key)))</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-            # Attempt to evaluate value</span><br><span style="color: hsl(0, 100%, 40%);">-            try:</span><br><span style="color: hsl(0, 100%, 40%);">-               new_value = eval(new_value)</span><br><span style="color: hsl(0, 100%, 40%);">-            # Catch exceptions and do not evaluate</span><br><span style="color: hsl(0, 100%, 40%);">-            except:</span><br><span style="color: hsl(0, 100%, 40%);">-               pass</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-            # Add to global dictionary</span><br><span style="color: hsl(0, 100%, 40%);">-            global_dict[new_key] = new_value</span><br><span style="color: hsl(0, 100%, 40%);">-      instream.close()</span><br><span style="color: hsl(120, 100%, 40%);">+               global_dict[k] = v</span><br><span> </span><br><span>    return global_dict</span><br><span> </span><br><span>@@ -2224,25 +2219,25 @@</span><br><span>         #generate new file for appending target data + required MCs</span><br><span>         file = open(target, "ab")</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+        filedata_till_128kb = filedata[0:VIRTUAL_BLOCK_SIZE]</span><br><span style="color: hsl(120, 100%, 40%);">+        filedata_after_128kb = filedata[VIRTUAL_BLOCK_SIZE:length]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        a = str(hex(FLASH_CODE_WORD))</span><br><span style="color: hsl(120, 100%, 40%);">+        mc1 = chr(int(a[8:10],16)) + chr(int(a[6:8],16)) + chr(int(a[4:6],16)) + chr(int(a[2:4],16))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        b = str(hex(MAGIC_NUM))</span><br><span style="color: hsl(120, 100%, 40%);">+        mc2 = chr(int(b[8:10],16)) + chr(int(b[6:8],16)) + chr(int(b[4:6],16)) + chr(int(b[2:4],16))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        c = str(hex(SBL_VIRTUAL_BLOCK_MAGIC_NUM))</span><br><span style="color: hsl(120, 100%, 40%);">+        mc3 = chr(int(c[8:10],16)) + chr(int(c[6:8],16)) + chr(int(c[4:6],16)) + chr(int(c[2:4],16))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>         while length > VIRTUAL_BLOCK_SIZE:</span><br><span style="color: hsl(120, 100%, 40%);">+            file.write(filedata_till_128kb)</span><br><span style="color: hsl(120, 100%, 40%);">+            filedata = mc1 + mc2 + mc3 + filedata_after_128kb</span><br><span style="color: hsl(120, 100%, 40%);">+            length = len(filedata)</span><br><span>             filedata_till_128kb = filedata[0:VIRTUAL_BLOCK_SIZE]</span><br><span>             filedata_after_128kb = filedata[VIRTUAL_BLOCK_SIZE:length]</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-            a = str(hex(FLASH_CODE_WORD))</span><br><span style="color: hsl(0, 100%, 40%);">-            mc1 = chr(int(a[8:10],16)) + chr(int(a[6:8],16)) + chr(int(a[4:6],16)) + chr(int(a[2:4],16))</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-            b = str(hex(MAGIC_NUM))</span><br><span style="color: hsl(0, 100%, 40%);">-            mc2 = chr(int(b[8:10],16)) + chr(int(b[6:8],16)) + chr(int(b[4:6],16)) + chr(int(b[2:4],16))</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-            c = str(hex(SBL_VIRTUAL_BLOCK_MAGIC_NUM))</span><br><span style="color: hsl(0, 100%, 40%);">-            mc3 = chr(int(c[8:10],16)) + chr(int(c[6:8],16)) + chr(int(c[4:6],16)) + chr(int(c[2:4],16))</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-            MC_inserted_data = filedata_till_128kb + mc1 + mc2 + mc3</span><br><span style="color: hsl(0, 100%, 40%);">-            file.write(MC_inserted_data)</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-            filedata = filedata_after_128kb</span><br><span style="color: hsl(0, 100%, 40%);">-            length = len(filedata)</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span>         #copy the leftover data (<128KB) in output file</span><br><span>         if length > 0:</span><br><span>             file.write(filedata)</span><br><span>@@ -2313,3 +2308,4 @@</span><br><span> #----------------------------------------------------------------------------</span><br><span> # HELPER FUNCTIONS END</span><br><span> #----------------------------------------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>diff --git a/util/ipqheader/mbncat.py b/util/qualcomm/mbncat.py</span><br><span>similarity index 100%</span><br><span>rename from util/ipqheader/mbncat.py</span><br><span>rename to util/qualcomm/mbncat.py</span><br><span>diff --git a/util/qualcomm/qgpt.py b/util/qualcomm/qgpt.py</span><br><span>new file mode 100755</span><br><span>index 0000000..596ec54</span><br><span>--- /dev/null</span><br><span>+++ b/util/qualcomm/qgpt.py</span><br><span>@@ -0,0 +1,249 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/python</span><br><span style="color: hsl(120, 100%, 40%);">+#============================================================================</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+#/** @file qgpt.py</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# GENERAL DESCRIPTION</span><br><span style="color: hsl(120, 100%, 40%);">+#   Generates QCom GPT header for wrapping Bootblock</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# Copyright (c) 2018, The Linux Foundation. All rights reserved.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# Redistribution and use in source and binary forms, with or without</span><br><span style="color: hsl(120, 100%, 40%);">+# modification, are permitted provided that the following conditions are</span><br><span style="color: hsl(120, 100%, 40%);">+# met:</span><br><span style="color: hsl(120, 100%, 40%);">+#     * Redistributions of source code must retain the above copyright</span><br><span style="color: hsl(120, 100%, 40%);">+#       notice, this list of conditions and the following disclaimer.</span><br><span style="color: hsl(120, 100%, 40%);">+#     * Redistributions in binary form must reproduce the above</span><br><span style="color: hsl(120, 100%, 40%);">+#       copyright notice, this list of conditions and the following</span><br><span style="color: hsl(120, 100%, 40%);">+#       disclaimer in the documentation and/or other materials provided</span><br><span style="color: hsl(120, 100%, 40%);">+#       with the distribution.</span><br><span style="color: hsl(120, 100%, 40%);">+#     * Neither the name of The Linux Foundation nor the names of its</span><br><span style="color: hsl(120, 100%, 40%);">+#       contributors may be used to endorse or promote products derived</span><br><span style="color: hsl(120, 100%, 40%);">+#       from this software without specific prior written permission.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED</span><br><span style="color: hsl(120, 100%, 40%);">+# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF</span><br><span style="color: hsl(120, 100%, 40%);">+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT</span><br><span style="color: hsl(120, 100%, 40%);">+# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS</span><br><span style="color: hsl(120, 100%, 40%);">+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR</span><br><span style="color: hsl(120, 100%, 40%);">+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF</span><br><span style="color: hsl(120, 100%, 40%);">+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR</span><br><span style="color: hsl(120, 100%, 40%);">+# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,</span><br><span style="color: hsl(120, 100%, 40%);">+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE</span><br><span style="color: hsl(120, 100%, 40%);">+# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN</span><br><span style="color: hsl(120, 100%, 40%);">+# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+#**/</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+import os</span><br><span style="color: hsl(120, 100%, 40%);">+import math</span><br><span style="color: hsl(120, 100%, 40%);">+import random</span><br><span style="color: hsl(120, 100%, 40%);">+import re</span><br><span style="color: hsl(120, 100%, 40%);">+import struct</span><br><span style="color: hsl(120, 100%, 40%);">+import sys</span><br><span style="color: hsl(120, 100%, 40%);">+import tempfile</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+from binascii import crc32</span><br><span style="color: hsl(120, 100%, 40%);">+from optparse import OptionParser</span><br><span style="color: hsl(120, 100%, 40%);">+from types import *</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def UpdateMBR(options, GPTBlobBuffer):</span><br><span style="color: hsl(120, 100%, 40%);">+    i = 0x1BE</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i + 0] = 0x00                  # not bootable</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i + 1] = 0x00                  # head</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i + 2] = 0x01                  # sector</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i + 3] = 0x00                  # cylinder</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i + 4] = 0xEE                  # type</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i + 5] = 0xFF                  # head</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i + 6] = 0xFF                  # sector</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i + 7] = 0xFF                  # cylinder</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i + 8:i + 8 + 4] = [0x01, 0x00, 0x00, 0x00]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i + 12:i + 16] = [0x00, 0x0f, 0x00, 0x00]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # magic byte for MBR partitioning - always at this location regardless of</span><br><span style="color: hsl(120, 100%, 40%);">+    # options.sector</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[510:512] = [0x55, 0xAA]</span><br><span style="color: hsl(120, 100%, 40%);">+    return i</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def UpdatePartitionEntry(options, GPTBlobBuffer):</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    i = 2 * options.sector_size</span><br><span style="color: hsl(120, 100%, 40%);">+    # GUID of Boot Block</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 16] = [0x2c, 0xba, 0xa0, 0xde, 0xdd, 0xcb, 0x05, 0x48,</span><br><span style="color: hsl(120, 100%, 40%);">+        0xb4, 0xf9, 0xf4, 0x28, 0x25, 0x1c, 0x3e, 0x98]</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 16</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    #This is to set Unique Partition GUID. Below Hex Value is : 00ChezaBootblock00</span><br><span style="color: hsl(120, 100%, 40%);">+    UniquePartitionGUID = 0x6b636f6c62746f6f42617a65684300</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    for b in range(16):</span><br><span style="color: hsl(120, 100%, 40%);">+        GPTBlobBuffer[i] = ((UniquePartitionGUID >> (b * 8)) & 0xFF)</span><br><span style="color: hsl(120, 100%, 40%);">+        i += 1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # LBA of BootBlock Start Content</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 8] = [0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 8</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # End LBA of BootBlock Content</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i] = options.end_lba & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+1] = (options.end_lba>>8) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+2] = (options.end_lba>>16) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+3] = (options.end_lba>>24) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+4] = (options.end_lba>>32) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+5] = (options.end_lba>>40) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+6] = (options.end_lba>>48) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+7] = (options.end_lba>>56) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 8</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # Attributes</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 8] = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 8</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # Lable</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 17] = [0x62, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x74, 0x00,</span><br><span style="color: hsl(120, 100%, 40%);">+        0x62, 0x00, 0x6c, 0x00, 0x6f, 0x00, 0x63, 0x00, 0x6b]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    return i</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def UpdateGPTHeader(options, GPTBlobBuffer):</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    i = options.sector_size</span><br><span style="color: hsl(120, 100%, 40%);">+    # Signature and Revision and HeaderSize i.e. "EFI PART" and 00 00 01 00</span><br><span style="color: hsl(120, 100%, 40%);">+    # and 5C 00 00 00</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 16] = [0x45, 0x46, 0x49, 0x20, 0x50, 0x41, 0x52, 0x54,</span><br><span style="color: hsl(120, 100%, 40%);">+        0x00, 0x00, 0x01, 0x00, 0x5C, 0x00, 0x00, 0x00]</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 16</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # CRC is zeroed out till calculated later</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 4] = [0x00, 0x00, 0x00, 0x00]</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 4</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # Reserved, set to 0</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 4] = [0x00, 0x00, 0x00, 0x00]</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 4</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # Current LBA</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 8] = [0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 8</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # Backup LBA, No Backup Gpt Used</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 8] = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 8</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # First Usuable LBA (qc_sec + bootblock location)</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 8] = [0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 8</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # Last Usuable LBA (qc_sec + bootblock end location)</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i] = options.end_lba & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+1] = (options.end_lba>>8) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+2] = (options.end_lba>>16) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+3] = (options.end_lba>>24) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+4] = (options.end_lba>>32) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+5] = (options.end_lba>>40) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+6] = (options.end_lba>>48) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+7] = (options.end_lba>>56) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 8</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # GUID</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 16] = [0x32,0x1B,0x10,0x98,0xE2,0xBB,0xF2,0x4B,</span><br><span style="color: hsl(120, 100%, 40%);">+        0xA0,0x6E,0x2B,0xB3,0x3D,0x00,0x0C,0x20]</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 16</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # Partition Table Entry LBA</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 8] = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 8</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # Number of Partition Entries</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 4] = [0x01, 0x00, 0x00, 0x00]</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 4</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # Size of One Partition Entry</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i:i + 4] = [0x80, 0x00, 0x00, 0x00]</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 4</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # CRC of Partition Entry</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    PartEntry = GPTBlobBuffer[options.sector_size*2:options.sector_size*2 + 128]</span><br><span style="color: hsl(120, 100%, 40%);">+    CalcEntryCRC = crc32(''.join(struct.pack("B", x) for x in PartEntry))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i] = CalcEntryCRC & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+1] = (CalcEntryCRC>>8) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+2] = (CalcEntryCRC>>16) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+3] = (CalcEntryCRC>>24) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    i += 4</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # CRC of Partition Table Header</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTHeader = GPTBlobBuffer[options.sector_size:options.sector_size + 92]</span><br><span style="color: hsl(120, 100%, 40%);">+    CalcEntryCRC = crc32(''.join(struct.pack("B", x) for x in GPTHeader))</span><br><span style="color: hsl(120, 100%, 40%);">+    i = options.sector_size + 16</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i] = CalcEntryCRC & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+1] = (CalcEntryCRC>>8) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+2] = (CalcEntryCRC>>16) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer[i+3] = (CalcEntryCRC>>24) & 0xFF</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    return i</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def openfile(name, perm):</span><br><span style="color: hsl(120, 100%, 40%);">+    try:</span><br><span style="color: hsl(120, 100%, 40%);">+        f = open(name, perm)</span><br><span style="color: hsl(120, 100%, 40%);">+    except:</span><br><span style="color: hsl(120, 100%, 40%);">+        print("could not open path {0}".format(name))</span><br><span style="color: hsl(120, 100%, 40%);">+        print("Do you have read permissions on the path?")</span><br><span style="color: hsl(120, 100%, 40%);">+        sys.exit(1)</span><br><span style="color: hsl(120, 100%, 40%);">+    return f</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if __name__ == '__main__':</span><br><span style="color: hsl(120, 100%, 40%);">+    usage = 'usage: %prog [OPTIONS] INFILE OUTFILE\n\n' + \</span><br><span style="color: hsl(120, 100%, 40%);">+            'Packages IMAGE in a GPT format.'</span><br><span style="color: hsl(120, 100%, 40%);">+    parser = OptionParser(usage)</span><br><span style="color: hsl(120, 100%, 40%);">+    parser.add_option('-s', type="int", dest='sector_size', default=4096,</span><br><span style="color: hsl(120, 100%, 40%);">+                      help='Sector size in bytes [Default:4096(4KB)]',</span><br><span style="color: hsl(120, 100%, 40%);">+                      metavar='SIZE')</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    (options, args) = parser.parse_args()</span><br><span style="color: hsl(120, 100%, 40%);">+    if len(args) != 2:</span><br><span style="color: hsl(120, 100%, 40%);">+        print("Invalid arguments! Exiting...\n")</span><br><span style="color: hsl(120, 100%, 40%);">+        parser.print_help()</span><br><span style="color: hsl(120, 100%, 40%);">+        sys.exit(1)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    if options.sector_size != 4096 and options.sector_size != 512:</span><br><span style="color: hsl(120, 100%, 40%);">+        print("Invalid Sector Size")</span><br><span style="color: hsl(120, 100%, 40%);">+        sys.exit(1)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    options.inputfile = args[0]</span><br><span style="color: hsl(120, 100%, 40%);">+    options.outputfile = args[1]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    try:</span><br><span style="color: hsl(120, 100%, 40%);">+        statinfo = os.stat(options.inputfile)</span><br><span style="color: hsl(120, 100%, 40%);">+    except OSError as err:</span><br><span style="color: hsl(120, 100%, 40%);">+        print('OS Error: {0}'.format(err))</span><br><span style="color: hsl(120, 100%, 40%);">+        sys.exit(1)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # 3(MBR+GPT+PART_ENTRY) + 1(if the input file size is not perfect division of sector size)</span><br><span style="color: hsl(120, 100%, 40%);">+    options.end_lba = (statinfo.st_size/options.sector_size)+4</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    GPTBlobBuffer = [0] * (options.sector_size*3) #Size of MBR+GPT+PART_ENTRY</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    UpdateMBR(options, GPTBlobBuffer)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    UpdatePartitionEntry(options, GPTBlobBuffer)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    UpdateGPTHeader(options, GPTBlobBuffer)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    fin = openfile(options.inputfile, 'r+')</span><br><span style="color: hsl(120, 100%, 40%);">+    fout = openfile(options.outputfile, 'wb')</span><br><span style="color: hsl(120, 100%, 40%);">+    for b in GPTBlobBuffer:</span><br><span style="color: hsl(120, 100%, 40%);">+        fout.write(struct.pack("B", b))</span><br><span style="color: hsl(120, 100%, 40%);">+    bb_buffer = fin.read(statinfo.st_size)</span><br><span style="color: hsl(120, 100%, 40%);">+    fout.write(bb_buffer)</span><br><span style="color: hsl(120, 100%, 40%);">+    fout.close()</span><br><span style="color: hsl(120, 100%, 40%);">+    fin.close()</span><br><span>diff --git a/util/qualcomm/scripts/cmm/debug_cb_405.cmm b/util/qualcomm/scripts/cmm/debug_cb_405.cmm</span><br><span>old mode 100644</span><br><span>new mode 100755</span><br><span>diff --git a/util/qualcomm/scripts/cmm/debug_cb_845.cmm b/util/qualcomm/scripts/cmm/debug_cb_845.cmm</span><br><span>old mode 100644</span><br><span>new mode 100755</span><br><span>diff --git a/util/qualcomm/scripts/cmm/debug_cb_common.cmm b/util/qualcomm/scripts/cmm/debug_cb_common.cmm</span><br><span>old mode 100644</span><br><span>new mode 100755</span><br><span>diff --git a/util/qualcomm/scripts/cmm/pbl32_to_bootblock64_jump.cmm b/util/qualcomm/scripts/cmm/pbl32_to_bootblock64_jump.cmm</span><br><span>old mode 100644</span><br><span>new mode 100755</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/c/coreboot/+/29973">change 29973</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/c/coreboot/+/29973"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ief4d92214cdc7ec06e90b0c7e73c11b6d6deddb9 </div>
<div style="display:none"> Gerrit-Change-Number: 29973 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: nsekar@codeaurora.org </div>
<div style="display:none"> Gerrit-Reviewer: Julius Werner <jwerner@chromium.org> </div>
<div style="display:none"> Gerrit-Reviewer: Martin Roth <martinroth@google.com> </div>
<div style="display:none"> Gerrit-Reviewer: Patrick Georgi <pgeorgi@google.com> </div>
<div style="display:none"> Gerrit-Reviewer: nsekar@codeaurora.org </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>