mobile-nixos icon indicating copy to clipboard operation
mobile-nixos copied to clipboard

SDM845 family init

Open samueldr opened this issue 1 year ago • 19 comments

This PR adds support for a generic mainline-based family of SDM845 devices.

I only was able to test on oneplus-enchilada and google-blueline. Given the state of the #420 PR, I assume the rebased fajita in here work just as well.

I booted the hello example systen, the phosh example system on both units, and even went further and used FDE on my OnePlus 6, and included my usual system config to start dogfooding.

I tested the modem data connection successfully in the phosh image on oneplus-enchilada, Wi-Fi works, bluetooth untested but seems to work.

This obsoletes:

  • #420 by @MilesBreslin (by including it in a rebased form)
  • #361
  • #191 by @colemickens

cc #44 and @craigem

@MilesBreslin: it would be nice if you can review the changes credited to you, and if you're fine with how they were rebased, and also verify I didn't misattribute anything.

What about the Pixel 3 (google-blueline)?

Yes, it's tested, but it's not in these changes. No it's not an error.

It's not supported yet by SDM845-mainline, but the work has been done and tested. Here's the relevant diff, if you apply those commits on top of these changes you can build the morally equivalent image for Pixel 3.

  • https://github.com/samueldr-wip/mobile-nixos-wip/compare/5f0f0f73f082d1a53bad315e6b6c557038436583...samueldr-wip:mobile-nixos-wip:wip/sdm845-family-with-blueline

See the following upstream MR for the current status:

  • https://gitlab.com/sdm845-mainline/linux/-/merge_requests/37

TODO

  • [ ] Self-review changes
  • [ ] Split some changes in discrete PRs to ease review
    • [ ] Changes to kernel config should be a discrete PR with all device configs re-normalized
  • [ ] Remove empty commits markers once reviewed
  • [ ] Hopefully get a oneplus-fajita test
  • [ ] Add service to mark current slot as bootable
  • [ ] Intestigate if erasing dtbo is required, and what happens when it's not erased

Closes #512

samueldr avatar Sep 14 '22 02:09 samueldr

You are missing the modem manager update and the --enable-qrtr in libqmi, but I don't think either of those are necessary anymore. A quick build of libqmi says QMI over QRTR: yes, so I think it's already there. Other than that, it looks rebased properly to me.

Thanks for keeping this moving though! I'll try to give this a shot with my oneplus-fajita sometime this week.

MilesBreslin avatar Sep 14 '22 05:09 MilesBreslin

You are missing the modem manager update and the --enable-qrtr in libqmi, but I don't think either of those are necessary anymore. A quick build of libqmi says QMI over QRTR: yes, so I think it's already there. Other than that, it looks rebased properly to me.

Pretty much, calls/SMS untested due to lacking the phone plan at the moment, but since cellular data just worked, it's AFAIUI confirmed working. That's why those specific changes were dropped.

samueldr avatar Sep 14 '22 05:09 samueldr

When I try to instantiate a oneplus-fajita or oneplus-enchilada image with 4c8022ad75e1a87cd9a4f8b2bc31349de91c20ca, it errors with:

$ NIX_PATH= nix-instantiate --system aarch64-linux --argstr device oneplus-fajita -A outputs.android-fastboot-images
trace: (Using pinned Nixpkgs at b784c5ae63dd288375af1b4d37b8a27dd8061887)
trace: *************************************
trace: * Evaluating device: oneplus-fajita *
trace: *************************************
error: attribute 'override' missing

       at /nix/store/06gmb4plrmlcmqz82xfv77pzwdaixp3h-source/nixos/modules/system/boot/kernel.nix:41:18:

           40|       apply = kernelPackages: kernelPackages.extend (self: super: {
           41|         kernel = super.kernel.override (originalArgs: {
             |                  ^
           42|           inherit randstructSeed;
(use '--show-trace' to show detailed location information)

Full trace: log.txt

As a workaround, if I replace sdm845-mainline's mobile.boot.stage-1.kernel.package with (pkgs.callPackage ./kernel { }) (i.e. I don't call kernel-append-dtbs), the image builds (though might have broken DTB selection on boot?).

tomfitzhenry avatar Sep 14 '22 22:09 tomfitzhenry

Ugh, I reproduced the issue, I've been accidentally hiding the underlying problem by using a local.nix config while finalizing the work... It only happens for a "full" rootfs build, which isn't something that I usually ended-up building, using android-bootimg to test updates, or target-disk-mode.


EDIT: @tomfitzhenry this has been fixed:

  • https://github.com/NixOS/mobile-nixos/compare/4c8022ad75e1a87cd9a4f8b2bc31349de91c20ca..30c583033569c2845c7a709f0e1ffc9a96637ff2?w=1

The kernel derivation has to respect a lot of unwritten rules in a full NixOS eval. Let's forward the override as-is from the wrapped kernel, and apply the wrap on the overriden kernel if desired.

I tested boot on a android-bootimg after applying the change, and it worked, I also built but did not attempt to boot an examples/hello system.

samueldr avatar Sep 15 '22 01:09 samueldr

Ugh, I reproduced the issue, I've been accidentally hiding the underlying problem by using a local.nix config while finalizing the work

Ah, I've accidentally done this a bunch of times too. :)

I tested boot on a android-bootimg after applying the change, and it worked, I also built but did not attempt to boot an examples/hello system.

I was also able to flash and boot android-bootimg on my google-blueline, and saw mobile-nixos stage-1 booting. I flashed the examples/hello image to my userdata partition, but mobile-nixos's init hangs while trying to e2fsck.

I'm not sure if I'm properly flashing, though:

$ fastboot flash userdata /nix/store/5rk82jsgxzczhrrif11pg6w0275v69wx-partition-MOBILE_HELLO/MOBILE_HELLO.img
Invalid sparse file format at header magic
Sending sparse 'userdata' 1/7 (262141 KB)          OKAY [  7.165s]
Writing 'userdata'                                 OKAY [  0.294s]
Sending sparse 'userdata' 2/7 (258009 KB)          OKAY [ 17.097s]
Writing 'userdata'                                 OKAY [  0.182s]
Sending sparse 'userdata' 3/7 (261950 KB)          OKAY [ 34.058s]
Writing 'userdata'                                 OKAY [  0.348s]
Sending sparse 'userdata' 4/7 (262041 KB)          OKAY [ 31.991s]
Writing 'userdata'                                 OKAY [  0.225s]
Sending sparse 'userdata' 5/7 (254590 KB)          OKAY [ 31.014s]
Writing 'userdata'                                 OKAY [  0.161s]
Sending sparse 'userdata' 6/7 (262141 KB)          OKAY [  8.077s]
Writing 'userdata'                                 OKAY [  0.143s]
Sending sparse 'userdata' 7/7 (163384 KB)          OKAY [  5.017s]
Writing 'userdata'                                 OKAY [  0.155s]
Finished. Total time: 136.381s

tomfitzhenry avatar Sep 15 '22 12:09 tomfitzhenry

I flashed the examples/hello image to my userdata partition, but mobile-nixos's init hangs while trying to e2fsck.

Update: I managed to get examples/hello and examples/phosh to work on google-blueline.

My issues were:

  • getting confused between slot_a and slot_b. Fixed by wiping slot_b (by first booting into twrp which has fastbootd, which seemed to be needed for fastboot erase system and fastboot erase boot).
  • mismatching boot.img between examples/hello and examples/phosh, which expect different /dev/disk/by-label/ devices, and thus stage-1 -> stage-2 failed. Fixed by ensuring that I keep boot.img and system.img consistent.

Thanks for the porting work! I noticed the NixOS boot is much faster on the Pixel 3 compared to PPP, expectedly...

tomfitzhenry avatar Sep 15 '22 14:09 tomfitzhenry

@tomfitzhenry

Hi, can you help me please see https://github.com/NixOS/mobile-nixos/issues/512 got error when try to build phosh.

thanks!

ds2k5 avatar Sep 29 '22 06:09 ds2k5

can you help me please see #512 got error when try to build phosh.

It sounds like you're referring to the phosh build error on https://github.com/NixOS/mobile-nixos/issues/512#issuecomment-1258944202

The error message "configure: error: cannot run test program while cross compiling" suggests you're attempting to cross-compile. I've never worked in a cross-compile environment.

On my x86_64 machine, to build aarch64-linux, I add --system aarch64-linux flag to nix-build (see https://github.com/NixOS/mobile-nixos/pull/511#issuecomment-1247346780 for example). This uses binfmt emulation (it runs aarch64 binaries via qemu). For this to work, your host machine will have to be configured to execute aarch64-linux binaries via QEMU. On NixOS this is boot.binfmt.emulatedSystems = [ "aarch64-linux" ];.

tomfitzhenry avatar Oct 01 '22 03:10 tomfitzhenry

hi tom,

did I understand right:

nixos-mobile/release.nix

#      } device).config.mobile.boot.stage-1.kernel.package
      } device).pkgs.callPackage ./kenel { }


run the build:

nix-build --system aarch64-linux examples/phosh --argstr device oneplus-fajita -A outputs.default

got this error:

copying path '/nix/store/5siy50wdf60ssk31757s6qa77mlxjkcm-systemd-minimal-251.4' from 'https://cache.nixos.org'...
copying path '/nix/store/9js52mr3nmyvyy1wi8f248zplfi6k437-pango-1.50.8-dev' from 'https://cache.nixos.org'...
error: a 'aarch64-linux' with features {} is required to build '/nix/store/46akwphzq6x2f1zn4rqlbbpcgjqp9mxx-99-extra.rules.drv', but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test}                                                                                                                                 

tryed with orginal release.nix

the same error

ds2k5 avatar Oct 01 '22 09:10 ds2k5

Mobile network not working on my enchilada. It did work on postmarketOS, so I guess it's not an upstream bug. ModemManager log, qmicli -d qrtr://0 --uim-get-card-status result

chuangzhu avatar Oct 01 '22 11:10 chuangzhu

@chuangzhu

how did you build the Image (phosh) for your Oneplus 6 / enchilada ?

Did you use a aarch64 VM ?

ds2k5 avatar Oct 01 '22 11:10 ds2k5

@ds2k5 I used emulated build on x86_64. I added this to my build machine:

  boot.binfmt.emulatedSystems = [ "aarch64-linux" ];

chuangzhu avatar Oct 01 '22 12:10 chuangzhu

thank you @chuangzhu

where ( path/file )to add this line:

boot.binfmt.emulatedSystems = [ "aarch64-linux" ];

ds2k5 avatar Oct 01 '22 13:10 ds2k5

@ds2k5 In the NixOS configuration. Check https://discourse.nixos.org/t/how-to-configure-qemu-binfmt-wrapper-on-a-non-nixos-machine/7879/6 if you are on a non-NixOS machine.

chuangzhu avatar Oct 01 '22 14:10 chuangzhu

thanks sorry I am a noob - did not know what you mean

using a NixOS in a VM (x86_64)

in witch file should I add this line ?

Do you mean this file (on the x86_64 VM):

mobile-nixos/examples/phosh/configuration.nix

got this error:

checking for PTHREAD_PROCESS_SHARED in pthread.h... ye
checking for pthread_mutex_timedlock... yes
[9/152] Compiling C object atk/libatk-1.0.so.0.23809.1.p/atkdocument.c.o
checking for pthread_mutexattr_setpshared... yes
checking for working PROCESS_SHARED locks... configure: error: in `/build/apr-1.7.0':
configure: error: cannot run test program while cross compiling
See `config.log' for more details
/nix/store/1b9p07z77phvv2hf6gm9f28syp39f1ag-bash-5.1-p16/bin/bash ./libtool  --tag=CXX   --mode=compile aarch64-unknown-linux-gnu-g++ -DHAVE_CONFIG_H -I. -I./gen  -I./gen -I./common -I./interfaces/cc/ -I./modules/speller/default/ -DLOCALEDIR="/nix/store/zkc1jagjxhsc430irhnss5wrpin4wymx-aspell-aarch64-unknown-linux-gnu-0.60.8/share/locale"   -g -O2 -fno-exceptions -c -o modules/speller/default/phonetic.lo modules/speller/default/phonetic.cpp
libtool: compile:  aarch64-unknown-linux-gnu-g++ -DHAVE_CONFIG_H -I. -I./gen -I./gen -I./common -I./interfaces/cc/ -I./modules/speller/default/ -DLOCALEDIR=/nix/store/zkc1jagjxhsc430irhnss5wrpin4wymx-aspell-aarch64-unknown-linux-gnu-0.60.8/share/locale -g -O2 -fno-exceptions -c modules/speller/default/phonetic.cpp  -fPIC -DPIC -o modules/speller/default/.libs/phonetic.o
[10/152] Compiling C object atk/libatk-1.0.so.0.23809.1.p/atkeditabletext.c.o
error: builder for '/nix/store/9ayc9l2ip0c7qw4w1g321zl8kx9xdd5w-apr-aarch64-unknown-linux-gnu-1.7.0.drv' failed with exit code 1;
       last 10 log lines:
       > checking for LOCK_EX in sys/file.h... yes
       > checking for F_SETLK in fcntl.h... yes
       > checking for SEM_UNDO in sys/sem.h... yes
       > checking for POLLIN in poll.h sys/poll.h... yes
       > checking for PTHREAD_PROCESS_SHARED in pthread.h... yes
       > checking for pthread_mutex_timedlock... yes
       > checking for pthread_mutexattr_setpshared... yes
       > checking for working PROCESS_SHARED locks... configure: error: in `/build/apr-1.7.0':
       > configure: error: cannot run test program while cross compiling
       > See `config.log' for more details
       For full logs, run 'nix log /nix/store/9ayc9l2ip0c7qw4w1g321zl8kx9xdd5w-apr-aarch64-unknown-linux-gnu-1.7.0.drv'.
error: 1 dependencies of derivation '/nix/store/6qh312vfmj4fnxp7j5ljrqb5kx4khpvq-apache-httpd-aarch64-unknown-linux-gnu-2.4.54.drv' failed to build                       
building '/nix/store/q2a4ymy9djm185mkc1dsw7zxjgqqal15-atk-aarch64-unknown-linux-gnu-2.38.0.drv'...
error: 1 dependencies of derivation '/nix/store/5r37gfcyl4hxmp1q6qwqki0r0hdc28ln-gnome-user-share-aarch64-unknown-linux-gnu-3.34.0.drv' failed to build                   
error: 1 dependencies of derivation '/nix/store/igv4sjphc4f7lwh6fpxnvx114ryhrg4z-gnome-control-center-aarch64-unknown-linux-gnu-42.3.drv' failed to build                 
error: 1 dependencies of derivation '/nix/store/rcjds728gh5pw4ri0snz12pg5fl81i27-system-generators.drv' failed to build
error: 1 dependencies of derivation '/nix/store/jc94yrf4gf4w3hph4nn5xhivi4k26qkj-system-path.drv' failed to build
error (ignored): error: cannot unlink '/tmp/nix-build-atk-2.38.0.drv-1': Directory not empty
error: 1 dependencies of derivation '/nix/store/dbcgahbffnq8hwjk1m8b0hcl34pwkz25-nixos-system-nixos-22.11pre-git.drv' failed to build                                     
error: 1 dependencies of derivation '/nix/store/ng1w4j5cna6v3lf68f4mmidz4kv12iap-closure-info.drv' failed to build
building '/nix/store/565qcrbv567ccrklmdgjapssrka1n8n7-mobile-nixos_oneplus-fajita_boot.img.drv'...
error: 1 dependencies of derivation '/nix/store/8vjqdlp2ggwxz7fd3ckdfqgxbj5q0f8g-partition-NIXOS_SYSTEM.drv' failed to build
error: 1 dependencies of derivation '/nix/store/iayzxq4y5rkvssvv66zrsli28ss5g50n-android-fastboot-images-oneplus-fajita.drv' failed to build             


ds2k5 avatar Oct 01 '22 14:10 ds2k5

@chuangzhu

Mobile network not working on my enchilada. It did work on postmarketOS, so I guess it's not an upstream bug. ModemManager log, qmicli -d qrtr://0 --uim-get-card-status result

This is odd, I verified mobile data on enchilada successfully on my end. On the unmodified phosh example system even.

samueldr avatar Oct 01 '22 18:10 samueldr

Tried example/phosh, same result.

chuangzhu avatar Oct 02 '22 20:10 chuangzhu

Tried example/phosh, same result.

ok thanks.... then I will use my aarch64 vm to build

ds2k5 avatar Oct 02 '22 21:10 ds2k5

Raced the generic changes out of this PR into master. We're left with a bit less to actually review here.

Note that I've added an update to 6.0.0, but it shouldn't be merged until they themselves tag it.

samueldr avatar Oct 16 '22 06:10 samueldr

Mobile network not working on my enchilada. It did work on postmarketOS, so I guess it's not an upstream bug. ModemManager log, qmicli -d qrtr://0 --uim-get-card-status result

By turning CONFIG_USB_NET_QMI_WWAN and CONFIG_USB_SERIAL_QUALCOMM on, mobile network works on my enchilada. This is my current config.aarch64.

chuangzhu avatar Oct 20 '22 15:10 chuangzhu

This is odd, I just verified, with the current state of this PR as of 1648db0bec4fc18b064a3159228aef5373eac13f I definitely can connect through NetworkManager to my mobile plan. I'm online, Wi-Fi disabled, IP verified to be mobile provider. Right now I'm not checking against phosh, but that was how I originally tested.


To remove all doubts of differences, have you followed the instructions from the README and (sorry, it's an annoying process) flashed a full OOS 11, updated it to the max, used the LineageOS firmware copy script?

Then, I usually fastboot flash --slot=all boot ..., just to completely abstract away the existence of A/B on my test runs.


@mn-enchilada /etc/nixos 1 $ zcat /proc/config.gz | grep 'CONFIG_USB_\(NET_QMI\|SERIAL_QUALCOMM\)'
# CONFIG_USB_NET_QMI_WWAN is not set
# CONFIG_USB_SERIAL_QUALCOMM is not set

Furthermore, the modem is absolutely not on a USB bus, so I'm pretty confident it wouldn't matter here.


Did a new full reboot cycle, and this time I had to restart ModemManager once for it to work, here's the segment at the tail end when it failed

Though it seems to differ from what you have.

Oct 21 02:26:35 mn-enchilada ModemManager[1065]: transaction 0x13 aborted, but message is not abortable                                                                        
Oct 21 02:26:35 mn-enchilada ModemManager[1065]: transaction 0x14 aborted, but message is not abortable                                                                        
Oct 21 02:26:35 mn-enchilada ModemManager[1065]: transaction 0x15 aborted, but message is not abortable                                                                        
Oct 21 02:26:43 mn-enchilada ModemManager[1065]: <warn>  [modem0] modem couldn't be initialized: Couldn't check unlock status: Couldn't get SIM lock status after 6 retries    
Oct 21 02:26:43 mn-enchilada ModemManager[1065]: <warn>  [modem0] couldn't initialize: 'Operation was cancelled'                                                               
Oct 21 02:26:46 mn-enchilada ModemManager[1065]: <info>  [modem1] state changed (unknown -> locked)                                                                            
Oct 21 02:26:46 mn-enchilada ModemManager[1065]: <warn>  [modem1] modem couldn't be initialized: Couldn't check unlock status: QMI operation failed: GW primary session index u
nknown                                                                                                                                                                         
Oct 21 02:26:46 mn-enchilada ModemManager[1065]: <info>  [modem1] state changed (locked -> failed)                                                                             
Oct 21 02:26:46 mn-enchilada ModemManager[1065]: <warn>  [modem1] couldn't open ports during Modem SIM hot swap enabling: Couldn't get primary port
Oct 21 02:26:46 mn-enchilada ModemManager[1065]: <error> [modem1] SIM is missing and SIM hot swap is configured, but ports are not opened.

samueldr avatar Oct 21 '22 06:10 samueldr

Odd, I git checkout -- .-ed the changes, built and flashed again, mobile network still works. Then I flashed the previously built bootimg (kernel 5.19.7), it does not work. I did use fastboot flash --slot=all boot to flash. The only difference I can tell is that the working one is built in a real aarch64-linux environment, while the 5.19.7 one is built using boot.binfmt.emulatedSystems on x86_64-linux.

Will do a nix-collect-garbage and build again to check.

chuangzhu avatar Oct 21 '22 06:10 chuangzhu

That is odd.

I'll note that I cross-compile the boot image, real cross-compilation.

samueldr avatar Oct 21 '22 06:10 samueldr

With this latest change set, marking the current slot as bootable is implemented. This is feature complete (AFAIK).

samueldr avatar Oct 22 '22 01:10 samueldr

Will do a nix-collect-garbage and build again to check.

Seems like emulated build is not to blame. Anyway, it runs on my enchilada. WiFi, mobile network, bluetooth, battery charger works well.

chuangzhu avatar Oct 22 '22 06:10 chuangzhu

Is camera and phone call supported on enchilada now?

Ninlives avatar Oct 26 '22 16:10 Ninlives

Camera likely doesn't work for the moment, but I'm under the impression there is work going on for that?

Calls/SMS weren't tested yet. SMS should work, as upstream states it will.

I believe call audio might not work for now.

samueldr avatar Oct 26 '22 18:10 samueldr

Ubuntu Touch reports to support most of OP6 functionality, may be we can have a look at their repository?

Ninlives avatar Oct 27 '22 02:10 Ninlives

Ubuntu Touch relies on Halium to run the vendor userspace blobs, and then relies on the vendor kernel

  • https://gitlab.com/ubports/porting/community-ports/android9/oneplus-6/kernel-oneplus-sdm845

It's a different approach and won't work here. It's basically running just enough Android to make things work.

samueldr avatar Oct 27 '22 03:10 samueldr

Oh, seems we still have a long way to go :P

Ninlives avatar Oct 27 '22 05:10 Ninlives