Pārlūkot izejas kodu

iflash driver and authorize by guid

zhangbo 3 gadi atpakaļ
vecāks
revīzija
d440638810
41 mainītis faili ar 1175 papildinājumiem un 37 dzēšanām
  1. 1 0
      GD32F450_BMC_BaseCode.initramfs
  2. 70 1
      app/AuthLicense/AuthLicense_main.c
  3. BIN
      app/AuthLicense/authlicense
  4. 612 0
      app/AuthLicense/iflash.c
  5. 8 0
      app/AuthLicense/iflash.h
  6. 1 0
      app/Makefile
  7. BIN
      app/NCP81111_Config/ncp81111_cfg
  8. BIN
      app/UpdateFirmware/updateFW_app
  9. 23 30
      app/bmc/AuthLicense.c
  10. 0 1
      app/bmc/Makefile
  11. BIN
      app/bmc/bmc_app
  12. 3 1
      app/bmc/main.c
  13. 1 0
      app/driver/InternalFlash/.iflash.ko.cmd
  14. 0 1
      app/driver/InternalFlash/.iflash.mod.o.cmd
  15. 1 0
      app/driver/InternalFlash/.iflash.o.cmd
  16. 0 0
      app/driver/InternalFlash/.internalFlash_main.o.cmd
  17. 2 0
      app/driver/InternalFlash/.tmp_versions/iflash.mod
  18. 33 0
      app/driver/InternalFlash/Makefile
  19. 0 0
      app/driver/InternalFlash/Module.symvers
  20. BIN
      app/driver/InternalFlash/iflash.ko
  21. 0 0
      app/driver/InternalFlash/iflash.mod.c
  22. 399 0
      app/driver/InternalFlash/internalFlash_main.c
  23. 1 0
      app/driver/InternalFlash/modules.order
  24. 0 1
      app/driver/Platform/.platform_STM32F429.ko.cmd
  25. 0 1
      app/driver/Platform/.platform_STM32F429.o.cmd
  26. BIN
      app/driver/Platform/platform_STM32F429.ko
  27. 0 0
      app/driver/STM32F4xx_HAL_Driver/.system_stm32f4xx.o.cmd
  28. 0 0
      app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal.o.cmd
  29. 0 0
      app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_dma.o.cmd
  30. 0 0
      app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_flash.o.cmd
  31. 0 0
      app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_flash_ex.o.cmd
  32. 0 0
      app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_gpio.o.cmd
  33. 0 0
      app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_iwdg.o.cmd
  34. 0 0
      app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_rcc.o.cmd
  35. 0 0
      app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_sram.o.cmd
  36. 0 0
      app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_ll_fmc.o.cmd
  37. 18 1
      app/driver/driver.h
  38. BIN
      app/i2c_scan/i2c-scan
  39. BIN
      app/ipmitool-1.8.18/ipmitool
  40. BIN
      app/test_app/test_app
  41. 2 0
      local/rc

+ 1 - 0
GD32F450_BMC_BaseCode.initramfs

@@ -147,6 +147,7 @@ file /usr/bin/adc.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/ADC/adc.ko 75
 file /usr/bin/spi.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/SPI/spi.ko 755 0 0
 file /usr/bin/crypto.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/Crypto/crypto.ko 755 0 0
 file /usr/bin/iwdg.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/WatchDog/iwdg.ko 755 0 0
+file /usr/bin/iflash.ko ${INSTALL_ROOT}/projects/${SAMPLE}/app/driver/InternalFlash/iflash.ko 755 0 0
 #
 #
 #

+ 70 - 1
app/AuthLicense/AuthLicense_main.c

@@ -18,6 +18,43 @@ void help()
 	printf("authlicense -guid \n");
 	printf("    -Read device GUID.\n");
 }
