]> git.kernelconcepts.de Git - karo-tx-redboot.git/blobdiff - packages/hal/arm/mx51/3stack/v2_0/src/redboot_cmds.c
TX51 pre-release
[karo-tx-redboot.git] / packages / hal / arm / mx51 / 3stack / v2_0 / src / redboot_cmds.c
index a4fe7a62a15cb98cc6b56da381e110268c5b0bae..4dea71041246298b83c30eef03b3dcf349fb07c5 100644 (file)
 #endif
 
 RedBoot_config_option("Board specifics",
-                      brd_specs,
-                      ALWAYS_ENABLED,
-                      true,
-                      CONFIG_INT,
-                      0
-                     );
+                                       brd_specs,
+                                       ALWAYS_ENABLED,
+                                       true,
+                                       CONFIG_INT,
+                                       0
+       );
 #endif  //CYGSEM_REDBOOT_FLASH_CONFIG
 
-char HAL_PLATFORM_EXTRA[20] = "PASS x.x [x32 DDR]";
-
-static void runImg(int argc, char *argv[]);
-
-RedBoot_cmd("run",
-            "Run an image at a location with MMU off",
-            "[<virtual addr>]",
-            runImg
-           );
-
-void launchRunImg(unsigned long addr)
-{
-    asm volatile ("mov r12, r0;");
-    HAL_CACHE_FLUSH_ALL();
-    HAL_DISABLE_L2();
-    HAL_MMU_OFF();
-    asm volatile (
-                 "mov r0, #0;"
-                 "mov r1, r12;"
-                 "mov r11, #0;"
-                 "mov r12, #0;"
-                 "mrs r10, cpsr;"
-                 "bic r10, r10, #0xF0000000;"
-                 "msr cpsr_f, r10;"
-                 "mov pc, r1"
-                 );
-}
-
-extern unsigned long entry_address;
-
-static void runImg(int argc,char *argv[])
-{
-    unsigned int virt_addr, phys_addr;
-
-    // Default physical entry point for Symbian
-    if (entry_address == 0xFFFFFFFF)
-        virt_addr = 0x800000;
-    else
-    virt_addr = entry_address;
-
-    if (!scan_opts(argc,argv,1,0,0,(void*)&virt_addr,
-                   OPTION_ARG_TYPE_NUM, "virtual address"))
-        return;
-
-    if (entry_address != 0xFFFFFFFF)
-        diag_printf("load entry_address=0x%lx\n", entry_address);
-    HAL_VIRT_TO_PHYS_ADDRESS(virt_addr, phys_addr);
-
-    diag_printf("virt_addr=0x%x\n",virt_addr);
-    diag_printf("phys_addr=0x%x\n",phys_addr);
-
-    launchRunImg(phys_addr);
-}
+char HAL_PLATFORM_EXTRA[40] = "PASS x.x [x32 DDR]";
 
 #if defined(CYGSEM_REDBOOT_FLASH_CONFIG) && defined(CYG_HAL_STARTUP_ROMRAM)
 
 RedBoot_cmd("romupdate",
-            "Update Redboot with currently running image",
-            "",
-            romupdate
-           );
+                       "Update Redboot with currently running image",
+                       "",
+                       romupdate
+       );
 
 extern int flash_program(void *_addr, void *_data, int len, void **err_addr);
 extern int flash_erase(void *addr, int len, void **err_addr);
 extern char *flash_errmsg(int err);
 extern unsigned char *ram_end; //ram end is where the redboot starts FIXME: use PC value
