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

Flash root: the audio DSP's firmware on /fw, so a boot off the flash has sound

vcvkkbfeac2981147
diff --git a/userland/build.sh b/userland/build.sh
index d69efb5..6924605 100755
--- a/userland/build.sh
+++ b/userland/build.sh
@@ -289,6 +289,17 @@ if [ -n "$FLASHBOOT" ] && [ -f $CACHE/dyld_shared_cache_arm64 ]; then
mkdir -p flashboot/sbin flashboot/redwood flashboot/dev flashboot/flash flashboot/Cryptexes
cp obj/stage0 flashboot/sbin/launchd
if [ -d $IOS/cryptex ]; then cp -al $IOS/cryptex flashboot/Cryptexes/OS; else mkdir -p flashboot/Cryptexes/OS; fi
+ # the audio DSP's firmware and the speaker amplifiers' configuration, as in the system image's /fw: the kernel
+ # reads the firmware as soon as there is a root (this image, adsp=1), the configuration maybe later -- by then
+ # from the iOS volume's /fw, which src/init.c (flash_root) binds to this
+ if [ -f ../fw-audio/adsp.mdt ]; then
+ mkdir -p flashboot/fw
+ cp ../fw-audio/adsp.mdt ../fw-audio/adsp.b0[2-9] ../fw-audio/adsp.b[1-9][0-9] flashboot/fw/
+ fi
+ if [ -f ../fw-audio/aw882xx_acf.bin ]; then
+ mkdir -p flashboot/fw
+ cp ../fw-audio/aw882xx_acf.bin flashboot/fw/
+ fi
D=flashboot/Cryptexes/OS/System/Library/Caches/com.apple.dyld
mkdir -p $D
for f in $CACHE/dyld_shared_cache_arm64*; do
diff --git a/userland/rc.jobs.flashsound b/userland/rc.jobs.flashsound
new file mode 100644
index 0000000..1edff6a
--- /dev/null
+++ b/userland/rc.jobs.flashsound
@@ -0,0 +1,17 @@
+# Commands run by the launchd job com.redwood.demo (see com.redwood.demo.plist).
+# The iOS root volume on the phone's flash as the root (flashboot.packfs resident, root_apfs=ufs_darwin
+# ufs=2 [ufs_native=1] adsp=1 sound=4): what is mounted, the firmware on /fw, reading files through
+# read(2) and through a mapping (page-in) with the APFS driver's numbers before and after, then
+# something to hear -- a tone of three seconds, the lock sound, a keyboard click, a fanfare -- which
+# a recording (rec_sound=N, ./xl sound) shows came through.
+/sbin/mount
+/redwood/bin/vol_ls fs /
+/redwood/bin/vol_ls ls /fw
+/redwood/bin/vol_ls sysctl kern.apfs_stats
+/redwood/bin/apfs_mmap_test read /usr/libexec 65536
+/redwood/bin/apfs_mmap_test mmap /usr/libexec
+/redwood/bin/apfs_mmap_test mmap /usr/libexec
+/redwood/bin/vol_ls sysctl kern.apfs_stats
+/redwood/bin/sound_test springboard wait 5 tone 3 wait 3 system 1100 wait 3 system 1104 wait 3 file /System/Library/Audio/UISounds/New/Fanfare.caf
+/redwood/bin/vol_ls sysctl kern.apfs_stats
+/bin/ps -A
diff --git a/userland/src/init.c b/userland/src/init.c
index 6c83a7f..8f0509b 100644
--- a/userland/src/init.c
+++ b/userland/src/init.c
@@ -140,6 +140,7 @@ flash_root(const char *dev)
{
static char buf[8192];
char devpath[96], name[256], from[800], to[400];
+ struct stat fw_st;
off_t pos = 0;
ssize_t n;
int fd, ok, apps = 0, bound = 0;
@@ -161,6 +162,10 @@ flash_root(const char *dev)
bind_dir(in_image("/xpc"), "/flash/System/Library/xpc"), "our launchd jobs, not iOS's");
check(bind_dir(in_image("/hal"), "/flash/System/Library/Audio/Plug-Ins/HAL"),
"our audio device, not Apple's plug-ins");
+ if (stat("/fw", &fw_st) == 0) {
+ /* the audio DSP's firmware and the speakers' configuration, from the RAM image as in a RAM boot */
+ check(synthetic_dir("/flash/fw") && bind_dir("/fw", "/flash/fw"), "the firmware on /fw (adsp=1, sound=N)");
+ }
fd = open("/flash/private/var/staged_system_apps", O_RDONLY | O_DIRECTORY, 0);
while (fd >= 0 && (n = getdirentries(fd, buf, sizeof(buf), &pos)) > 0) {
diff --git a/userland/src/vol_ls.c b/userland/src/vol_ls.c
index e05ac18..9773a4b 100644
--- a/userland/src/vol_ls.c
+++ b/userland/src/vol_ls.c
@@ -10,6 +10,8 @@
* vol_ls hash FILE... FNV-1a of the whole file through read(2) and through a
* mapping, and its size: the hash tools/apfs prints on the
* build machine for the same file
+ * vol_ls sysctl NAME... a string the kernel keeps (kern.apfs_stats: where the APFS
+ * driver's time went -- reads, page-ins, the lock)
*/
#include <dirent.h>
#include <errno.h>
@@ -20,6 +22,7 @@
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/stat.h>
+#include <sys/sysctl.h>
#include <unistd.h>
#define FNV_INIT 0xcbf29ce484222325ULL
@@ -205,7 +208,7 @@ main(int argc, char **argv)
int i, bad = 0;
if (argc < 3) {
- printf("usage: vol_ls fs PATH | ls DIR... | cat FILE [BYTES] | hash FILE...\n");
+ printf("usage: vol_ls fs PATH | ls DIR... | cat FILE [BYTES] | hash FILE... | sysctl NAME...\n");
return 2;
}
if (strcmp(argv[1], "fs") == 0) {
@@ -214,6 +217,21 @@ main(int argc, char **argv)
if (strcmp(argv[1], "cat") == 0) {
return do_cat(argv[2], argc > 3 ? atol(argv[3]) : 4096);
}
+ if (strcmp(argv[1], "sysctl") == 0) {
+ for (i = 2; i < argc; i++) {
+ static char text[16384];
+ size_t len = sizeof(text) - 1;
+
+ if (sysctlbyname(argv[i], text, &len, NULL, 0) != 0) {
+ printf("%s: %s\n", argv[i], strerror(errno));
+ bad++;
+ continue;
+ }
+ text[len] = 0;
+ printf("%s:\n%s\n", argv[i], text);
+ }
+ return bad ? 1 : 0;
+ }
for (i = 2; i < argc; i++) {
if (strcmp(argv[1], "ls") == 0) {
bad += do_ls(argv[i]);