Skip to content

Conversation

@me-cafebabe
Copy link
Contributor

For example, in dev_tree_appended() path, platform_dt_absolute_match() filters the dtbs with matching ids, and this compatible matching logic will prefer the first of these filtered dtbs with matching compatible

The compatible matching logic is useful when the user wants to boot from boot.img containing mainline kernel and multiple devices' dtb (which shares qcom,board-id)

@me-cafebabe me-cafebabe force-pushed the main branch 2 times, most recently from b5825ca to f7f6afe Compare August 18, 2025 16:57
Copy link
Member

@TravMurav TravMurav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! First of all, I'm sorry for not replying to this earlier.

Overall the idea sounds fine to me, but see one comment below. Aside from that:

Fixes linking errors when building an image with a more serious
toolchain

Could you help me understand in which case you get linking errors? i.e. what's the workflow that fails for you without adding the ifdefs?

/* Xiaomi Redmi 6 Pro (sakura) and Xiaomi Mi A2 Lite (daisy) are software compatible */
model = "Xiaomi Redmi 6 Pro";
compatible = "xiaomi,sakura";
dtb_compatible = "xiaomi,daisy";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just put daisy into the array of compatible values? This would indeed make the matching logic a bit more complicated since one'd need to iterate over all compatibles, but the compatible in the line above was kinda meant for that already. I'd strongly prefer to not have two props that do the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I've only moved it to the second element instead of doing iterating though, but that's fine until when more elements will have to be added (really?) i guess?

@me-cafebabe
Copy link
Contributor Author

Could you help me understand in which case you get linking errors? i.e. what's the workflow that fails for you without adding the ifdefs?

when setting TOOLCHAIN_PREFIX to this
https://github.com/LineageOS/android_prebuilts_gcc_linux-x86_arm_arm-linux-androideabi-4.9/tree/lineage-19.1/bin

SebaUbuntu and others added 4 commits October 2, 2025 23:39
Fixes linking errors when building an image with a more serious
toolchain that complains about missing symbols

Change-Id: Icbd6243f428b3fe0b4a0576ca3c143487dfada2a
Change-Id: I858e29b8e74648a13289966b96de1360fa0e554a
…nd dtb

Makes sure we load the correct dtb node based on lk2nd's device
selection logic when boot.img contains multiple dtbs with same ids.

For example, on msm8953-xiaomi-common.dts, we see 3 devices sharing
the same msm-id and board-id. If a given boot.img contains dtbs for
all these devices, without this logic lk2nd will always load the
first of these dtbs, regardless of the device it's being run on.

Try using compatible string from the second element of lk2nd's
`compatible` property first, because there's some devices
supposed to use some other devices' dtb in mainline kernel
(e.g. xiaomi-sakura uses xiaomi-daisy dtb).

This shouldn't affect booting downstream kernels, since they normally
don't define `<vendor>,<device>` on their dts compatible.

Change-Id: Ib7ed0908038f178d34eaa6b4952691c17055c22b
… for kernel

The two devices are identical, only except a different partition scheme.

Even though we already have defined `lk2nd,dtb-files`,
we still want this because this is for matching dtb in boot.img
rather than matching filename.

Change-Id: I2ed59a3ec21c3276a4fa901dc3b06935c2aca40b

val = fdt_stringlist_get(dtb, node, "compatible", 1, &len);
if (val && len > 0)
lk2nd_dev.dtb_compatible = strndup(val, len);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I see how it's tempting to just hack things together to make your single usecase work, I think this makes the code more confusing since it's hard to understand what is the meaning of which prop, and it would violate expectations one would have of DT matching.

I.e. you're currently creating two seemingly unrelated fields in the struct, but they now suddenly are an "array" of at most two fields, used for dtb mathing. Except contrary to the usual dtb logic, if the second (less specific, fallback) compatible is present, it would be preferred, even if a more specific compatible is available.

I'd strongly prefer this to align to common dt logic, i.e. I'd expect the lk2nd_dev.compatible be changed to something like lk2nd_dev.compatibles with a setup similar to .dtbfiles, and your selection logic to iterate over all of them to find the best pick.

This will unfortunately require a slight refactoring where all uses of lk2nd_dev.compatible will have to be changed to lk2nd_dev.compatibles[0], with a bit more care taken with assignments to create a correct pointer structure.

What would I do to refactor for this implementation:

  1. Study the usage of lk2nd_dev.compatible, I believe it's mainly used in lk2nd device module for picking the dtb in case of lk1st->lk2nd boot. Based on the usage, I'd change the variable to a char** like dtbfiles, use lkfdt_stringlist_get_all to assign it in the parser, and pointer to a string literal where it's assigned at compile time/from cmdline. Then refactor all read usages like suggested above. (I'd put it as a separate refactor commit)
  2. Based on that work of refactoring lk2nd compatible list, I'd create a new function int lk2nd_is_compatible(char *compatible) that would compare a provided compatible against a list and return either -1 (no match) or an index of the provided compatible (i.e. sakura=0, daisy=1), which could be used to rank dtbs in a container by best match (i.e. loop over them and find the lowest index - that's the one to boot). This would allow you to add sakura.dtb later if you have to and keep the logic working. This funciton could also be reusable later if we ever want to implement other system containers like BLS#2 (UKI) for example.

@me-cafebabe
Copy link
Contributor Author

Okay, let's skip the two commits for the compatible thingy for now. Are the other two commits good to go in?

@TravMurav
Copy link
Member

Okay, let's skip the two commits for the compatible thingy for now. Are the other two commits good to go in?

Yes, commits 1 and 2 are fine by me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants