Blame view

cmd/cmd_fsl_caam.c 2.51 KB
d41ce506b   Eric Lee   Initial Release, ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  /*
   * Copyright (C) 2012-2016 Freescale Semiconductor, Inc.
   * Copyright 2018 NXP
   *
   *
   * See file CREDITS for list of people who contributed to this
   * project.
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License as
   * published by the Free Software Foundation; either version 2 of
   * the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   */
  
  
  #include <common.h>
  #include <command.h>
  #include <fsl_caam.h>
  
  static int do_caam(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  {
  
  	int ret, i;
  
  	if (argc < 2)
  	return CMD_RET_USAGE;
  
  	if (strcmp(argv[1], "genblob") == 0) {
  
  	if (argc != 5)
  	    return CMD_RET_USAGE;
  
  	void *data_addr;
  	void *blob_addr;
  	int size;
  
  	data_addr = (void *)simple_strtoul(argv[2], NULL, 16);
  	blob_addr = (void *)simple_strtoul(argv[3], NULL, 16);
  	size      = simple_strtoul(argv[4], NULL, 10);
  	if (size <= 48)
  		return CMD_RET_USAGE;
  
  	caam_open();
  	ret = caam_gen_blob((uint32_t)data_addr, (uint32_t)blob_addr, (uint32_t)size);
  
  	if(ret != SUCCESS){
  		printf("Error during blob encap operation: 0x%x
  ", ret);
  		return 0;
  	}
  
  	/* Print the generated DEK blob */
  	printf("DEK blob is available at 0x%08X and equals:
  ",(unsigned int)blob_addr);
  	for(i=0;i<size;i++)
  		printf("%02X ",((uint8_t *)blob_addr)[i]);
  	printf("
  
  ");
  
  
  	return 1;
  
  	}
  
  	else if (strcmp(argv[1], "decap") == 0){
  
  	if (argc != 5)
  		return CMD_RET_USAGE;
  
  	void *blob_addr;
  	void *data_addr;
  	int size;
  
  	blob_addr = (void *)simple_strtoul(argv[2], NULL, 16);
  	data_addr = (void *)simple_strtoul(argv[3], NULL, 16);
  	size      = simple_strtoul(argv[4], NULL, 10);
  	if (size <= 48)
  		return CMD_RET_USAGE;
  
  	caam_open();
  	ret = caam_decap_blob((uint32_t)(data_addr), (uint32_t)(blob_addr), (uint32_t)size);
  	if(ret != SUCCESS)
  		printf("Error during blob decap operation: 0x%x
  ", ret);
  	else {
  		printf("Success, blob decap at SM PAGE1 original data is:
  ");
  		int i = 0;
  		for (i = 0; i < size; i++) {
  		printf("0x%x  ",*(unsigned char*)(data_addr+i));
  		if (i % 16 == 0)
  			printf("
  ");
  		}
  		printf("
  ");
  	}
  
  	return 1;
  	}
  
  	return CMD_RET_USAGE;
  }
  
  U_BOOT_CMD(
  	caam, 5, 1, do_caam,
  	"Freescale i.MX CAAM command",
  	"caam genblob data_addr blob_addr data_size
   \
  	caam decap blobaddr data_addr data_size
   \
  	
   "
  	);