Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libbootimg: Fix support of Stock Sony ELF boot images #2

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

AdrianDC
Copy link
Contributor

@AdrianDC AdrianDC commented Jun 5, 2016

  • Unlike all boot images built for CyanogenMod or AOSP based
    ROMs over the last years, the elf bootimages from Stock
    also include additional metadata in the header section
    that is required for the device to power up with its kernel
  • Add a 3900 8bits array at the end of the header,
    followed by the 16 chars of the added bootimage name,
    in order to match the Sony ELF 4096 first block
    and therefore save the additional data from Stock images
  • Regular Sony ELF images have about 1200-1600 chars there
    so filling the 4096 block is more than enough for this,
    and moving the bootimage name at the end makes things safer

Change-Id: Ic2b619b6f5e862920dcfefa5b86b016987305d4a
Signed-off-by: AdrianDC [email protected]

@AdrianDC
Copy link
Contributor Author

AdrianDC commented Jun 5, 2016

Tested on both Primary and Secondary Stock 4.3 based installations.
Stock kernel now injected properly, simple update giving the same binary result.

@AdrianDC
Copy link
Contributor Author

Confirmed working fine for Huashan ELF stock bootimages.

@AdrianDC
Copy link
Contributor Author

Up

@AdrianDC
Copy link
Contributor Author

Updated with support for the newer Sony ELF boot images.

  • Tested on the original ELF 8960 devices : SP / T / TX / V
  • Tested on the newer ELF 8974 devices : Z2
  • Tested on regular bootimage devices : X Performance
  • Other device under test
  • Also compatible with No-Kexec V4.1 changes to the boot name

AdrianDC and others added 6 commits October 5, 2017 17:33
 * Unlike all boot images built for CyanogenMod or AOSP based
    ROMs over the last years, the elf bootimages from Stock
    also include additional metadata in the header section
    that is required for the device to power up with its kernel

 * Add a 3900 8bits array at the end of the header,
    followed by the 16 chars of the added bootimage name,
    in order to match the Sony ELF 4096 first block
    and therefore save the additional data from Stock images

 * Regular Sony ELF images have about 1200-1600 chars there
    so filling the 4096 block is more than enough for this,
    and moving the bootimage name at the end makes things safer

Change-Id: Ic2b619b6f5e862920dcfefa5b86b016987305d4a
Signed-off-by: AdrianDC <[email protected]>
 The boot image found in sony firmwares (stock) is different to the already
  implemented version. This change adds support for these images (found in
  the Z2) by introducing more flexibility in the ELF handling
  and the output format (ELF --> ANDROID!)

 In particular:

 - Use a more dynamic structure to describe elf files:
    Add handling information (e.g., the elf version) and separate structures
    for the ELF header, the program headers, and the section headers
 - Adjust the read/load operations to account for the new structure
 - Add handling code for the differentiation between the two known ELF versions
 - Adjust the writing code such that it can output the content of an ELF
    image as a standard ANDROID! image:
    The newer ELF versions are not booted if a single (unused) bit is modifed
    Possibly the (unlocked) bootloader performs a signature check only for
    ELF files
 - Add some debug code that allows to print either to stdout or the kernel
    log (useful for on-device debugging)
 - Extend the Sony Stock support in a dynamic way
 - Add dependencies for klog_write
 - Also fix all minor warnings

 The code has been tested with the boot image of an Xperia Z2,
  and on the devices from the original ELF implementation (SP)

Change-Id: I0e9a41ae6ce26bf4608ef86cec1e2735f746abb6
Signed-off-by: Alexander Diewald <[email protected]>
Signed-off-by: Adrian DC <[email protected]>
 * Used for debugging in the first place
 * Call libbootimg_get_elf_version earlier for outputs

Change-Id: Id16fa289957b168c3fb6b578a8a83a0a6ddd88c5
Signed-off-by: Adrian DC <[email protected]>
 * Kept as reference to easily compare alternative headers

Change-Id: I25b62f898acb192c0b9ac7df5489839e0525b1d4
Signed-off-by: Adrian DC <[email protected]>
 * Additional errors / success outputs
 * Display sizes in decimals instead of hexadecimal
 * Rewrite the ELF headers details outputs
 * Cleanup code styles

Change-Id: I3b4e2277474497d8d8d97056562457df88a20779
Signed-off-by: Adrian DC <[email protected]>
 * Usage of the second (rpm) should only be on 8960
 * Usage of the DTB data added for v2 (8974)
 * The ELF format should not have blank padding added

Change-Id: I66926b91b173563e767a76cb9bf332e4e6e0a9fa
Signed-off-by: Adrian DC <[email protected]>
@AdrianDC AdrianDC force-pushed the master branch 2 times, most recently from f68b50d to 7b92072 Compare October 5, 2017 16:45
 * Store the initial 8 bytes of metadata that used to be ignored
    with an offset in order to rebuild the ELF original structure

 * Store the additional signature stored after the cmdline
    inside the section data on Sony ELF v2 bootimages

Change-Id: I4324c88431c4d265d7e5c61f1491b6b1bfffb242
Signed-off-by: Adrian DC <[email protected]>
 * Compatibility for the ELF partition used on the
    msm8996 devices like the Xperia X Performance

 * Structures aligned with 64bits addresses,
    offsets and sizes to match Stock bootimage

 * Usage of "__attribute__((packed))" to avoid
    structures padding breakage

 * Add the VER_ELF_4 identifier
 * Properly convert 32bits -> 64bits and reverse
 * Use the 64bits structures as main data
 * Add the libbootimg_load_elf_header function
    to separate the ELF header handling

Change-Id: I40559ecc32833aed7b3ca7f3ebf8d53b9bc9b471
Signed-off-by: Adrian DC <[email protected]>
 * Allows seeing hidden chars as hexadecimal values

Change-Id: Ie35813f75d59596d484f9aab0bc659dcf3ea8ffe
@AdrianDC
Copy link
Contributor Author

AdrianDC commented Oct 5, 2017

Up. Used globally on Sony and non-Sony devices since 2016.

@cryptomilk
Copy link
Contributor

You should fix the build.

include/libbootimg.h

The #include <cutils/klog.h> obviously needs #ifdef DEBUG_KMSG protection!

@AdrianDC AdrianDC force-pushed the master branch 2 times, most recently from 6ca06c8 to 056a34a Compare December 25, 2017 21:59
 * A new situation on the Sony X Performance has shown
    that the "Processor" field from cpuinfo can be missing,
    therefore breaking the 32 / 64bits detection

 * Instead, use the native uname handling to get the name of
    the host machine, allowing to detect aarch64/armv8 properly

Change-Id: Ib7f1aa6303390b4cc64e402e7ee242a272ddf722
Signed-off-by: Adrian DC <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants