I would like to and am trying to get pmOS running on the M8.
I can get the kernel source from here compiling with the gou_msm_fix and pmouse_base patches enabled. Using a config from the same repo here.
However I'm running into a problem when trying to bool the kernel on the device. I can flash the boot.img via pmbootstrap flasher flash_kernel but when I reboot I just boot straight into fastboot. When trying to boot the kernel directly pmboostrap flasher boot I get an error from fastboot:
I've looked at extracting the generated boot.img dtb and I get different files to when is in the TWRP image that I'm analysing (and is installed on the device). In the generated image I get 00_kernel, 01_dtbdump!htc,msm8974.dtb and 02_dtbdump.dtb and in the TWRP image 00_kernel and 01_dtbdump.dtb. However on both attempts when using extract-dtb i get an error about extracting the dtbdump.dtb file:
FileNotFoundError: [Errno 2] No such file or directory: 'dtb/02_dtbdump.dtb' -> 'dtb/02_dtbdump_M8_XB/XC.dtb' for the generated image and:
FileNotFoundError: [Errno 2] No such file or directory: 'dtb/01_dtbdump.dtb' -> 'dtb/01_dtbdump_GLU_WLJ_XA_v2.0/1.dtb' for the TWRP image.
Also because of my device being S-On I can't flash the system partition from fastboot, but using the Android recovery I seem to be able to. But can't really test whether that actually works because of the above issues.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items ...
Show closed items
Linked items 0
Link issues together to show that they're related.
Learn more.
@fooforever: Thanks for creating this detailed issue!
@osm0sis: you have quite some knowledge about all the boot.img formats. Maybe you can answer these questions if you have a minute:
Is there anything special about the HTC devices (the One M8 specifically), that we need to look out for regarding boot.img and dtb files?
Looks like the extract-dtb tool we use can't handle extracting these dtb files. Can you recommend us a tool (or could author @PabloCastellano take a look at this case and try to fix it)?
Judging from the most recent here: https://download.lineageos.org/m8, seems like a normal QCDT to me. AIK with repackimg.sh --original repacks an identical image. That's using my unpackbootimg and mkbootimg, of course.
I'm still getting the same dtb not found issue when trying to do flasher boot and still ust rebooting to fastboot after flasher flash_kernel and a reboot. I ran zap, rebuilt device and linux, then ran install. So there's something else going on here.
Just to be 100% sure that the DTB file has been attached to the kernel image, could you run pmbootstrap bootimg_analyze on the boot.img file generated by postmarketOS? (Get a shortcut to it with pmbootstrap export.)
It should give you exactly the same output as running the command on the known working boot.img file.
Just got chance to have a look at this, pulled the up to date master first then zapped and rebuild everything and I'm still having the same problem, also checking the generated boot image against the twrp one with bootimg_analyze gives the same output for both.
pmbootstrap flasher boot: "FAILED (remote: dtb not found)"
osm0sis' mkbootimg (which is the default now) had the same result
bootimg_analyze gives the same output for both boot.img files
extract-dtb fails to extract the files
Some thoughts:
After reading the extract-dtb error again: It tries to extract files to a subfolder which does not exist. Pull request https://github.com/PabloCastellano/extract-dtb/pull/4 will fix this, here is the raw extract-dtb.py script which you could download and use as standalone until we have properly integrated this change back into postmarketOS. I would be interested what happens if you run this version on both boot.img files, the one from pmOS and the one from TWRP - I guess the DTB files are different? (and there are a lot of them, a recursive diff will help with comparing them)
Not that helpful for debugging, but to work around this issue, it should be possible to use abootimg to put the postmarketOS and kernel (from pmbootstrap export) into the known working boot.img file.
So some results, still no apparently compatible image. But I've run the extract dtb script over everything and this is what I found, file listings for all the extractions here: https://pastebin.com/i3aW2q8v.
pmbootstrat seems to generate a similar but not identical dtb to the twrp image, it has a few less file and things are name/numbered differently(maybe because there are files missing?)
However when I do an aboot -u twrp.img -k /tmp/postmarketOS-export/vmlinuz-htc-m8 -r /tmp/postmarketOS-export/initramfs-htc-m8 the dtbs seem to be concatenated or at least both are included without duplicated because there are 51 files vs 36 in the twrp image and 30 in the pmos image.
Ok so I found there is a dmesg function the the HTC fastboot commands fastboot oem dmesg. After installing the pmOS image via ADB sideload from TWRP I rebooted to try and load the image but predictably got dropped back into fastboot mode. Then I ran dmesg, output here: https://pastebin.com/erKTAw92 This seems to confirm the dtb problems, with the messages stamped [3387014] to [3392359] spewing out dtb output and errors about not finding a valid device tree address. This must mean the dtb is being appended to the boot image incorrectly in some way.
Cool trick with the dmesg output and thanks for the detailed analysis of the dtb files.
However when I do an aboot -u twrp.img -k /tmp/postmarketOS-export/vmlinuz-htc-m8 -r /tmp/postmarketOS-export/initramfs-htc-m8 the dtbs seem to be concatenated or at least both are included without duplicated because there are 51 files vs 36 in the twrp image and 30 in the pmos image.
This would mean the vmlinuz file has appended dtbs... is that the case?
For the dtb files not matching up, I have two explanations:
The kernel is different, and produces different dtb files (I'd like to run some more tests before we can rule that out, see below).
Our tooling is broken and doesn't append the right dtbs to the kernel, although we are using the same source.
I'm pretty sure that the kernel sources are different when using the TWRP boot.img, but the LineageOS sources. I've tried to find the kernel sources, that the TWRP image used, but it only says "Builds with OmniROM android-5.0 tree" here and the omirom kernel repository doesn't seem to be there anymore. At least not for Android 5.0 when looking into the branches.
But we have to source to the LineageOS 14.1 kernel, which you are using. And here is a zip file, which should have a boot.img file inside, generated from these kernel sources.
I hope that the following helps with finding out more:
Can your device boot that lineageos image?
How does the output differ when using extract-dtb on that?
Does the abootimg approach work with that one?
I think we're getting closer, thanks for not giving up
The plot thickens, I pulled the lineage 15 build from here dated 18/2 which according to the thread matches extactly the commit I'm pulling sources from. This boots on the device no problem.
I can't seem to repack the kernel and ramdisk from pmos into the lineage boot.img because they are too big. BUT
Looking the the dtb extracts from the lineage boot image and the kernel generated by pmbootstrap, they're almost identical! take a look. So Ollie you were right the kernel does have a dtb already appended to it. The only thing that is different between these two dtb extracts is that number 1-5 should be 11-15 and vice versa.
So the question now is how do I stop all the other dtb files from being generated and potentially messing things up? And what determines the numbering of the files in the dtb? and do they actually matter?
So the question now is how do I stop all the other dtb files from being generated and potentially messing things up?
That can all be adjusted in the kernel's aport:
boot.img dtbs
The dtbs that get appended to the boot.img file get placed in /boot/dt.img (that's the location after you install the kernel package). And they get generated here (should be somewhere in your kernel APKBUILD):
The dtbs appended to the vmlinuz file can be configured in the menuconfig I think. From what I know, first the regular vmlinuz file gets created, and afterwards the dtbs get appended and the file gets renamed. Also in the linux APKBUILD there's a function that tries to find the correct vmlinuz file, and prefers ones with dtb files appended (because that is usually what we want). You could hardcode the file to take at this point:
# zImage (find the right one)cd"$builddir/arch/$_carch/boot"_target="$pkgdir/boot/vmlinuz-$_flavor"for _zimg in zImage-dtb Image.gz-dtb *zImage Image;do[-e"$_zimg"]||continuemsg "zImage found: $_zimg"install-Dm644"$_zimg""$_target"breakdone if![-e"$_target"];thenerror "Could not find zImage in $PWD!"return 1fi
And what determines the numbering of the files in the dtb?
Probably the naming of the files and/or folders on disk. Ideas:
you could add commands right before executing dtbTool that moves the files so they get packed in the right order
the dtbTool program used for building that is just a Python script, so you could hardcode the order there for testing
and do they actually matter?
I hope they do, since that's the best lead we have right now
I disabled packing the dtb into there kernel image by unsetting Build a concatenated zImage/dtb by default in the menuconfig. This gets me a kernel without the dtb appended as expected, which makes the extracts look almost like they should except for the numbering as mentioned above. This image still won't boot because of dtb problems and neither does the pmos kernel repacked into the lineage image. But it seems like the pmos image does better than the repacked one(dmesg. I don't know what an actual boot should look like because I can't capture the bootloader dmesg because it actually boots android and I can only get a linux dmesg. Do you think it could be the numbering? Is there anyone else around here that might know more about boot images?
Another idea for debugging would be copying the dt.img file from the extracted LineageOS boot.img to ~/.local/var/pmbootstrap/chroot_device-your-device/boot/dt.img (after pmbootstrap install).
Then you can generate a new boot.img with pmbootstrap mkinitfs (better verify that it used the right dt.img file by extracting the resulting boot.img from postmarketOS again). Maybe that gets it booting as a stop-gap solution.
If that doesn't get you anywhere, in #postmarketOS-lowlevel you might get more help by other people (e.g. McBitter, not tagging you so you don't need to read the whole thread now if the solution above is possibly helping). (And I'm still around to help out with more ideas of course, but I'm not an expert on the subject.)
If I change the dt.img with the one from the lineage boot (as above suggested) I do get a boot image that appears to get further than before. So I'm not not being dropped straight back into fastboot, but I get stuck on the boot screen. I don't get any network device show up on the pc though. Although it does re appear as a new usb device (id 0bb4:0f25) which doesn't seem to match when its in fastboot or recovery modes (with mtp and mass storage enabled, disabled). I did have to go round about to get the system image on the device (process below) so I'm not sure if that will have messed with things. This is because pmbootstrap refused to build the flashable zip after swapping out the dt.img ( I'm guessing the chroot is checksummed somewhere or something).
To get this far:
build everything as normal
make flashable zip (can't flash system from fastboot)
adb sideload system via the flashable zip
swap out the dt.img file in the chroot for the lineage os boot.img one
pmbootstrap initfs to rebuild boot.img with new dt.img
Heh, I thought skales is a person. But it's just the name of the repository, and Stephen Boyd (@bebarino) made the first commit and it seems like he's maintaining it.
@bebarino: Sorry to drag you in from the side, but we could need your advice here if you have a minute. Here's a quick summary:
@fooforever is porting the HTC One M8 to postmarketOS
The device does not boot up with our boot.img file.
When extracting the generated dt.img file, and comparing it to the one from LineageOS (who build their kernel from the same source), they are slightly different:
The only thing that is different between these two dtb extracts is that number 1-5 should be 11-15 and vice versa.
So it looks like a bug in the dtbTool, which produces the files in the wrong order.
@bebarino: What do you think about that, and do you have any advice for proceeding further?
@fooforever: I hope everything was summarized right here, please correct me if necessary.
Dtbtool from skales does a sort of all the IDs in the QCDT blob and then writes them out in a sequence. If I read this right it sounds like that sort is wrong? Is there a difference in how the sorting is done between the two versions of dtbtool?
@bebarino You sound like you might know more about this than me, does the numbering even matter? And if it does where are the IDs defined, maybe I can track down the issue
I was thinking that the qcom,msm-id and qcom,board-id and qcom,pmic-id
properties were being improperly sorted somehow and that's causing the QCDT
image to have the wrong order of dtb blobs.
I believe the order matters because those properties in each dtb blob are
used to sort the blobs into a "priority" order that the bootloader can then
run through in order to find the closest match to the hardware that the
boot.img is running on without requiring the bootloader to sort the blobs
in memory at boot.
Can you extract all those IDs and then list them next to the file names for
the dtbs? That would be useful to see what sort of ordering is happening
and if that is somehow broken.
@bebarino https://github.com/bebarino You sound like you might know
more about this than me, does the numbering even matter? And if it does
where are the IDs defined, maybe I can track down the issue
I've extracted all the individual DTBs intso DTSs the extracted all the IDs. There's 2 id fields qcom,msm-id and htc,project-id. The qcom,msm-id is exactly the same for every file, so it must be sorting on the htc,project-id field. There does seem to be something weird going on with the sort on the pmos extracted ones. The lineage dtb extracts are sorted in ascending order by the htc,project-id field but, the pmos ones don't seem to be. They have the same or very close IDs but are sorted incorrectly. Dropped the data into a spreadsheet & csv so you can have a look.
The mkbootimg in skales isn't looking at an htc,project-id property so
maybe that needs to be added into the sorting? I've never heard of that
property, but if the bootloader looks for it then it may need to be used
too.
I've extracted all the individual DTBs intso DTSs the extracted all the
IDs. There's 2 id fields qcom,msm-id and htc,project-id. The qcom,msm-id is
exactly the same for every file, so it must be sorting on the
htc,project-id field. There does seem to be something weird going on with
the sort on the pmos extracted ones. The lineage dtb extracts are sorted in
ascending order by the htc,project-id field but, the pmos ones don't seem
to be. They have the same or very close IDs but are sorted incorrectly.
Dropped the data into a spreadsheet & csv so you can have a look.
@ollieparanoid Just seen the referenced PR, would M8 be suitable for merge too? I'm using the same trick, but was waiting to get a booting kernel right out of pmbootstrap if we found a fix.
@fooforever: yep, that would be suitable. Just make sure to mention in the documentation how to work around the issue (actually that information was missing from the htc-a5ul page and I've just added it - good that you mentioned it!)