#ifndef FLASH_LAYOUT_H
#define FLASH_LAYOUT_H

//----------------------------------------------------------------------------
// NAND customization
//----------------------------------------------------------------------------
#define NAND_FLASH_TOTAL_SIZE           ((UINT64)4*1024*1024*1024)
#define NAND_FLASH_3RD_SIZE             ((UINT64)(124*1024*1024))     /* 124 MB */
#define NAND_FLASH_PQ_SIZE              ((UINT64)(14*1024*1024))      /*  14 MB */

#define NAND_FLASH_3RD_RW_SIZE          ((UINT64)(233*1024*1024))     /* 233 MB */

    #ifdef CC_DISABLE_BASIC_PART
#define NAND_FLASH_ROOTFS_SIZE          ((UINT64)(60*1024*1024))      /*  48 MB */ /* Normal behavior */
#define NAND_FLASH_APPIMAGE_SIZE        ((UINT64)(48*1024*1024))          /* 256 KB */ /* Normal behavior */
    #else
#define NAND_FLASH_ROOTFS_SIZE          ((UINT64)(8*1024*1024))       /*   8 MB */ /* Debug+Development purpose */
#define NAND_FLASH_APPIMAGE_SIZE        ((UINT64)(144*1024*1024))      /*  128 MB */ /* Debug+Development purpose */
#endif /* endif CC_DISABLE_BASIC_PART */

#define NAND_FLASH_LOADER_SIZE              ((UINT64)(2*1024*1024))       /*   2 MB */
#define NAND_FLASH_UBOOT_SIZE               ((UINT64)(2*1024*1024))       /*   2 MB */
#define NAND_FLASH_MISC_SIZE                ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_RECV_SIZE                ((UINT64)(20*1024*1024))      /*  20 MB */
#define NAND_FLASH_BOOT_SIZE                ((UINT64)(20*1024*1024))      /*  20 MB */
#define NAND_FLASH_SYSM_SIZE                ((UINT64)(372*1024*1024))     /* 372 MB */
#define NAND_FLASH_USRD_SIZE                ((UINT64)(512*1024*1024))     /* 512 MB */
#define NAND_FLASH_CACH_SIZE                ((UINT64)(100*1024*1024))     /* 100 MB */
#define NAND_FLASH_RSVD_SIZE                ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SINGLE_CHANNELLIST_SIZE  ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_AQ_SIZE                  ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_CAPTURE_LOGO_SIZE        ((UINT64)(4*1024*1024))       /*   4 MB */
#define NAND_FLASH_LOADER_LOGO_SIZE         ((UINT64)(4*1024*1024))       /*   4 MB */
#define NAND_FLASH_TRUSTZONE_SIZE           ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SIGNATURE_SIZE           ((UINT64)(2*1024*1024))       /*   2 MB */
#define NAND_FLASH_KERNEL_SIZE              ((UINT64)(3*1024*1024))       /*   2 MB */
#define NAND_FLASH_PERM_SIZE                ((UINT64)(8*1024*1024))       /*   5 MB */
#define NAND_FLASH_PANEL_SIZE               ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_CIPLUS_SIZE              ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_EDID_SIZE                ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SERVICE_MODE_SIZE        ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_DVBS_DEFAULT_DB_SIZE     ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_EPG_CACHE_SIZE           ((UINT64)(6*1024*1024))       /*   6 MB */
#define NAND_FLASH_ADSPBIN_SIZE             ((UINT64)(2*1024*1024))       /*   2 MB */
#define NAND_FLASH_UPGRADE_SIZE             ((UINT64)(400*1024*1024))     /* 400 MB */
#define NAND_FLASH_VERSION_SIZE             ((UINT64)(1*1024*1024))       /*   1 MB */
#if (defined(REPLACE_EEPROM_WITH_EMMC)||defined(REPLACE_EEPROM_WITH_FLASH))
#define NAND_FLASH_REPLACE_EEPROM_SIZE      ((UINT64)(10*1024*1024))      /*  10 MB for each*/
#endif /* endif REPLACE_EEPROM_WITH_FLASH */
#define NAND_FLASH_RESERVE_SIZE             ((UINT64)(1*1024*1024))          /* 256 KB */
#define NAND_FLASH_SONY_BE_DDRI_SIZE        ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SONY_BE_MLFW_SIZE        ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SONY_BE_LDAT_SIZE        ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SONY_BE_MAFW_SIZE        ((UINT64)(6*1024*1024))       /*   6 MB */
#define NAND_FLASH_SONY_BE_DFW1_SIZE        ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SONY_BE_DFW2_SIZE        ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SONY_BE_PDAT_SIZE        ((UINT64)(1*1024*1024))       /*   5 MB */
#define NAND_FLASH_SONY_BE_BDIX_SIZE        ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SONY_BE_BDAT_SIZE        ((UINT64)(1*1024*1024))       /*   2 MB */
#define NAND_FLASH_SONY_BE_NDAT_SIZE        ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SONY_BE_CDAT_SIZE        ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SONY_BE_MDAT_SIZE        ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SONY_BE_FDAT_SIZE        ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SONY_BE_UDAT_SIZE        ((UINT64)(1*1024*1024))       /*   1 MB */
#define NAND_FLASH_SONY_BE_RESV_SIZE        ((UINT64)(8*1024*1024))       /*   8 MB */

