WinCE redundant image support
authorlothar <lothar>
Wed, 1 Jun 2011 11:19:56 +0000 (11:19 +0000)
committerlothar <lothar>
Wed, 1 Jun 2011 11:19:56 +0000 (11:19 +0000)
packages/devs/eth/arm/tx25karo/v1_0/include/devs_eth_arm_tx25.inl
packages/hal/arm/mx25/var/v2_0/src/soc_misc.c
packages/redboot/v2_0/src/flash.c
packages/redboot/v2_0/src/winceinc.h

index ca72d79..6aeb65b 100644 (file)
@@ -101,15 +101,15 @@ TX27 -> TX25 GPIO cross reference
                                TX27  GP  Fkt GPIO         Pad             IOMUXC SW_PAD  SW_PAD strap
                                GPIO  ALT ALT                                      OFFSET  CTRL    MUX   option
 FEC_MDC                        PD9       5       0       GPIO3_5  FEC_MDC         0x1c8   0x3c0
-FEC_MDIO               PD8       5       0       GPIO3_6  FEC_MDIO        0x1cc   0x3c4                 
+FEC_MDIO               PD8       5       0       GPIO3_6  FEC_MDIO        0x1cc   0x3c4
 FEC_RX_CLK             PD14  -   -       NC                                                                             REGOFF: 0
-FEC_RX_DV              PD13  -   -       NC                                                                             
+FEC_RX_DV              PD13  -   -       NC
 FEC_RXD0               PD12  5   0       GPIO3_10 FEC_RDATA0  0x1dc   0x3d4             MODE0: 1
 FEC_RXD1               PD5       5       0       GPIO3_11 FEC_RDATA1  0x1e0   0x3d8             MODE1: 1
 FEC_RXD2               PD6       -       -       NC       PULLUP                                                        MODE2: 1
 FEC_RXD3               PD7       -       -       NC                                                                             INTSEL: 0
 FEC_RX_ER              PD4       5       5       GPIO4_10 D10             0x09c   0x294
-FEC_TX_CLK             PD11  5   0       GPIO3_13 FEC_TX_CLK  0x1e8   0x3e0             
+FEC_TX_CLK             PD11  5   0       GPIO3_13 FEC_TX_CLK  0x1e8   0x3e0
 FEC_TX_EN              PF23  5   0       GPIO3_9  FEC_TX_EN   0x1d8   0x3d0
 FEC_TXD0               PD0       5       0       GPIO3_7  FEC_TDATA0  0x1d0   0x3c8
 FEC_TXD1               PD1       5       0       GPIO3_8  FEC_TDATA1  0x1d4   0x3cc
@@ -157,26 +157,26 @@ static struct tx25_gpio_setup {
        cyg_uint8 shift;
 } tx25_fec_gpio_data[] = {
        /* iomux, func, gpfn, gpgrp, gpshift */
-       { 0x1c8,    0, 0x15,    3,     5, },
-       { 0x1cc,    0, 0x15,    3,     6, },
-       { 0x1dc,    0, 0x15,    3,    10, },
-       { 0x1e0,    0, 0x15,    3,    11, },
-       { 0x09c, 0x85,    5,    4,    10, },
-       { 0x1e8,    0, 0x15,    3,    13, },
-       { 0x1d8,    0, 0x15,    3,     9, },
-       { 0x1d0,    0, 0x15,    3,     7, },
-       { 0x1d4,    0, 0x15,    3,     8, },
-       { 0x1e4, 0x80, 0x15,    3,    12, },
-       { 0x024, 0x05, 0x05,    2,     5, }, /* RX_ER signal; make sure it's a GPIO _without_ SION! */
-       { 0x094, 0x85,    5,    4,     8, },
-       { 0x090,    5,    5,    4,     7, },
-       { 0x098,    5,    5,    4,     9, },
+       { 0x1c8,        0, 0x15,        3,         5, },
+       { 0x1cc,        0, 0x15,        3,         6, },
+       { 0x1dc,        0, 0x15,        3,        10, },
+       { 0x1e0,        0, 0x15,        3,        11, },
+       { 0x09c, 0x85,    5,    4,        10, },
+       { 0x1e8,        0, 0x15,        3,        13, },
+       { 0x1d8,        0, 0x15,        3,         9, },
+       { 0x1d0,        0, 0x15,        3,         7, },
+       { 0x1d4,        0, 0x15,        3,         8, },
+       { 0x1e4, 0x80, 0x15,    3,        12, },
+       { 0x024, 0x05, 0x05,    2,         5, }, /* RX_ER signal; make sure it's a GPIO _without_ SION! */
+       { 0x094, 0x85,    5,    4,         8, },
+       { 0x090,        5,        5,    4,         7, },
+       { 0x098,        5,        5,    4,         9, },
 };
 
 static struct tx25_gpio_setup tx25_fec_strap_pins[] = {
-       { 0x1dc,    0, 0x15,   3, 10, },
-       { 0x1e0,    0, 0x15,   3, 11, },
-       { 0x1e4,    0, 0x15,   3, 12, },
+       { 0x1dc,        0, 0x15,   3, 10, },
+       { 0x1e0,        0, 0x15,   3, 11, },
+       { 0x1e4,        0, 0x15,   3, 12, },
 };
 
 static inline void tx25_phy_power_off(void)
@@ -383,11 +383,11 @@ static void tx25_fec_phy_init(void)
        }
 }
 
-ETH_PHY_REG_LEVEL_ACCESS_FUNS(eth0_phy, 
-                              tx25_fec_phy_init,
-                              mxc_fec_phy_reset,
-                              mxc_fec_phy_write,
-                              mxc_fec_phy_read);
+ETH_PHY_REG_LEVEL_ACCESS_FUNS(eth0_phy,
+                                                         tx25_fec_phy_init,
+                                                         mxc_fec_phy_reset,
+                                                         mxc_fec_phy_write,
+                                                         mxc_fec_phy_read);
 
 #define SOC_MAC_ADDR_LOCK_BIT  2
 
