Loading...
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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | // SPDX-License-Identifier: GPL-2.0 /* * Copyright 2020 NXP * */ #include <common.h> #include <hang.h> #include <malloc.h> #include <asm/io.h> #include <dm.h> #include <asm/arch/s400_api.h> #include <misc.h> DECLARE_GLOBAL_DATA_PTR; int ahab_release_rdc(u8 core_id, bool xrdc, u32 *response) { struct udevice *dev = gd->arch.s400_dev; int size = sizeof(struct imx8ulp_s400_msg); struct imx8ulp_s400_msg msg; int ret; if (!dev) { printf("s400 dev is not initialized\n"); return -ENODEV; } msg.version = AHAB_VERSION; msg.tag = AHAB_CMD_TAG; msg.size = 2; msg.command = AHAB_RELEASE_RDC_REQ_CID; if (xrdc) msg.data[0] = (0x78 << 8) | core_id; else msg.data[0] = (0x74 << 8) | core_id; ret = misc_call(dev, false, &msg, size, &msg, size); if (ret) printf("Error: %s: ret %d, core id %u, response 0x%x\n", __func__, ret, core_id, msg.data[0]); if (response) *response = msg.data[0]; return ret; } int ahab_auth_oem_ctnr(ulong ctnr_addr, u32 *response) { struct udevice *dev = gd->arch.s400_dev; int size = sizeof(struct imx8ulp_s400_msg); struct imx8ulp_s400_msg msg; int ret; if (!dev) { printf("s400 dev is not initialized\n"); return -ENODEV; } msg.version = AHAB_VERSION; msg.tag = AHAB_CMD_TAG; msg.size = 3; msg.command = AHAB_AUTH_OEM_CTNR_CID; msg.data[0] = upper_32_bits(ctnr_addr); msg.data[1] = lower_32_bits(ctnr_addr); ret = misc_call(dev, false, &msg, size, &msg, size); if (ret) printf("Error: %s: ret %d, cntr_addr 0x%lx, response 0x%x\n", __func__, ret, ctnr_addr, msg.data[0]); if (response) *response = msg.data[0]; return ret; } int ahab_release_container(u32 *response) { struct udevice *dev = gd->arch.s400_dev; int size = sizeof(struct imx8ulp_s400_msg); struct imx8ulp_s400_msg msg; int ret; if (!dev) { printf("s400 dev is not initialized\n"); return -ENODEV; } msg.version = AHAB_VERSION; msg.tag = AHAB_CMD_TAG; msg.size = 1; msg.command = AHAB_RELEASE_CTNR_CID; ret = misc_call(dev, false, &msg, size, &msg, size); if (ret) printf("Error: %s: ret %d, response 0x%x\n", __func__, ret, msg.data[0]); if (response) *response = msg.data[0]; return ret; } int ahab_verify_image(u32 img_id, u32 *response) { struct udevice *dev = gd->arch.s400_dev; int size = sizeof(struct imx8ulp_s400_msg); struct imx8ulp_s400_msg msg; int ret; if (!dev) { printf("s400 dev is not initialized\n"); return -ENODEV; } msg.version = AHAB_VERSION; msg.tag = AHAB_CMD_TAG; msg.size = 2; msg.command = AHAB_VERIFY_IMG_CID; msg.data[0] = 1 << img_id; ret = misc_call(dev, false, &msg, size, &msg, size); if (ret) printf("Error: %s: ret %d, img_id %u, response 0x%x\n", __func__, ret, img_id, msg.data[0]); if (response) *response = msg.data[0]; return ret; } int ahab_forward_lifecycle(u16 life_cycle, u32 *response) { struct udevice *dev = gd->arch.s400_dev; int size = sizeof(struct imx8ulp_s400_msg); struct imx8ulp_s400_msg msg; int ret; if (!dev) { printf("s400 dev is not initialized\n"); return -ENODEV; } msg.version = AHAB_VERSION; msg.tag = AHAB_CMD_TAG; msg.size = 2; msg.command = AHAB_FWD_LIFECYCLE_UP_REQ_CID; msg.data[0] = life_cycle; ret = misc_call(dev, false, &msg, size, &msg, size); if (ret) printf("Error: %s: ret %d, life_cycle 0x%x, response 0x%x\n", __func__, ret, life_cycle, msg.data[0]); if (response) *response = msg.data[0]; return ret; } int ahab_read_common_fuse(u16 fuse_id, u32 *fuse_words, u32 fuse_num, u32 *response) { struct udevice *dev = gd->arch.s400_dev; int size = sizeof(struct imx8ulp_s400_msg); struct imx8ulp_s400_msg msg; int ret; if (!dev) { printf("s400 dev is not initialized\n"); return -ENODEV; } if (!fuse_words) { printf("Invalid parameters for fuse read\n"); return -EINVAL; } if ((fuse_id != 1 && fuse_num != 1) || (fuse_id == 1 && fuse_num != 4)) { printf("Invalid fuse number parameter\n"); return -EINVAL; } msg.version = AHAB_VERSION; msg.tag = AHAB_CMD_TAG; msg.size = 2; msg.command = AHAB_READ_FUSE_REQ_CID; msg.data[0] = fuse_id; ret = misc_call(dev, false, &msg, size, &msg, size); if (ret) printf("Error: %s: ret %d, fuse_id 0x%x, response 0x%x\n", __func__, ret, fuse_id, msg.data[0]); if (response) *response = msg.data[0]; fuse_words[0] = msg.data[1]; if (fuse_id == 1) { /* OTP_UNIQ_ID */ fuse_words[1] = msg.data[2]; fuse_words[2] = msg.data[3]; fuse_words[3] = msg.data[4]; } return ret; } int ahab_write_fuse(u16 fuse_id, u32 fuse_val, bool lock, u32 *response) { struct udevice *dev = gd->arch.s400_dev; int size = sizeof(struct imx8ulp_s400_msg); struct imx8ulp_s400_msg msg; int ret; if (!dev) { printf("s400 dev is not initialized\n"); return -ENODEV; } msg.version = AHAB_VERSION; msg.tag = AHAB_CMD_TAG; msg.size = 3; msg.command = AHAB_WRITE_FUSE_REQ_CID; msg.data[0] = (32 << 16) | (fuse_id << 5); if (lock) msg.data[0] |= (1 << 31); msg.data[1] = fuse_val; ret = misc_call(dev, false, &msg, size, &msg, size); if (ret) printf("Error: %s: ret %d, fuse_id 0x%x, response 0x%x\n", __func__, ret, fuse_id, msg.data[0]); if (response) *response = msg.data[0]; return ret; } |