+
+void saveToFlash(uint8_t *license)
+{
+	iflash_t iflash_arg;
+	int ret = 0;
+	int fd = open("/dev/iflash", O_RDWR);
+	ret = ioctl(fd, IFLASH_UNLOCK, NULL);
+	if(ret != 0)
+	{
+		printf("error: ret = %d\n", ret);
+	}
+
+	iflash_arg.sector = 7;
+	ret = ioctl(fd, IFLASH_ERASESECTOR, &iflash_arg);
+	if(ret != 0)
+	{
+		printf("error: ret = %d\n", ret);
+	}
+
+	iflash_arg.address = 0x08060000;
+	iflash_arg.len = 128;
+	memcpy(iflash_arg.data, license, 128);
+	ret = ioctl(fd, IFLASH_WRITEBYTE, &iflash_arg);
+	if(ret != 0)
+	{
+		printf("error: ret = %d\n", ret);
+	}
+
+	ret = ioctl(fd, IFLASH_LOCK, NULL);
+	if(ret != 0)
+	{
+		printf("error: ret = %d\n", ret);
+	}
+	
+	close(fd);
+}
+
 int main(int argc, char* argv[])
 {
 	int i;
@@ -30,11 +67,39 @@ int main(int argc, char* argv[])
     uint8_t  HexLicense[128] = {0};
     uint8_t CharLicense[256+10] = {0};
 
+    iflash_t iflash_arg;
+
 	if(argc != 2)
 	{
 		help();
 		return -1;
 	}
+
+	if(strcmp(argv[1], "-test") == 0)
+	{
+		int fd = open("/dev/iflash", O_RDWR);
+		ioctl(fd, IFLASH_UNLOCK, NULL);
+
+		iflash_arg.sector = 7;
+		ioctl(fd, IFLASH_ERASESECTOR, &iflash_arg);
+
+		iflash_arg.address = 0x08060000;
+		iflash_arg.len = 8;
+		iflash_arg.data[0] = 1;
+		iflash_arg.data[1] = 2;
+		iflash_arg.data[2] = 3;
+		iflash_arg.data[3] = 4;
+		iflash_arg.data[4] = 5;
+		iflash_arg.data[5] = 6;
+		iflash_arg.data[6] = 7;
+		iflash_arg.data[7] = 8;
+		ioctl(fd, IFLASH_WRITEBYTE, &iflash_arg);
+
+		ioctl(fd, IFLASH_LOCK, NULL);
+		close(fd);
+		return 0;
+	}
+
 	//读取License
 	if(strcmp(argv[1], "-r") == 0)
 	{			
@@ -123,8 +188,12 @@ int main(int argc, char* argv[])
 			if(CheckLicense(GUID, HexLicense) == 0)
 			{
 				//将license写入Flash
-				//TODO:
+				saveToFlash(HexLicense);
 				printf("Save license to falsh ok.\n");
+
+				//唤醒后台监控脚本
+				system("killall -9 damon.sh");
+				system("damon.sh &");
 				return 0;
 			}
 			else

BIN
app/AuthLicense/authlicense


+ 612 - 0
app/AuthLicense/iflash.c

@@ -0,0 +1,612 @@
+
+#include "iflash.h"
+
+enum {RESET = 0, SET = !RESET};
+
+#define     __IO    volatile 
+
+/* Base address of the Flash sectors */ 
+#define ADDR_FLASH_SECTOR_0     ((uint32_t)0x08000000) /* Base address of Sector 0, 16 Kbytes   */
+#define ADDR_FLASH_SECTOR_1     ((uint32_t)0x08004000) /* Base address of Sector 1, 16 Kbytes   */
+#define ADDR_FLASH_SECTOR_2     ((uint32_t)0x08008000) /* Base address of Sector 2, 16 Kbytes   */
+#define ADDR_FLASH_SECTOR_3     ((uint32_t)0x0800C000) /* Base address of Sector 3, 16 Kbytes   */
+#define ADDR_FLASH_SECTOR_4     ((uint32_t)0x08010000) /* Base address of Sector 4, 64 Kbytes   */
+#define ADDR_FLASH_SECTOR_5     ((uint32_t)0x08020000) /* Base address of Sector 5, 128 Kbytes  */
+#define ADDR_FLASH_SECTOR_6     ((uint32_t)0x08040000) /* Base address of Sector 6, 128 Kbytes  */
+#define ADDR_FLASH_SECTOR_7     ((uint32_t)0x08060000) /* Base address of Sector 7, 128 Kbytes  */
+#define ADDR_FLASH_SECTOR_8     ((uint32_t)0x08080000) /* Base address of Sector 8, 128 Kbytes  */
+#define ADDR_FLASH_SECTOR_9     ((uint32_t)0x080A0000) /* Base address of Sector 9, 128 Kbytes  */
+#define ADDR_FLASH_SECTOR_10    ((uint32_t)0x080C0000) /* Base address of Sector 10, 128 Kbytes */
+#define ADDR_FLASH_SECTOR_11    ((uint32_t)0x080E0000) /* Base address of Sector 11, 128 Kbytes */
+
+#define ADDR_FLASH_SECTOR_12     ((uint32_t)0x08100000) /* Base address of Sector 12, 16 Kbytes  */
+#define ADDR_FLASH_SECTOR_13     ((uint32_t)0x08104000) /* Base address of Sector 13, 16 Kbytes  */
+#define ADDR_FLASH_SECTOR_14     ((uint32_t)0x08108000) /* Base address of Sector 14, 16 Kbytes  */
+#define ADDR_FLASH_SECTOR_15     ((uint32_t)0x0810C000) /* Base address of Sector 15, 16 Kbytes  */
+#define ADDR_FLASH_SECTOR_16     ((uint32_t)0x08110000) /* Base address of Sector 16, 64 Kbytes  */
+#define ADDR_FLASH_SECTOR_17     ((uint32_t)0x08120000) /* Base address of Sector 17, 128 Kbytes */
+#define ADDR_FLASH_SECTOR_18     ((uint32_t)0x08140000) /* Base address of Sector 18, 128 Kbytes */
+#define ADDR_FLASH_SECTOR_19     ((uint32_t)0x08160000) /* Base address of Sector 19, 128 Kbytes */
+#define ADDR_FLASH_SECTOR_20     ((uint32_t)0x08180000) /* Base address of Sector 20, 128 Kbytes */
+#define ADDR_FLASH_SECTOR_21     ((uint32_t)0x081A0000) /* Base address of Sector 21, 128 Kbytes */
+#define ADDR_FLASH_SECTOR_22     ((uint32_t)0x081C0000) /* Base address of Sector 22, 128 Kbytes */
+#define ADDR_FLASH_SECTOR_23     ((uint32_t)0x081E0000) /* Base address of Sector 23, 128 Kbytes */
+
+#define SECTOR_MASK               ((uint32_t)0xFFFFFF07)
+
+
+/** @defgroup FLASH_Flags 
+  * @{
+  */ 
+#define FLASH_FLAG_EOP                 ((uint32_t)0x00000001)  /*!< FLASH End of Operation flag               */
+#define FLASH_FLAG_OPERR               ((uint32_t)0x00000002)  /*!< FLASH operation Error flag                */
+#define FLASH_FLAG_WRPERR              ((uint32_t)0x00000010)  /*!< FLASH Write protected error flag          */
+#define FLASH_FLAG_PGAERR              ((uint32_t)0x00000020)  /*!< FLASH Programming Alignment error flag    */
+#define FLASH_FLAG_PGPERR              ((uint32_t)0x00000040)  /*!< FLASH Programming Parallelism error flag  */
+#define FLASH_FLAG_PGSERR              ((uint32_t)0x00000080)  /*!< FLASH Programming Sequence error flag     */
+#define FLASH_FLAG_RDERR               ((uint32_t)0x00000100)  /*!< Read Protection error flag (PCROP)        */
+#define FLASH_FLAG_BSY                 ((uint32_t)0x00010000)  /*!< FLASH Busy flag                           */ 
+
+/** @defgroup FLASH_Sectors
+  * @{
+  */
+#define FLASH_Sector_0     ((uint16_t)0x0000) /*!< Sector Number 0   */
+#define FLASH_Sector_1     ((uint16_t)0x0008) /*!< Sector Number 1   */
+#define FLASH_Sector_2     ((uint16_t)0x0010) /*!< Sector Number 2   */
+#define FLASH_Sector_3     ((uint16_t)0x0018) /*!< Sector Number 3   */
+#define FLASH_Sector_4     ((uint16_t)0x0020) /*!< Sector Number 4   */
+#define FLASH_Sector_5     ((uint16_t)0x0028) /*!< Sector Number 5   */
+#define FLASH_Sector_6     ((uint16_t)0x0030) /*!< Sector Number 6   */
+#define FLASH_Sector_7     ((uint16_t)0x0038) /*!< Sector Number 7   */
+#define FLASH_Sector_8     ((uint16_t)0x0040) /*!< Sector Number 8   */
+#define FLASH_Sector_9     ((uint16_t)0x0048) /*!< Sector Number 9   */
+#define FLASH_Sector_10    ((uint16_t)0x0050) /*!< Sector Number 10  */
+#define FLASH_Sector_11    ((uint16_t)0x0058) /*!< Sector Number 11  */
+#define FLASH_Sector_12    ((uint16_t)0x0080) /*!< Sector Number 12  */
+#define FLASH_Sector_13    ((uint16_t)0x0088) /*!< Sector Number 13  */
+#define FLASH_Sector_14    ((uint16_t)0x0090) /*!< Sector Number 14  */
+#define FLASH_Sector_15    ((uint16_t)0x0098) /*!< Sector Number 15  */
+#define FLASH_Sector_16    ((uint16_t)0x00A0) /*!< Sector Number 16  */
+#define FLASH_Sector_17    ((uint16_t)0x00A8) /*!< Sector Number 17  */
+#define FLASH_Sector_18    ((uint16_t)0x00B0) /*!< Sector Number 18  */
+#define FLASH_Sector_19    ((uint16_t)0x00B8) /*!< Sector Number 19  */
+#define FLASH_Sector_20    ((uint16_t)0x00C0) /*!< Sector Number 20  */
+#define FLASH_Sector_21    ((uint16_t)0x00C8) /*!< Sector Number 21  */
+#define FLASH_Sector_22    ((uint16_t)0x00D0) /*!< Sector Number 22  */
+#define FLASH_Sector_23    ((uint16_t)0x00D8) /*!< Sector Number 23  */
+
+/** 
+  * @brief FLASH Status  
+  */ 
+typedef enum
+{ 
+  FLASH_BUSY = 1,
+  FLASH_ERROR_RD,
+  FLASH_ERROR_PGS,
+  FLASH_ERROR_PGP,
+  FLASH_ERROR_PGA,
+  FLASH_ERROR_WRP,
+  FLASH_ERROR_PROGRAM,
+  FLASH_ERROR_OPERATION,
+  FLASH_COMPLETE
+}FLASH_Status;
+
+
+/** @defgroup FLASH_Voltage_Range 
+  * @{
+  */ 
+#define VoltageRange_1        ((uint8_t)0x00)  /*!< Device operating range: 1.8V to 2.1V */
+#define VoltageRange_2        ((uint8_t)0x01)  /*!<Device operating range: 2.1V to 2.7V */
+#define VoltageRange_3        ((uint8_t)0x02)  /*!<Device operating range: 2.7V to 3.6V */
+#define VoltageRange_4        ((uint8_t)0x03)  /*!<Device operating range: 2.7V to 3.6V + External Vpp */
+
+/** @defgroup FLASH_Program_Parallelism   
+  * @{
+  */
+#define FLASH_PSIZE_BYTE           ((uint32_t)0x00000000)
+#define FLASH_PSIZE_HALF_WORD      ((uint32_t)0x00000100)
+#define FLASH_PSIZE_WORD           ((uint32_t)0x00000200)
+#define FLASH_PSIZE_DOUBLE_WORD    ((uint32_t)0x00000300)
+#define CR_PSIZE_MASK              ((uint32_t)0xFFFFFCFF)
+
+#define PERIPH_BASE           ((uint32_t)0x40000000) 
+#define AHB1PERIPH_BASE       (PERIPH_BASE + 0x00020000)
+#define FLASH_R_BASE          (AHB1PERIPH_BASE + 0x3C00)
+
+/** @defgroup FLASH_Keys 
+  * @{
+  */ 
+
+#define FLASH_KEY1               ((uint32_t)0x45670123)
+#define FLASH_KEY2               ((uint32_t)0xCDEF89AB)
+
+
+typedef struct
+{
+  __IO uint32_t ACR;      /*!< FLASH access control register,   Address offset: 0x00 */
+  __IO uint32_t KEYR;     /*!< FLASH key register,              Address offset: 0x04 */
+  __IO uint32_t OPTKEYR;  /*!< FLASH option key register,       Address offset: 0x08 */
+  __IO uint32_t SR;       /*!< FLASH status register,           Address offset: 0x0C */
+  __IO uint32_t CR;       /*!< FLASH control register,          Address offset: 0x10 */
+  __IO uint32_t OPTCR;    /*!< FLASH option control register ,  Address offset: 0x14 */
+  __IO uint32_t OPTCR1;   /*!< FLASH option control register 1, Address offset: 0x18 */
+} FLASH_TypeDef;
+
+
+
+#define FLASH               ((FLASH_TypeDef *) FLASH_R_BASE)
+
+/*******************  Bits definition for FLASH_CR register  ******************/
+#define FLASH_CR_PG                          ((uint32_t)0x00000001)
+#define FLASH_CR_SER                         ((uint32_t)0x00000002)
+#define FLASH_CR_STRT                        ((uint32_t)0x00010000)
+#define FLASH_CR_LOCK                        ((uint32_t)0x80000000)
+
+
+
+static uint32_t GetSector(uint32_t Address);
+void FLASH_Unlock(void);
+FLASH_Status FLASH_EraseSector(uint32_t FLASH_Sector, uint8_t VoltageRange);
+FLASH_Status FLASH_WaitForLastOperation(void);
+FLASH_Status FLASH_GetStatus(void);
+FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);
+FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
+FLASH_Status FLASH_ProgramByte(uint32_t Address, uint8_t Data);
+void FLASH_Lock(void);
+
+
+
+
+
+/*准备写入的测试数据*/
+#define DATA_32                 ((uint32_t)0x13246578)
+#define BUFLENGTH 32
+uint32_t wrbuf[BUFLENGTH] = {0xabcdef12};  
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* 要擦除内部FLASH的起始地址(含) */
+#define FLASH_USER_START_ADDR   ADDR_FLASH_SECTOR_7   
+/* 要擦除内部FLASH的结束地址(不含) */
+#define FLASH_USER_END_ADDR     ADDR_FLASH_SECTOR_8  
+
+
+// /**
+//   * @brief  InternalFlash_Test,对内部FLASH进行读写测试
+//   * @param  None
+//   * @retval None
+//   */
+// int InternalFlash_Test(void)
+// {
+// 	/*要擦除的起始扇区(包含)及结束扇区(不包含),如8-12,表示擦除8、9、10、11扇区*/
+// 	uint32_t uwStartSector = 0;
+// 	uint32_t uwEndSector = 0;
+	
+// 	uint32_t uwAddress = 0;
+// 	uint32_t uwSectorCounter = 0;
+
+// 	// __IO uint32_t uwData32 = 0;
+// 	__IO uint32_t uwMemoryProgramStatus = 0;
+
+// 	int i = 0;
+	
+//   /* FLASH 解锁 ********************************/
+//   /* 使能访问FLASH控制寄存器 */
+//   FLASH_Unlock();
+    
+//   /* 擦除用户区域 (用户区域指程序本身没有使用的空间,可以自定义)**/
+//   /* 清除各种FLASH的标志位 */  
+// //  FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | 
+// //                  FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); 
+    
+//     *((volatile uint32_t *)0x40023c0C) = (((uint32_t)0x00000001) | ((uint32_t)0x00000002) | ((uint32_t)0x00000010) | \
+//                                         ((uint32_t)0x00000020) | ((uint32_t)0x00000040) | ((uint32_t)0x00000080));
+    
+
+
+// 	uwStartSector = GetSector(FLASH_USER_START_ADDR);
+// 	uwEndSector = GetSector(FLASH_USER_END_ADDR);
+
+//   /* 开始擦除操作 */
+//   uwSectorCounter = uwStartSector;
+//   while (uwSectorCounter <= uwEndSector) 
+//   {
+//      // VoltageRange_3 以“字”的大小进行操作  
+//     if (FLASH_EraseSector(uwSectorCounter, VoltageRange_3) != FLASH_COMPLETE)
+//     { 
+//       /*擦除出错,返回,实际应用中可加入处理 */
+// 			return -1;
+//     }
+//     /* 计数器指向下一个扇区 */
+//     if (uwSectorCounter == FLASH_Sector_11)
+//     {
+//       uwSectorCounter += 40;
+//     } 
+//     else 
+//     {
+//       uwSectorCounter += 8;
+//     }
+//   }
+
+//   /* 以“字节”的大小为单位写入数据 ********************************/
+//   uwAddress = FLASH_USER_START_ADDR;
+
+
+//   for (i=0;i < BUFLENGTH;i++)
+//   {
+//     uint32_t rr = 0x12345600;//wrbuf[i];
+//     if (FLASH_ProgramWord(uwAddress, rr) == FLASH_COMPLETE)
+//     {
+//       uwAddress = uwAddress + 4;
+//     }
+//     else
+//     { 
+//       /*写入出错,返回,实际应用中可加入处理 */
+// 			break;
+//     }
+//   }
+	
+
+//   /* 给FLASH上锁,防止内容被篡改*/
+//   FLASH_Lock(); 
+
+// }
+
+
+int WriteLicensetoFlash(uint8_t *license )
+{
+    int index=0;
+    uint32_t eraseSector = 0;
+    uint32_t address = ADDR_FLASH_SECTOR_6;
+    uint32_t *ptr = (uint32_t*)license;
+    FLASH_Unlock();
+  /* 清除各种FLASH的标志位 */  
+    *((volatile uint32_t *)0x40023c0C) = (((uint32_t)0x00000001) | ((uint32_t)0x00000002) | ((uint32_t)0x00000010) | \
+                                        ((uint32_t)0x00000020) | ((uint32_t)0x00000040) | ((uint32_t)0x00000080));
+    
+    eraseSector = GetSector(ADDR_FLASH_SECTOR_6);
+    if(FLASH_EraseSector(eraseSector, VoltageRange_3) != FLASH_COMPLETE)
+    {
+      printf("Erase Flash sector 7 failed!\n");
+      FLASH_Lock();
+      return -1;
+    }
+
+    for(index=0;index<32;index++)
+    {
+      FLASH_ProgramWord(address, (uint32_t)0x11223344);
+      address += 4;
+      ptr++;
+    }
+
+    FLASH_Lock(); 
+}
+
+/**
+  * @brief  根据输入的地址给出它所在的sector
+  *					例如:
+						uwStartSector = GetSector(FLASH_USER_START_ADDR);
+						uwEndSector = GetSector(FLASH_USER_END_ADDR);	
+  * @param  Address:地址
+  * @retval 地址所在的sector
+  */
+static uint32_t GetSector(uint32_t Address)
+{
+  uint32_t sector = 0;
+  
+  if((Address < ADDR_FLASH_SECTOR_1) && (Address >= ADDR_FLASH_SECTOR_0))
+  {
+    sector = FLASH_Sector_0;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_2) && (Address >= ADDR_FLASH_SECTOR_1))
+  {
+    sector = FLASH_Sector_1;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_3) && (Address >= ADDR_FLASH_SECTOR_2))
+  {
+    sector = FLASH_Sector_2;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_4) && (Address >= ADDR_FLASH_SECTOR_3))
+  {
+    sector = FLASH_Sector_3;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_5) && (Address >= ADDR_FLASH_SECTOR_4))
+  {
+    sector = FLASH_Sector_4;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_6) && (Address >= ADDR_FLASH_SECTOR_5))
+  {
+    sector = FLASH_Sector_5;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_7) && (Address >= ADDR_FLASH_SECTOR_6))
+  {
+    sector = FLASH_Sector_6;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_8) && (Address >= ADDR_FLASH_SECTOR_7))
+  {
+    sector = FLASH_Sector_7;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_9) && (Address >= ADDR_FLASH_SECTOR_8))
+  {
+    sector = FLASH_Sector_8;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_10) && (Address >= ADDR_FLASH_SECTOR_9))
+  {
+    sector = FLASH_Sector_9;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_11) && (Address >= ADDR_FLASH_SECTOR_10))
+  {
+    sector = FLASH_Sector_10;  
+  }
+  
+
+  else if((Address < ADDR_FLASH_SECTOR_12) && (Address >= ADDR_FLASH_SECTOR_11))
+  {
+    sector = FLASH_Sector_11;  
+  }
+
+  else if((Address < ADDR_FLASH_SECTOR_13) && (Address >= ADDR_FLASH_SECTOR_12))
+  {
+    sector = FLASH_Sector_12;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_14) && (Address >= ADDR_FLASH_SECTOR_13))
+  {
+    sector = FLASH_Sector_13;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_15) && (Address >= ADDR_FLASH_SECTOR_14))
+  {
+    sector = FLASH_Sector_14;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_16) && (Address >= ADDR_FLASH_SECTOR_15))
+  {
+    sector = FLASH_Sector_15;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_17) && (Address >= ADDR_FLASH_SECTOR_16))
+  {
+    sector = FLASH_Sector_16;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_18) && (Address >= ADDR_FLASH_SECTOR_17))
+  {
+    sector = FLASH_Sector_17;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_19) && (Address >= ADDR_FLASH_SECTOR_18))
+  {
+    sector = FLASH_Sector_18;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_20) && (Address >= ADDR_FLASH_SECTOR_19))
+  {
+    sector = FLASH_Sector_19;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_21) && (Address >= ADDR_FLASH_SECTOR_20))
+  {
+    sector = FLASH_Sector_20;  
+  } 
+  else if((Address < ADDR_FLASH_SECTOR_22) && (Address >= ADDR_FLASH_SECTOR_21))
+  {
+    sector = FLASH_Sector_21;  
+  }
+  else if((Address < ADDR_FLASH_SECTOR_23) && (Address >= ADDR_FLASH_SECTOR_22))
+  {
+    sector = FLASH_Sector_22;  
+  }
+  else/*(Address < FLASH_END_ADDR) && (Address >= ADDR_FLASH_SECTOR_23))*/
+  {
+    sector = FLASH_Sector_23;  
+  }
+  return sector;
+}
+
+void FLASH_Unlock(void)
+{
+  if((FLASH->CR & FLASH_CR_LOCK) != RESET)
+  {
+    /* Authorize the FLASH Registers access */
+    FLASH->KEYR = FLASH_KEY1;
+    FLASH->KEYR = FLASH_KEY2;
+  }  
+}
+
+FLASH_Status FLASH_EraseSector(uint32_t FLASH_Sector, uint8_t VoltageRange)
+{
+  uint32_t tmp_psize = 0x0;
+  FLASH_Status status = FLASH_COMPLETE;
+
+//  /* Check the parameters */
+//  assert_param(IS_FLASH_SECTOR(FLASH_Sector));
+//  assert_param(IS_VOLTAGERANGE(VoltageRange));
+  
+  if(VoltageRange == VoltageRange_1)
+  {
+     tmp_psize = FLASH_PSIZE_BYTE;
+  }
+  else if(VoltageRange == VoltageRange_2)
+  {
+    tmp_psize = FLASH_PSIZE_HALF_WORD;
+  }
+  else if(VoltageRange == VoltageRange_3)
+  {
+    tmp_psize = FLASH_PSIZE_WORD;
+  }
+  else
+  {
+    tmp_psize = FLASH_PSIZE_DOUBLE_WORD;
+  }
+  /* Wait for last operation to be completed */
+  status = FLASH_WaitForLastOperation();
+  
+  if(status == FLASH_COMPLETE)
+  { 
+    /* if the previous operation is completed, proceed to erase the sector */
+    FLASH->CR &= CR_PSIZE_MASK;
+    FLASH->CR |= tmp_psize;
+    FLASH->CR &= SECTOR_MASK;
+    FLASH->CR |= FLASH_CR_SER | FLASH_Sector;
+    FLASH->CR |= FLASH_CR_STRT;
+    
+    /* Wait for last operation to be completed */
+    status = FLASH_WaitForLastOperation();
+    
+    /* if the erase operation is completed, disable the SER Bit */
+    FLASH->CR &= (~FLASH_CR_SER);
+    FLASH->CR &= SECTOR_MASK; 
+  }
+  /* Return the Erase Status */
+  return status;
+}
+
+
+FLASH_Status FLASH_WaitForLastOperation(void)
+{ 
+  __IO FLASH_Status status = FLASH_COMPLETE;
+   
+  /* Check for the FLASH Status */
+  status = FLASH_GetStatus();
+
+  /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
+     Even if the FLASH operation fails, the BUSY flag will be reset and an error
+     flag will be set */
+  while(status == FLASH_BUSY)
+  {
+    status = FLASH_GetStatus();
+  }
+  /* Return the operation status */
+  return status;
+}
+
+FLASH_Status FLASH_GetStatus(void)
+{
+  FLASH_Status flashstatus = FLASH_COMPLETE;
+  
+  if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY) 
+  {
+    flashstatus = FLASH_BUSY;
+  }
+  else 
+  {  
+    if((FLASH->SR & FLASH_FLAG_WRPERR) != (uint32_t)0x00)
+    { 
+      flashstatus = FLASH_ERROR_WRP;
+    }
+    else
+    {
+      if((FLASH->SR & FLASH_FLAG_RDERR) != (uint32_t)0x00)
+      { 
+        flashstatus = FLASH_ERROR_RD;
+      } 
+      else 
+      {
+        if((FLASH->SR & (uint32_t)0xE0) != (uint32_t)0x00)
+        {
+          flashstatus = FLASH_ERROR_PROGRAM; 
+        }
+        else
+        {
+          if((FLASH->SR & FLASH_FLAG_OPERR) != (uint32_t)0x00)
+          {
+            flashstatus = FLASH_ERROR_OPERATION;
+          }
+          else
+          {
+            flashstatus = FLASH_COMPLETE;
+          }
+        }
+      }
+    }
+  }
+  /* Return the FLASH Status */
+  return flashstatus;
+}
+
+FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
+{
+//  FLASH_Status status = FLASH_COMPLETE;
+
+//  /* Check the parameters */
+//  assert_param(IS_FLASH_ADDRESS(Address));
+
+  /* Wait for last operation to be completed */
+  // status = FLASH_WaitForLastOperation();
+  
+  // if(status == FLASH_COMPLETE)
+  // {
+    /* if the previous operation is completed, proceed to program the new data */
+    FLASH->CR &= CR_PSIZE_MASK;
+    FLASH->CR |= FLASH_PSIZE_WORD;
+    FLASH->CR |= FLASH_CR_PG;
+  
+    *(__IO uint32_t*)Address = Data;
+        
+  //   /* Wait for last operation to be completed */
+  //   status = FLASH_WaitForLastOperation();
+
+  //   /* if the program operation is completed, disable the PG Bit */
+  //   FLASH->CR &= (~FLASH_CR_PG);
+  // } 
+  /* Return the Program Status */
+  return 0;
+}
+
+FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
+{
+  FLASH_Status status = FLASH_COMPLETE;
+
+  // /* Check the parameters */
+  // assert_param(IS_FLASH_ADDRESS(Address));
+
+  /* Wait for last operation to be completed */
+  status = FLASH_WaitForLastOperation();
+  
+  if(status == FLASH_COMPLETE)
+  {
+    /* if the previous operation is completed, proceed to program the new data */
+    FLASH->CR &= CR_PSIZE_MASK;
+    FLASH->CR |= FLASH_PSIZE_HALF_WORD;
+    FLASH->CR |= FLASH_CR_PG;
+  
+    *(__IO uint16_t*)Address = Data;
+        
+    /* Wait for last operation to be completed */
+    status = FLASH_WaitForLastOperation();
+
+    /* if the program operation is completed, disable the PG Bit */
+    FLASH->CR &= (~FLASH_CR_PG);
+  } 
+  /* Return the Program Status */
+  return status;
+}
+
+FLASH_Status FLASH_ProgramByte(uint32_t Address, uint8_t Data)
+{
+  FLASH_Status status = FLASH_COMPLETE;
+
+  // /* Check the parameters */
+  // assert_param(IS_FLASH_ADDRESS(Address));
+
+  /* Wait for last operation to be completed */
+  status = FLASH_WaitForLastOperation();
+  
+  if(status == FLASH_COMPLETE)
+  {
+    /* if the previous operation is completed, proceed to program the new data */
+    FLASH->CR &= CR_PSIZE_MASK;
+    FLASH->CR |= FLASH_PSIZE_BYTE;
+    FLASH->CR |= FLASH_CR_PG;
+  
+    *(__IO uint8_t*)Address = Data;
+        
+    /* Wait for last operation to be completed */
+    status = FLASH_WaitForLastOperation();
+
+    /* if the program operation is completed, disable the PG Bit */
+    FLASH->CR &= (~FLASH_CR_PG);
+  } 
+
+  /* Return the Program Status */
+  return status;
+}
+
+void FLASH_Lock(void)
+{
+  /* Set the LOCK Bit to lock the FLASH Registers access */
+  FLASH->CR |= FLASH_CR_LOCK;
+}

