Jump to content

Samsung Galaxy S9 (samsung-starqltechn): Difference between revisions

From postmarketOS Wiki
Dsankouski (talk | contribs)
Dsankouski (talk | contribs)
Split mainline and u-boot sections. Describe assembling mainline for stock bootloader.
Line 62: Line 62:
== How to enter flash mode ==
== How to enter flash mode ==
== Installation ==
== Installation ==
== Notes ==
== Mainline ==
=== Uart ===
Mainline kernel can be booted with stock bootloader. Logs may be viewed only from pstore(ramoops) You need to assemble android boot image.
=== Assembling boot image ===
* clone mainline sources
* build kernel. See also [[Compiling_kernels_with_envkernel.sh]]
* append dtb to gzipped kernel image
** pushd .output/arch/arm64/boot
** <code>cat Image.gz dts/qcom/sdm845-samsung-starqltechn.dtb > Image.gz-dtb</code>
* generate initramfs image
* make android bootimage <code>mkbootimg --base 0x0 --kernel_offset 0x00008000 --ramdisk_offset 0x02000000 --tags_offset 0x01e00000 --pagesize 4096 --second_offset 0x00f00000 --ramdisk "$INITRAMFS" --kernel Image.gz-dtb -o boot.img</code>
 
=== Boot ===
Flash boot image from twrp to boot partition. Reboot to system. Phone will stay on manufacturer logo. Check logs in pstore. If there's only twrp logs in pstore, try to reboot phone with power+volume down, after rebooting to system from twrp.
 
== U-boot ==
U-boot can be used as a second stage bootloader, and also a tool to experiment with uart on usb.


`/dev/ttyHS8` can be exposed on USB D+D- lines. It's configured in data mover mode by downstream kernel.
Using u-boot as a second stage bootloader involves packing u-boot with it's payload in a single file. That file is used as a payload for stock bootloader.


== Mainline ==
=== Second stage bootloader ===
==== Easy way: Semi-automated boot image generation ====
{{todo|not completed - make this guide work}}
{{todo|not completed - make this guide work}}
Easy automated android boot image generation, intended to be flashed in phone's boot partition. Kernel logs may be only via pstore(ramoops) now. This way is hacky now, because there's no support for u-boot FIT images yet.


==== Building ====
In this section, we'll generate an android boot image with u-boot as second stage bootloader for linux kernel in FIT image format. Kernel logs accessible only via pstore(ramoops) for now.
 
Stock payload file generation is automated, in custom u-boot APKBUILD file. It's a bit hacky, because there's no support for u-boot FIT images yet in postmarketos project, so it's not intended to be upstreamed in aports repo.
Note, that manual generation of stock payload is a bit tricky due to the fact that stock bootloader randomizes linux load address. This means, that u-boot will not know FIT image address in RAM, and should find it in runtime.
 
