sec_socid.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2019. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. *
  31. * The following software/firmware and/or related documentation ("MediaTek Software")
  32. * have been modified by MediaTek Inc. All revisions are subject to any receiver\'s
  33. * applicable license agreements with MediaTek Inc.
  34. */
  35. #include <platform/mt_typedefs.h>
  36. #include "sec_unlock.h"
  37. #include "fastboot.h"
  38. #include <video.h>
  39. #include <string.h>
  40. #include <debug.h>
  41. #include <printf.h>
  42. #include <verified_boot_common.h>
  43. #include <verified_boot_error.h>
  44. #include <boot_mode.h>
  45. #include <pal_log.h>
  46. extern BOOT_ARGUMENT *g_boot_arg;
  47. static char int_to_str(char c)
  48. {
  49. if (c <= 9)
  50. return (c + 48);
  51. return (c - 9) + 64;
  52. }
  53. uint32_t get_socid_chip(uint8_t *socid, uint32_t len)
  54. {
  55. uint32_t ret = 0;
  56. #ifdef MTK_SEC_SOCID_SUPPORT
  57. if (socid == NULL || g_boot_arg == NULL) {
  58. ret = ERR_VB_INVALID_ADDR;
  59. goto end;
  60. }
  61. memcpy(socid, g_boot_arg->socid, len);
  62. #else
  63. if (socid == NULL) {
  64. ret = ERR_VB_INVALID_ADDR;
  65. goto end;
  66. }
  67. memset(socid, 0x0, len);
  68. #endif
  69. end:
  70. return ret;
  71. }
  72. void fastboot_get_socid(const char *arg, void *data, unsigned sz)
  73. {
  74. #define MAX_SOCID_MSG_SZ (128)
  75. uint32_t ret = 0;
  76. uint32_t i, j;
  77. char msg[MAX_SOCID_MSG_SZ] = {0};
  78. char socid[SOC_ID_LEN] = {0};
  79. char socid_first_half[SOC_ID_LEN + 1] = {0};
  80. char socid_second_half[SOC_ID_LEN + 1] = {0};
  81. ret = get_socid_chip((uint8_t *)socid, SOC_ID_LEN);
  82. if (ret)
  83. goto end;
  84. /* separate 64 characters into two lines in order to fit fastboot
  85. * message length.
  86. */
  87. for (i = 0, j = 0; i < SOC_ID_LEN && j < (SOC_ID_LEN / 2); i += 2, j++) {
  88. socid_first_half[i] = int_to_str((socid[j] & 0xF0) >> 4);
  89. socid_first_half[i + 1] = int_to_str(socid[j] & 0x0F);
  90. }
  91. socid_first_half[SOC_ID_LEN] = '\0';
  92. for (i = 0, j = (SOC_ID_LEN / 2); i < SOC_ID_LEN && j < SOC_ID_LEN; i += 2, j++) {
  93. socid_second_half[i] = int_to_str((socid[j] & 0xF0) >> 4);
  94. socid_second_half[i + 1] = int_to_str(socid[j] & 0x0F);
  95. }
  96. socid_second_half[SOC_ID_LEN] = '\0';
  97. fastboot_info("dump socid...");
  98. fastboot_info(socid_first_half);
  99. fastboot_info(socid_second_half);
  100. fastboot_info("finish dump");
  101. end:
  102. if (ret) {
  103. if (snprintf(msg, MAX_SOCID_MSG_SZ, "\nget_socid failed - Err:0x%x\n", ret) >= 0) {
  104. msg[MAX_SOCID_MSG_SZ - 1] = '\0';
  105. fastboot_fail(msg);
  106. } else {
  107. fastboot_fail("unknown error\n");
  108. }
  109. } else
  110. fastboot_okay("");
  111. return;
  112. }