@@ -412,7 +412,7 @@ cyg_bool _tx25_provide_fec_esa(unsigned char *addr)
                if (cyg_plf_redboot_esa_validate(addr)) {
                        diag_printf("Ethernet FEC MAC address from fuse bank: ");
                        diag_printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
-                                   addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
+                                               addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
                        CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
                                                                                "fec_esa_data", addr2, CONFIG_ESA);
                        if (memcmp(addr, addr2, sizeof(addr)) != 0) {
@@ -433,7 +433,7 @@ cyg_bool _tx25_provide_fec_esa(unsigned char *addr)
 
                diag_printf("Ethernet FEC MAC address from fconfig: ");
                diag_printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
-                           addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
+                                       addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
 
 #ifdef CYGSEM_REDBOOT_PLF_ESA_VALIDATE
                if (cyg_plf_redboot_esa_validate(addr)) {
@@ -443,7 +443,7 @@ cyg_bool _tx25_provide_fec_esa(unsigned char *addr)
 
                diag_printf("** Error: Invalid MAC address: ");
                diag_printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
-                           addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
+                                       addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
 
 #ifdef SOC_MAC_ADDR_LOCK_BIT
                if ((readl(SOC_MAC_ADDR_BASE - 0x68) & SOC_MAC_ADDR_LOCK_BIT) == 0) {
@@ -462,40 +462,40 @@ cyg_bool _tx25_provide_fec_esa(unsigned char *addr)
 }
 
 static mxc_fec_priv_t mxc_fec_private = {
-       .phy = &eth0_phy,                             // PHY access routines
+       .phy = &eth0_phy,                                                         // PHY access routines
        .provide_esa = _tx25_provide_fec_esa,
 };
 
 ETH_DRV_SC(mxc_fec_sc,
                   &mxc_fec_private, // Driver specific data
-           mxc_fec_name,
-           mxc_fec_start,
-           mxc_fec_stop,
-           mxc_fec_control,
-           mxc_fec_can_send,
-           mxc_fec_send,
-           mxc_fec_recv,
-           mxc_fec_deliver,     // "pseudoDSR" called from fast net thread
-           mxc_fec_poll,        // poll function, encapsulates ISR and DSR
-           mxc_fec_int_vector);
+                  mxc_fec_name,
+                  mxc_fec_start,
+                  mxc_fec_stop,
+                  mxc_fec_control,
+                  mxc_fec_can_send,
+                  mxc_fec_send,
+                  mxc_fec_recv,
+                  mxc_fec_deliver,             // "pseudoDSR" called from fast net thread
+                  mxc_fec_poll,                // poll function, encapsulates ISR and DSR
+                  mxc_fec_int_vector);
 
 NETDEVTAB_ENTRY(mxc_fec_netdev,
-                mxc_fec_name,
-                tx25_fec_init,
-                &mxc_fec_sc);
+                               mxc_fec_name,
+                               tx25_fec_init,
+                               &mxc_fec_sc);
 #endif
 
 #if defined(CYGPKG_REDBOOT) && defined(CYGSEM_REDBOOT_FLASH_CONFIG)
 RedBoot_config_option("Set FEC network hardware address [MAC]",
-                      fec_esa,
-                      ALWAYS_ENABLED, true,
-                      CONFIG_BOOL, false
-                     );
+                                         fec_esa,
+                                         ALWAYS_ENABLED, true,
+                                         CONFIG_BOOL, true
+                                         );
 RedBoot_config_option("FEC network hardware address [MAC]",
-                      fec_esa_data,
-                      "fec_esa", true,
-                      CONFIG_ESA, 0
-                     );
+                                         fec_esa_data,
+                                         "fec_esa", true,
+                                         CONFIG_ESA, 0
+                                         );
 #endif // CYGPKG_REDBOOT && CYGSEM_REDBOOT_FLASH_CONFIG
 
 #ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
index 66f5fb0..e167224 100644 (file)
@@ -139,7 +139,7 @@ void hal_hardware_init(void)
                        system_rev |= 1 << MINOR_NUMBER_OFFSET;
                } else if (ver == 0x2) {
                        HAL_PLATFORM_EXTRA[5] = '1';
-                       HAL_PLATFORM_EXTRA[7] = '1';
+                       HAL_PLATFORM_EXTRA[7] = '2';
                        system_rev |= 1 << MAJOR_NUMBER_OFFSET;
                        system_rev |= 2 << MINOR_NUMBER_OFFSET;
                } else {
index caefc0c..c726213 100644 (file)
@@ -62,6 +62,7 @@
 
 #ifdef CYGBLD_BUILD_REDBOOT_WITH_WINCE_SUPPORT
 #include <wince.h>
+#include <winceinc.h>
 #endif
 
 #ifdef CYGSEM_REDBOOT_FLASH_COMBINED_FIS_AND_CONFIG
 extern void conf_endian_fixup(void *p);
 #endif
 
+#if defined(CYGBLD_BUILD_REDBOOT_WITH_WINCE_SUPPORT) && defined(CYGSEM_REDBOOT_FLASH_CONFIG)
+#include <flash_config.h>
+
+#if (REDBOOT_IMAGE_SIZE != CYGBLD_REDBOOT_MIN_IMAGE_SIZE)
+#error REDBOOT_IMAGE_SIZE != CYGBLD_REDBOOT_MIN_IMAGE_SIZE
+#endif
+
+RedBoot_config_option("automatic boot partition selection",
+                                       xt0_auto_OS_part_sel,
+                                       ALWAYS_ENABLED, true,
+                                       CONFIG_BOOL,
+                                       false
+       );
+
+RedBoot_config_option("first OS boot partition",
+                                       xt1_first_OS_part,
+                                       "xt0_auto_OS_part_sel", true,
+                                       CONFIG_STRING,
+                                       "osimage1"
+       );
+
+RedBoot_config_option("second OS boot partition",
+                                       xt2_second_OS_part,
+                                       "xt0_auto_OS_part_sel", true,
+                                       CONFIG_STRING,
+                                       "osimage2"
+       );
+
+#endif // CYGBLD_BUILD_REDBOOT_WITH_WINCE_SUPPORT && CYGSEM_REDBOOT_FLASH_CONFIG
+
 // Round a quantity up
 #define _rup(n,s) ((((n)+(s-1))/s)*s)
 
@@ -1237,15 +1268,51 @@ fis_delete(int argc, char *argv[])
        }
 }
 
