Skip to content

Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.

C

Wi-Fi works on the phone: a WPA2 network joined, a page fetched over its own radio

vcvkk3a57ccb8bf02
diff --git a/prebuilt/SHA256SUMS b/prebuilt/SHA256SUMS
index 5041c50..6c54998 100644
--- a/prebuilt/SHA256SUMS
+++ b/prebuilt/SHA256SUMS
@@ -1,6 +1,6 @@
-Built 2026-10-13 19:42 from this tree.
+Built 2026-10-13 20:34 from this tree.
-5844b4b77046b056af969644f3fcdd3caab1f02689ec12db6a58e41c0bebd7a0 prebuilt/mach.development.bcm2837
+107f4e4c56a1ac71f34ca3671b732ab5dda752ace2a96215212e07c1fe9d1cd1 prebuilt/mach.development.bcm2837
1332a598d2dec00a1d8e930044e4f00a12ad44c6e5e50eecf4b7fe7fae803bf2 prebuilt/loader.efi
d2a35a4a1d6658ffb3696914f727661b52c9333de8a3af8a31642b8023ce03ac prebuilt/userland/child
1a413befd511384052e1962c1394adce20f718e1f2657ce63ab09828ebc4bd1b prebuilt/userland/cpu_test
diff --git a/prebuilt/mach.development.bcm2837 b/prebuilt/mach.development.bcm2837
index 8f90e25..608e887 100755
Binary files a/prebuilt/mach.development.bcm2837 and b/prebuilt/mach.development.bcm2837 differ
diff --git a/xnu/files/bsd/dev/redwood_lx.c b/xnu/files/bsd/dev/redwood_lx.c
index 5907680..54bc005 100644
--- a/xnu/files/bsd/dev/redwood_lx.c
+++ b/xnu/files/bsd/dev/redwood_lx.c
@@ -25,6 +25,7 @@
#include <sys/random.h>
#include <sys/redwood_input.h>
#include <sys/redwood_lx.h>
+#include <sys/redwood_net.h>
#include <sys/systm.h>
#include <vm/memory_types.h>
#include <vm/vm_kern.h>
@@ -232,6 +233,62 @@ lx_os_radio_address(unsigned char *address)
return redwood_wifi_radio_address(address);
}
+int
+lx_os_network(unsigned char *name, unsigned *name_length, unsigned char *passphrase, unsigned *passphrase_length)
+{
+ return redwood_wifi_network(name, name_length, passphrase, passphrase_length);
+}
+
+/* ---- frames: the radio as the link behind en0 (sys/redwood_net.h) ------------------------------------ */
+
+static bool lx_link_attached;
+
+/* (called by one thread at a time: the frame is put together in one place) */
+static bool
+lx_link_transmit(mbuf_t packet, size_t length)
+{
+ static uint8_t frame[REDWOOD_NET_FRAME_MAX];
+
+ if (length > sizeof(frame) || mbuf_copydata(packet, 0, length, frame) != 0) {
+ return false;
+ }
+ return lx_transmit(frame, length) == 0;
+}
+
+static struct redwood_net_link lx_link = {
+ .name = "the phone's radio (ath11k)",
+ .wireless = true,
+ .transmit = lx_link_transmit,
+};
+
+void
+lx_os_net_attach(const unsigned char *address)
+{
+ if (lx_link_attached) {
+ return;
+ }
+ memcpy(lx_link.address, address, sizeof(lx_link.address));
+ lx_link_attached = redwood_net_attach(&lx_link);
+ say("lx: %s\n", lx_link_attached ? "the radio is the link behind en0" : "EN0 HAS A LINK ALREADY: the radio's frames go "
+ "nowhere");
+}
+
+void
+lx_os_net_link(int up)
+{
+ if (lx_link_attached) {
+ redwood_net_link_state(up != 0);
+ }
+}
+
+void
+lx_os_net_input(const unsigned char *frame, unsigned long length)
+{
+ if (lx_link_attached && length <= REDWOOD_NET_FRAME_MAX) {
+ redwood_net_input(frame, length);
+ }
+}
+
/* ---- the driver ---------------------------------------------------------------------------------------- */
/* The object has its own; this is the one of a kernel built without it. */
@@ -243,8 +300,25 @@ lx_start(void)
return ENXIO;
}
+__attribute__((weak)) void
+lx_stop(void)
+{
+}
+
+__attribute__((weak)) int
+lx_transmit(__unused const unsigned char *frame, __unused unsigned long length)
+{
+ return ENXIO;
+}
+
int
redwood_lx_start(void)
{
return lx_start();
}
+
+void
+redwood_lx_stop(void)
+{
+ lx_stop();
+}
diff --git a/xnu/files/bsd/dev/redwood_wifi.c b/xnu/files/bsd/dev/redwood_wifi.c
index d9795a7..9479bae 100644
--- a/xnu/files/bsd/dev/redwood_wifi.c
+++ b/xnu/files/bsd/dev/redwood_wifi.c
@@ -111,6 +111,10 @@
* made and the radio scans, listening only; what it heard goes to the log
* (other people's networks by name and address: the log is not for
* passing on)
+ * wifi_join=1 with wifi_lx=2: the station joins the network named in fw/network of
+ * the small image (redwood_wifi_network() below) and the driver stays
+ * up as the link behind en0; with wifi_keep=1 while the system runs,
+ * else until the steps are over (wifi_hold=S: S seconds longer)
* wifi_lx_step=MS the driver's start says each stub it comes to and waits MS there: for
* a run that ends without a word (follow it with XL_FOLLOW=2)
* wifi_lx=1 step 15 is ath11k's own instead of the stand-in (redwood_lx.c), with
@@ -1650,6 +1654,7 @@ dsp_shutdown(const char *why)
printf("wifi: %u: %s: the DSP is asked to stop, then TrustZone to shut it down\n", step, why);
if (!leaving) {
+ redwood_lx_stop(); /* (the driver, if it stayed up: it leaves its network and goes down in order) */
redwood_wlfw_stop(step); /* (what the stand-in of step 15 has to say first, while there is a link) */
link_stop();
}
@@ -3161,6 +3166,21 @@ static void radio_space_faults(void);
* the interface is removed, the radio stopped, and the driver's own removal runs to its end.
* The data path is still stubs: the firmware scans without it.
*
+ * With the data path built (dp.c and its neighbours: 18 of the driver's files, no stubs) and
+ * wifi_join=1 (the same day): the rings of the data path are set up -- 636 words into the
+ * radio's registers before the bus is started, 44 MB of ours shown to the radio -- and HTC
+ * connects the data service besides WMI. The station asks for the network it was given by
+ * name in a scan (1.9 s), finds its access point (channel 36, -53 dBm; WPA2 with a passphrase,
+ * CCMP), authenticates, associates (20 MHz, HT and VHT, two streams) and answers the access
+ * point's handshake; 130 ms after the association both keys are with the firmware and frames
+ * pass. With wifi_keep=1 and the system started on top, configd's DHCP has an address in 4 to
+ * 6 s, names resolve, and pages are fetched over HTTPS: iOS on the network through the
+ * phone's own radio. 20 MB come down in 10.5 s (15 Mbit/s) with one processor, the rings
+ * looked at by a thread and the radio's buffers not behind the processor's cache; what of
+ * that holds the rate down was not taken apart. With four processors the network works as
+ * well. At the run's end the network is left, the driver removes itself and the DSP stops
+ * when asked.
+ *
* A PHONE THAT RESETS WITHOUT A WORD: twice on the way, two seconds after calibration. The
* driver's registration failed (the hash table peer.c needs was a stub that fails), and where
* its start fails that late core.c asks for the mode "off" before it stops the bus; our thread
@@ -3440,7 +3460,7 @@ smmu_look(void)
*/
#define RADIO_ADDRESSES 0xa0000000ull
#define RADIO_ADDRESSES_SIZE 0x10000000u
-#define RADIO_TABLES 16 /* of 4K: the root, one of the second level, and 2 MB of addresses each other */
+#define RADIO_TABLES 32 /* of 4K: the root, one of the second level, and 2 MB of addresses each other */
#define RADIO_PTE (3ull | 1ull << 6 | 2ull << 8 | 1ull << 10 | 1ull << 11) /* a page; for requests of either
* privilege; shared, accessed, not
* global: Linux's for a device */
@@ -3827,6 +3847,49 @@ redwood_wifi_radio_address(uint8_t *address)
return good;
}
+/*
+ * The network the radio is to join: the file "network" among the firmware in the small image,
+ * the name on its first line, the passphrase on its second (userland/build.sh takes it from
+ * fw-wifi/network, which is in no repository). Not a boot argument: those are echoed by the
+ * loader and printed with a panic. The log says how long the two are, and nothing else of them.
+ */
+bool
+redwood_wifi_network(uint8_t *name, unsigned *name_length, uint8_t *passphrase, unsigned *passphrase_length)
+{
+ uint64_t size = 0;
+ const uint8_t *file = image_file("network", &size), *end = file + size, *line = file;
+ unsigned lengths[2] = { 0, 0 }, sizes[2] = { *name_length, *passphrase_length };
+ uint8_t *where[2] = { name, passphrase };
+
+ if (file == NULL) {
+ printf("wifi: %u: the driver asks which network to join: none was given (fw/network of the small image)\n", step);
+ return false;
+ }
+ for (unsigned n = 0; n < 2 && line < end; n++) {
+ const uint8_t *stop = line;
+
+ while (stop < end && *stop != '\n') {
+ stop++;
+ }
+ lengths[n] = (unsigned)(stop - line) - (stop > line && stop[-1] == '\r' ? 1 : 0);
+ if (lengths[n] > sizes[n]) {
+ lengths[n] = 0;
+ } else {
+ memcpy(where[n], line, lengths[n]);
+ }
+ line = stop + 1;
+ }
+ printf("wifi: %u: the driver asks which network to join: a name of %u bytes and a passphrase of %u bytes were given%s\n", step,
+ lengths[0], lengths[1], lengths[0] == 0 || lengths[1] < 8 || lengths[1] > 63 ? ": NOT A NAME OF 1 TO 32 BYTES AND A "
+ "PASSPHRASE OF 8 TO 63" : "");
+ if (lengths[0] == 0 || lengths[1] < 8 || lengths[1] > 63) {
+ return false;
+ }
+ *name_length = lengths[0];
+ *passphrase_length = lengths[1];
+ return true;
+}
+
/* ---- all of it together ---------------------------------------------------------------------------- */
static bool(*const steps[])(void) = {
diff --git a/xnu/files/bsd/sys/redwood_input.h b/xnu/files/bsd/sys/redwood_input.h
index fc27bdf..fa10b1e 100644
--- a/xnu/files/bsd/sys/redwood_input.h
+++ b/xnu/files/bsd/sys/redwood_input.h
@@ -58,10 +58,13 @@ void redwood_wlfw_stop(uint32_t step); /* ... a
void redwood_wifi_quiesce(void); /* on the way back to the loader: the Wi-Fi DSP, if it still runs, shut down */
/* ath11k's object and the kernel's side of it (bsd/dev/redwood_lx.c), and what that asks of the phone's radio */
int redwood_lx_start(void); /* the driver brought up on the radio as far as it is built: 0 or an errno */
+void redwood_lx_stop(void); /* ... and down again, if it stayed up (a network joined) */
bool redwood_wifi_dsp_is_up(void); /* the DSP that runs the radio's firmware has been started and has a link */
const uint8_t *redwood_wifi_driver_file(const char *name, uint64_t *size); /* a file by the name Linux has for it */
bool redwood_wifi_radio_map(uint64_t physical, uint64_t size, unsigned long long *address); /* memory shown to the radio */
bool redwood_wifi_radio_address(uint8_t *address); /* the radio's own address (boot-arg wifi_mac), if one was given */
+/* the network to join (fw/network of the small image): name and passphrase, buffer sizes in and lengths out */
+bool redwood_wifi_network(uint8_t *name, unsigned *name_length, uint8_t *passphrase, unsigned *passphrase_length);
/*
* The GPU kept on (boot-arg adreno_keep=1), for iokit/Kernel/RedwoodGPU.cpp: see "the GPU kept on"
diff --git a/xnu/files/bsd/sys/redwood_lx.h b/xnu/files/bsd/sys/redwood_lx.h
index 3f8c83a..0d9dccc 100644
--- a/xnu/files/bsd/sys/redwood_lx.h
+++ b/xnu/files/bsd/sys/redwood_lx.h
@@ -54,11 +54,26 @@ int lx_os_firmware(const char *name, const void **data, unsigned long *size);
int lx_os_rproc_boot(void);
/* the radio's own address (six bytes), if the machine has one for it: 1, or 0 and nothing written */
int lx_os_radio_address(unsigned char *address);
+/*
+ * The network the radio is to join, if the machine was given one: its name and its passphrase,
+ * into buffers whose sizes come in and whose contents' lengths go out. 1, or 0.
+ */
+int lx_os_network(unsigned char *name, unsigned *name_length, unsigned char *passphrase, unsigned *passphrase_length);
+
+/* ---- frames: the radio as what carries the machine's network interface ---- */
+void lx_os_net_attach(const unsigned char *address); /* there is a radio, and this is its address */
+void lx_os_net_link(int up); /* frames can pass now (a network is joined) / no longer */
+void lx_os_net_input(const unsigned char *frame, unsigned long length); /* an Ethernet frame has arrived */
/*
- * ---- the one name the object shows the kernel: bring the driver up on the radio and go as far
- * as what is built goes. 0, or an errno. Returns when that is over, or has failed.
+ * ---- the names the object shows the kernel. lx_start(): bring the driver up on the radio and
+ * do what the kernel's options ask (scan; join a network). 0, or an errno. Returns when that is
+ * over or has failed; with a network joined the driver stays up, lx_transmit() sends an
+ * Ethernet frame through it (0, or an errno), and lx_stop() leaves the network and takes the
+ * driver down in order (and does nothing if it is not up).
*/
int lx_start(void);
+void lx_stop(void);
+int lx_transmit(const unsigned char *frame, unsigned long length);
#endif