Repository navigation
Conversation
The A6 (S5L8950X, iPhone 5) has two Apple Swift ARMv7s cores, the A5's PMGR core control and the same AIC. Add it to the S5L machine: - apple.c: match "apple,s5l8950x". The A5 boards' memblock carve-out under iBoot's scanout (0x9f600000..0x9f6fc000) is skipped on the A6, where that address is ordinary RAM; the A6 boards reserve their scanout in the DT. - headsmp.S: run the Cortex-A9 errata fixups and the SCU tag invalidation only on a Cortex-A9 (MIDR part 0xc09). Swift has an integrated L2 and no A9 SCU, CBAR or diagnostic register. - platsmp.c: look up "apple,s5l8950x-pmgr" first. Its core control registers sit at the A5's offsets (+0x1210 stop, +0x1214 start, +0x1220 run; iOS 8.4.1 AppleS5L8950XPerformanceController). On a core that is not a Cortex-A9, power down by switching the D-cache off and cleaning L1, without the A9's ACTLR.SMP write. The A5 boards run the same code as before. Tested on an iPhone5,2: both cores come up and the USB shell is reached. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
…RM PMU
The A6's Swift cores are Apple's own (MIDR 0x613f0001, implementer
'a') and have no ARM PMU. time_init enabled the Cortex-A9 cycle counter
unconditionally, and its first CP15 c9 write (PMUSERENR) was an
undefined instruction: the iPhone 5 panicked at time 0 ("Attempted to
kill the idle task").
Use the cycle counter, its calibration and the PMU overflow tick only on
a Cortex-A9 (the A5). Other cores get the 24 MHz watchdog counter as
clocksource and sched_clock, and the AIC timer as the tick. The USB SOF
tick no longer reads the cycle counter before its checks.
With this the iPhone 5 boots to /init in 5.4 s.
Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Three differences on the A6 watchdog: - WDT_CUR_TIME only counts while WDT_CTRL bit 3 (enable) is set. If the boot loader left CTRL at 0, set bit 3 without the reset enable, so the counter runs; a watchdog the boot loader armed (0xc) is left alone. The calibration loop is bounded, so a counter that never moves cannot hang the boot. - A reset needs enable and reset enable together (0xc), programmed the way iBEC's wdt_enable() does: CTRL 0, bite time, count, CTRL 0xc, count 0. The restart handler and the reboot notifier do that on the S5L8950X. - The A6 skips the CPU calibration (no cycle counter), which was the only place that mapped the counter, so the clocksource found nothing mapped and the phone ran on jiffies. Map the counter in a helper that both call. The A5 boards keep their sequence. Tested on an iPhone5,2: the watchdog counter is the clocksource, and panic=10 and reboot reset the phone through the watchdog. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
On the iPhone 5 the only clockevent was the AIC timer of CPU0. CPU1 got
the dummy clockevent, and with no broadcast device it never ticked:
with idle=poll RCU stalled on it ("timer wakeup didn't happen"), and
with WFI idle the whole system froze at about 10.8 s, the first time
something waited for a timer on CPU1.
The AIC timer is a per-core register: the 0x2000 window is banked by
the accessing core, like WHOAMI, EVENT/IACK and IPI_SEND, and the timer
fires as a local event (type 7) in that core's EVENT. iOS 10.3.4 on the
N42 does not use it (XNU ticks each core from the Swift generic timer),
but iBoot runs on it, and so does Linux on CPU0.
On the A6, once a secondary core is online (CPUHP_AP_ONLINE_DYN,
interrupts on), arm a 10 ms shot in its banked window, then in its
explicit window (0x5000 + (cpu << 7)), and wait up to 200 ms of AIC
timebase for the event on that core. The first window that fires
becomes the core's oneshot clockevent, rating 400, which replaces the
dummy. A failed test disarms through the core's explicit window only,
so it cannot stop CPU0's tick, and logs FAIL. Per-CPU timer event
counts are in /sys/module/aic1/parameters/timer_events.
There is no offline teardown: going offline, the core's timer stays its
tick device until the tick code lets go of it, and
apple_aic1_secondary_init() quiesces the window before the core comes
back.
The A5 (P105, J1) keeps its PMU tick and CPU0-only AIC timer: the
online state is installed only on "apple,s5l8950x".
Tested on an iPhone5,2: "PASS -- CPU1 has its own clockevent", and a
two-core boot reaches the USB shell with no nohlt or irqaffinity.
Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
aic1_irq_unmask() routes every line to CPU0 (TARGET = BIT(0)) and the chip has no irq_set_affinity, so no device interrupt ever reaches another core. The IRQ core did not know that: /proc/irq/N claimed affinity 0-1, and irqaffinity=0 on the command line only changed what it claimed. Set the affinity and effective affinity of each line to CPU0 when it is mapped, mark it single-target and exclude it from balancing. Routing is unchanged, on the A5 as well; irqaffinity=0 is no longer needed. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The A6 (S5L8950X, iPhone 5) has the A5's OTG and HSIC PHY with other PMGR offsets and tuning values, so it gets its own compatible and no S5L8940X fallback. On the S5L8950X the PHY can also take the PMGR gates of the OTG block (UPERF, USB-OTG, USBREG) as clocks, after the reference clock, and holds them from probe. Allow up to four clocks, named in that order. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The A6's OTG PHY is the A5's, with its PMGR power states at other offsets: UPERF +0x1084, USB-OTG +0x1088, USB-EHCI +0x108c, USB-OHCI0 +0x1094 and USBREG +0x109c. Its tuning differs too: uotgtune1 is 0x749. Move the gate offsets and the tuning values into per-SoC match data and add "apple,s5l8950x-otgphy" (iPhone5,2 iOS 8.4.1 iBEC and ADT). The S5L8940X and S5L8942X entries carry the values the driver used before. Tested on an iPhone5,2: the dwc2 gadget comes up with CDC ACM and networking. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The A6's OTG controller is the A5's dwc2 and runs with the S5L8942X quirks and parameters. Add "apple,s5l8950x-dwc2" in front of the S5L8942X and S5L8940X compatibles, and require the PHY like theirs. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
s5l8950x.dtsi describes the A6 as the iPhone5,2 iOS 8.4.1 (12H321) ADT, iBEC and kernelcache give it: two Swift cores started through PMGR, the AIC, the 24 MHz watchdog counter, PMGR, GPIO (232 pins), UART1-6, the OTG PHY and the dwc2 gadget, and simple-framebuffer over iBoot's 640x1136 scanout. The boot loader fills memory and framebuffer. Every PMGR gate is disabled in the SoC file and enabled by the board next to its consumer. A registered gate that nobody holds is switched off by clk_disable_unused, and iBoot leaves most of them on. When the SoC file registered the CDMA, SPI1, UART1-5 and I2C0-2 gates with no consumer, the N42 booted into clk: Disabling unused clocks phy-apple-s5l-usb 36000000.phy: PHY reference clock selection did not latch udc 36100000.usb: failed to start ...: -5 although no USB gate is among them. A gate that is not registered keeps the state iBoot left. CDMA has no Linux consumer and stays unregistered. s5l8950x-5.dtsi holds what the N41 and N42 share; so far UART6, the debug port. The two boards differ in cellular bands, which Linux does not drive. The N41 is untested. Tested on an iPhone5,2: both cores, the framebuffer console and the USB gadget. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The N42's otgphyctrl is PHY version 4. Besides uotgtune1 = 0x749 and uotgtune2 = 0x2ff3, its ADT node has hsic-tuning-val = 0xa30a3a3, which AppleS5L8930XUSBPhy writes to +0x5c (iPhone5,2 iOS 10.3.4). Add it to the per-SoC data and write it with the other tuning values on a cold start, and on its own when the PHY was left running. HSIC port 4 carries the BCM4334 Wi-Fi. The other SoCs have no HSIC tuning value and write nothing new. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The OTG PHY switched UPERF, USB-OTG and USBREG on with raw PMGR writes
in phy_init, behind the clock framework's back. Describe the three as
PMGR gate clocks in s5l8950x.dtsi (+0x1084, +0x1088, +0x109c; ADT
device-clocks ids 0x04, 0x35, 0x06) and give them to the PHY, which
switches them on at probe in the order the boot loader uses and keeps
them on, the way the H2FMI driver holds its gates. The gadget is the
console and the network, so nothing switches them off again: not a
failed probe, not an unbind, and with the enable count held not
clk_disable_unused either.
The clocks are optional and looked up by name ("uperf", "otg",
"usbreg"). P105, J1 and the other trees name only "ref", get none, and
run the code they ran before; phy_init's register checks stay for them
and are a no-op on the A6 once the gates are held.
The host side's USB-EHCI and USB-OHCI0 gates stay with the host PHY's
power-on and are not clocks, so nothing at late_initcall reaches them
either. When the reference clock selection does not latch, the error
now says what OPHYCLK, OPHYPWR and the three gate registers read.
Tested on an iPhone5,2: the gadget comes up without clk_ignore_unused.
Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The iPhone 5 (N42, ADT "pmu,d1972") has a Dialog D1972 PMU. Move the GPIO count and the power-off register sequence into per-chip data, and add "apple,pmu-d1972", from AppleD1972PMU (iPhone5,2 iOS 10.3.4): - 8-bit register addresses, 12 GPIOs at 0x68 + n; - power off (_shutdownGated): 0x7d = 0, clear 0x01..0x09, wake masks 0x12..0x1a (88 ff ff ff ff ae ff ff ff), alarm control 0x62 = 0x01, 0xa2 = 0, 0xa4 = 0, boot flags 0xb0 &= ~0xd0, clear the wake bit of the input GPIOs (>= 0x60), standby 0x1b |= 0x01. The D1946, D1974, D2333 and Chestnut paths are unchanged. Tested on an iPhone5,2: the PMU probes, and its GPIOs drive the Bluetooth and Wi-Fi power lines. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Move the per-chip charger registers and the current encoding into struct pmu_chg_chip and add "apple,pmu-d1972-charger" for the iPhone 5, from AppleD1972PMUPowerSource (iPhone5,2 iOS 10.3.4): - the USB input current limit is register 0x3f (0x3d on the D1946); - the code is linear, 10 mA per step from 70 mA: (mA - 70) / 10; - VBUS online is status register 0x0a bit 6; a VBUS sag drops 0x3f to 0x03 (100 mA). The battery temperature comes from the HDQ gauge, not a PMU ADC channel, and corrupt gauge words once alternated "battery at 6272.0 C" with good readings. On the D1972 a reading outside -20..+70 C counts as no reading (the existing 100 mA fallback), and leaving the fallback takes three good readings in a row. Entering it on a missing reading is logged once. The D1946 path is unchanged. The driver keeps its armed=0 default: on the iPhone 5 it reports VBUS and the input limit, and logs the limit it would set without writing it. Tested on an iPhone5,2: VBUS online and the 100 mA limit read, no write. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The iPhone 5's D1972 PMU has no WLED strings, unlike the A5's D1946 and the A5X's D1974. Its panel backlight is an external TI LM3534 on I2C0 (0x63), whose brightness comes over the SoC's DWI block (0x3f107000, version 1). Add apple-lm3534, after AppleLMBacklight and AppleS5L8940XDWI (iPhone5,2 iOS 10.3.4): - enable and disable with LM3534 register 0x10 bit 0, keeping the other bits iBoot set, and wait 600 us after enabling; - send 11-bit brightness (0..2047) on the DWI sync channel: +0x14 = 0xa0000000 | level, then +0x10 = 0x71 once busy (bit 0) is clear. Tested on an iPhone5,2: "LM3534 reg 0x10=0x03 (on), DWI v1 attached", and a brightness of 300 is written and read back. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The iPhone 5's backlight needs it. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
…S5L8950X
On the iPhone 5 most bq27540 reads failed ("no answer for 0x14") and
the rest decoded to garbage: 65404 mV (0xff7c), and temperatures of
6272 C and -119 C (0xffab, 0x05ff) that the charger then acted on. The
driver took "the last 8 frames" after a fixed 4.5 ms sleep, never
checked the echo and read 16-bit values without a consistency check, so
a missing or extra frame came through as a valid reading.
Add "apple,s5l8950x-hdq-battery", which runs the transaction the way
the N42 iBEC (12H321) and iOS AppleHDQGasGaugeControl-109.30.4
(_sendBreak, _hdqRead8, hdqRead16) do:
- break: UCON bit 4 held for 200 us and cleared by hand, 40 us, drain;
- a 0 is sent as 0xC0 (not 0xE0), a 1 as 0xFE;
- each echoed frame is read back with a deadline and must equal what
was sent; then 8 gauge frames, where a frame >= 0xF9 is a 1; frames
with a UERSTAT error are dropped like iBEC's uart_getc does;
- 8-bit reads get 4 tries 70 us apart, and 16-bit values are read hi,
lo, hi and taken only when both hi reads agree (10 tries).
A refresh reads into temporaries, rejects values no bq27540 reports
(2500..5000 mV, -40..+90 C, at most 100%, ...), and commits all of them
together. After a failure the bus rests for 5 s and the last good
values are served for up to 30 s, so one bad transaction never reaches
a consumer. Each failure or rejection logs one line with the raw frames
and their UERSTAT bytes.
The A5 boards ("apple,s5l8940x-hdq-battery") keep the original path.
Tested on an iPhone5,2: 100%, 4229 mV, -84 mA, 25.9 C, 1448/1450 mAh
(design 1440), 160 cycles.
Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
… its firmware On the iPad mini the digitizer is booted from userspace: Project Cascadia's z2-boot uploads the mtprops' firmware and calibration through /dev/hx-touch and then hands the chip to this driver. The iPhone 5 has the same iOS driver class, AppleMultitouchN1SPI, so the kernel can run that sequence itself and the panel works with no daemon. When the node has firmware-name, a work item does iOS 8.4.1's bootload: - a reset, then the HBPP check; - the firmware packet, unchanged; - the proximity and panel calibration, from the boot loader's apple,z2-prox-cal-blob and apple,z2-cal-blob properties, or from apple/z2-prox-cal.bin and apple/z2-cal.bin when the DT has none; - performCalibSeq, with apple,fll-mval, apple,ref-clk-div-val and apple,clk32-clock-enable-val written raw, as iOS 10.3.4's MTSPIBootloader_N1 does; - EXECUTE. Then it does what iOS does next: wake, device info, the GETs (d9 gives the surface) and SET bf/af. The bf value is a module parameter because it differs per device. If the boot fails, the chip is powered off and /dev/hx-touch is released. Boards without firmware-name keep the userspace path unchanged. Also add an spi_device_id table so the SPI core stops warning. The bootload steps and the first frames are logged at debug level. Tested on an iPhone5,2: firmware (64340 bytes) and calibration accepted, family 0x57, a 5000 x 8900 surface, and with a finger on the screen 526 interrupts and one-touch frames whose coordinates moved. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Add what the N41 and N42 share to s5l8950x-5.dtsi, from the iPhone5,2 iOS 8.4.1 (12H321) ADT and the 10.3.4 (14G61) ADT and kernelcache: - gpio-keys: Home, Hold, Volume Up and Down, and the ringer switch; - I2C0: the D1972 PMU (0x74) with its charger, the touch power switches and WL_REG_ON; the LM3534 backlight (0x63) and the DWI block; - I2C1: the LIS3DSH accelerometer and AK8963 compass (no driver binds them yet); - SPI1: the Gen1 Z2 touch controller, its 32768 Hz PWM clock, and the firmware name and clock values that let the kernel boot it; - UART3: the BCM4334 Bluetooth; - UART5 as HDQ for the bq27540 gauge, with Apple's transaction; - EHCI with the BCM4334 Wi-Fi on HSIC port 4; - the CLCD and DSIM, disabled until there is a display driver. Each consumer's PMGR gate is enabled next to it. The I2C controllers take their gates as their clock, so the driver holds them from probe. The wifi0, bluetooth0 and touchscreen0 aliases let the boot loader fill in the unit's MAC and Bluetooth addresses and its touch calibration. Without the Wi-Fi address brcmfmac would use the NVRAM placeholder 02:00:00:00:00:00. Tested on an iPhone5,2: WPA2 on 5 GHz with DHCP, DNS and HTTP; the Bluetooth patchram loads; the gauge, charger, backlight and touch work as their driver commits describe; the buttons probe. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The N42 ADT places the brightness controller at 0xf700000. Use its register window to restore brightness after blanking. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Add "apple,s5l8950x-fmi" for the A6 (iPhone 5) H2FMI, which the driver runs read-only, and an optional clocks list for the PMGR power-state gates the controller needs. It is required on the S5L8950X, where a read of a gated block stalls the bus: ADT flash-controller0 clock-gates 0x14..0x18 (FMI0, FMI0-BCH, FMI1, FMI1-BCH, FMI-DLL). The A6 node must not list "apple,s5l8940x-fmi" as a fallback: a driver without the S5L8950X entry would bind it writable. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The iPhone 5 (N42) carries a SanDisk 1Xnm64GeX2 PPN 1.5.5 package with the P105 16 GB address layout but 1056 instead of 1064 blocks per CAU (12H321 ADT flash-controller0/disk: caus 2, cau-bits 4, blocks-per-cau 1056, block-bits 11, page-address-bits 8, 256 MLC and 128 SLC pages, page-size 16448). Accept that profile, and add h2fmi_geometry_writable(): program and erase stay limited to the two P105 profiles they were measured on, so any other accepted package is read-only whatever the compatible says. Log the first 64 parameter bytes when a package is rejected, so a new profile can be added from one boot log. KUnit: h2fmi_n42_geometry_test; the P105 vectors are unchanged. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The A6 has the A5's H2FMI (12H321 ADT flash-controller0, "fmi,s5l8950x": the same six FMI/FMC/ECC windows at 0x31200000 and 0x31300000, IRQs 33 and 34). The boot chain lives on the same NAND, so it binds as "apple,s5l8950x-fmi" with match data that keeps every write path closed: - h2fmi_cmd_write(), the one place an opcode reaches FMC_CMD, refuses program (8A, 17), mutation status (79) and erase (6A D7) on a read-only instance, and NAND reset (FF) and set feature (EF, E7) where no SDR reset is allowed; - the MTDs have no MTD_WRITEABLE and no _write_oob, and the SFTL provider gets no program_page or erase_block; - h2fmi_program_page() and h2fmi_ppn_erase() return -EROFS. On the S5L8950X the packages are never reset to SDR, at probe or to recover a failed transaction, unless mtd_apple_h2fmi.sdr_reset=1: the driver runs on the DDR interface iBoot leaves, and a failed transaction stops it instead. The PMGR gates in the node's clocks are switched on before the first register read, since reading a gated block on the A6 stalls the bus without an abort. They are never switched off again, not by a failed probe and not by an unbind: the ADT lists the same ids as power gates, and switching them off drops the DDR and DLL state iBoot trained, which only a reboot restores. The held enable count also keeps clk_disable_unused away from them. P105 has no clocks in its node and keeps its behaviour. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
…C reads it On the iPhone 5 the package reported 49 (clean) for the first page of a block the VFL lists, and h2fmi_ppn_read() failed it with -EIO because the data phase was not all FF. On the A5 an erased page always read back FF, and the driver insists on it, since erase and program verification rely on it. iBEC on the iPhone 5 (12H321, single-page PPN read at 0xbff09810, status switch at 0xbff09914) never looks at the data of a 49 page: 40 is good, 42 good with a refresh note, 43..45 an error, other 4x a failure, 49 "clean". Do the same on the read-only S5L8950X only: a 49 page reads as FF data and metadata in both the SFTL provider and the MTD read path. The flag is ignored unless the instance is read-only, so a writable driver keeps the strict check. The first eight such pages are logged at debug level with what the data phase held. P105 is unchanged. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The iPhone 5 (N42) runs the same 12H321 SwissPPNFTL as the P105 16 GB profile on a package with 1056 instead of 1064 blocks per CAU. Add a read-only (writer = false) profile for it. Buses, CAUs, blocks and pages come from the ADT. The VFL header on the phone reports 16 and 1046 FTL and VFL superblocks, and the VFL seed is at block 1055, lane 0. The other constants follow the P105 layout with its tail moved down by the block count; the loader checks each against the media and refuses a mismatch, and logs at debug level what the media holds at those checks (VFL member list, VFL header +10/+12/+14, context cursor). P105 loading is unchanged apart from those debug messages on its error paths. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
On the iPhone 5 the SFTL loads the 16 GB medium read-only, but the LwVM parser adds only p1: "LwVM partition 2 is not contiguous, skipped". A Linux partition is one range of the disk, and iOS stores Data in 16 MiB chunks out of order. The SFTL block frontend owns the disk and already reads it one 4 KiB logical page at a time, so it can translate each page itself. After the main disk is added, read the LwVM header (and its copy in the last page of the first chunk if the CRC fails, as the parser does) and give every partition that block/partitions/lwvm.c skips because it is scattered its own disk, applesftl<N>lwvm<P>. Each page of a request is looked up in the chunk map, so a request can cross chunks in any order, and the size of the partition ends the last, partial chunk. These disks are read-only with no write path at all: writes end with -EROFS and other operations with -EOPNOTSUPP before the FTL is reached, no write cache or FUA is advertised, and reads share the parent's lock and buffer. They have a dynamic device number and no partition scan. Only profiles that opt in get them, and only on a read-only medium (a second view of a disk that is written would read stale pages). The N42 profile opts in. The P105 profiles do not, so the iPad mini 1 is unchanged whether its medium loads read-only or read-write. The decoder applies the parser's checks (signature, CRC, media size, 1..8 partitions, no entry in the header chunk or past the disk) and reports a partition with a hole, a doubled or out-of-range chunk instead of serving it. Contiguous layouts get no new disk and no new message. KUnit (apple-sftl-lwvm) covers the chunk size, contiguous, interleaved and partial-last-chunk layouts, broken partitions and rejected tables with synthetic headers. Tested on an iPhone5,2: applesftl0lwvm2 is Data, 13.5 GB in 803 chunks, readable (its contents are encrypted). Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
…one 5 After iOS had written for about eight hours, the N42 read-only load stopped in the journal replay: record 1265 repeated the sequence of record 1264 and the strict "every sequence exactly once" rule refused it. 1265 records after the checkpoint is less than one superblock (4096 slots), so the repeat most likely sits where a block closed with a summary and the next one started. iOS does not appear to replay by a global sequence count. The 12H321 SwissFTL in iBEC (s_cxt_boot, s_cxt_scan_diff, s_scan_all_sb, s_btoc_read) loads the checkpoint, then scans superblocks and their block tables of contents, and on a uECC "exits early to be coherent" instead of failing. That is read from its strings and assertions, not decompiled. Under block-by-block replay a repeated sequence just means the later block's record is applied last. Do that on profiles with equal_sequences (only the N42 one): records with the same sequence are put in block order (the block's first sequence, then the position in it) and a record that repeats the previous sequence is applied without advancing the expected one. Each repeat is logged at debug level with both records. The P105 profiles still refuse a repeated sequence, and the new KUnit case checks both: the 16 GB fixture, now parametrised by block and superblock count, fails on P105 and loads on the N42 layout, with the repeated record readable. Tested on an iPhone5,2: the medium loads, and the System partition's HFS+ mounts read-only. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
… the iPhone 5
Add the H2FMI flash controller from ADT /arm-io/flash-controller0 as
"apple,s5l8950x-fmi" (read-only in the driver, no s5l8940x fallback):
the six FMI/FMC/ECC windows at 0x1200000..0x1380000 and IRQs 33 and 34.
The ADT's seventh window, the FMI DLL at 0x1000000, is not used.
Its PMGR gates follow the ADT: clock-gates 0x14..0x18 map through the
pmgr device-clocks table to power-state indices 0x32..0x36 ("FMI0",
"FMI0-BCH", "FMI1", "FMI1-BCH", "FMI-DLL"), registers 0x3f1010c8 to
0x3f1010d8 (UART6's gate 0x25 -> index 0x44 -> 0x3f101110 checks the
mapping). The gates are disabled with the controller, so that an
unclaimed gate is never switched off by clk_disable_unused, and the
iPhone 5 include enables them all.
Tested on an iPhone5,2: SanDisk PPN, 2 buses x 2 CAUs x 1056 blocks;
the SFTL loads and the System partition mounts read-only.
N41's NAND stays disabled until an N41 is tested.
Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Use the N42 profile identity for the scattered-partition messages. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Orchard models native and legacy 16 GB contexts separately. Generate the repeat at the end of the selected context and summary. The N42 replay case and the P105 native cases pass under ARM QEMU. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The iPhone 5's GPU (S5L8950X) is an SGX543MP3 with the A5's register layout, and the driver already counts cores from CORE_ID. iOS's A6 kext is a different build, though: class SGXDriver543RC2. Its microkernel is 0xdf0 bytes shorter, its PDS templates are smaller, and it has none of the A5's tables or the four extra buffers. Each offset this driver takes from the A5's kext therefore has another value or is gone. Move everything that depends on the build into struct sgx_variant, selected by compatible: - the sizes of __data and __const; - where the microkernel, the second code buffer and the boot program are; - the handler entry points; - the template offsets and sizes; - the USE addresses patched into the PDS programs; - the LIMM patches; - the boot program's two patched words; - the other cores' entry point; - BIF_MMU_CTRL; - whether the A5's tables exist. sgx_a5 keeps the existing values. sgx_a6 has the values read from the N42's 12H321 kernelcache: - initSGX 0x80ad0048; - loader 0x80ad5fb8; - setup 0x80ad66a0; - fill 0x80ad6cb0; - entries 0x80ad6688 and 0x80ad668c. Its initSGX makes the same register writes as the A5's, with three differences: - BIF_MMU_CTRL is 3, not 2; - no erratum 31195 bypass bits (the A6's ADT has no brn_31195); - USE_CODE_BASE_1 is not written. The A6's microkernel goes in its own file, apple/sgx543-s5l8950x.fw, in the same container format. Both kexts are build 12H321, so the firmware check compares the variant's section sizes. The driver is Project Cascadia's (rzxvx); the A5 side is unchanged. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The A6's GPU runs at about 330 MHz, not the A5's 256.5 MHz. The microkernel's timer ticks once every HOST_UK_TIMER_CLOCK core clocks; it was told 256500 and ticked 6461 times in 5.02 s. That is 1287 ticks a second, times 256500 clocks, so 330.1 MHz. The A5's figure came the same way: 2500 ticks a second when told 102600, i.e. 256.5 MHz. Make the clock part of struct sgx_variant. The timer and APPLE_SGX_PARAM_CLOCK_KHZ take it from there. The A6's render details header is 8 bytes shorter: - entry 0 is at +0x18, not +0x20, and entry 1 is 0x84 bytes later (+0x9c); - the A6 microkernel reads the header at 0x14/0x18 where the A5's reads 0x1c/0x20; - the A6 kext's 3D block builder (0x80ad2798) puts details + 0x18 into the TA command; - its render-target init leaves entry 1's constants at +0x9c. Make the entry offset part of struct sgx_variant. The render queue writes the context into both entries there, and the poller reads entry 0's word 1. A submit's details must be large enough for that layout. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Direct scanout on the N42 ran at 47.9 fps: each flip waited out a whole frame, most likely because the A5's line counter (0x39200054 >> 9) does not go round there. iOS's AppleH5PDisplayPipe (12H321) takes the pipe's VBI instead: general control at clcd reg 0 + 0x1000, interrupt enable +0x28 and status +0x2c (write 1 to clear), bit 0 the VBI, on the clcd node's interrupt index 0 (43; AppleMobileCLCD has index 1). Where the device tree names that window and interrupt, a flip queues the new layer base, the VBI writes it in the vertical blank and completes the flip, and the VBI is the vblank. No VBI within a frame and a millisecond: the base is written at once and the line-counter wait runs. apple_sgx.vbi=0 turns the path off. The A5's DT has neither, so it keeps today's path. debugfs: screen adds the VBI count and period, flips at a VBI or timed out, the interrupt registers and position samples; gpu (new) gives the renders done and the time the GPU had one. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The flip's wait timed out in 2 jiffies (10-20 ms at HZ=100), so a flip committed early in a frame could miss its VBI and be written mid-frame. It is a hang guard only: 40 ms now. A flip holds a vblank reference until its VBI, so that the VBI is the vblank and the flip's event carries the count it landed on; the count is taken before the waiting commit is woken. As iOS's interruptFilter and enable_interrupts do, every raised bit is acknowledged and only the VBI is enabled. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
A flip the display cannot point at (a buffer that is not contiguous, the screen's pitch and size) is shown by a copy onto the boot framebuffer. Its event went as soon as the copy was queued, so a compositor flipping client buffers that way (cage with weston-simple-egl) ran unpaced at ~370 frames a second, 1.3 cores busy. Where the display pipe's VBI is there, such a flip now completes at the next VBI, as a pointed one does; an async flip still completes at once. debugfs screen counts them. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Apply per-device calibration to the input current ramp, back off after VBUS sag and expose thermal charge limits. D1972 writes require explicit opt-in. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The ADT's /charger node has charge-limits = <900 570 420 270> (mA), the charge currents iOS picks between by thermal index. Pass them to the D1972 charger. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Register the wdt-version 1 watchdog (the 24 MHz counter that is already the clocksource) as a watchdog device, so a hung system is reset within the timeout and a healthy one runs for ever: the kernel pets it from boot until userspace (systemd's RuntimeWatchdogSec=) opens /dev/watchdog. A ping moves BITE_TIME to CUR_TIME + timeout; CUR_TIME is never written, being the clocksource. The comparator fires when the counter reaches BITE_TIME, not while it is above it (iBoot enables RESET_EN with CUR_TIME at 0x80000000 and a small BITE_TIME), so a bite past the 32-bit wrap is correct and timeouts go up to 178 s. On the A6, ENABLE stays set: the counter only runs with it. It is started at boot whatever the boot loader armed, with no way out: this hardware has no power off, so a halt ends in the bite as well. The restart path keeps its own bite. apple_wdt_timeout= (60 s) sets the timeout; 0 leaves the watchdog as the boot loader left it. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The board has no way to cut its own power, so a power off halted and waited for the watchdog's timeout. A phone booted from iOS that powers off belongs back in iOS: restart through the watchdog at once, as a low-priority power-off handler that a real one would replace. Halt and power off also get the 10 s net the reboot notifier arms for a restart. For the flights, a ping whose bite lies past the counter's 32-bit wrap is logged, and debugfs apple-wdt/state shows the counter, the bite and CTRL. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
brkosebay
force-pushed
the
a6/n42-pr-watchdog
branch
from
December 1, 2026 17:35
b1355f4 to
0b9c97a
Compare
brkosebay
marked this pull request as draft
December 1, 2026 17:49
|
Closing with thanks, @brkosebay. Both commits are already on Small cleanups we may do on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR depends on #63. Both PRs target armv7, so this head also contains its predecessors’ commits. The subsystem changes start after c1dcc96.
Register the S5L watchdog with Linux, let systemd pet it and handle halt and restart. This is the kernel part of the installed Orchard Boot path.
During omarchy-nbd3-reboot on 30 November, systemctl reboot returned N42 to iOS. In omarchy-nbd3-hang a crash with panic=0 was followed by watchdog recovery after 59 seconds.
Built this head with the N42 integration config, ARCH=arm, LLVM 19, olddefconfig, zImage and dtbs. Hardware observations above refer to the development flights. Each commit carries Assisted-by: LLM and the author’s Signed-off-by trailer.