+extern cyg_uint32 emmc_set_boot_partition (cyg_uint32 *src_ptr, cyg_uint32 length);
+extern cyg_uint32 esd_set_boot_partition(cyg_uint32 *src_ptr, cyg_uint32 length);
+extern cyg_uint32 mmc_data_write(cyg_uint32 *src_ptr, cyg_uint32 length, cyg_uint32 offset);
+extern cyg_uint32 mmc_data_read(cyg_uint32 *dest_ptr, cyg_uint32 length, cyg_uint32 offset);
 
 #ifdef CYGPKG_IO_FLASH
 void romupdate(int argc, char *argv[])
 {
-    void *err_addr, *base_addr;
-    int stat;
-    unsigned int nfc_config3_reg, temp;
-
-    if (IS_FIS_FROM_MMC() || IS_BOOTING_FROM_MMC()) {
-        diag_printf("Updating ROM in MMC/SD flash\n");
-        /* eMMC 4.3 and eSD 2.1 supported only on TO 2.0 */
-        if (((system_rev >> MAJOR_NUMBER_OFFSET) & 0xf) == 0x2) {
-            if(!emmc_set_boot_partition((cyg_uint32*)ram_end, CYGBLD_REDBOOT_MIN_IMAGE_SIZE)) {
-                /* eMMC 4.3 */
-                diag_printf("Card supports MMC-4.3, programming for boot operation.\n");
-                return;
-            } else if(!esd_set_boot_partition((cyg_uint32*)ram_end, CYGBLD_REDBOOT_MIN_IMAGE_SIZE)) {
-                /* eSD 2.1 */
-                diag_printf("Card supports SD-2.1, programming for boot operation.\n");
-                return;
-            }
-        }
-        base_addr = (void*)0;
-        /* Read the first 1K from the card */
-        mmc_data_read((cyg_uint32*)ram_end, 0x400, base_addr);
-        diag_printf("Programming Redboot to MMC/SD flash\n");
-        mmc_data_write((cyg_uint32*)ram_end, CYGBLD_REDBOOT_MIN_IMAGE_SIZE, (cyg_uint32)base_addr);
-
-        return;
-    } else if (IS_FIS_FROM_NAND() || IS_BOOTING_FROM_NAND()) {
-        diag_printf("Updating ROM in NAND flash\n");
-        base_addr = (void*)0;
-        nfc_config3_reg = readl(NFC_FLASH_CONFIG3_REG);
-        temp = nfc_config3_reg & (~ 0x7003);
-        writel(temp, NFC_FLASH_CONFIG3_REG);
-    } else {
-        diag_printf("romupdate not supported\n");
-        diag_printf("Use \"factive [NAND|MMC]\" to select either NAND or MMC flash\n");
-    }
-
-    // Erase area to be programmed
-    if ((stat = flash_erase((void *)base_addr,
-                            CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
-                            (void **)&err_addr)) != 0) {
-        diag_printf("Can't erase region at %p: %s\n",
-                    err_addr, flash_errmsg(stat));
-        return;
-    }
-    // Now program it
-    if ((stat = flash_program((void *)base_addr, (void *)ram_end,
-                              CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
-                              (void **)&err_addr)) != 0) {
-        diag_printf("Can't program region at %p: %s\n",
-                    err_addr, flash_errmsg(stat));
-    }
-    if (IS_FIS_FROM_NAND() || IS_BOOTING_FROM_NAND())
-    writel(nfc_config3_reg, NFC_FLASH_CONFIG3_REG);
+       void *err_addr, *base_addr;
+       int stat;
+       unsigned int nfc_config3_reg = 0, temp;
+
+       if (IS_FIS_FROM_MMC() || IS_BOOTING_FROM_MMC()) {
+               diag_printf("Updating ROM in MMC/SD flash\n");
+               /* eMMC 4.3 and eSD 2.1 supported only on TO 2.0 and higher */
+               if (((system_rev >> MAJOR_NUMBER_OFFSET) & 0xf) >= 0x2) {
+                       if(!emmc_set_boot_partition((cyg_uint32*)ram_end, CYGBLD_REDBOOT_MIN_IMAGE_SIZE)) {
+                               /* eMMC 4.3 */
+                               diag_printf("Card supports MMC-4.3, programming for boot operation.\n");
+                               return;
+                       } else if(!esd_set_boot_partition((cyg_uint32*)ram_end, CYGBLD_REDBOOT_MIN_IMAGE_SIZE)) {
+                               /* eSD 2.1 */
+                               diag_printf("Card supports SD-2.1, programming for boot operation.\n");
+                               return;
+                       }
+               }
+               base_addr = NULL;
+               /* Read the first 1K from the card */
+               mmc_data_read((cyg_uint32*)ram_end, 0x400, (cyg_uint32)base_addr);
+               diag_printf("Programming Redboot to MMC/SD flash\n");
+               mmc_data_write((cyg_uint32*)ram_end, CYGBLD_REDBOOT_MIN_IMAGE_SIZE, (cyg_uint32)base_addr);
+
+               return;
+       } else if (IS_FIS_FROM_NAND() || IS_BOOTING_FROM_NAND()) {
+               diag_printf("Updating ROM in NAND flash\n");
+               base_addr = NULL;
+               nfc_config3_reg = readl(NFC_FLASH_CONFIG3_REG);
+               temp = nfc_config3_reg & ~0x7003;
+               writel(temp, NFC_FLASH_CONFIG3_REG);
+       } else if (IS_BOOTING_FROM_SPI_NOR() || IS_FIS_FROM_SPI_NOR()) {
+               diag_printf("Updating ROM in SPI-NOR flash\n");
+               base_addr = NULL;
+       } else {
+               diag_printf("romupdate not supported\n");
+               diag_printf("Use \"factive [NAND|MMC|SPI]\" to select either NAND, MMC or SPI flash\n");
+       }
+
+       // Erase area to be programmed
+       if ((stat = flash_erase(base_addr,
+                                                                       CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
+                                                                       &err_addr)) != 0) {
+               diag_printf("Can't erase region at %p: %s\n",
+                                       err_addr, flash_errmsg(stat));
+               return;
+       }
+       // Now program it
+       if ((stat = flash_program((void *)base_addr, (void *)ram_end,
+                                                                       CYGBLD_REDBOOT_MIN_IMAGE_SIZE,
+                                                                       (void **)&err_addr)) != 0) {
+               diag_printf("Can't program region at %p: %s\n",
+                                       err_addr, flash_errmsg(stat));
+       }
+       if (IS_FIS_FROM_NAND() || IS_BOOTING_FROM_NAND())
+               writel(nfc_config3_reg, NFC_FLASH_CONFIG3_REG);
 }
 RedBoot_cmd("factive",
-            "Enable one flash media for Redboot",
-            "[NAND | MMC]",
-            factive
-           );
+                       "Enable one flash media for Redboot",
+                       "[NAND | MMC | SPI]",
+                       factive
+       );
 
 typedef void reset_func_t(void);
 
 extern reset_func_t reset_vector;
 
