mobile: Makronix Mobile Edition, phase 1 (kernel, boot image, flash; hotdogb)
One tree with the desktop: mobile/ is a subtree, userland and pkgsrc are shared, platform differences live in soc/<soc>/soc.conf and devices/<codename>/device.conf. tools/ is POSIX sh; tools/mkbootimg.sh reproduces byte for byte the boot image that boots on the OnePlus 7T. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d41a8c0db1
commit
7d7243cb63
17 files changed
+9604
No files matched your search
@@ -0,0 +1 @@
|
||||
build/
|
||||
@@ -0,0 +1,53 @@
|
||||
# AGENTS.md -- how work happens in mobile/
|
||||
|
||||
Makronix Mobile Edition. Read `GOAL.md` first. The rules of `../AGENTS.md`
|
||||
apply here wherever they make sense for Linux: measurements beat claims, docs
|
||||
before code, changes to imported sources only as patches.
|
||||
|
||||
## One tree
|
||||
|
||||
`mobile/` is a subtree of the `makronix` repository. Userland sources
|
||||
(pkgsrc, the `makronix` set, patches, `PINS`) are shared with the desktop and
|
||||
live once, at the root; `mobile/` does not copy or fork them. Where the
|
||||
phone differs from the PC, the difference is a variable or an entry in
|
||||
`soc.conf` / `device.conf`, never a second copy of a file. If `mobile/` needs
|
||||
a change in shared code, make it in the shared place and let the PC build prove
|
||||
it still works.
|
||||
|
||||
## The device is the unit
|
||||
|
||||
The phone in your hand decides which tree and which sequence is right. **Check
|
||||
`DEVICE_NAME` before you build or flash.** On 2026-11-07 an image built for the
|
||||
OnePlus 7T Pro (a different panel, a different init sequence) garbled the
|
||||
display of a 7T. hotdogb is the 7T; hotdog is the 7T Pro and is not supported
|
||||
here.
|
||||
|
||||
## Layout
|
||||
|
||||
soc/<soc>/soc.conf what every phone with this SoC shares
|
||||
devices/<codename>/ one phone: device.conf, kernel.config, cmdline, dtb
|
||||
tools/ POSIX sh; lib.sh loads soc.conf then device.conf
|
||||
docs/ PORTING.md (new phone), BOOT.md (boot chain)
|
||||
base/ pkgsrc/ patches/ later phases; empty now
|
||||
build/ output, ignored
|
||||
|
||||
## Rules
|
||||
|
||||
- No tool knows a device by name. A new phone is a new `devices/<codename>/`
|
||||
and, for a new SoC, a `soc/<soc>/soc.conf`. If you reach for an `if` on a
|
||||
device name in a tool, the setting belongs in a `.conf` instead.
|
||||
- `tools/` is POSIX `sh`. No Python, no bashisms, no prebuilt binaries that
|
||||
need a foreign libc.
|
||||
- Pins (`DTB_SHA256_PREFIX`, `INITRAMFS_SHA256_PREFIX`) make a build
|
||||
reproducible; `make check` enforces them. Change a pin only together with
|
||||
the measurement that justifies it.
|
||||
- Flashing: the test slot first. The fallback slot holds the last image known
|
||||
to boot and is written only with `FORCE_FALLBACK=1`, on purpose.
|
||||
|
||||
## Where the kernel lives (today)
|
||||
|
||||
`KERNEL_TREE` defaults to `~/src/nura/sm8150-linux` (7.0). That is the tree
|
||||
the running kernel comes from; the DTB is pinned as a binary because its
|
||||
source sits in the 6.17 tree (`~/src/sm8150-617`, branch `hotdogb-dts`).
|
||||
Moving both into one place, as a patch series over a pinned upstream, is the
|
||||
next change to this layout.
|
||||
@@ -0,0 +1,42 @@
|
||||
# GOAL.md -- was Makronix Mobile Edition ist
|
||||
|
||||
Definiert von Konrad, aufgeschrieben am 2026-11-07. Dieses Dokument beschreibt
|
||||
das Ziel, nicht den Weg.
|
||||
|
||||
## Was es ist
|
||||
|
||||
Makronix für Telefone. Derselbe Gedanke wie `~/src/makronix` -- ein eigenes,
|
||||
stark opinionated Gesamtsystem, bei dem alles zusammengehört --, aber mit einem
|
||||
Linux-Unterbau für Telefone statt NetBSD. NetBSD ist der Unterbau für richtige
|
||||
Computer, Linux ist der Unterbau für Telefone.
|
||||
|
||||
- **Unterbau:** Linux, ein vendored Hard Fork von pmOS (pmaports), von uns
|
||||
gepflegt und umbenannt. libc ist offen (Alpine/musl oder glibc), der
|
||||
Versuch in Phase 2/3 entscheidet. glibc ist ausdrücklich erlaubt.
|
||||
- **Userland:** pkgsrc, wie bei Makronix, im Set `makronix` unter `/usr/pkg`.
|
||||
Es ist **dasselbe Userland und dieselben Quellen** wie beim Desktop: ein
|
||||
Baum, ein pkgsrc-Pin (`../PINS`), kein zweiter Zweig. `mobile/` ist ein
|
||||
Teilbaum des Repos `makronix`. Was plattformspezifisch ist, wird über eine
|
||||
Variable oder die `device.conf` unterschieden, nicht durch eine Kopie.
|
||||
- **Desktop:** CDE als Standard, später touchtauglich gemacht.
|
||||
- **Geräte:** zuerst OnePlus 7T (hotdogb). Weitere Telefone folgen; die
|
||||
Struktur ist darauf gebaut (`docs/PORTING.md`).
|
||||
|
||||
## Reihenfolge
|
||||
|
||||
1. Baum und reproduzierbarer Build: Kernel, Boot-Image, Flash (fertig für hotdogb).
|
||||
2. Base-Fork: pmaports vendoren, offline baubar.
|
||||
3. pkgsrc auf dem Telefon, das Set `makronix`.
|
||||
4. CDE als Standard-Session.
|
||||
5. Touch.
|
||||
6. Restliche Hardware (Audio, Modem, WLAN, Akku), weitere Geräte.
|
||||
|
||||
Eine zweite, lange Spur: NetBSD direkt auf dem Telefon (Treiber neu schreiben,
|
||||
nicht aus Linux kopieren: GPL gegen BSD). Sie blockiert die Linux-Spur nicht;
|
||||
die Basis ist austauschbar angelegt.
|
||||
|
||||
## Wann Phase 1 fertig ist
|
||||
|
||||
`make bootimg DEVICE=<d>` baut aus den gepinnten Eingaben ein Image, und
|
||||
`make flash` bringt es auf den Test-Slot, ohne dass jemand Handarbeit macht.
|
||||
Für hotdogb gilt das (Image byte-identisch mit dem Baseline, das bootet).
|
||||
@@ -0,0 +1,35 @@
|
||||
# Makronix Mobile -- kernel, boot image, flash, for any device under devices/.
|
||||
#
|
||||
# make devices list the supported phones
|
||||
# make kernel DEVICE=hotdogb build the kernel Image
|
||||
# make bootimg DEVICE=hotdogb pack build/boot_<device>.img
|
||||
# make flash DEVICE=hotdogb flash it to the test slot (phone in fastboot)
|
||||
|
||||
DEVICE ?= hotdogb
|
||||
KERNEL_TREE ?= $(HOME)/src/nura/sm8150-linux
|
||||
INITRAMFS ?= $(HOME)/.local/var/pmbootstrap/chroot_rootfs_oneplus-hotdogb/boot/initramfs
|
||||
SLOT ?=
|
||||
|
||||
DEV = devices/$(DEVICE)
|
||||
IMG = build/boot_$(DEVICE).img
|
||||
IMAGE = $(KERNEL_TREE)/arch/arm64/boot/Image
|
||||
|
||||
.PHONY: devices kernel bootimg flash check
|
||||
devices:
|
||||
@for d in devices/*/; do \
|
||||
n=$$(basename $$d); \
|
||||
printf '%-12s %s\n' $$n "$$(sed -n 's/^DEVICE_NAME=//p' $$d/device.conf | tr -d '"')"; \
|
||||
done
|
||||
|
||||
kernel:
|
||||
sh tools/build-kernel.sh $(DEV) $(KERNEL_TREE)
|
||||
|
||||
check:
|
||||
sh tools/check.sh $(DEV) $(INITRAMFS)
|
||||
|
||||
bootimg: check
|
||||
@mkdir -p build
|
||||
sh tools/mkbootimg.sh $(DEV) $(IMAGE) $(INITRAMFS) $(IMG)
|
||||
|
||||
flash: bootimg
|
||||
sh tools/flash.sh $(DEV) $(IMG) $(SLOT)
|
||||
@@ -0,0 +1,13 @@
|
||||
# devices/hotdogb
|
||||
|
||||
OnePlus 7T. NOT the 7T Pro (hotdog): the 7T Pro has a 1440x3120 panel and a
|
||||
different init sequence; its sequence garbles this phone's display
|
||||
(measured 2026-11-07).
|
||||
|
||||
- `kernel.config` -- the config of the kernel that runs on the phone
|
||||
(7.0.0-sm8150, display working, ADSP off).
|
||||
- `cmdline` -- the baseline command line.
|
||||
- `sm8150-oneplus-hotdogb.dtb` -- the DTB of the flashed baseline, pinned by
|
||||
`DTB_SHA256_PREFIX`. Built from branch `hotdogb-dts` of
|
||||
~/src/sm8150-617 (6.17 dts includes). TODO: move the DTS source here.
|
||||
- Boot chain: slot b holds the known-good image. Test on slot a only.
|
||||
@@ -0,0 +1 @@
|
||||
clk_ignore_unused iommu.passthrough=0 arm-smmu.disable_bypass=0 console=ttyGS0,115200 keep_bootcon no_console_suspend printk.devkmsg=on loglevel=8 ignore_loglevel fbcon=map:0 fbcon=font:TER16x32 fbcon=vc:1-1 printk.time=1 panic=0 consoleblank=0 pmos_boot_uuid=edd3187a-72d3-41c3-b751-7aac22b7cd14 pmos_root_uuid=96ce9790-9f31-444a-a59a-d21e2877c535 pmos_rootfsopts=defaults
|
||||
@@ -0,0 +1,16 @@
|
||||
# hotdogb -- OnePlus 7T (SM8150, 1080x2400 Samsung SOFEF03F, DSC command mode)
|
||||
# POSIX sh fragment. Paths are relative to this directory. SoC defaults come
|
||||
# from soc/$SOC/soc.conf (tools/lib.sh); anything set here wins.
|
||||
SOC=sm8150
|
||||
DEVICE_NAME="OnePlus 7T"
|
||||
|
||||
KERNEL_CONFIG=kernel.config
|
||||
CMDLINE=cmdline
|
||||
DTB=sm8150-oneplus-hotdogb.dtb
|
||||
|
||||
# pinned inputs of the baseline that boots on the phone (make check)
|
||||
DTB_SHA256_PREFIX=915e91eb7e2b1d3b
|
||||
INITRAMFS_SHA256_PREFIX=7dac53b05ffeec5d
|
||||
|
||||
# the stock bootloader wants a partition-sized image
|
||||
BOOT_PAD=100663296
|
||||
File diff suppressed because it is too large.
Load diff
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
# Boot chain (hotdogb)
|
||||
|
||||
- Bootloader: OnePlus ABL. Takes `boot_a`/`boot_b` (A/B), Android boot image
|
||||
header v2, kernel as `Image` (uncompressed), separate DTB at 0x01f00000.
|
||||
- The image is padded to 100663296 bytes (96 MiB), the size of the baseline.
|
||||
- `head.S` of the kernel carries the non-EFI image header the stock chain
|
||||
accepts (branch, zero word, offset 0x80000).
|
||||
- Display: the ABL leaves a lit panel and a framebuffer at 0x9c000000. The
|
||||
panel driver must **hand off** (not reset the panel) and use the 7T
|
||||
SOFEF03F sequence; the 7T Pro driver garbles this phone. A good boot logs:
|
||||
|
||||
handoff: reset_gpio=0 power_mode=0x9c ... compression_mode=0x00
|
||||
handoff: compression enable sent, err 0
|
||||
|
||||
- Access on a running system: USB network 172.16.42.1, ssh with a key; to get
|
||||
to fastboot, `reboot bootloader` leaves the display garbled, and fastboot may
|
||||
need Power 15 s, then Power + Vol Up + Vol Down.
|
||||
|
||||
## Verification
|
||||
|
||||
`tools/mkbootimg.sh` was compared with `cmp` against the image that booted on
|
||||
the phone on 2026-11-07 (kernel 7.0.0-sm8150-g2509837001fc-dirty, baseline
|
||||
DTB, pmOS initramfs): identical, 100663296 bytes.
|
||||
@@ -0,0 +1,30 @@
|
||||
# Adding a phone
|
||||
|
||||
Nothing in `tools/` changes. You add data.
|
||||
|
||||
1. **SoC.** If `soc/<soc>/soc.conf` exists, use it. If not, copy
|
||||
`soc/sm8150/soc.conf` and set `ARCH`, `CROSS_COMPILE`, `KERNEL_IMAGE`, the
|
||||
boot image addresses and header version, `FASTBOOT_PRODUCT` and the slot
|
||||
names. The boot image addresses are in the stock boot image
|
||||
(`unpackbootimg`); do not guess them.
|
||||
2. **Device directory** `devices/<codename>/` with
|
||||
- `device.conf` -- `SOC`, `DEVICE_NAME`, `KERNEL_CONFIG`, `CMDLINE`, `DTB`;
|
||||
optional pins (`DTB_SHA256_PREFIX`, `INITRAMFS_SHA256_PREFIX`) and
|
||||
`BOOT_PAD` if the bootloader wants a partition-sized image;
|
||||
- `kernel.config`, `cmdline`, the `.dtb` (its source later);
|
||||
- `AGENTS.md` -- what makes this phone different, and what has been
|
||||
measured on it.
|
||||
3. **Check it is the right phone.** Read `fastboot getvar product` and the
|
||||
model string from a running system; put the former in `FASTBOOT_PRODUCT`.
|
||||
Sibling phones (7T and 7T Pro) share a SoC and differ in panel and
|
||||
firmware: name them separately and never share a panel sequence.
|
||||
4. **Build and compare.** `make bootimg DEVICE=<codename>`. If you have the
|
||||
stock boot image, compare the header (`unpackbootimg`) before flashing.
|
||||
5. **First flash** to the test slot only; the fallback slot stays untouched
|
||||
until the new image has booted and been confirmed.
|
||||
6. **Record** what you measured (display, touch, USB, what is off) in the
|
||||
device's `AGENTS.md`.
|
||||
|
||||
Tool limits today: boot header v2 only (`mkbootimg.sh` refuses others),
|
||||
`FLASH_METHOD=fastboot` only. A phone that needs another format adds it to
|
||||
the tool and to this list, once.
|
||||
@@ -0,0 +1,22 @@
|
||||
# sm8150 -- Qualcomm Snapdragon 855/855+ (msmnile). POSIX sh fragment.
|
||||
# Everything here is shared by every phone with this SoC; a device overrides
|
||||
# any of it in its own device.conf. Paths are relative to the device dir.
|
||||
ARCH=arm64
|
||||
CROSS_COMPILE=aarch64-linux-gnu-
|
||||
KERNEL_IMAGE=arch/arm64/boot/Image
|
||||
|
||||
# Android boot image (header v2) as the Qualcomm ABL expects it
|
||||
BOOT_HEADER_VERSION=2
|
||||
BOOT_KERNEL_ADDR=0x00008000
|
||||
BOOT_RAMDISK_ADDR=0x01000000
|
||||
BOOT_SECOND_ADDR=0x00f00000
|
||||
BOOT_TAGS_ADDR=0x00000100
|
||||
BOOT_DTB_ADDR=0x01f00000
|
||||
BOOT_PAGESIZE=4096
|
||||
|
||||
# flashing
|
||||
FLASH_METHOD=fastboot
|
||||
FASTBOOT_PRODUCT=msmnile
|
||||
BOOT_PARTITION_PREFIX=boot_
|
||||
TEST_SLOT=a
|
||||
FALLBACK_SLOT=b
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Build the kernel Image for one device from a kernel tree.
|
||||
#
|
||||
# Usage: build-kernel.sh DEVICEDIR KERNEL_TREE
|
||||
# The device's kernel.config becomes the tree's .config; an up-to-date tree
|
||||
# is not rebuilt. Prints the path of the Image.
|
||||
|
||||
set -eu
|
||||
. "$(dirname "$0")/lib.sh"
|
||||
|
||||
[ $# -eq 2 ] || { echo "usage: $0 DEVICEDIR KERNEL_TREE" >&2; exit 2; }
|
||||
load_device "$1"
|
||||
tree=$2
|
||||
|
||||
cmp -s "$KERNEL_CONFIG" "$tree/.config" || cp "$KERNEL_CONFIG" "$tree/.config"
|
||||
make -C "$tree" ARCH="$ARCH" CROSS_COMPILE="$CROSS_COMPILE" \
|
||||
-j"$(nproc)" olddefconfig "$(basename "$KERNEL_IMAGE")"
|
||||
echo "$tree/$KERNEL_IMAGE"
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Verify the pinned inputs of a device: the DTB and the initramfs must be the
|
||||
# ones the baseline was built from. A device without a pin is not checked.
|
||||
#
|
||||
# Usage: check.sh DEVICEDIR INITRAMFS
|
||||
|
||||
set -eu
|
||||
. "$(dirname "$0")/lib.sh"
|
||||
|
||||
[ $# -eq 2 ] || { echo "usage: $0 DEVICEDIR INITRAMFS" >&2; exit 2; }
|
||||
load_device "$1"
|
||||
initramfs=$2
|
||||
|
||||
pin() { # pin NAME FILE EXPECTED
|
||||
[ -n "$3" ] || return 0
|
||||
_got=$(sha256sum "$2" | cut -c1-16)
|
||||
[ "$_got" = "$3" ] || die "$1 is $_got, pinned $3 ($2)"
|
||||
}
|
||||
|
||||
pin dtb "$DTB" "${DTB_SHA256_PREFIX:-}"
|
||||
pin initramfs "$initramfs" "${INITRAMFS_SHA256_PREFIX:-}"
|
||||
echo "pins ok"
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Flash a boot image to a phone in fastboot. The test slot (TEST_SLOT, a) is
|
||||
# the default; the fallback slot holds the known-good image and is written
|
||||
# only with FORCE_FALLBACK=1. The device must report FASTBOOT_PRODUCT.
|
||||
#
|
||||
# Usage: flash.sh DEVICEDIR IMAGE [SLOT]
|
||||
|
||||
set -eu
|
||||
. "$(dirname "$0")/lib.sh"
|
||||
|
||||
[ $# -ge 2 ] || { echo "usage: $0 DEVICEDIR IMAGE [SLOT]" >&2; exit 2; }
|
||||
load_device "$1"
|
||||
img=$2 slot=${3:-$TEST_SLOT}
|
||||
|
||||
[ "$FLASH_METHOD" = fastboot ] || die "flash method $FLASH_METHOD not implemented"
|
||||
[ "$slot" != "$FALLBACK_SLOT" ] || [ "${FORCE_FALLBACK:-0}" = 1 ] ||
|
||||
die "slot $slot is the fallback; set FORCE_FALLBACK=1 to overwrite it"
|
||||
[ -n "$(fastboot devices)" ] || die "no device in fastboot"
|
||||
prod=$(fastboot getvar product 2>&1 | sed -n 's/^product: *//p')
|
||||
[ "$prod" = "$FASTBOOT_PRODUCT" ] ||
|
||||
die "product is '$prod', expected '$FASTBOOT_PRODUCT'"
|
||||
|
||||
fastboot flash "$BOOT_PARTITION_PREFIX$slot" "$img"
|
||||
fastboot set_active "$slot"
|
||||
fastboot reboot
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Shared by the tools: load a device's configuration.
|
||||
#
|
||||
# . "$(dirname "$0")/lib.sh"
|
||||
# load_device devices/hotdogb
|
||||
#
|
||||
# The device's SOC (set in its device.conf) names soc/<SOC>/soc.conf, which is
|
||||
# read first; the device.conf is read second and overrides it. Afterwards:
|
||||
#
|
||||
# DEVDIR the device directory
|
||||
# DTB, CMDLINE, KERNEL_CONFIG ... made absolute
|
||||
# everything else as set in the two files
|
||||
#
|
||||
# Adding a phone is adding devices/<codename>/ (docs/PORTING.md); no tool
|
||||
# changes.
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||
|
||||
load_device() {
|
||||
DEVDIR=$(cd "$1" && pwd) || { echo "no such device dir: $1" >&2; exit 2; }
|
||||
[ -f "$DEVDIR/device.conf" ] || { echo "$DEVDIR: no device.conf" >&2; exit 2; }
|
||||
|
||||
SOC=$(sed -n 's/^SOC=//p' "$DEVDIR/device.conf" | head -n 1)
|
||||
[ -n "$SOC" ] || { echo "$DEVDIR/device.conf: SOC not set" >&2; exit 2; }
|
||||
[ -f "$ROOT/soc/$SOC/soc.conf" ] || { echo "no soc/$SOC/soc.conf" >&2; exit 2; }
|
||||
|
||||
. "$ROOT/soc/$SOC/soc.conf"
|
||||
. "$DEVDIR/device.conf"
|
||||
|
||||
for _v in DTB CMDLINE KERNEL_CONFIG; do
|
||||
eval "_p=\${$_v:-}"
|
||||
[ -z "$_p" ] || eval "$_v=\$DEVDIR/\$_p"
|
||||
done
|
||||
}
|
||||
|
||||
die() {
|
||||
echo "$0: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
Executable
+103
@@ -0,0 +1,103 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Pack an Android boot image, header version 2, in POSIX sh.
|
||||
#
|
||||
# No mkbootimg binary: the one pmbootstrap ships is musl-linked and does not
|
||||
# run on the host, and tools/ is POSIX sh (AGENTS.md). The header layout is
|
||||
# AOSP's boot_img_hdr_v2; the id field is a SHA-1 over kernel, ramdisk, second,
|
||||
# recovery dtbo and dtb as AOSP's mkbootimg computes it. For hotdogb the
|
||||
# result is byte for byte the image that boots on the phone (docs/BOOT.md).
|
||||
#
|
||||
# Usage: mkbootimg.sh DEVICEDIR KERNEL INITRAMFS OUT
|
||||
|
||||
set -eu
|
||||
. "$(dirname "$0")/lib.sh"
|
||||
|
||||
[ $# -eq 4 ] || { echo "usage: $0 DEVICEDIR KERNEL INITRAMFS OUT" >&2; exit 2; }
|
||||
load_device "$1"
|
||||
kernel=$2 ramdisk=$3 out=$4
|
||||
|
||||
[ "$BOOT_HEADER_VERSION" = 2 ] || die "only boot header v2 is implemented, device wants $BOOT_HEADER_VERSION"
|
||||
dtb=$DTB
|
||||
cmdline=$(cat "$CMDLINE")
|
||||
|
||||
[ ${#cmdline} -lt 512 ] || die "cmdline too long"
|
||||
|
||||
# le VALUE BYTES: little-endian integer on stdout
|
||||
le() {
|
||||
_v=$(($1)) _n=$2
|
||||
while [ "$_n" -gt 0 ]; do
|
||||
printf "\\$(printf %03o $((_v & 255)))"
|
||||
_v=$((_v >> 8))
|
||||
_n=$((_n - 1))
|
||||
done
|
||||
}
|
||||
|
||||
# zeros N: N NUL bytes on stdout
|
||||
zeros() {
|
||||
[ "$1" -le 0 ] || head -c "$1" /dev/zero
|
||||
}
|
||||
|
||||
size() {
|
||||
wc -c < "$1" | tr -d ' '
|
||||
}
|
||||
|
||||
ksz=$(size "$kernel") rsz=$(size "$ramdisk") dsz=$(size "$dtb")
|
||||
|
||||
# hex SHA-1 of the AOSP id input
|
||||
idsum() {
|
||||
{
|
||||
cat "$kernel"; le "$ksz" 4
|
||||
cat "$ramdisk"; le "$rsz" 4
|
||||
le 0 4 # second
|
||||
le 0 4 # recovery dtbo
|
||||
le "$dsz" 4; cat "$dtb"
|
||||
} | sha1sum | cut -d' ' -f1
|
||||
}
|
||||
|
||||
hex2bin() {
|
||||
_h=$1
|
||||
while [ -n "$_h" ]; do
|
||||
printf "\\$(printf %03o 0x$(printf %s "$_h" | cut -c1-2))"
|
||||
_h=$(printf %s "$_h" | cut -c3-)
|
||||
done
|
||||
}
|
||||
|
||||
tmp=$out.tmp
|
||||
{
|
||||
printf 'ANDROID!'
|
||||
le "$ksz" 4; le "$BOOT_KERNEL_ADDR" 4
|
||||
le "$rsz" 4; le "$BOOT_RAMDISK_ADDR" 4
|
||||
le 0 4; le "$BOOT_SECOND_ADDR" 4
|
||||
le "$BOOT_TAGS_ADDR" 4
|
||||
le "$BOOT_PAGESIZE" 4
|
||||
le 2 4 # header_version
|
||||
le 0 4 # os_version
|
||||
zeros 16 # name
|
||||
printf '%s' "$cmdline"; zeros $((512 - ${#cmdline}))
|
||||
hex2bin "$(idsum)"; zeros 12 # id: 20 bytes of SHA-1, padded to 32
|
||||
zeros 1024 # extra_cmdline
|
||||
le 0 4; le 0 8 # recovery dtbo size, offset
|
||||
le 1660 4 # header_size
|
||||
le "$dsz" 4; le "$BOOT_DTB_ADDR" 8
|
||||
} > "$tmp"
|
||||
|
||||
# the header occupies exactly one page
|
||||
hs=$(size "$tmp")
|
||||
zeros $((BOOT_PAGESIZE - hs)) >> "$tmp"
|
||||
|
||||
pad() { # append FILE, padded to a page
|
||||
cat "$1" >> "$tmp"
|
||||
_r=$(( (BOOT_PAGESIZE - $(size "$1") % BOOT_PAGESIZE) % BOOT_PAGESIZE ))
|
||||
zeros "$_r" >> "$tmp"
|
||||
}
|
||||
pad "$kernel"; pad "$ramdisk"; pad "$dtb"
|
||||
|
||||
# partition-sized image, if the device wants one
|
||||
if [ -n "${BOOT_PAD:-}" ]; then
|
||||
cur=$(size "$tmp")
|
||||
[ "$cur" -le "$BOOT_PAD" ] || { rm -f "$tmp"; die "image larger than BOOT_PAD"; }
|
||||
zeros $((BOOT_PAD - cur)) >> "$tmp"
|
||||
fi
|
||||
mv "$tmp" "$out"
|
||||
echo "$out: $(size "$out") bytes, kernel $ksz, ramdisk $rsz, dtb $dsz"
|
||||
Reference in new issue
Block a user