hc
2023-11-06 9df731a176aab8e03b984b681b1bea01ccff6644
u-boot/arch/arm/mach-rockchip/board.c
....@@ -56,6 +56,10 @@
5656
5757 DECLARE_GLOBAL_DATA_PTR;
5858
59
+#ifdef CONFIG_ARM64
60
+static ulong orig_images_ep;
61
+#endif
62
+
5963 __weak int rk_board_late_init(void)
6064 {
6165 return 0;
....@@ -246,30 +250,48 @@
246250 static int boot_from_udisk(void)
247251 {
248252 struct blk_desc *desc;
249
- char *devtype;
250
- char *devnum;
251
-
252
- devtype = env_get("devtype");
253
- devnum = env_get("devnum");
253
+ struct udevice *dev;
254
+ int devnum = -1;
255
+ char buf[32];
254256
255257 /* Booting priority: mmc1 > udisk */
256
- if (!strcmp(devtype, "mmc") && !strcmp(devnum, "1"))
258
+ if (!strcmp(env_get("devtype"), "mmc") && !strcmp(env_get("devnum"), "1"))
257259 return 0;
258260
259261 if (!run_command("usb start", -1)) {
260
- desc = blk_get_devnum_by_type(IF_TYPE_USB, 0);
261
- if (!desc) {
262
- printf("No usb device found\n");
262
+ for (blk_first_device(IF_TYPE_USB, &dev);
263
+ dev;
264
+ blk_next_device(&dev)) {
265
+ desc = dev_get_uclass_platdata(dev);
266
+ printf("Scanning usb %d ...\n", desc->devnum);
267
+ if (desc->type == DEV_TYPE_UNKNOWN)
268
+ continue;
269
+
270
+ if (desc->lba > 0L && desc->blksz > 0L) {
271
+ devnum = desc->devnum;
272
+ break;
273
+ }
274
+ }
275
+ if (devnum < 0) {
276
+ printf("No usb mass storage found\n");
263277 return -ENODEV;
264278 }
265279
266
- if (!run_command("rkimgtest usb 0", -1)) {
280
+ desc = blk_get_devnum_by_type(IF_TYPE_USB, devnum);
281
+ if (!desc) {
282
+ printf("No usb %d found\n", devnum);
283
+ return -ENODEV;
284
+ }
285
+
286
+ snprintf(buf, 32, "rkimgtest usb %d", devnum);
287
+ if (!run_command(buf, -1)) {
288
+ snprintf(buf, 32, "%d", devnum);
267289 rockchip_set_bootdev(desc);
268290 env_set("devtype", "usb");
269
- env_set("devnum", "0");
270
- printf("Boot from usb 0\n");
291
+ env_set("devnum", buf);
292
+ printf("=== Booting from usb %d ===\n", devnum);
271293 } else {
272
- printf("No usb dev 0 found\n");
294
+ printf("No available udisk image on usb %d\n", devnum);
273295 return -ENODEV;
274296 }
275297 }
....@@ -358,6 +380,8 @@
358380 static void cmdline_handle(void)
359381 {
360382 struct blk_desc *dev_desc;
383
+ int if_type;
384
+ int devnum;
361385
362386 param_parse_pubkey_fuse_programmed();
363387
....@@ -373,19 +397,51 @@
373397 * rockchip_get_boot_mode() actually only read once,
374398 * we need to update boot mode according to udisk BCB.
375399 */
376
- if ((dev_desc->if_type == IF_TYPE_MMC && dev_desc->devnum == 1) ||
377
- (dev_desc->if_type == IF_TYPE_USB && dev_desc->devnum == 0)) {
400
+ if_type = dev_desc->if_type;
401
+ devnum = dev_desc->devnum;
402
+ if ((if_type == IF_TYPE_MMC && devnum == 1) || (if_type == IF_TYPE_USB)) {
378403 if (get_bcb_recovery_msg() == BCB_MSG_RECOVERY_RK_FWUPDATE) {
379
- if (dev_desc->if_type == IF_TYPE_MMC && dev_desc->devnum == 1) {
404
+ if (if_type == IF_TYPE_MMC && devnum == 1) {
380405 env_update("bootargs", "sdfwupdate");
381
- } else if (dev_desc->if_type == IF_TYPE_USB && dev_desc->devnum == 0) {
406
+ } else if (if_type == IF_TYPE_USB) {
382407 env_update("bootargs", "usbfwupdate");
383408 env_set("reboot_mode", "recovery-usb");
384409 }
385410 } else {
386
- if (dev_desc->if_type == IF_TYPE_USB && dev_desc->devnum == 0)
411
+ if (if_type == IF_TYPE_USB)
387412 env_set("reboot_mode", "normal");
388413 }
414
+ }
415
+
416
+ if (rockchip_get_boot_mode() == BOOT_MODE_QUIESCENT)
417
+ env_update("bootargs", "androidboot.quiescent=1 pwm_bl.quiescent=1");
418
+}
419
+
420
+static void scan_run_cmd(void)
421
+{
422
+ char *config = CONFIG_ROCKCHIP_CMD;
423
+ char *cmd, *key;
424
+
425
+ key = strchr(config, ' ');
426
+ if (!key)
427
+ return;
428
+
429
+ cmd = strdup(config);
430
+ cmd[key - config] = 0;
431
+ key++;
432
+
433
+ if (!strcmp(key, "-")) {
434
+ run_command(cmd, 0);
435
+ } else {
436
+#ifdef CONFIG_DM_KEY
437
+ ulong map;
438
+
439
+ map = simple_strtoul(key, NULL, 10);
440
+ if (key_is_pressed(key_read(map))) {
441
+ printf("## Key<%ld> pressed... run cmd '%s'\n", map, cmd);
442
+ run_command(cmd, 0);
443
+ }
444
+#endif
389445 }
390446 }
391447
....@@ -398,7 +454,7 @@
398454 rockchip_set_serialno();
399455 #endif
400456 setup_download_mode();
401
-
457
+ scan_run_cmd();
402458 #ifdef CONFIG_ROCKCHIP_USB_BOOT
403459 boot_from_udisk();
404460 #endif
....@@ -406,7 +462,8 @@
406462 charge_display();
407463 #endif
408464 #ifdef CONFIG_DRM_ROCKCHIP
409
- rockchip_show_logo();
465
+ if (rockchip_get_boot_mode() != BOOT_MODE_QUIESCENT)
466
+ rockchip_show_logo();
410467 #endif
411468 #ifdef CONFIG_ROCKCHIP_EINK_DISPLAY
412469 rockchip_eink_show_uboot_logo();
....@@ -458,57 +515,31 @@
458515 printf("Cmd interface: disabled\n");
459516 }
460517
461
-#if defined(CONFIG_MTD_BLK) && defined(CONFIG_USING_KERNEL_DTB)
462
-static void board_mtd_blk_map_partitions(void)
463
-{
464
- struct blk_desc *dev_desc;
465
-
466
- dev_desc = rockchip_get_bootdev();
467
- if (dev_desc)
468
- mtd_blk_map_partitions(dev_desc);
469
-}
470
-#endif
471
-
472518 int board_init(void)
473519 {
474520 board_debug_init();
475
- /* optee select security level */
476
-#ifdef CONFIG_OPTEE_CLIENT
477
- trusty_select_security_level();
478
-#endif
479
-
480521 #ifdef DEBUG
481522 soc_clk_dump();
482523 #endif
483
-
484
-#ifdef CONFIG_USING_KERNEL_DTB
485
-#ifdef CONFIG_MTD_BLK
486
- board_mtd_blk_map_partitions();
524
+#ifdef CONFIG_OPTEE_CLIENT
525
+ trusty_select_security_level();
487526 #endif
527
+#ifdef CONFIG_USING_KERNEL_DTB
488528 init_kernel_dtb();
489529 #endif
490530 early_download();
491531
492
- /*
493
- * pmucru isn't referenced on some platforms, so pmucru driver can't
494
- * probe that the "assigned-clocks" is unused.
495
- */
496532 clks_probe();
497533 #ifdef CONFIG_DM_REGULATOR
498
- if (regulators_enable_boot_on(is_hotkey(HK_REGULATOR)))
499
- debug("%s: Can't enable boot on regulator\n", __func__);
534
+ regulators_enable_boot_on(is_hotkey(HK_REGULATOR));
500535 #endif
501
-
502536 #ifdef CONFIG_ROCKCHIP_IO_DOMAIN
503537 io_domain_init();
504538 #endif
505
-
506539 set_armclk_rate();
507
-
508540 #ifdef CONFIG_DM_DVFS
509541 dvfs_init(true);
510542 #endif
511
-
512543 #ifdef CONFIG_ANDROID_AB
513544 if (ab_decrease_tries())
514545 printf("Decrease ab tries count fail!\n");
....@@ -537,6 +568,10 @@
537568 /* Common fixup for DRM */
538569 #ifdef CONFIG_DRM_ROCKCHIP
539570 rockchip_display_fixup(blob);
571
+#endif
572
+
573
+#ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION
574
+ vendor_storage_fixup(blob);
540575 #endif
541576
542577 return rk_board_fdt_fixup(blob);
....@@ -603,6 +638,9 @@
603638 * But relocation is in board_quiesce_devices() until all decompress
604639 * done, mainly for saving boot time.
605640 */
641
+
642
+ orig_images_ep = images->ep;
643
+
606644 if (data[10] == 0x00) {
607645 if (round_down(images->ep, SZ_2M) != images->ep)
608646 images->ep = round_down(images->ep, SZ_2M);
....@@ -736,9 +774,10 @@
736774 return boot_flags;
737775 }
738776
739
-#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
740
-#include <fdt_support.h>
777
+#if defined(CONFIG_USB_GADGET)
741778 #include <usb.h>
779
+#if defined(CONFIG_USB_GADGET_DWC2_OTG)
780
+#include <fdt_support.h>
742781 #include <usb/dwc2_udc.h>
743782
744783 static struct dwc2_plat_otg_data otg_data = {
....@@ -808,7 +847,17 @@
808847 {
809848 return 0;
810849 }
811
-#endif
850
+#elif defined(CONFIG_USB_DWC3_GADGET) /* CONFIG_USB_GADGET_DWC2_OTG */
851
+#include <dwc3-uboot.h>
852
+
853
+int board_usb_cleanup(int index, enum usb_init_type init)
854
+{
855
+ dwc3_uboot_exit(index);
856
+ return 0;
857
+}
858
+
859
+#endif /* CONFIG_USB_DWC3_GADGET */
860
+#endif /* CONFIG_USB_GADGET */
812861
813862 static void bootm_no_reloc(void)
814863 {
....@@ -1049,15 +1098,13 @@
10491098 #endif
10501099 #ifdef CONFIG_ARM64
10511100 bootm_headers_t *bootm_images = (bootm_headers_t *)images;
1052
- ulong kernel_addr;
10531101
10541102 /* relocate kernel after decompress cleanup */
1055
- kernel_addr = env_get_ulong("kernel_addr_r", 16, 0);
1056
- if (kernel_addr != bootm_images->ep) {
1057
- memmove((char *)bootm_images->ep, (const char *)kernel_addr,
1103
+ if (orig_images_ep && orig_images_ep != bootm_images->ep) {
1104
+ memmove((char *)bootm_images->ep, (const char *)orig_images_ep,
10581105 bootm_images->os.image_len);
10591106 printf("== DO RELOCATE == Kernel from 0x%08lx to 0x%08lx\n",
1060
- kernel_addr, bootm_images->ep);
1107
+ orig_images_ep, bootm_images->ep);
10611108 }
10621109 #endif
10631110
....@@ -1109,16 +1156,39 @@
11091156 #endif
11101157 }
11111158
1112
-#ifdef CONFIG_ENVF
1113
- char * sys_bootargs;
1159
+#if defined(CONFIG_ENVF) || defined(CONFIG_ENV_PARTITION)
1160
+ char *part_type[] = { "mtdparts", "blkdevparts" };
1161
+ char *part_list;
1162
+ char *env;
1163
+ int id = 0;
11141164
1115
- sys_bootargs = env_get("sys_bootargs");
1116
- if (sys_bootargs) {
1117
- env_update("bootargs", sys_bootargs);
1165
+ env = env_get(part_type[id]);
1166
+ if (!env)
1167
+ env = env_get(part_type[++id]);
1168
+ if (env) {
1169
+ if (!strstr(env, part_type[id])) {
1170
+ part_list = calloc(1, strlen(env) + strlen(part_type[id]) + 2);
1171
+ if (part_list) {
1172
+ strcat(part_list, part_type[id]);
1173
+ strcat(part_list, "=");
1174
+ strcat(part_list, env);
1175
+ }
1176
+ } else {
1177
+ part_list = env;
1178
+ }
1179
+ env_update("bootargs", part_list);
11181180 if (dump)
1119
- printf("## sys_bootargs: %s\n\n", sys_bootargs);
1181
+ printf("## parts: %s\n\n", part_list);
1182
+ }
1183
+
1184
+ env = env_get("sys_bootargs");
1185
+ if (env) {
1186
+ env_update("bootargs", env);
1187
+ if (dump)
1188
+ printf("## sys_bootargs: %s\n\n", env);
11201189 }
11211190 #endif
1191
+
11221192 #ifdef CONFIG_MTD_BLK
11231193 if (!env_get("mtdparts")) {
11241194 char *mtd_par_info = mtd_part_parse(NULL);
....@@ -1129,6 +1199,10 @@
11291199 }
11301200 }
11311201 #endif
1202
+
1203
+#ifdef CONFIG_ANDROID_AB
1204
+ ab_update_root_partition();
1205
+#endif
11321206 /*
11331207 * Initrd fixup: remove unused "initrd=0x...,0x...",
11341208 * this for compatible with legacy parameter.txt