#define NAND_PART_SIZE_0                    (NAND_FLASH_LOADER_SIZE)                /* loader image                  */
#define NAND_PART_SIZE_1                    (NAND_FLASH_UBOOT_SIZE)                 /* nand_1  - uboot env           */
#define NAND_PART_SIZE_2                    (NAND_FLASH_MISC_SIZE)
#define NAND_PART_SIZE_3                    (NAND_FLASH_RECV_SIZE)
//#define NAND_PART_SIZE_4                    (NAND_FLASH_BOOT_SIZE)
//#define NAND_PART_SIZE_5                    (NAND_FLASH_SYSM_SIZE)
//#define NAND_PART_SIZE_6                    (NAND_FLASH_USRD_SIZE)
//#define NAND_PART_SIZE_7                    (NAND_FLASH_CACH_SIZE)
#define NAND_PART_SIZE_4                    (NAND_FLASH_KERNEL_SIZE)
#define NAND_PART_SIZE_5                    (NAND_FLASH_KERNEL_SIZE)
#define NAND_PART_SIZE_6                    (NAND_FLASH_ROOTFS_SIZE)
#define NAND_PART_SIZE_7                    (NAND_FLASH_ROOTFS_SIZE)
//#define NAND_PART_SIZE_8                    (NAND_FLASH_RSVD_SIZE)
#define NAND_PART_SIZE_8                   (NAND_FLASH_APPIMAGE_SIZE)              /* nand_8  - basic               */
//#define NAND_PART_SIZE_9                    (NAND_FLASH_SIGNATURE_SIZE)             /* nand_2  - sig A               */
#define NAND_PART_SIZE_9                   (NAND_FLASH_PERM_SIZE)                  /* nand_10 - perm                */
#define NAND_PART_SIZE_10                   (NAND_FLASH_SIGNATURE_SIZE)             /* nand_3  - sig B               */
#define NAND_PART_SIZE_11                   (NAND_FLASH_KERNEL_SIZE)   //linux kerA
#define NAND_PART_SIZE_12                   (NAND_FLASH_KERNEL_SIZE)    //linux kerB
#define NAND_PART_SIZE_13                   (NAND_FLASH_ROOTFS_SIZE)
#define NAND_PART_SIZE_14                   (NAND_FLASH_ROOTFS_SIZE)
#define NAND_PART_SIZE_15                   (NAND_FLASH_TRUSTZONE_SIZE)
#define NAND_PART_SIZE_16                   (NAND_FLASH_PQ_SIZE)
#define NAND_PART_SIZE_17                   (NAND_FLASH_AQ_SIZE)
#define NAND_PART_SIZE_18                   (NAND_FLASH_SINGLE_CHANNELLIST_SIZE)                /* nand_6  - rootfs A            */
#define NAND_PART_SIZE_19                   (NAND_FLASH_SINGLE_CHANNELLIST_SIZE)                /* nand_7  - rootfs B            */
#define NAND_PART_SIZE_20                   (NAND_FLASH_APPIMAGE_SIZE)              /* nand_8  - basic               */
#define NAND_PART_SIZE_21                   (NAND_FLASH_3RD_RW_SIZE)                /* nand_9  - 3rd_rw              */
#define NAND_PART_SIZE_22                   (NAND_FLASH_PERM_SIZE)                  /* nand_10 - perm                */
#define NAND_PART_SIZE_23                   (NAND_FLASH_RESERVE_SIZE)               /* nand_11 - reserved             */
#define NAND_PART_SIZE_24                   (NAND_FLASH_3RD_SIZE)                   /* nand_12 - 3rd_ro              */
#define NAND_PART_SIZE_25                   (NAND_FLASH_PANEL_SIZE)                 /* nand_17 - Flash Panel         */
#define NAND_PART_SIZE_26                   (NAND_FLASH_CIPLUS_SIZE)                /* nand_18 - ci                  */
#define NAND_PART_SIZE_27                   (NAND_FLASH_EDID_SIZE)                  /* nand_19 - edid                */
#define NAND_PART_SIZE_28                   (NAND_FLASH_SERVICE_MODE_SIZE)          /* nand_20 - Service mode        */
#define NAND_PART_SIZE_29                   (NAND_FLASH_DVBS_DEFAULT_DB_SIZE)       /* nand_21 - DVBS Default DB     */
#define NAND_PART_SIZE_30                   (NAND_FLASH_EPG_CACHE_SIZE)             /* nand_22 - EPG Cache           */
#define NAND_PART_ID_ADSPBIN                (31)
#define NAND_PART_SIZE_31                   (NAND_FLASH_ADSPBIN_SIZE)               /* ADSP partition */
#if 1
#define NAND_PART_SIZE_32                   (NAND_FLASH_UPGRADE_SIZE)               /* Upgrade partition */
#define NAND_PART_SIZE_33                   (NAND_FLASH_VERSION_SIZE)               /* Version partition */
#define NAND_PART_SIZE_34                   (NAND_FLASH_SONY_BE_DDRI_SIZE)          /* Sony backend IC DDR Init FW */
#define NAND_PART_SIZE_35                   (NAND_FLASH_SONY_BE_MLFW_SIZE)          /* Sony backend IC Main Loader FW*/
#define NAND_PART_SIZE_36                   (NAND_FLASH_SONY_BE_LDAT_SIZE)          /* Sony backend IC L-Data */     
#define NAND_PART_SIZE_37                   (NAND_FLASH_SONY_BE_MAFW_SIZE)          /* Sony backend IC Main FW */    
#define NAND_PART_SIZE_38                   (NAND_FLASH_SONY_BE_DFW1_SIZE)          /* Sony backend IC DFW1 */       
#define NAND_PART_SIZE_39                   (NAND_FLASH_SONY_BE_DFW2_SIZE)          /* Sony backend IC DFW2 */       
#define NAND_PART_SIZE_40                   (NAND_FLASH_SONY_BE_PDAT_SIZE)          /* Sony backend IC P-Data */     
#define NAND_PART_SIZE_41                   (NAND_FLASH_SONY_BE_BDIX_SIZE)          /* Sony backend IC BDI */        
#define NAND_PART_SIZE_42                   (NAND_FLASH_SONY_BE_BDAT_SIZE)          /* Sony backend IC B-Data */     
#define NAND_PART_SIZE_43                   (NAND_FLASH_SONY_BE_NDAT_SIZE)          /* Sony backend IC N-Data */     
#define NAND_PART_SIZE_44                   (NAND_FLASH_SONY_BE_CDAT_SIZE)          /* Sony backend IC C-Data */     
#define NAND_PART_SIZE_45                   (NAND_FLASH_SONY_BE_MDAT_SIZE)          /* Sony backend IC M-Data */     
#define NAND_PART_SIZE_46                   (NAND_FLASH_SONY_BE_FDAT_SIZE)          /* Sony backend IC F-Data */     
#define NAND_PART_SIZE_47                   (NAND_FLASH_SONY_BE_UDAT_SIZE)          /* Sony backend IC U-Data */     
#define NAND_PART_SIZE_48                   (NAND_FLASH_SONY_BE_RESV_SIZE)          /* Sony backend IC reserve1 */   
#define NAND_PART_SIZE_49                   (NAND_FLASH_SONY_BE_RESV_SIZE)          /* Sony backend IC reserve2 */   
#define NAND_PART_SIZE_50                   (NAND_FLASH_SONY_BE_RESV_SIZE)          /* Sony backend IC reserve3 */   
#define NAND_PART_SIZE_51                   (NAND_FLASH_SONY_BE_RESV_SIZE)          /* Sony backend IC reserve4 */   
#if (defined(REPLACE_EEPROM_WITH_EMMC)||defined(REPLACE_EEPROM_WITH_FLASH))
#define NAND_PART_ID_EEPROM_A               (52)
#define NAND_PART_ID_EEPROM_B               (53)
#define NAND_PART_SIZE_52                   (NAND_FLASH_REPLACE_EEPROM_SIZE)        /* nand_23 - EEPROM A 10MB(must be one block size)    */
#define NAND_PART_SIZE_53                   (NAND_FLASH_REPLACE_EEPROM_SIZE)        /* nand_23 - EEPROM A 10MB(must be one block size)    */
#endif /* endif REPLACE_EEPROM_WITH_FLASH */
#endif

