rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* Copyright Statement: |
| 2 | * |
| 3 | * This software/firmware and related documentation ("MediaTek Software") are |
| 4 | * protected under relevant copyright laws. The information contained herein is |
| 5 | * confidential and proprietary to MediaTek Inc. and/or its licensors. Without |
| 6 | * the prior written permission of MediaTek inc. and/or its licensors, any |
| 7 | * reproduction, modification, use or disclosure of MediaTek Software, and |
| 8 | * information contained herein, in whole or in part, shall be strictly |
| 9 | * prohibited. |
| 10 | * |
| 11 | * MediaTek Inc. (C) 2016~2017. All rights reserved. |
| 12 | * |
| 13 | * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 14 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 15 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER |
| 16 | * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL |
| 17 | * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED |
| 18 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR |
| 19 | * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH |
| 20 | * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, |
| 21 | * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES |
| 22 | * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. |
| 23 | * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO |
| 24 | * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK |
| 25 | * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE |
| 26 | * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR |
| 27 | * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S |
| 28 | * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE |
| 29 | * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE |
| 30 | * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE |
| 31 | * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 32 | * |
| 33 | * The following software/firmware and/or related documentation ("MediaTek |
| 34 | * Software") have been modified by MediaTek Inc. All revisions are subject to |
| 35 | * any receiver's applicable license agreements with MediaTek Inc. |
| 36 | */ |
| 37 | |
| 38 | //- vim: set ts=4 sts=4 sw=4 et: -------------------------------------------- |
| 39 | #ifndef __BOOTS_H__ |
| 40 | #define __BOOTS_H__ |
| 41 | |
| 42 | #include <stdio.h> |
| 43 | #include <stdlib.h> |
| 44 | #include <stdint.h> |
| 45 | #include <memory.h> |
| 46 | #include <stdbool.h> |
| 47 | |
| 48 | #include "boots_cfg.h" |
| 49 | |
| 50 | /** VERSION: |
| 51 | * Major is for architecture or big change., |
| 52 | * Minor is for feature add or change., |
| 53 | * Revision is for bugfix. |
| 54 | * REV: For branch |
| 55 | */ |
| 56 | #define VERSION "1.26.1" |
| 57 | #define REV "trunk-200918" |
| 58 | |
| 59 | #if HELP_COLOR_SUPPORT |
| 60 | #define NONE "\033[m" |
| 61 | #define BLUE "\033[0;32;34m" |
| 62 | #define RED "\033[0;32;31m" |
| 63 | #else |
| 64 | #define NONE "" |
| 65 | #define BLUE "" |
| 66 | #define RED "" |
| 67 | #endif |
| 68 | |
| 69 | #define HCI_BUF_SIZE 0x1000 |
| 70 | |
| 71 | #define BOOTS_MSG_LVL_DBG 4 |
| 72 | #define BOOTS_MSG_LVL_INFO 3 |
| 73 | #define BOOTS_MSG_LVL_WARN 2 |
| 74 | #define BOOTS_MSG_LVL_ERR 1 |
| 75 | #define BOOTS_MSG_LVL_NONE 0 |
| 76 | |
| 77 | #define BPRINT_D_RAW(fmt, ...) \ |
| 78 | do { if (BOOTS_MSG_LVL_DEFAULT >= BOOTS_MSG_LVL_DBG) \ |
| 79 | printf(fmt, ##__VA_ARGS__); } while (0); |
| 80 | #define BPRINT_D(fmt, ...) \ |
| 81 | do { if (BOOTS_MSG_LVL_DEFAULT >= BOOTS_MSG_LVL_DBG) \ |
| 82 | printf("[%s:D] "fmt"\n", LOG_TAG, ##__VA_ARGS__); } while (0); |
| 83 | #define BPRINT_I_RAW(fmt, ...) \ |
| 84 | do { if (BOOTS_MSG_LVL_DEFAULT >= BOOTS_MSG_LVL_INFO) \ |
| 85 | printf(fmt, ##__VA_ARGS__); } while (0); |
| 86 | #define BPRINT_I(fmt, ...) \ |
| 87 | do { if (BOOTS_MSG_LVL_DEFAULT >= BOOTS_MSG_LVL_INFO) \ |
| 88 | printf("[%s] "fmt"\n", LOG_TAG, ##__VA_ARGS__); } while (0); |
| 89 | #define BPRINT_W(fmt, ...) \ |
| 90 | do { if (BOOTS_MSG_LVL_DEFAULT >= BOOTS_MSG_LVL_WARN) \ |
| 91 | printf(BLUE "[%s:W] "fmt NONE"\n", LOG_TAG, ##__VA_ARGS__); } while (0); |
| 92 | #define BPRINT_E(fmt, ...) \ |
| 93 | do { if (BOOTS_MSG_LVL_DEFAULT >= BOOTS_MSG_LVL_ERR) \ |
| 94 | printf(RED "[%s:E] " fmt " !!!" NONE "\n", LOG_TAG, ##__VA_ARGS__);} while (0); |
| 95 | |
| 96 | #define SHOW_RAW(len, buf) \ |
| 97 | do { \ |
| 98 | int i = 0; \ |
| 99 | while (i < len) { \ |
| 100 | printf("%02X ", buf[i]); \ |
| 101 | i++; \ |
| 102 | } \ |
| 103 | printf("\n"); \ |
| 104 | } while (0); |
| 105 | |
| 106 | #define MAX(a, b) \ |
| 107 | (((a) > (b)) ? (a) : (b)) |
| 108 | |
| 109 | #define ARRAY_SIZE(arr) \ |
| 110 | (sizeof(arr) / sizeof((arr)[0])) |
| 111 | |
| 112 | #define CHECK_USERID() \ |
| 113 | if (getuid() != 0) { \ |
| 114 | BPRINT_E("Please run boots as ROOT!!!"); \ |
| 115 | exit(1); \ |
| 116 | } |
| 117 | |
| 118 | #ifndef UNUSED |
| 119 | #define UNUSED(x) ((void)x) |
| 120 | #endif |
| 121 | |
| 122 | #define STREAM_TO_UINT32(p) \ |
| 123 | (((uint32_t)(*(p))) | (((uint32_t)(*(p + 1))) << 8) | \ |
| 124 | (((uint32_t)(*(p + 2))) << 16) | (((uint32_t)(*(p + 3))) << 24)) |
| 125 | #define STREAM_TO_UINT16(p) \ |
| 126 | (((uint16_t)(*(p))) | (((uint16_t)(*(p + 1))) << 8)) |
| 127 | |
| 128 | #define UINT32_TO_STREAM(p, val) { \ |
| 129 | *(p) = (uint8_t)(val); \ |
| 130 | *(p + 1) = (uint8_t)((val) >> 8); \ |
| 131 | *(p + 2) = (uint8_t)((val) >> 16); \ |
| 132 | *(p + 3) = (uint8_t)((val) >> 24); \ |
| 133 | } |
| 134 | #define UINT16_TO_STREAM(p, val) { \ |
| 135 | *(p) = (uint8_t)(val); \ |
| 136 | *(p + 1) = (uint8_t)((val) >> 8); \ |
| 137 | } |
| 138 | |
| 139 | /** Boots BT Interface */ |
| 140 | typedef enum { |
| 141 | BOOTS_IF_NONE = 0, |
| 142 | BOOTS_BTIF_STPBT, |
| 143 | BOOTS_BTIF_HCI, |
| 144 | BOOTS_BTIF_ALL, |
| 145 | BOOTS_CSIF_SKT, |
| 146 | BOOTS_CSIF_UART, |
| 147 | BOOTS_CSIF_ETH, |
| 148 | BOOTS_CLIF_USER, |
| 149 | BOOTS_CLIF_UART, |
| 150 | } boots_if_e; |
| 151 | |
| 152 | typedef struct { |
| 153 | boots_if_e inf; // interface |
| 154 | char *n; // name |
| 155 | char *p; // path |
| 156 | } boots_btif_s; |
| 157 | |
| 158 | typedef struct { |
| 159 | boots_if_e btif; |
| 160 | boots_if_e csif; |
| 161 | boots_if_e clif; |
| 162 | char bt[16]; |
| 163 | char cs[16]; |
| 164 | char cli[16]; |
| 165 | int cs_speed; |
| 166 | int cli_speed; |
| 167 | } boots_if_s; |
| 168 | |
| 169 | //--------------------------------------------------------------------------- |
| 170 | static boots_btif_s boots_btif[] = { |
| 171 | {BOOTS_BTIF_STPBT, "stpbt", "/dev/stpbt"}, |
| 172 | {BOOTS_BTIF_HCI, "hci", NULL}, |
| 173 | {BOOTS_IF_NONE, "", NULL}, // Should leave bottom |
| 174 | }; |
| 175 | |
| 176 | //--------------------------------------------------------------------------- |
| 177 | #endif // __BOOTS_H__ |