Commit 244e083d5d0a35b755f1181871ce1f2522332773
Committed by
Ye Li
1 parent
745e43f852
Exists in
smarc_8mm-imx_v2018.03_4.14.98_2.0.0_ga
and in
5 other branches
MA-11948 [Android] Support flash bootloader to target device
Sometimes we need flash bootloader to other mmc device instead of the current one. Support flash bootloader to the device which is specified by 'target_ubootdev' environment variable, fall back to default one if 'target_ubootdev' is not set. Change-Id: I5dd796aaa7b46e5209f245aa8131e4cac90ed086 Signed-off-by: Luo Ji <ji.luo@nxp.com> (cherry picked from commit f80ce90aab1cffde391782f6a3adb914433dc52b)
Showing 1 changed file with 37 additions and 9 deletions Side-by-side Diff
drivers/usb/gadget/f_fastboot.c
... | ... | @@ -859,7 +859,40 @@ |
859 | 859 | printf("flash backup gpt image successfully\n"); |
860 | 860 | return 0; |
861 | 861 | } |
862 | +static int get_fastboot_target_dev(char *mmc_dev, struct fastboot_ptentry *ptn) | |
863 | +{ | |
864 | + int dev = 0; | |
865 | + struct mmc *target_mmc; | |
862 | 866 | |
867 | + /* Support flash bootloader to mmc 'target_ubootdev' devices, if the | |
868 | + * 'target_ubootdev' env is not set just flash bootloader to current | |
869 | + * mmc device. | |
870 | + */ | |
871 | + if ((!strncmp(ptn->name, FASTBOOT_PARTITION_BOOTLOADER, | |
872 | + sizeof(FASTBOOT_PARTITION_BOOTLOADER))) && | |
873 | + (env_get("target_ubootdev"))) { | |
874 | + dev = simple_strtoul(env_get("target_ubootdev"), NULL, 10); | |
875 | + target_mmc = find_mmc_device(dev); | |
876 | + if ((target_mmc == NULL) || mmc_init(target_mmc)) { | |
877 | + printf("MMC card init failed!\n"); | |
878 | + return -1; | |
879 | + } else { | |
880 | + printf("Flash target is mmc%d\n", dev); | |
881 | + if (target_mmc->part_config != MMCPART_NOAVAILABLE) | |
882 | + sprintf(mmc_dev, "mmc dev %x %x", dev, /*slot no*/ | |
883 | + FASTBOOT_MMC_BOOT_PARTITION_ID/*part no*/); | |
884 | + else | |
885 | + sprintf(mmc_dev, "mmc dev %x", dev); | |
886 | + } | |
887 | + } else if (ptn->partition_id != FASTBOOT_MMC_NONE_PARTITION_ID) | |
888 | + sprintf(mmc_dev, "mmc dev %x %x", | |
889 | + fastboot_devinfo.dev_id, /*slot no*/ | |
890 | + ptn->partition_id /*part no*/); | |
891 | + else | |
892 | + sprintf(mmc_dev, "mmc dev %x", | |
893 | + fastboot_devinfo.dev_id /*slot no*/); | |
894 | + return 0; | |
895 | +} | |
863 | 896 | static void process_flash_mmc(const char *cmdbuf) |
864 | 897 | { |
865 | 898 | if (download_bytes) { |
... | ... | @@ -905,14 +938,9 @@ |
905 | 938 | int mmcret; |
906 | 939 | |
907 | 940 | printf("writing to partition '%s'\n", ptn->name); |
908 | - | |
909 | - if (ptn->partition_id != FASTBOOT_MMC_NONE_PARTITION_ID) | |
910 | - sprintf(mmc_dev, "mmc dev %x %x", | |
911 | - fastboot_devinfo.dev_id, /*slot no*/ | |
912 | - ptn->partition_id /*part no*/); | |
913 | - else | |
914 | - sprintf(mmc_dev, "mmc dev %x", | |
915 | - fastboot_devinfo.dev_id /*slot no*/); | |
941 | + /* Get target flash device. */ | |
942 | + if (get_fastboot_target_dev(mmc_dev, ptn) != 0) | |
943 | + return; | |
916 | 944 | |
917 | 945 | if (!is_raw_partition(ptn) && |
918 | 946 | is_sparse_image(interface.transfer_buffer)) { |