+ 8 - 0
app/AuthLicense/iflash.h

@@ -0,0 +1,8 @@
+#ifndef __IFLASH_H__
+#define __IFLASH_H__
+#include <stdio.h>
+#include <stdint.h>
+
+int WriteLicensetoFlash(uint8_t *license );
+
+#endif /* __IFLASH_H__ */

+ 1 - 0
app/Makefile

@@ -9,6 +9,7 @@ all	:
 	make -C ./driver/GPIO_I2C
 	make -C ./driver/Crypto
 	make -C ./driver/WatchDog
+	make -C ./driver/InternalFlash
 	
 	# make apps
 	make -C ./bmc

BIN
app/NCP81111_Config/ncp81111_cfg


BIN
app/UpdateFirmware/updateFW_app


+ 23 - 30
app/bmc/AuthLicense.c

@@ -375,23 +375,13 @@ int CheckLicense()
     uint8_t  GUID[12] = {0};
     uint32_t tmp = 0;
     uint8_t  *pLicense = (uint8_t*)0x08060000; 
-    uint8_t  LICENSE[128] = {0xE9,0x5F,0x60,0x69,0x92,0x01,0xDD,0x0F,0x98,0x42,0x57,0x15,
-                             0x6B,0x64,0x69,0xBE,0x03,0x0A,0x6A,0x17,0x25,0x7C,0xDC,0xAC,
-                             0xDF,0x10,0x04,0xBB,0x5C,0xE9,0xDA,0x70,0xD7,0xD9,0x22,0x8C,
-                             0xE9,0xAA,0xD7,0x2F,0x09,0x86,0xCE,0xE2,0x52,0xAD,0x9B,0x08,
-                             0x86,0x65,0xAF,0x52,0x55,0x38,0xC2,0xA9,0xD6,0x60,0x7B,0x36,
-                             0x5F,0x7F,0x41,0xBD,0x73,0x8C,0x7B,0x2A,0x14,0x12,0xDA,0x72,
-                             0x49,0x9C,0x11,0x96,0xD1,0x6B,0xA9,0x01,0x3B,0x6B,0x2E,0x1D,
-                             0x1F,0x67,0x97,0x21,0xA0,0x77,0xDD,0x29,0x3D,0xC1,0xE7,0x8C,
-                             0xC2,0x5F,0xB2,0x6B,0xA1,0x9F,0xAE,0x84,0x5F,0x6C,0x64,0x52,
-                             0x71,0x0B,0x59,0x51,0x29,0x07,0x32,0x9B,0x0B,0x6D,0x1E,0xB9,
-                             0x47,0x3B,0x73,0xBA,0x7F,0x14,0x95,0x87};    //从Flash中读出的带随机数填充的128字节License
+    uint8_t  LICENSE[128] = {0};    //从Flash中读出的带随机数填充的128字节License
     uint8_t  CalLicense[16] = {0};  //计算得出的有效的16字节License
     MD5_CTX md5;
     int i;
 
     //获取GUID