+#ifdef CYGBLD_BUILD_REDBOOT_WITH_WINCE_SUPPORT
+static bool load_ce_img(struct fis_image_desc *img)
+{
+       bool ret = true;
+
+       FLASH_Enable((void *)img->flash_base, (void *)(img->flash_base + img->size));
+       if (!ce_is_bin_image((void *)img->flash_base, img->size)) {
+               diag_printf("** Error: This does not seem to be a valid Windows CE image\n");
+               ret =  false;
+       }
+       if (ret) {
+               if (!ce_bin_load((void *)img->flash_base, img->size)) {
+                       diag_printf("** Error: Failed to load Windows CE image\n");
+                       ret =  false;
+               }
+       }
+       FLASH_Disable((void *)img->flash_base, (void *)(img->flash_base + img->size));
+       return ret;
+}
+
+static void store_boot_img_name(char *image_name)
+{
+
+       ce_std_driver_globals *std_drv_glb = &_KARO_CECFG_START;
+
+       strncpy(std_drv_glb->chBootPartition, image_name, sizeof(std_drv_glb->chBootPartition));
+
+       std_drv_glb->chBootPartition[15] = '\0';
+}
+#endif
+
 static void
 fis_load(int argc, char *argv[])
 {
-       char *name;
-       struct fis_image_desc *img;
+       char *name = NULL;
+       struct fis_image_desc *img = NULL;
        CYG_ADDRESS mem_addr;
        bool mem_addr_set = false;
        bool show_cksum = false;
+#ifdef CYGBLD_BUILD_REDBOOT_WITH_WINCE_SUPPORT
        bool load_ce = false;
+#else
+#define load_ce                0
+#endif
+       bool auto_part_name = false;
        struct option_info opts[4];
 #if defined(CYGSEM_REDBOOT_FIS_CRC_CHECK)
        unsigned long cksum;
@@ -1269,28 +1336,41 @@ fis_load(int argc, char *argv[])
                        &decompress, 0, "decompress");
 #endif
 
-       CYG_ASSERT(num_options <= num_options, "Too many options");
+       CYG_ASSERT(num_options <= NUM_ELEMS(opts), "Too many options");
 
        if (!scan_opts(argc, argv, 2, opts, num_options, &name,
                                        OPTION_ARG_TYPE_STR, "image name")) {
                fis_usage("invalid arguments");
                return;
        }
