From 8eb9f33146697d64dc8a616c6328841c3a2f2f7e Mon Sep 17 00:00:00 2001 From: Nick Chan Date: Sat, 2 Nov 2024 14:18:11 +0800 Subject: [PATCH 1/2] Add support for booting on t8012 (T2) Address some peculiarities specific to T2: - Reserved memory at top is very large, either 512 MB or 1536 MB, and only lowest 512 MB is for OS use. - Some ranges in /arm-io/ranges is not aligned to the page size. We align them ourselves instead. - On models with a screen, the framebuffer is extremely narrow at 60 pixels in width, so add a smaller logo. Signed-off-by: Nick Chan --- Makefile | 2 +- data/bootlogo_48.bin | Bin 0 -> 9216 bytes data/bootlogo_48.png | Bin 0 -> 3059 bytes data/makelogo.sh | 1 + src/fb.c | 15 ++++++++++++++- src/memory.c | 5 ++++- src/startup.c | 18 +++++++++++++++++- 7 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 data/bootlogo_48.bin create mode 100644 data/bootlogo_48.png diff --git a/Makefile b/Makefile index 1b7795460..72efd494e 100644 --- a/Makefile +++ b/Makefile @@ -95,7 +95,7 @@ OBJECTS := \ afk.o \ aic.o \ asc.o \ - bootlogo_128.o bootlogo_256.o \ + bootlogo_48.o bootlogo_128.o bootlogo_256.o \ chainload.o \ chainload_asm.o \ chickens.o \ diff --git a/data/bootlogo_48.bin b/data/bootlogo_48.bin new file mode 100644 index 0000000000000000000000000000000000000000..76df9e8b20001b8b20f7f04b429213b2940f988c GIT binary patch literal 9216 zcmeI2dr(w$6vr>S%kHuZ2)itAkma$kyhgwsk?<7=io67TVHp!Bnp8MVjfkOX{gdf5 zVAANMqYgsh2sLG;l17cGsURd~4uzRElY*4;Qt;dFx3E06Wxe~rwwdnC;oiHuclmtJ zIluEezaKCR1Ll9z=>smu3LGn|k@rSlTd>dgJPu;QT=05s6r3G|U?}%AB^XuUh!zXv zw7R^s<@%o_{G*v8uo7BeQd9~*cIf=pd2Qtx8wHW@+ z;{O!Ch}0J)k3q%C2>eF)xA}^(SjZsQnt|9tYmbm{DG2jI8wMrz4E9W7P#ZQ0*WOJ; z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^=k7!RS5{Y#BUVHz^k#B>wLDBd&DPKRM5&SfNYOi$Te&1;N!BDicv>+)dX^aLs zN6?(%@p!D*HCkvs&2*I;*L&*7e@aNl@4k!oag)?hdbGE?q5F9n67uDt`>C$%h;c(qKdGe&XkE8jKn3#y>=4Q2o*49>J zXJ;GKFR;--KNB=bhSF&%?8dehKZVm|{PpYCk(HG-oaeMZp#4x~Wu;oS|dX9BW)-`RQ|X zUn|KoknD-B7#j;M{yTT>ATKXZ%^pDZIvpGwj9OQj!m96Ce|st3A#0w7)S=#W6n{Ud zl{_HJbYT E-_ks7Q2+n{ literal 0 HcmV?d00001 diff --git a/data/bootlogo_48.png b/data/bootlogo_48.png new file mode 100644 index 0000000000000000000000000000000000000000..0b2ec48e160b6c6dec95e29b7a70ac51a491d2cc GIT binary patch literal 3059 zcmZvec{J4j8ppq8jK-RMD>aoZ+l+k|8QCH+gDf$|7!zZ5OURHdWQkDplWsAoEX733 zB)i;1NKyz{laNrq>W=O?_ndp~J)h+{=lQ(e&+~kqzn)8OuJ)orib4PYh&nnT-FX(V zd!Pcm+Y7Xl#xpRigS!g=oL2<^W-vj$*Iiec?8K0XJ`NbcHBLD18Pd?Jm(&|ql?|11!0hYvgX6~>O>y)+!1Mm3Z3Y@ z7DGmVROm`rjrv>|`$!4|g;w;`D!10BltV>iOKlW_@74t~t9ou7(uy4Dr<*CQ44ji& za^LUMtygHXSby%KSr^17RbdY+DOp+Mc?Ex-YO;7w zbi4@%K7xb;&gE>DuX4*k2?8O3;z;)p1fyEqF6FHHGP4d;>XldN^YE`tqy&&UeMQXA z;p$j{U8_uJ_5xu_3E?e(mU&4AAMp*BM;=#0{nJ3;Uvlqvb-K?l23`Lw!vH=Veu` z46pKeq+QUA;d0s<-e-N!Iak?K?d!4gRSZA@DLeSzFF|K}0Y~r^rQ2o`6=G-PyRu?} zpVvH0n@d=24`|sq-PgOZn%Vh77FBI!KQjw85t?QyF_~?X@7^rRvE`x`}*r2_H$6*lWpGOg?;oMT_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L6sIelo zieEjHF_|oL+f1RmESAHiQ4$Maf@z+V#)N{eMrkkgMZveO{XKhG`{-tz+ArbGMDE&l zJ2aa&=MUEGFUyn@iwf?z@;Ri5x>E;6v$v ztu4%kPNx!r7<2+DLfa!0L&e#I6T)z?P&%D#28Uy*I1HT-iNlhJL{bDzheXB0!wFbi z1Pw=n2gPX9FmMAM1iT#;1mQ)O{}cU>gcJco5r{ZI522^4jo@wlexF~w0Txi%Wr8tu zoY|k)e+UC@T^^x_LKvCp8=2{uXd)112n4KeS?s?AL{cyzBxX0{{}-Gt^mxbphys_base + ba->mem_size - 0x800000000, BIT(30)); + if (chip_id == T8012) { + int anode = adt_path_offset(adt, "/arm-io/mcc"); + + /* + * Lower 512 MB intented for OS use, upper 512 or 1536 MB is some sort + * of SSD cache. Cannot use dram-size, it may not exist in older firmwares + * This property is changed from 4 to 2 by iBoot on 1 GB RAM models. + */ + + u32 dcs_num_channels = 0; + if (anode > 0 && ADT_GETPROP(adt, anode, "dcs_num_channels", &dcs_num_channels) > 0) + mem_size_actual = dcs_num_channels * 0x20000000; + else + mem_size_actual = 0x40000000; + } else { + mem_size_actual = ALIGN_UP(ba->phys_base + ba->mem_size - 0x800000000, BIT(30)); + } printf("Correcting mem_size_actual to 0x%lx\n", mem_size_actual); } } From 927c09f1300d441dc336a58f7389e78ec23922e4 Mon Sep 17 00:00:00 2001 From: Nick Chan Date: Mon, 4 Nov 2024 03:46:22 +0800 Subject: [PATCH 2/2] kboot: Add logic to allow T2 to boot into Linux - Some devices does not have a display internal or external, do not try to prepare framebuffer on it. - The SSD cache on T2 can be used as normal memory, so add it to /memory in addition to the normal memory described by iBoot. - Only half of the memory channels are used on T2 with 1 GB of memory, and this fact must be learned at runtime because the amount of memory depends on the storage configuration of the host Mac. Signed-off-by: Nick Chan --- src/kboot.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/src/kboot.c b/src/kboot.c index 1a46a77ad..cdd177f0d 100644 --- a/src/kboot.c +++ b/src/kboot.c @@ -204,7 +204,8 @@ static int dt_set_chosen(void) printf("FDT: initrd at %p size 0x%lx\n", initrd_start, initrd_size); } - if (cur_boot_args.video.base) { + if (cur_boot_args.video.base && + (adt_path_offset(adt, "/arm-io/disp0") > 0 || (chip_id != T8012 && chip_id != T7000))) { int fb = fdt_path_offset(dt, "/chosen/framebuffer"); if (fb < 0) bail("FDT: /chosen node not found in devtree\n"); @@ -335,8 +336,26 @@ static int dt_set_memory(void) if (node < 0) bail("FDT: /memory node not found in devtree\n"); - if (fdt_setprop(dt, node, "reg", memreg, sizeof(memreg))) - bail("FDT: couldn't set memory.reg property\n"); + if (chip_id == T8012) { + u64 cache_min = ALIGN_UP(dram_max, BIT(29)); + u64 cache_max = dram_base + dram_size; + + /* + * Set the SSD cache as OS memory, supposedly we will deal with the x86 SSD interface with a + * kernel driver that allocates memory anyways + */ + u64 memreg_t2[4] = {memreg[0], memreg[1], cpu_to_fdt64(cache_min), + cpu_to_fdt64(cache_max - cache_min)}; + + printf("FDT: Usable memory range 2 (SSD cache): 0x%lx..0x%lx (0x%lx)\n", cache_min, + cache_max, cache_max - cache_min); + + if (fdt_setprop(dt, node, "reg", memreg_t2, sizeof(memreg_t2))) + bail("FDT: couldn't set memory.reg property\n"); + } else { + if (fdt_setprop(dt, node, "reg", memreg, sizeof(memreg))) + bail("FDT: couldn't set memory.reg property\n"); + } return 0; } @@ -2310,6 +2329,37 @@ static int dt_transfer_virtios(void) return 0; } +static int dt_set_pmgr(void) +{ + if (chip_id != T8012) + return 0; + + if (mem_size_actual > 0x40000000) + return 0; + + int pmgr_node = fdt_path_offset(dt, "/soc/power-management@20e000000"); + if (pmgr_node < 0) { + printf("FDT: Failed to find pmgr node\n"); + return 0; + } + + int dcs2_node = fdt_path_offset(dt, "/soc/power-management@20e000000/power-controller@80258"); + if (dcs2_node < 0) + bail("FDT: failed to find ps_dcs2 node\n"); + + /* Allow failure */ + fdt_delprop(dt, dcs2_node, "apple,always-on"); + + int dcs3_node = fdt_path_offset(dt, "/soc/power-management@20e000000/power-controller@80260"); + if (dcs3_node < 0) + bail("FDT: failed to find ps_dcs3 node\n"); + + /* Allow failure */ + fdt_delprop(dt, dcs3_node, "apple,always-on"); + + return 0; +} + void kboot_set_initrd(void *start, size_t size) { initrd_start = start; @@ -2495,6 +2545,8 @@ int kboot_prepare_dt(void *fdt) return -1; if (dt_set_isp_fwdata()) return -1; + if (dt_set_pmgr()) + return -1; #ifndef RELEASE if (dt_transfer_virtios()) return 1;