+static void launchRunImg(unsigned long addr)
+{
+       asm volatile ("mov r1, r0;");
+       HAL_MMU_OFF();
+       asm volatile (
+               "mov r11, #0;"
+               "mov r12, #0;"
+               "mrs r10, cpsr;"
+               "bic r10, r10, #0xF0000000;"
+               "msr cpsr_f, r10;"
+               "mov pc, r1"
+               );
+}
+
 void factive(int argc, char *argv[])
 {
-    unsigned long phys_addr;
-    unsigned int *fis_addr = IRAM_BASE_ADDR;
-
-    if (argc != 2) {
-        diag_printf("Invalid factive cmd\n");
-        return;
-    }
-
-    if (strcasecmp(argv[1], "NOR") == 0) {
-        diag_printf("Not supported\n");
-        return;
-    } else if (strcasecmp(argv[1], "NAND") == 0) {
+       unsigned int *fis_addr = (unsigned int *)IRAM_BASE_ADDR;
+
+       if (argc != 2) {
+               diag_printf("Invalid factive cmd\n");
+               return;
+       }
+
+       if (strcasecmp(argv[1], "NOR") == 0) {
+               diag_printf("Not supported\n");
+               return;
+       } else if (strcasecmp(argv[1], "NAND") == 0) {
 #ifndef MXCFLASH_SELECT_NAND
-        diag_printf("Not supported\n");
-        return;
+               diag_printf("Not supported\n");
+               return;
 #endif
-        *fis_addr = FROM_NAND_FLASH;
-    } else if (strcasecmp(argv[1], "MMC") == 0) {
+               *fis_addr = FROM_NAND_FLASH;
+       } else if (strcasecmp(argv[1], "MMC") == 0) {
 #ifndef MXCFLASH_SELECT_MMC
-        diag_printf("Not supported\n");
-        return;
+               diag_printf("Not supported\n");
+               return;
+#else
+               *fis_addr = FROM_MMC_FLASH;
+#endif
+       } else if (strcasecmp(argv[1], "SPI") == 0) {
+#ifndef IMXFLASH_SELECT_SPI_NOR
+               diag_printf("Not supported\n");
+               return;
 #else
-        *fis_addr = FROM_MMC_FLASH;
+               *fis_addr = FROM_SPI_NOR_FLASH;
 #endif
-    } else {
-        diag_printf("Invalid command: %s\n", argv[1]);
-        return;
-    }
+       } else {
+               diag_printf("Invalid command: %s\n", argv[1]);
+               return;
+       }
 
-    //HAL_VIRT_TO_PHYS_ADDRESS(ram_end, phys_addr);
-    launchRunImg(reset_vector);
+       //HAL_VIRT_TO_PHYS_ADDRESS(ram_end, phys_addr);
+       launchRunImg((unsigned long)reset_vector);
 }
 #endif //CYGPKG_IO_FLASH
 #endif /* CYG_HAL_STARTUP_ROMRAM */