-    printf("GUID: ");
+    //printf("GUID: ");
     for(i=0;i<3;i++)
     {
         tmp = *pUID;
@@ -400,19 +390,19 @@ int CheckLicense()
         GUID[4*i+2] = (tmp>>16)&0xff;
         GUID[4*i+3] = (tmp>>24)&0xff;
         pUID++;
-        printf("%02x %02x %02x %02x ",  GUID[4*i+0],GUID[4*i+1],GUID[4*i+2],GUID[4*i+3]);
+        //printf("%02x %02x %02x %02x ",  GUID[4*i+0],GUID[4*i+1],GUID[4*i+2],GUID[4*i+3]);
     }
-    printf("\n");
+    //printf("\n");
 
-    // //获取License
-    // printf("License: ");
-    // for(i=0;i<128;i++)
-    // {
-    //     LICENSE[i] = *pLicense;
-    //     pLicense++;
-    //     printf("%02x ", LICENSE[i]);
-    // }
-    // printf("\n" );
+    //获取License
+    //printf("License: ");
+    for(i=0;i<128;i++)
+    {
+        LICENSE[i] = *pLicense;
+        pLicense++;
+        //printf("%02x ", LICENSE[i]);
+    }
+    //printf("\n" );
 
     //根据GUID计算License    
     preHandle((uint32_t*)GUID, 0x33445566, 2);    //预处理
