Skip to content

Commit 42160f3

Browse files
committed
fix: booting stock kernel on moto sanders
Also adds ability to override dt matching algoirthm
1 parent 7d94961 commit 42160f3

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

lk2nd/device/2nd/gpl/motorola-unit-info.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#define SMEM_KERNEL_RESERVE SMEM_ID_VENDOR0
1414
#define SMEM_KERNEL_RESERVE_SIZE 1024
1515

16-
static uint32_t prod_id;
17-
static const struct mmi_unit_info *mmi_unit_info;
16+
uint32_t mmi_prod_id = 0;
17+
const struct mmi_unit_info *mmi_unit_info = NULL;
1818

1919
static void readprop_u32(const void *dtb, int node, const char *name, uint32_t *val) {
2020
int len;
@@ -30,7 +30,7 @@ static void print_unit_info(const struct mmi_unit_info *info)
3030
dprintf(INFO, "Motorola unit info v%d: prod_id=%#04x, rev=%#04x, serial=%#08x%08x, "
3131
"machine='%s', barcode='%s', carrier='%s', baseband='%s', device='%s', "
3232
"radio='%s' (%#x), powerup_reason=%#08x\n",
33-
info->version, prod_id, info->system_rev, info->system_serial_high, info->system_serial_low,
33+
info->version, mmi_prod_id, info->system_rev, info->system_serial_high, info->system_serial_low,
3434
info->machine, info->barcode, info->carrier, info->baseband, info->device,
3535
info->radio_str, info->radio, info->powerup_reason);
3636
}
@@ -68,7 +68,7 @@ static int motorola_unit_info(const void *dtb, int node)
6868
memset(info, 0, SMEM_KERNEL_RESERVE_SIZE);
6969
info->version = MMI_UNIT_INFO_VER;
7070

71-
readprop_u32(dtb, chosen, "mmi,prod_id", &prod_id);
71+
readprop_u32(dtb, chosen, "mmi,prod_id", &mmi_prod_id);
7272
readprop_u32(dtb, chosen, "linux,hwrev", &info->system_rev);
7373
readprop_u32(dtb, chosen, "linux,seriallow", &info->system_serial_low);
7474
readprop_u32(dtb, chosen, "linux,serialhigh", &info->system_serial_high);

platform/msm_shared/dev_tree.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#endif
5151
#include <boot_stats.h>
5252
#include <verifiedboot.h>
53+
#include "../../lk2nd/device/2nd/gpl/motorola-unit-info.h"
5354

5455
#define NODE_PROPERTY_MAX_LEN 64
5556
#define ADD_OF(a, b) (UINT_MAX - b > a) ? (a + b) : UINT_MAX
@@ -1452,6 +1453,25 @@ int dev_tree_validate(struct dt_table *table, unsigned int page_size, uint32_t *
14521453
return 0;
14531454
}
14541455

1456+
static bool is_stock_match(struct dt_entry *cur_dt_entry)
1457+
{
1458+
// Stock Motorola devices use a different way to match the DTB.
1459+
{
1460+
extern const uint32_t mmi_prod_id;
1461+
extern const struct mmi_unit_info *mmi_unit_info;
1462+
1463+
if (mmi_unit_info != NULL && mmi_prod_id != 0) {
1464+
if (cur_dt_entry) {
1465+
if (cur_dt_entry->variant_id == mmi_prod_id &&
1466+
cur_dt_entry->board_hw_subtype == mmi_unit_info->system_rev) {
1467+
return true;
1468+
}
1469+
}
1470+
}
1471+
}
1472+
return false;
1473+
}
1474+
14551475
static int platform_dt_absolute_match(struct dt_entry *cur_dt_entry, struct dt_entry_node *dt_list)
14561476
{
14571477
uint32_t cur_dt_hlos_ddr;
@@ -1498,18 +1518,21 @@ static int platform_dt_absolute_match(struct dt_entry *cur_dt_entry, struct dt_e
14981518
* 2. find the matched DTB then return 1
14991519
* 3. otherwise return 0
15001520
*/
1501-
if(!((cur_dt_msm_id == (board_platform_id() & 0x0000ffff)) &&
1521+
if ((
1522+
!((cur_dt_msm_id == (board_platform_id() & 0x0000ffff)) &&
15021523
(cur_dt_hw_platform == board_hardware_id()) &&
15031524
(cur_dt_hw_subtype == board_hardware_subtype()) &&
15041525
(cur_dt_hlos_ddr == (target_get_hlos_subtype() & 0x700)) &&
1505-
((cur_dt_entry->variant_id & 0x00ffff00) <= (board_target_id() & 0x00ffff00))))
1526+
((cur_dt_entry->variant_id & 0x00ffff00) <= (board_target_id() & 0x00ffff00)))) &&
1527+
!is_stock_match(cur_dt_entry))
15061528
return 0;
1507-
if (
1529+
if ((
15081530
(cur_dt_entry->soc_rev <= board_soc_version()) &&
15091531
((cur_dt_entry->pmic_rev[0] & 0x00ffff00) <= (board_pmic_target(0) & 0x00ffff00)) &&
15101532
((cur_dt_entry->pmic_rev[1] & 0x00ffff00) <= (board_pmic_target(1) & 0x00ffff00)) &&
15111533
((cur_dt_entry->pmic_rev[2] & 0x00ffff00) <= (board_pmic_target(2) & 0x00ffff00)) &&
1512-
((cur_dt_entry->pmic_rev[3] & 0x00ffff00) <= (board_pmic_target(3) & 0x00ffff00))) {
1534+
((cur_dt_entry->pmic_rev[3] & 0x00ffff00) <= (board_pmic_target(3) & 0x00ffff00))) ||
1535+
is_stock_match(cur_dt_entry)) {
15131536

15141537
#if WITH_LK2ND_DEVICE
15151538
if (!dt_list)

0 commit comments

Comments
 (0)