==== Building: generate android boot image ====
* setup pmbootstrap with [https://gitlab.com/dsankouski/pmaports/-/tree/device/samsung-starqltechn-mainline-semi-automated-boot-img custom aports]
* setup pmbootstrap with [https://gitlab.com/dsankouski/pmaports/-/tree/device/samsung-starqltechn-mainline-semi-automated-boot-img custom aports]
* go through setup dialog, setup pmbootstrap to use custom aports, and build for starqltechn:
* go through setup dialog, setup pmbootstrap to use custom aports, and build for starqltechn:
Line 86: Line 103:
[18:07:06] Device codename [starqltechn]:
[18:07:06] Device codename [starqltechn]:
</code>
</code>
* run <code>pmbootstrap build device-samsung-starqltechn</code>
This will build mainline linux kernel, and device package
* run <code>pmbootstrap build u-boot-starqltechn</code>
* run <code>pmbootstrap build u-boot-starqltechn</code>
First, it will build u-boot, mainline linux kernel fork, and concatenate it in vmlinuz file, which is used later as a payload to generate android boot image.
It will install device package with linux kernel, build u-boot, and concatenate u-boot with kernel in one file, which is used later as a payload for stock bootloader. Add <code>--force</code> flag if you want to rebuild it.
* run <code>pmbootstrap chroot -b</code> - this chroots to buildroot
* run <code>pmbootstrap chroot -b</code> - this chroots to buildroot
* run <code>cd /home/pmos/build/pkg/u-boot-postmarketos-starqltechn/</code>
* run <code>cd /home/pmos/build/pkg/u-boot-postmarketos-starqltechn/</code>
Line 97: Line 116:
{{todo|getting kernel logs(should be in /sys/fs/pstore folder), modifying initramfs}}
{{todo|getting kernel logs(should be in /sys/fs/pstore folder), modifying initramfs}}


=== Hard way: Manual procedure with usb-uart cable ===
=== Experimenting: procedure with usb-uart cable ===
This intendent for getting uart console at u-boot stage, with ability to load and boot kernel to RAM via uart. Initramfs console in possible.
This intendent for getting uart console at u-boot stage, with ability to load and boot kernel to RAM via uart. Initramfs console in possible.
This way also allows you to use phone as daily driver during development, since storage is not touched
This way also allows you to use phone as daily driver during development, since storage is not touched
Line 131: Line 150:


{{todo|how to setup initramfs console}}
{{todo|how to setup initramfs console}}
== Notes ==
=== Uart ===
`/dev/ttyHS8` can be exposed on USB D+D- lines. It's configured in data mover mode by downstream kernel.
=== Getting logs from pstore ===
Boot to twrp, and check <code>/sys/fs/pstore</code> folder


== See also ==
== See also ==

Revision as of 12:17, 26 December 2021

Samsung Galaxy S9 (SM-G9600/
DS)
Manufacturer Samsung
Name Galaxy S9 (SM-G9600/
DS)
Codename samsung-starqltechn
Released 2018
Hardware
Chipset Qualcomm SDM845 Snapdragon 845
CPU Octa-core (4x 2.8 GHz Kryo 385 Gold & 4x 1.7 GHz Kryo 385 Silver)
GPU Adreno 630
Display 5.8 inch 18.5:9, 2960 x 1440 pixel 568 PPI, capacitive touchscreen, 10 multi-touch points, Super AMOLED, Corning Gorilla Glass 5, glossy: yes
Storage 64 GB
Memory 4 GB
Architecture aarch64
Software
Original software Android 8 - 10
postmarketOS
Category testing
Pre-built images no
Mainline no
Features
Flashing
Broken
USB Networking
Works
Internal storage
No data
SD card
No data
Battery
No data
Screen
Broken
Touchscreen
No data
Multimedia
3D Acceleration
No data
Audio
No data
Camera
No data
Camera Flash
No data
Connectivity
WiFi
Broken
Bluetooth
No data
GPS
No data
NFC
No data
Modem
Calls
No data
SMS
No data
Mobile data
No data
Miscellaneous
FDE
No data
USB OTG
No data
HDMI/DP
No data
Sensors
Accelerometer
No data
Magnetometer
No data
Ambient Light
No data
Proximity
No data
Hall Effect
No data
Haptics
No data
Barometer
No data


Contributors

  • dsankouski

Maintainer(s)

Users owning this device


How to enter flash mode

Installation

Mainline

Mainline kernel can be booted with stock bootloader. Logs may be viewed only from pstore(ramoops) You need to assemble android boot image.

Assembling boot image

  • clone mainline sources
  • build kernel. See also Compiling_kernels_with_envkernel.sh
  • append dtb to gzipped kernel image
    • pushd .output/arch/arm64/boot
    • cat Image.gz dts/qcom/sdm845-samsung-starqltechn.dtb > Image.gz-dtb
  • generate initramfs image
  • make android bootimage mkbootimg --base 0x0 --kernel_offset 0x00008000 --ramdisk_offset 0x02000000 --tags_offset 0x01e00000 --pagesize 4096 --second_offset 0x00f00000 --ramdisk "$INITRAMFS" --kernel Image.gz-dtb -o boot.img

Boot

Flash boot image from twrp to boot partition. Reboot to system. Phone will stay on manufacturer logo. Check logs in pstore. If there's only twrp logs in pstore, try to reboot phone with power+volume down, after rebooting to system from twrp.

U-boot

U-boot can be used as a second stage bootloader, and also a tool to experiment with uart on usb.

Using u-boot as a second stage bootloader involves packing u-boot with it's payload in a single file. That file is used as a payload for stock bootloader.

Second stage bootloader

TODO TODO: not completed - make this guide work

In this section, we'll generate an android boot image with u-boot as second stage bootloader for linux kernel in FIT image format. Kernel logs accessible only via pstore(ramoops) for now.

Stock payload file generation is automated, in custom u-boot APKBUILD file. It's a bit hacky, because there's no support for u-boot FIT images yet in postmarketos project, so it's not intended to be upstreamed in aports repo. Note, that manual generation of stock payload is a bit tricky due to the fact that stock bootloader randomizes linux load address. This means, that u-boot will not know FIT image address in RAM, and should find it in runtime.

Building: generate android boot image

  • setup pmbootstrap with custom aports
  • go through setup dialog, setup pmbootstrap to use custom aports, and build for starqltechn:

[18:07:04] Work path [/home/dzmitry/.local/var/pmbootstrap]:

[18:07:05] NOTE: pmaports path: <path to custom pmaports>

[18:07:05] Channel [edge]:

[18:07:06] Vendor [samsung]:

[18:07:06] Device codename [starqltechn]:

  • run pmbootstrap build device-samsung-starqltechn

This will build mainline linux kernel, and device package

  • run pmbootstrap build u-boot-starqltechn

It will install device package with linux kernel, build u-boot, and concatenate u-boot with kernel in one file, which is used later as a payload for stock bootloader. Add --force flag if you want to rebuild it.

  • run pmbootstrap chroot -b - this chroots to buildroot
  • run cd /home/pmos/build/pkg/u-boot-postmarketos-starqltechn/
  • run cp -avr boot /
  • run mkinitfs
  • exit chroot exit
  • flash android boot image from <pmbootstrap work path. usually ~/.local/var/pmbootstrap>/chroot_buildroot_aarch64/boot/boot.img
TODO TODO: getting kernel logs(should be in /sys/fs/pstore folder), modifying initramfs

Experimenting: procedure with usb-uart cable

This intendent for getting uart console at u-boot stage, with ability to load and boot kernel to RAM via uart. Initramfs console in possible. This way also allows you to use phone as daily driver during development, since storage is not touched

Building

  • build u-boot.bin file. Follow u-boot docs installation section
  • build mainline kernel
    • clone sources
    • source /home/dzmitry/side/pmos/pmbootstrap/helpers/envkernel.sh
    • make defconfig
    • make
  • assemble initramfs
  • TODO TODO: assemble u-boot fit image:

    Installing

    This section is useless for now, because currently there's no way to tell if something is alive, when you boot from the flash. See next section.

    Booting kernel and getting console

    Is performed with kexec-similar stuff for now. See guide for that method. Remember, you should have a cable from in `UART USB-debug cable schematic` section of Samsung_Galaxy_A5_2017_(samsung-a5y17lte)#Notes, and 1.8V compatible uart adapter

    • Download prebuilt twrp image, with kexec and manual muic switching support
    • Boot into twrp
    • Connect uart-usb cable
    • Switch muic uart on usb, and run u-boot.
      • go to Advanced -> Terminal
      • run /exec.sh command. It will switch uart on usb, load u-boot(it's included in twrp image) in RAM, and run it.
      • You are in u-boot console now ;)
    • Load u-boot payload via kermit (you may use my high speed version for linux at 921600bps)
      • in u-boot prompt run loadb 0x90000000
    • in u-boot prompt run bootm 0x90000000 command
    TODO TODO: how to setup initramfs console

    Notes

    Uart

    `/dev/ttyHS8` can be exposed on USB D+D- lines. It's configured in data mover mode by downstream kernel.

    Getting logs from pstore

    Boot to twrp, and check /sys/fs/pstore folder

    See also

    u-boot

    u-boot sdm845 devices docs

    aport fork for SM-G9600

    mainline kernel fork for SM-G9600