@@ -420,12 +410,12 @@ int CheckLicense()
     MD5_Update(&md5,GUID,12);
     MD5_Final(CalLicense, &md5);
 
-    printf("CalLicense: ");
-    for(i=0;i<16;i++)
-    {
-        printf("%02x ", CalLicense[i]);
-    }
-    printf("\n");
+    // printf("CalLicense: ");
+    // for(i=0;i<16;i++)
+    // {
+    //     printf("%02x ", CalLicense[i]);
+    // }
+    // printf("\n");
 
     //比对License
     if(Authorize(CalLicense, LICENSE, 0) == 1) //授权通过
@@ -437,7 +427,10 @@ int CheckLicense()
     {
         printf("\n\n====================================================\n");
         printf("\n\tLicense is invalid, Please authorize! \n");
-        printf("\n====================================================\n\n");
+        printf("\tGUID: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x \n", 
+            GUID[0], GUID[1], GUID[2], GUID[3], GUID[4], GUID[5], GUID[6], GUID[7], 
+            GUID[8], GUID[9], GUID[10], GUID[11] );
+        printf("====================================================\n\n");
         return -1;
     }
 }

+ 0 - 1
app/bmc/Makefile

@@ -17,7 +17,6 @@ SRC	+= ./sensor_driver.c
 SRC	+= ./sensor_sdr.c
 SRC	+= ./OemFRU.c
 SRC	+= ./Util.c