#ifdef CC_MTD_ENCRYPT_SUPPORT
#define NAND_PART_ENCRYPT_13                (0)                 /* rootfs */
#define NAND_PART_ENCRYPT_14                (0)                 /* rootfs */
#define NAND_PART_ENCRYPT_21                (0)                 /* 3rd_rw */
#define NAND_PART_ENCRYPT_22                (0)                 /* perm */
#define NAND_PART_ENCRYPT_23                (0)                 /* reserved */
#endif /* endif CC_MTD_ENCRYPT_SUPPORT */

#define NAND_PART_NAME_0                "uboot"
#define NAND_PART_NAME_1                "uboot_env"
//#define NAND_PART_NAME_2                "misc"
//#define NAND_PART_NAME_3                "recovery"
//#define NAND_PART_NAME_4                "boot"
//#define NAND_PART_NAME_5                "system"
//#define NAND_PART_NAME_6                "userdata"
//#define NAND_PART_NAME_7                "cache"
#define NAND_PART_NAME_2                "flash_sig_A"
#define NAND_PART_NAME_3               "flash_sig_B"
#define NAND_PART_NAME_4               "kernelA"
#define NAND_PART_NAME_5               "kernelB"
#define NAND_PART_NAME_6               "rootfsA"
#define NAND_PART_NAME_7               "rootfsB"
//#define NAND_PART_NAME_8                "reserved"
//#define NAND_PART_NAME_9                "reservedsiga"
#define NAND_PART_NAME_8               "basic"
#define NAND_PART_NAME_9               "perm"
#define NAND_PART_NAME_10               "reservedsigb"
//#define NAND_PART_NAME_9                "flash_sig_A"
//#define NAND_PART_NAME_10               "flash_sig_B"
//#define NAND_PART_NAME_11               "kernelA"
//#define NAND_PART_NAME_12               "kernelB"
//#define NAND_PART_NAME_13               "rootfsA"
//#define NAND_PART_NAME_14               "rootfsB"
#define NAND_PART_NAME_11               "reservedA"
#define NAND_PART_NAME_12               "reservedB"
#define NAND_PART_NAME_13               "reservedC"
#define NAND_PART_NAME_14               "reservedD"
//#ifdef CC_TZBIN_INDIVIDUAL_PARTITION
    #define NAND_PART_NAME_15           "tzbp"
