Advertisement

kernel:imx8qm平台下fastboot烧写spi_norflash

阅读量:

在fastboot的功能里面实现烧写flexspi的uboot到nor_flash上面

复制代码
 643 修改:

    
 644     uboot/drivers/usb/gadget/f_fastboot.c
    
 645     @@ -25,6 +25,9 @@
    
 646      #include <linux/compiler.h>
    
 647      #include <version.h>
    
 648      #include <g_dnl.h>
    
 649     +#include <spi.h>
    
 650     +#include <spi_flash.h>
    
 651     +#include <dm/device-internal.h>
    
 652      #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
    
 653      #include <fb_mmc.h>
    
 654      #endif
    
 655     @@ -234,6 +237,9 @@ static struct usb_gadget_strings *fastboot_strings[] = {
    
 656      #define TEE_HWPARTITION_ID 2
    
 657      #endif
    
 658 
    
 659         +#define ANDROID_BOOTLOADER_NOR_OFFSET  0x0        //0 offset
    
 660         +#define ANDROID_BOOTLOADER_NOR_SIZE    0x100000   //1MB size
    
 661          #define ANDROID_MBR_OFFSET         0
    
 662          #define ANDROID_MBR_SIZE           0x200
    
 663          #ifdef  CONFIG_BOOTLOADER_OFFSET_33K
    
 664     @@ -259,8 +265,11 @@ struct fastboot_device_info fastboot_devinfo;
    
 665      enum {
    
 666           PTN_GPT_INDEX = 0,
    
 667           PTN_TEE_INDEX,
    
 668 +         PTN_BOOTLOADER_NOR_INDEX,
    
 669           PTN_BOOTLOADER_INDEX,
    
 670 +         PTN_MAX_INDEX,
    
 671         };
    
 672 
    
 673           static unsigned int download_bytes_unpadded;
    
 674 
    
 675       static struct cmd_fastboot_interface interface = {
    
 676     @@ -639,6 +648,60 @@ int write_backup_gpt(void)
    
 677             return 0;
    
 678     }
    
 679 
    
 680     +int save_img_to_nor(uchar *buff, u32 start_address, size_t len)
    
 681     +{
    
 682     +#if 1
    
 683     +#ifdef CONFIG_DM_SPI_FLASH
    
 684     +       int ret = 0;
    
 685     +       unsigned int bus = 0;
    
 686     +       unsigned int cs = 0;
    
 687     +       unsigned int speed = 29000000;
    
 688     +       unsigned int mode = 0;
    
 689     +    struct spi_flash *flash;
    
 690     +       struct udevice *new, *bus_dev;
    
 691     +
    
 692     +       /* Remove the old device, otherwise probe will just be a nop */
    
 693     +       ret = spi_find_bus_and_cs(bus, cs, &bus_dev, &new);
    
 694     +       if (!ret) {
    
 695     +               device_remove(new);
    
 696     +       }
    
 697     +       flash = NULL;
    
 698     +       ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &new);
    
 699     +       if (ret) {
    
 700     +               printf("Failed to initialize SPI flash at %u:%u (error %d)\n",
    
 701     +                      bus, cs, ret);
    
 702     +               return 1;
    
 703     +       }else
    
 704     +               {
    
 705     +               printf(" Initialize SPI flash at %u:%u with speed %u; mode %u(success %d)\n",
    
 706     +                      bus, cs, speed, mode, ret);
    
 707     +               };
    
 708     +
    
 709     +       flash = dev_get_uclass_priv(new);
    
 710     +
    
 711     +       ret = spi_flash_erase(flash, start_address , len);
    
 712     +       printf("SF: %zu bytes @ %#x Erased: %s\n", (size_t)len, (u32)start_address,
    
 713     +              ret ? "ERROR" : "OK");
    
 714     +       if (ret) {
    
 715     +               printf("SPI flash erase failed\n");
    
 716     +               return 1;
    
 717     +       }
    
 718     +
    
 719     +       ret = spi_flash_write(flash, start_address, len, buff);
    
 720     +       printf("SF: %zu bytes @ %#x : Written\n", (size_t)len, (u32)start_address);
    
 721     +       if (ret) {
    
 722     +               printf("SPI flash write failed\n");
    
 723     +               return 1;
    
 724     +       }
    
 725     +#endif
    
 726     +       return ret;
    
 727     +#endif
    
 728     +    printf("save_img_to_nor back\n");
    
 729     +    return 0;
    
 730     +}
    
 731     +
    
 732     +
    
 733      static void process_flash_mmc(const char *cmdbuf)
    
 734       {
    
 735                   if (download_bytes) {
    
 736     @@ -660,6 +723,16 @@ static void process_flash_mmc(const char *cmdbuf)
    
 737                     ptn = fastboot_flash_find_ptn(cmdbuf);
    
 738                     if (ptn == NULL) {
    
 739                             fastboot_fail("partition does not exist");
    
 740     +               } else if (memcmp(ptn->name, "bootloader_nor", 14) == 0){
    
 741     +                               printf("writing to partition '%s'\n", ptn->name);
    
 742     +
    
 743     +                       if (save_img_to_nor(interface.transfer_buffer, ptn->start, ptn->length)) {
    
 744     +                               printf("Writing '%s' FAILED!\n", ptn->name);
    
 745     +                               fastboot_fail("Write partition");
    
 746     +                       } else {
    
 747     +                               printf("Writing '%s' DONE!\n", ptn->name);
    
 748     +                               fastboot_okay("OKAY");
    
 749     +                       }
    
 750                     } else if ((download_bytes >
    
 751                                ptn->length * MMC_SATA_BLOCK_SIZE) &&
    
 752                                         !(ptn->flags & FASTBOOT_PTENTRY_FLAGS_WRITE_ENV)) {
    
 753     @@ -967,7 +1040,7 @@ static int _fastboot_parts_add_ptable_entry(int ptable_index,
    
 754                     if (part_get_info(dev_desc,
    
 755                                             mmc_dos_partition_index, &info)) {
    
 756                             debug("Bad partition index:%d for partition:%s\n",
    
 757     -                      mmc_dos_partition_index, name);
    
 758     +                      mmc_dos_partition_index, (const char *)info.name);
    
 759                                          return -1;
    
 760                                                  }
    
 761                                  ptable[ptable_index].start = info.start;
    
 762     @@ -1072,6 +1145,11 @@ static int _fastboot_parts_load_from_ptable(void)
    
 763                 ptable[PTN_TEE_INDEX].partition_id = TEE_HWPARTITION_ID;
    
 764             strcpy(ptable[PTN_TEE_INDEX].fstype, "raw");
    
 765 
    
 766     +   /* Bootloader_nor */
    
 767     +    strcpy(ptable[PTN_BOOTLOADER_NOR_INDEX].name, "bootloader_nor");
    
 768     +    ptable[PTN_BOOTLOADER_NOR_INDEX].start = ANDROID_BOOTLOADER_NOR_OFFSET;
    
 769     +    ptable[PTN_BOOTLOADER_NOR_INDEX].length = ANDROID_BOOTLOADER_NOR_SIZE;
    
 770     +
    
 771         /* Bootloader */
    
 772          strcpy(ptable[PTN_BOOTLOADER_INDEX].name, FASTBOOT_PARTITION_BOOTLOADER);
    
 773          ptable[PTN_BOOTLOADER_INDEX].start =
    
 774     @@ -1085,7 +1163,7 @@ static int _fastboot_parts_load_from_ptable(void)
    
 775                 int tbl_idx;
    
 776                 int part_idx = 1;
    
 777                 int ret;
    
 778     -       for (tbl_idx = PTN_BOOTLOADER_INDEX + 1; tbl_idx < MAX_PTN; tbl_idx++) {
    
 779     +       for (tbl_idx = PTN_MAX_INDEX; tbl_idx < MAX_PTN; tbl_idx++) {
    
 780                 ret = _fastboot_parts_add_ptable_entry(tbl_idx,
    
 781                                 part_idx++,
    
 782                                 user_partition,
    
 783     @@ -1095,7 +1173,7 @@ static int _fastboot_parts_load_from_ptable(void)
    
 784                 if (ret)
    
 785                         break;
    
 786             }
    
 787     -       for (i = 0; i <= part_idx; i++)
    
 788     +       for (i = 0; i <= tbl_idx-1; i++)
    
 789                     fastboot_flash_add_ptn(&ptable[i]);
    
 790 
    
 791             return 0;
    
 792 
    
 793     uboot/drivers/mtd/spi/spi_flash_ids.c
    
 794     @@ -135,6 +135,7 @@ const struct spi_flash_info spi_flash_ids[] = {
    
 795             {"n25q1024a",      INFO(0x20bb21, 0x0,  64 * 1024,  2048, RD_FULL | WR_QPP | E_FSR | SECT_4K) },
    
 796             {"mt25qu02g",      INFO(0x20bb22, 0x0,  64 * 1024,  4096, RD_FULL | WR_QPP | E_FSR | SECT_4K) },
    
 797             {"mt25ql02g",      INFO(0x20ba22, 0x0,  64 * 1024,  4096, RD_FULL | WR_QPP | E_FSR | SECT_4K) },
    
 798     //+       {"mt35xu256aba",   INFO(0x2c5b19, 0x0, 128 * 1024,   256, E_FSR   | SECT_4K) },
    
 799     +       {"mt35xu256aba",   INFO(0x2c5b19, 0x0, 128 * 1024,   256, E_FSR) },
    
 800             {"mt35xu512aba",   INFO(0x2c5b1a, 0x0, 128 * 1024,   512, E_FSR) },
    
 801         #endif
    
 802         #ifdef CONFIG_SPI_FLASH_SST            /* SST */
    
 803 
    
 804 
    
 805     uboot/configs/mx8qm_lpddr4_vinson_android_defconfig
    
 806         @@ -45,7 +45,8 @@ CONFIG_FSL_FSPI=y
    
 807          CONFIG_DM_SPI=y
    
 808          CONFIG_DM_SPI_FLASH=y
    
 809          CONFIG_SPI_FLASH=y
    
 810         -CONFIG_SPI_FLASH_BAR=y
    
 811         +CONFIG_QSPI_BOOT=y
    
 812         +CONFIG_SPI_FLASH_4BYTES_ADDR=y
    
 813         +CONFIG_SPI_FLASH_USE_4K_SECTORS=y
    
 814          CONFIG_SPI_FLASH_STMICRO=y
    
 815          CONFIG_CMD_SF=y
    
 816 
    
 817     uboot/arch/arm/dts/fsl-imx8qm-lpddr4-vinson.dts
    
 818     @@ -398,7 +398,7 @@
    
 819     pinctrl-0 = <&pinctrl_flexspi0>;
    
 820     status = "okay";
    
 821 
    
 822     -       flash0: mt35xu512aba@0 {
    
 823     +       flash0: mt35xu256aba@0 {
    
 824                     reg = <0>;
    
 825                     #address-cells = <1>;
    
 826                     #size-cells = <1>;
    
 827 
    
 828 
    
    
    
    
    代码解释

至此,fastboot支持烧写bootloader_nor分区,并且能够正常的烧写启动。

涉及修改的是在bootloader中fastboot工具实现的数据烧写逻辑。此外,在处理setctor4k相关标记时遇到了问题。因此决定移除该标记。即每次对nor_flash进行重置操作时都会完全清除。此外,在nxp release版本中的imx8 bootloader中有关于分区显示逻辑存在一些问题。我也做了相应的调整和优化

全部评论 (0)

还没有任何评论哟~