-       if ((img = fis_lookup(name, NULL)) == NULL) {
-               diag_printf("No image '%s' found\n", name);
-               return;
+
+#ifdef CYGBLD_BUILD_REDBOOT_WITH_WINCE_SUPPORT
+       // check if the name of the OS partition should be chosen automatically
+       if (load_ce) {
+               if (!flash_get_config("xt0_auto_OS_part_sel", &auto_part_name, CONFIG_BOOL)) {
+                       diag_printf("fconfig variable 'xt0_auto_OS_part_sel' not found; use 'fconfig -i' to create it\n");
+                       return;
+               }
        }
-       if (!mem_addr_set || load_ce) {
-               mem_addr = img->mem_base;
+#endif
+       if (name) {
+               if ((img = fis_lookup(name, NULL)) == NULL) {
+                       if (!auto_part_name) {
+                               diag_printf("No image '%s' found\n", name);
+                               return;
+                       }
+               } else {
+                       if (!mem_addr_set && !load_ce) {
+                               mem_addr = img->mem_base;
+                       }
+               }
        }
        // Load image from FLASH into RAM
 #ifdef CYGSEM_REDBOOT_VALIDATE_USER_RAM_LOADS
-       if (!valid_address((void *)mem_addr)) {
-               if (!load_ce) {
-                       diag_printf("Not a loadable image - try using -b ADDRESS option\n");
-               } else {
-                       diag_printf("Not a loadable image\n");
-               }
+       // this does not make sense for WINCE as the load address is stored in the descriptor
+       // inside the image itself. It does not matter what load address is specified in the FIS directory
+       if (!load_ce && !valid_address((void *)mem_addr)) {
+               diag_printf("Not a loadable image - try using -b ADDRESS option\n");
                return;
        }
 #endif
@@ -1299,15 +1379,39 @@ fis_load(int argc, char *argv[])
                if (mem_addr_set) {
                        diag_printf("Warning: -b argument ignored for Windows CE image\n");
                }
-               FLASH_Enable((void *)img->flash_base, (void *)(img->flash_base + img->size));
-               if (!ce_is_bin_image((void *)img->flash_base, img->size)) {
-                       diag_printf("** Error: This does not seem to be a valid Windows CE image\n");
-                       return;
-               }
-               if (!ce_bin_load((void *)img->flash_base, img->size)) {
-                       diag_printf("** Error: Failed to load Windows CE image\n");
+               if (!auto_part_name) {
+                       if (!load_ce_img(img))
+                               return;
+               } else {
+                       if (!img || !load_ce_img(img)) {
+                               // try the first OS image
+                               if (!flash_get_config("xt1_first_OS_part", &name, CONFIG_STRING)) {
+                                       diag_printf("fconfig variable 'xt1_first_OS_part' not found; use 'fconfig -i' to create it\n");
+                               }
+                               if (name) {
+                                       if ((img = fis_lookup(name, NULL)) == NULL) {
+                                               diag_printf("No image '%s' found\n", name);
+                                       } else {
+                                               diag_printf("loading WINCE OS from partition '%s'\n", name);
+                                       }
+                               }
+                               if (!img || !load_ce_img(img)) {
+                                       if (!flash_get_config("xt2_second_OS_part", &name, CONFIG_STRING)) {
+                                               diag_printf("fconfig variable 'xt2_second_OS_part' not found; use 'fconfig -i' to create it\n");
+                                               return;
+                                       }
+                                       if ((img = fis_lookup(name, NULL)) == NULL) {
+                                               diag_printf("No image '%s' found\n", name);
+                                               return;
+                                       } else {
+                                               diag_printf("loading WINCE OS from partition '%s'\n", name);
+                                       }
+                                       if (!load_ce_img(img))
+                                               return;
+                               }
+                       }
+                       store_boot_img_name(name);
                }
-               FLASH_Disable((void *)img->flash_base, (void *)(img->flash_base + img->size));
                // Set load address/top
                load_address = mem_addr;
                load_address_end = mem_addr + img->data_length;
index 446bb14..222c9b2 100755 (executable)
@@ -228,8 +228,9 @@ typedef struct
 typedef struct
 {
        OAL_ARGS_HEADER header;
-       char            deviceId[16];   // Device identification
+       char                    deviceId[16];   // Device identification
        OAL_KITL_ARGS   kitl;
+       char                    chBootPartition[16];
 } ce_std_driver_globals;
 
 externC ce_std_driver_globals   _KARO_CECFG_START;