//    #define TRUSTZONE_FLASH_PARTITION   (15)
//#endif /* endif CC_TZBIN_INDIVIDUAL_PARTITION */
#define NAND_PART_NAME_16               "pq"
#define NAND_PART_NAME_17               "aq"
#define NAND_PART_NAME_18               "channelA"
#define NAND_PART_NAME_19               "channelB"
//#define NAND_PART_NAME_20               "basic"
#define NAND_PART_NAME_20               "reserve_basic"
#define NAND_PART_NAME_21               "3rd_rw"
//#define NAND_PART_NAME_22               "perm"
#define NAND_PART_NAME_22               "reserve_perm"
#define NAND_PART_NAME_23               "reserved"
#define NAND_PART_NAME_24               "3rd_ro"
#define NAND_PART_NAME_25               "panel"
#define NAND_PART_NAME_26               "ci"
#define NAND_PART_NAME_27               "edid"
#define NAND_PART_NAME_28               "svc"
#define NAND_PART_NAME_29               "ddb"
#if 1
#define NAND_PART_NAME_30               "epg"
#define NAND_PART_NAME_31               "adsp"
#define NAND_PART_NAME_32               "upgrade"
#define NAND_PART_NAME_33               "version"
#define NAND_PART_NAME_34               "ddri"
#define NAND_PART_NAME_35               "mlfw"
#define NAND_PART_NAME_36               "ldat"
#define NAND_PART_NAME_37               "mafw"
#define NAND_PART_NAME_38               "dfw1"
#define NAND_PART_NAME_39               "dfw2"
#define NAND_PART_NAME_40               "pdat"
#define NAND_PART_NAME_41               "bdix"
#define NAND_PART_NAME_42               "bdat"
#define NAND_PART_NAME_43               "ndat"
#define NAND_PART_NAME_44               "cdat"
#define NAND_PART_NAME_45               "mdat"
#define NAND_PART_NAME_46               "fdat"
#define NAND_PART_NAME_47               "udat"
#define NAND_PART_NAME_48               "reserved"
#define NAND_PART_NAME_49               "reserved"
#define NAND_PART_NAME_50               "reserved"
#define NAND_PART_NAME_51               "reserved"
#if (defined(REPLACE_EEPROM_WITH_EMMC)||defined(REPLACE_EEPROM_WITH_FLASH))
#define NAND_PART_NAME_52               "eeprom_A"
#define NAND_PART_NAME_53               "eeprom_B"
#endif
#endif

