• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# coding=utf-8
3
4'''
5* Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
6* Licensed under the Apache License, Version 2.0 (the "License");
7* you may not use this file except in compliance with the License.
8* 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, software
13* distributed under the License is distributed on an "AS IS" BASIS,
14* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15* See the License for the specific language governing permissions and
16* limitations under the License.
17*
18* Description: part of hupg build scripts
19'''
20
21from ctypes import *
22
23###############################定义基本类型###############################################
24hi_char=c_char
25hi_s8=c_byte
26hi_u8=c_ubyte
27hi_s16=c_short
28hi_u16=c_ushort
29hi_s32=c_int
30hi_u32=c_uint
31
32#升级文件头中提供了32字节预留字段供用户使用。
33#示例为默认填充了8字节,用于存储芯片产品类型;如不需要,屏蔽即可;或者填充其他内容。
34class app_upg_user_info(Structure):
35    _fields_ = [
36        ("chip_product", hi_char*8),
37        ("reserved", hi_u8*24),
38        ]
39
40def fill_user_info(chip_name):
41    info_bin = bytearray(sizeof(app_upg_user_info))
42    info = app_upg_user_info.from_buffer(info_bin)
43    info.chip_product = bytes(chip_name, encoding='utf8')#如不需要填充芯片产品字段,屏蔽此行
44    print("[upg fill user info]chip:%s"%(info.chip_product))
45
46    return info_bin
47