1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 #ifndef __BOOTUTIL_SERIAL_PRIV_H__ 21 #define __BOOTUTIL_SERIAL_PRIV_H__ 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* 28 * From shell.h 29 */ 30 #define SHELL_NLIP_PKT_START1 6 31 #define SHELL_NLIP_PKT_START2 9 32 33 #define SHELL_NLIP_DATA_START1 4 34 #define SHELL_NLIP_DATA_START2 20 35 36 /* 37 * From newtmgr.h 38 */ 39 #define MGMT_ERR_OK 0 40 #define MGMT_ERR_EUNKNOWN 1 41 #define MGMT_ERR_ENOMEM 2 42 #define MGMT_ERR_EINVAL 3 43 #define MGMT_ERR_ENOENT 5 44 #define MGMT_ERR_ENOTSUP 8 45 #define MGMT_ERR_EBUSY 10 46 47 #define NMGR_OP_READ 0 48 #define NMGR_OP_WRITE 2 49 50 #define MGMT_GROUP_ID_DEFAULT 0 51 #define MGMT_GROUP_ID_IMAGE 1 52 #define MGMT_GROUP_ID_PERUSER 64 53 54 #define NMGR_ID_ECHO 0 55 #define NMGR_ID_CONS_ECHO_CTRL 1 56 #define NMGR_ID_RESET 5 57 58 #ifndef __packed 59 #define __packed __attribute__((__packed__)) 60 #endif 61 62 struct nmgr_hdr { 63 #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) 64 uint8_t _res1:3; 65 uint8_t nh_version:2; 66 uint8_t nh_op:3; /* NMGR_OP_XXX */ 67 #else 68 uint8_t nh_op:3; /* NMGR_OP_XXX */ 69 uint8_t nh_version:2; 70 uint8_t _res1:3; 71 #endif 72 uint8_t nh_flags; 73 uint16_t nh_len; /* length of the payload */ 74 uint16_t nh_group; /* NMGR_GROUP_XXX */ 75 uint8_t nh_seq; /* sequence number */ 76 uint8_t nh_id; /* message ID within group */ 77 } __packed; 78 79 /* 80 * From imgmgr.h 81 */ 82 #define IMGMGR_NMGR_ID_STATE 0 83 #define IMGMGR_NMGR_ID_UPLOAD 1 84 #define IMGMGR_NMGR_ID_SLOT_INFO 6 85 86 void boot_serial_input(char *buf, int len); 87 extern const struct boot_uart_funcs *boot_uf; 88 89 /** 90 * @brief Selects direct image to upload according to the "image" 91 * parameter of the mcumgr update frame. 92 * 93 * @param[in] image_id the value of the "image" parameter of the 94 * mcumgr update frame to be translated. 95 * 96 * @return flash area ID for the image if defined; 97 * -EINVAL when flash area for given image number has not been 98 * defined. 99 */ 100 extern int flash_area_id_from_direct_image(int image_id); 101 102 #ifdef __cplusplus 103 } 104 #endif 105 106 #endif /* __BOOTUTIL_SERIAL_PRIV_H__ */ 107