#define NAND_FLASH_STATIC_LAST_PART_ID      (12)
#if (defined(REPLACE_EEPROM_WITH_EMMC)||defined(REPLACE_EEPROM_WITH_FLASH))
#define NAND_PART_END                       (54)                /* total 32 Partitions */
//#define NAND_PART_END                       (31)                /* total 32 Partitions */
#else
#define NAND_PART_END                       (52)                /* total 32 Partitions */
//#define NAND_PART_END                       (30)                /* total 32 Partitions */
#endif
#define NAND_FLASH_STATIC_PART_SIZE \
        ((NAND_PART_SIZE_0) + \
        (NAND_PART_SIZE_1) + (NAND_PART_SIZE_2) + (NAND_PART_SIZE_3) + \
        (NAND_PART_SIZE_4) + (NAND_PART_SIZE_5) + (NAND_PART_SIZE_6) + \
        (NAND_PART_SIZE_7) + (NAND_PART_SIZE_8) + (NAND_PART_SIZE_9) + \
        (NAND_PART_SIZE_10) + (NAND_PART_SIZE_11) + (NAND_PART_SIZE_12))

/*Flash PQ customization*/
#ifdef SUPPORT_FLASH_PQ
#define FLASH_PQ_USE_NAND_FLASH                 (1)
#define FLASH_PQ_BASE_PARTITION                 (16)

#ifndef DEMO_BOARD
/* customer */
#define SUPPORT_FLASH_PQ_ENABLE_QTY_SMART_PIC   (1)
#define SUPPORT_FLASH_PQ_ENABLE_GAMMA           (0)
#define SUPPORT_FLASH_PQ_ENABLE_QTY_MAX_MIN     (1)
#define SUPPORT_NVM_GAMMA                       (1)
#endif
#endif

#ifdef SUPPORT_FLASH_AQ
#define FLASH_AQ_BASE_PARTITION             (17)
#define FLASH_AQ_BASE_ADDRESS               (0)
#endif

/* Flash Panel Table */
#ifdef CC_PANEL_FROM_FLASH
//----------------------------------------------------------------------------
// Flash Panel
//----------------------------------------------------------------------------
#ifndef LOAD_PANEL_FROM_FLASH_CUSTOM
#define LOAD_PANEL_FROM_FLASH_CUSTOM            CustomPanelLoadTableFromFlash
#define DUMP_PANEL_LIST_FROM_FLASH_CUSTOM       CustomDumpPanelListFromFlash
#define PANEL_VERSION_LENGTH                    16
#endif
#define PANEL_FLASH_HEADER_ADDRESS          (0)
#define PANEL_FLASH_HEADER_LENGTH           (32)
#define PANEL_FLASH_TABLE_SIZE              (180)
#define PANEL_FLASH_TABLE_BASE_PARTITION    (25)
#define PANEL_FLASH_TABLE_ADDRESS           (32)
#endif

/* Flash EDID */
#define HDMIEDID_NAND_FLASH_PART_ID         (27)
#define HDMIEDID_NAND_FLASH_OFFSET          (0)
#define HDMIEDID_NAND_FLASH_PART_SIZE       (NAND_FLASH_EDID_SIZE)
#define VGAEDID_NAND_FLASH_PART_ID          (27)
#define VGAEDID_NAND_FLASH_OFFSET           (0)
#define VGAEDID_NAND_FLASH_PART_SIZE        (NAND_FLASH_EDID_SIZE)

/* Flash HDCP */
#define HDCP_NAND_FLASH_PART_ID             (0)
#define HDCP_NAND_FLASH_OFFSET              (0)

#endif /*FLASH_LAYOUT_H*/
