void write_to_flash(unsigned char* psrc, unsigned size) { #ifdef CONFIG_SECURE_NAND extern int aml_nand_save_secure(struct mtd_info *mtd, u_char *buf, unsigned int size); extern struct mtd_info * nand_secure_mtd; unsigned char * secure_ptr = psrc; int error = 0; printk("%s %d save secure here \n",__func__, __LINE__); error = aml_nand_save_secure(nand_secure_mtd, secure_ptr, size); if(error){ printk("save secure failed\n"); } printk("///////////////////////////////////////save secure success//////////////////////////////////\n"); return; #elif CONFIG_SPI_NOR_SECURE_STORAGE extern int secure_storage_spi_write(u8 *buf,u32 len); unsigned char * secure_ptr = psrc; int error = 0; printk("%s %d save secure here \n",__func__, __LINE__); error=secure_storage_spi_write(secure_ptr, size); if(error){ printk("save secure failed\n"); } printk("///////////////////////////////////////save secure success//////////////////////////////////\n"); return; #endif }
int do_securestore(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { unsigned int len,addr; const char *cmd; int err; if (argc < 2) goto usage; cmd = argv[1]; if((!strcmp(cmd,"nand"))||(!strcmp(cmd,"spi"))){ if(!strcmp(cmd,"nand")){ storage_type = SECURE_STORAGE_NAND_TYPE; } if(!strcmp(cmd,"spi")){ storage_type = SECURE_STORAGE_SPI_TYPE; } if(argc == 3){ if(!strcmp(argv[2],"permit")){ storage_status = SECURE_STORAGE_WRITE_PERMIT; printf("secure storage write to %s permit\n",cmd); } if(!strcmp(argv[2],"prohibit")){ storage_status = SECURE_STORAGE_WRITE_PROHIBIT; printf("secure storage write to %s prohibited\n",cmd); } } return 0; } if(!strcmp(cmd,"emmc")){ //storage_type = SECURE_STORAGE_EMMC_TYPE; return 0; } if(!storage_type ){ printf("please set device\n"); return 1; } if(!strcmp(cmd,"write")){ if((argc > 2)&&(argc < 4)){ goto usage; } if(storage_status != SECURE_STORAGE_WRITE_PERMIT){ printf("secure storage write is prohibited\n"); goto usage; } if(argc >=4){ addr = simple_strtoul(argv[2], NULL, 16); len = simple_strtoul(argv[3], NULL, 16); } else{ addr = SECUREOS_KEY_DEFAULT_ADDR_TEST; len = SECUREOS_KEY_DEFAULT_SIZE_TEST; } if(storage_type == SECURE_STORAGE_NAND_TYPE){ err = secure_storage_nand_write((char*)addr,len); if(err){ printf("%s:%d,write key fail to nand\n",__func__,__LINE__); return err; } printf("write to nand ok\n"); } else if(storage_type == SECURE_STORAGE_SPI_TYPE){ err = secure_storage_spi_write((char*)addr,len); if(err){ printf("%s:%d,write key fail to spi\n",__func__,__LINE__); return err; } printf("write to spi ok\n"); } else{ printf("not support\n"); return 1; } return 0; } if(!strcmp(cmd,"read")){ if((argc > 2)&&(argc < 4)){ goto usage; } if(argc >=4){ addr = simple_strtoul(argv[2], NULL, 16); len = simple_strtoul(argv[3], NULL, 16); } else{ addr = SECUREOS_KEY_DEFAULT_ADDR_TEST; len = SECUREOS_KEY_DEFAULT_SIZE_TEST; } if(storage_type == SECURE_STORAGE_NAND_TYPE){ err = secure_storage_nand_read((char*)addr,len); if(err){ printf("%s:%d,read key fail from nand\n",__func__,__LINE__); return err; } printf("from nand read key ok\n"); } else if(storage_type == SECURE_STORAGE_SPI_TYPE){ err = secure_storage_spi_read((char*)addr,len); if(err){ printf("%s:%d,read key fail from spi\n",__func__,__LINE__); return 1; } printf("from spi read key ok\n"); } else{ printf("not support\n"); return 1; } return 0; } usage: cmd_usage(cmdtp); return 1; }