-SRC	+= ./iflash.c
 
 SRC	+= ./SysTimer/TimerTask.c
 

BIN
app/bmc/bmc_app


+ 3 - 1
app/bmc/main.c

@@ -38,7 +38,6 @@
 #include "driver.h"
 #include "sensor_tbl.h"
 #include "com_IPMI_SDRRecord.h"
-#include "iflash.h"
 
 
 /* gloabl varible */
@@ -105,7 +104,10 @@ void main(void)
 
 	//检查软件授权
 	if(CheckLicense() != 0)
+	{
+		system("killall -9 damon.sh");
 		exit(0);
+	}
 
 	PlatformInit();
 	Init_IPMI_FRU_SDR_SEL();

+ 1 - 0
app/driver/InternalFlash/.iflash.ko.cmd

@@ -0,0 +1 @@
+cmd_/gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/iflash.ko := arm-uclinuxeabi-ld -EL -r  -T /gd32f450_prj/linux-cortexm-1.14.2/linux/scripts/module-common.lds  -o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/iflash.ko /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/iflash.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/iflash.mod.o

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 1
app/driver/InternalFlash/.iflash.mod.o.cmd


+ 1 - 0
app/driver/InternalFlash/.iflash.o.cmd

@@ -0,0 +1 @@
+cmd_/gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/iflash.o := arm-uclinuxeabi-ld -EL    -r -o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/iflash.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/system_stm32f4xx.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_iwdg.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/internalFlash_main.o 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
app/driver/InternalFlash/.internalFlash_main.o.cmd


+ 2 - 0
app/driver/InternalFlash/.tmp_versions/iflash.mod

@@ -0,0 +1,2 @@
+/gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/iflash.ko
+/gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/system_stm32f4xx.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_iwdg.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.o /gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/internalFlash_main.o

+ 33 - 0
app/driver/InternalFlash/Makefile

@@ -0,0 +1,33 @@
+
+KERNELDIR	:= $(INSTALL_ROOT)/linux
+
+iflash-objs := ../STM32F4xx_HAL_Driver/system_stm32f4xx.o
+iflash-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.o
+#gpio-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_cortex.o
+iflash-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.o
+iflash-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.o
+iflash-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.o
+iflash-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.o
+iflash-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.o
+iflash-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_iwdg.o
+iflash-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.o
+iflash-objs += ../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.o
+
+iflash-objs += internalFlash_main.o
+obj-m	+= iflash.o
+
+#PWD := $(shell pwd)	
+#APPDIR := $(INSTALL_ROOT)/projects/SP19017_OpticalFiber/app
+
+EXTRA_CFLAGS := -I$(PWD)/../STM32F4xx_HAL_Driver
+EXTRA_CFLAGS += -I$(PWD)/../STM32F4xx_HAL_Driver/Inc
+EXTRA_CFLAGS += -I$(PWD)/../STM32F4xx_HAL_Driver/Inc/Legacy
+EXTRA_CFLAGS += -I$(PWD)/../../common_include
+EXTRA_CFLAGS += -I$(PWD)/../
+
+modules	:
+	make -C $(KERNELDIR) M=`pwd` modules CFLAGS="" LDFLAGS=""
+#	rm -f *.o
+
+clean:
+	make -C $(KERNELDIR) M=`pwd` clean

+ 0 - 0
app/driver/InternalFlash/Module.symvers


BIN
app/driver/InternalFlash/iflash.ko


+ 0 - 0
app/driver/Platform/platform_STM32F429.mod.c → app/driver/InternalFlash/iflash.mod.c


+ 399 - 0
app/driver/InternalFlash/internalFlash_main.c

@@ -0,0 +1,399 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/cdev.h>
+#include <linux/fs.h>
+#include <linux/errno.h>
+#include <asm/current.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <asm/uaccess.h>
+//#include <stdint.h>
+#include "stm32f4xx.h"
+#include "stm32f4xx_hal_flash.h"
+#include "driver.h"
+#include "stm32_hal_legacy.h"
+
+
+
+
+static int major = MAJOR_IFLASH;
+static int minor = 0;
+static dev_t devno;
+static struct cdev *iflash_cdev = NULL;
+static int count = 1;
+#define DEVNAME "iflash"
+
+static int iflash_open(struct inode *inode, struct file *filep);
+static int iflash_close(struct inode *inode, struct file *filep);
+static ssize_t iflash_read(struct file *filep, char __user *buf, size_t size, loff_t *offset);
+static ssize_t iflash_write(struct file *filep, const char __user *buf, size_t size, loff_t *offset);
+static int iflash_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg);
+static struct file_operations iflash_ops = 
+{
+	.owner = THIS_MODULE,
+	.open = iflash_open,
+	.release = iflash_close,
+	.ioctl = iflash_ioctl,
+	.read = iflash_read,
+	.write = iflash_write,
+	
+};
+
+static int iflash_open(struct inode *inode, struct file *filep)
+{
+	return 0;
+}
+
+static int iflash_close(struct inode *inode, struct file *filep)
+{
+	return 0;
+}
+
+static int iflash_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg)
+{
+	iflash_t iflash_arg;
+	uint32_t sector = 0;
+	uint32_t address = 0;
+	int i;
+	int ret = 0;
+	int try = 3;
+	if ( copy_from_user(&iflash_arg, (void*)arg, sizeof(iflash_t)) )
+		return -EFAULT;
+	
+	switch(cmd)
+	{
+		case IFLASH_UNLOCK:
+			//printk("IFLASH_UNLOCK()\n");
+			ret = HAL_FLASH_Unlock();
+			break;
+		case IFLASH_LOCK:
+			//printk("IFLASH_LOCK()\n");
+			ret = HAL_FLASH_Lock();
+			break;
+		case IFLASH_ERASESECTOR:
+			//printk("IFLASH_ERASESECTOR()\n");
+			switch(iflash_arg.sector)
+			{
+				case 0:
+					sector = FLASH_SECTOR_0;
+					break;
+				case 1:
+					sector = FLASH_SECTOR_1;
+					break;
+				case 2:
+					sector = FLASH_SECTOR_2;
+					break;
+				case 3:
+					sector = FLASH_SECTOR_3;
+					break;
+				case 4:
+					sector = FLASH_SECTOR_4;
+					break;
+				case 5:
+					sector = FLASH_SECTOR_5;
+					break;
+				case 6:
+					sector = FLASH_SECTOR_6;
+					break;
+				case 7:
+					sector = FLASH_SECTOR_7;
+					break;
+				case 8:
+					sector = FLASH_SECTOR_8;
+					break;
+				case 9:
+					sector = FLASH_SECTOR_9;
+					break;
+				case 10:
+					sector = FLASH_SECTOR_10;
+					break;
+				case 11:
+					sector = FLASH_SECTOR_11;
+					break;
+				case 12:
+					sector = FLASH_SECTOR_12;
+					break;
+				case 13:
+					sector = FLASH_SECTOR_13;
+					break;
+				case 14:
+					sector = FLASH_SECTOR_14;
+					break;
+				case 15:
+					sector = FLASH_SECTOR_15;
+					break;
+				case 16:
+					sector = FLASH_SECTOR_16;
+					break;
+				case 17:
+					sector = FLASH_SECTOR_17;
+					break;
+				case 18:
+					sector = FLASH_SECTOR_18;
+					break;
+				case 19:
+					sector = FLASH_SECTOR_19;
+					break;
+				case 20:
+					sector = FLASH_SECTOR_20;
+					break;
+				case 21:
+					sector = FLASH_SECTOR_21;
+					break;
+				case 22:
+					sector = FLASH_SECTOR_22;
+					break;
+				case 23:
+					sector = FLASH_SECTOR_23;
+					break;
+			}
+			FLASH_Erase_Sector(sector, FLASH_VOLTAGE_RANGE_3);
+			break;
+		case IFLASH_WRITEWORD:
+			//printk("IFLASH_WRITEWORD()\n");
+			address = iflash_arg.address;
+			for(i=0;i<iflash_arg.len;i+=4)
+			{
+				try = 3;
+				while(try>0)
+				{
+					ret = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address+i, ((uint32_t*)&iflash_arg.data[i]));
+					if(ret = 0)
+						try=0;
+					else if(try > 0)
+					{
+						try--;
+					}
+					else
+					{
+						return ret;
+					}
+				}
+			}
+			break;
+		case IFLASH_WRITEHALFWORD:
+			//printk("IFLASH_HALFWORD()\n");
+			address = iflash_arg.address;
+			for(i=0;i<iflash_arg.len;i+=2)
+			{
+				try = 3;
+				while(try>0)
+				{
+					ret = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, address+i, *((uint16_t*)&iflash_arg.data[i]));
+					if(ret = 0)
+						try=0;
+					else if(try > 0)
+					{
+						try--;
+					}
+					else
+					{
+						return ret;
+					}
+				}
+			}
+			break;
+		case IFLASH_WRITEBYTE:
+			//printk("IFLASH_WRITEBYTE()\n");
+			address = iflash_arg.address;
+			for(i=0;i<iflash_arg.len;i++)
+			{
+				try = 3;
+				while(try>0)
+				{
+					ret = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, address+i, (uint32_t)iflash_arg.data[i]);
+					if(ret = 0)
+						try=0;
+					else if(try > 0)
+					{
+						try--;
+					}
+					else
+					{
+						return ret;
+					}
+				}
+			}
+			break;
+		case IFLASH_WRITE_BYTES:
+			ret = HAL_FLASH_Unlock();
+			if(ret != 0)
+			{
+				printk("Unlock flash error.");
+				return ret;
+			}
+
+			switch(iflash_arg.sector)
+			{
+				case 0:
+					sector = FLASH_SECTOR_0;
+					break;
+				case 1:
+					sector = FLASH_SECTOR_1;
+					break;
+				case 2:
+					sector = FLASH_SECTOR_2;
+					break;
+				case 3:
+					sector = FLASH_SECTOR_3;
+					break;
+				case 4:
+					sector = FLASH_SECTOR_4;
+					break;
+				case 5:
+					sector = FLASH_SECTOR_5;
+					break;
+				case 6:
+					sector = FLASH_SECTOR_6;
+					break;
+				case 7:
+					sector = FLASH_SECTOR_7;
+					break;
+				case 8:
+					sector = FLASH_SECTOR_8;
+					break;
+				case 9:
+					sector = FLASH_SECTOR_9;
+					break;
+				case 10:
+					sector = FLASH_SECTOR_10;
+					break;
+				case 11:
+					sector = FLASH_SECTOR_11;
+					break;
+				case 12:
+					sector = FLASH_SECTOR_12;
+					break;
+				case 13:
+					sector = FLASH_SECTOR_13;
+					break;
+				case 14:
+					sector = FLASH_SECTOR_14;
+					break;
+				case 15:
+					sector = FLASH_SECTOR_15;
+					break;
+				case 16:
+					sector = FLASH_SECTOR_16;
+					break;
+				case 17:
+					sector = FLASH_SECTOR_17;
+					break;
+				case 18:
+					sector = FLASH_SECTOR_18;
+					break;
+				case 19:
+					sector = FLASH_SECTOR_19;
+					break;
+				case 20:
+					sector = FLASH_SECTOR_20;
+					break;
+				case 21:
+					sector = FLASH_SECTOR_21;
+					break;
+				case 22:
+					sector = FLASH_SECTOR_22;
+					break;
+				case 23:
+					sector = FLASH_SECTOR_23;
+					break;
+			}
+			FLASH_Erase_Sector(sector, FLASH_VOLTAGE_RANGE_3);
+
+
+			address = iflash_arg.address;
+			for(i=0;i<iflash_arg.len;i++)
+			{				
+				try = 3;
+				while(try>0)
+				{
+					ret = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, address+i, (uint32_t)iflash_arg.data[i]);
+					if(ret = 0)
+						try=0;
+					else if(try > 0)
+					{
+						try--;
+					}
+					else
+					{
+						return ret;
+					}
+				}
+			}
+
+			ret = HAL_FLASH_Lock();
+			if(ret != 0)
+			{
+				printk("Lock flash error.");
+				return ret;
+			}
+
+	default:
+		printk("---> Invalid action\n");
+		return -EINVAL;
+		break;		
+
+	}
+	return ret;
+}
+
+static ssize_t iflash_read(struct file *filep, char __user *buf, size_t size, loff_t *offset)
+{
+	return 0;
+}
+
+static ssize_t iflash_write(struct file *filep, const char __user *buf, size_t size, loff_t *offset)
+{
+	return 0;
+}
+
+
+
+static int __init iflash_init(void)
+{
+	int ret;
+	iflash_cdev = cdev_alloc();
+	if(iflash_cdev == NULL){
+		return -ENOMEM;
+	}
+
+
+	cdev_init(iflash_cdev,&iflash_ops);
+	devno = MKDEV(major,minor);
+	ret = register_chrdev_region(devno, count, DEVNAME);
+	if(ret){
+		goto ERR_STEP;
+	}
+	
+	ret = cdev_add(iflash_cdev, devno, count);
+	if(ret){
+		goto ERR_STEP1;
+	}
+	printk("iflash module start...\n");
+	return 0;
+
+ERR_STEP1:
+	unregister_chrdev_region(devno,count);
+ERR_STEP:
+	cdev_del(iflash_cdev);
+	return ret;
+}
+
+static void __exit iflash_exit(void)
+{
+	unregister_chrdev_region(MKDEV(major,minor),count);
+	cdev_del(iflash_cdev);
+}
+
+module_init(iflash_init);
+module_exit(iflash_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jimbo");
+MODULE_DESCRIPTION("this is iflash module");
+
+
+

+ 1 - 0
app/driver/InternalFlash/modules.order

@@ -0,0 +1 @@
+kernel//gd32f450_prj/linux-cortexm-1.14.2/projects/GD32F450_BMC_BaseCode/app/driver/InternalFlash/iflash.ko

+ 0 - 1
app/driver/Platform/.platform_STM32F429.ko.cmd

@@ -1 +0,0 @@
-cmd_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_STM32F429.ko := arm-uclinuxeabi-ld -EL -r  -T /gd32f450_prj/linux-cortexm-1.14.2/linux/scripts/module-common.lds  -o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_STM32F429.ko /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_STM32F429.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_STM32F429.mod.o

+ 0 - 1
app/driver/Platform/.platform_STM32F429.o.cmd

@@ -1 +0,0 @@
-cmd_/gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_STM32F429.o := arm-uclinuxeabi-ld -EL    -r -o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_STM32F429.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/system_stm32f4xx.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.o /gd32f450_prj/linux-cortexm-1.14.2/projects/gd32450i-eval/app/driver/Platform/platform_main.o 

BIN
app/driver/Platform/platform_STM32F429.ko


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
app/driver/STM32F4xx_HAL_Driver/.system_stm32f4xx.o.cmd


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal.o.cmd


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_dma.o.cmd


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_flash.o.cmd


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_flash_ex.o.cmd


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_gpio.o.cmd


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_iwdg.o.cmd


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_rcc.o.cmd


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_hal_sram.o.cmd


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
app/driver/STM32F4xx_HAL_Driver/Src/.stm32f4xx_ll_fmc.o.cmd


+ 18 - 1
app/driver/driver.h

@@ -15,6 +15,7 @@
 #define MAJOR_GPIO_I2C 	106
 #define MAJOR_CRYPTO 	107
 #define MAJOR_IWDG	108
+#define MAJOR_IFLASH 109
 
 #define IOCTL_MAGIC	'x' 
 #define GENERATE_CMD(__MAGIC__, __MAJOR__, __CMD__)	\
@@ -77,7 +78,16 @@
 /* IWDG */
 #define FEED_WATCHDOG					GENERATE_CMD(IOCTL_MAGIC, MAJOR_IWDG, 0)		
 #define START_IWATCHDOG					GENERATE_CMD(IOCTL_MAGIC, MAJOR_IWDG, 1)		
-#define STOP_IWATCHDOG					GENERATE_CMD(IOCTL_MAGIC, MAJOR_IWDG, 2)		
+#define STOP_IWATCHDOG					GENERATE_CMD(IOCTL_MAGIC, MAJOR_IWDG, 2)	
+
+/* Internal flash */
+#define IFLASH_UNLOCK					GENERATE_CMD(IOCTL_MAGIC, MAJOR_IFLASH, 0)		
+#define IFLASH_LOCK 					GENERATE_CMD(IOCTL_MAGIC, MAJOR_IFLASH, 1)		
+#define IFLASH_ERASESECTOR				GENERATE_CMD(IOCTL_MAGIC, MAJOR_IFLASH, 2)		
+#define IFLASH_WRITEWORD				GENERATE_CMD(IOCTL_MAGIC, MAJOR_IFLASH, 3)		
+#define IFLASH_WRITEHALFWORD			GENERATE_CMD(IOCTL_MAGIC, MAJOR_IFLASH, 4)		
+#define IFLASH_WRITEBYTE				GENERATE_CMD(IOCTL_MAGIC, MAJOR_IFLASH, 5)			
+#define IFLASH_WRITE_BYTES				GENERATE_CMD(IOCTL_MAGIC, MAJOR_IFLASH, 6)	
 
 typedef struct {
 	uint32_t address;
@@ -137,4 +147,11 @@ typedef struct {
 	uint8_t  loop;
 } crypto_t;
 
+typedef struct {
+	uint8_t  sector;
+	uint32_t address;
+	uint32_t len;
+	uint8_t  data[256];
+} iflash_t;
+
 #endif /* __DRIVER_H__ */

BIN
app/i2c_scan/i2c-scan


BIN
app/ipmitool-1.8.18/ipmitool


BIN
app/test_app/test_app


+ 2 - 0
local/rc

@@ -19,6 +19,7 @@ insmod /usr/bin/spi.ko
 #insmod /usr/bin/gpio_i2c.ko
 insmod /usr/bin/crypto.ko
 insmod /usr/bin/iwdg.ko
+insmod /usr/bin/iflash.ko
 
 #################### create node ########################
 #mknod /dev/test_module c 99 0
@@ -36,6 +37,7 @@ mknod /dev/spi5 c 104 4
 #mknod /dev/gpio_i2c c 106 0
 mknod /dev/crypto c 107 0
 mknod /dev/iwdg c 108 0
+mknod /dev/iflash c 109 0
 ################### run app ####################
 #/bin/telnetd
 /usr/bin/bmc_app & 

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels