SmartAudio/lichee/brandy/u-boot-2011.09/usb_sunxi/usb_burn.h

181 lines
5.7 KiB
C
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* (C) Copyright 2007-2013
* Allwinner Technology Co., Ltd. <www.allwinnertech.com>
* Jerry Wang <wangflord@allwinnertech.com>
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#ifndef __USB_PBURN_H__
#define __USB_PBURN_H__
#include <common.h>
#define SUNXI_USB_PBURN_DEV_MAX (4)
unsigned char sunxi_usb_pbur_normal_LangID[8] = {0x04, 0x03, 0x09, 0x04, '\0'};
unsigned char sunxi_usb_pburn_iSerialNum0[32] = "20101201120001";
unsigned char sunxi_usb_pburn_iManufacturer[32] = "AllWinner Technology";
unsigned char sunxi_usb_pburn_iProduct[32] = "USB Mass Storage";
#define SUNXI_USB_STRING_LANGIDS (0)
#define SUNXI_USB_STRING_IMANUFACTURER (1)
#define SUNXI_USB_STRING_IPRODUCT (2)
#define SUNXI_USB_STRING_ISERIALNUMBER (3)
unsigned char *sunxi_usb_pburn_dev[SUNXI_USB_PBURN_DEV_MAX] = {sunxi_usb_pbur_normal_LangID, \
sunxi_usb_pburn_iSerialNum0, \
sunxi_usb_pburn_iManufacturer, \
sunxi_usb_pburn_iProduct};
const unsigned char pburn_InquiryData[40] = {0x00, 0x80, 0x02, 0x02, 0x1f, \
0x00, 0x00, 0x00, \
'U', 'S', 'B', '2', '.', '0', 0x00, 0x00, \
'U' , 'S', 'B', ' ', 'S', 't', 'o' , 'r' , 'a' , 'g' , 'e', \
0x00, 0x00, 0x00, 0x00, 0x00,
'0', '1', '0', '0', '\0' };
const unsigned char pburn_RequestSense[20] = {0x07,0x00,0x02,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x3a,0x00,0x00,0x00,0x00,0x00};
#define SUNXI_USB_PBURN_IDLE (0)
#define SUNXI_USB_PBURN_SETUP (1)
#define SUNXI_USB_PBURN_SEND_DATA (2)
#define SUNXI_USB_PBURN_RECEIVE_DATA (3)
#define SUNXI_USB_PBURN_STATUS (4)
#define SUNXI_USB_PBURN_EXIT (5)
#define SUNXI_USB_PBURN_RECEIVE_NULL (6)
#define SUNXI_USB_PBURN_RECEIVE_PART_INFO (7)
#define SUNXI_USB_PBURN_RECEIVE_PART_VERIFY (8)
typedef struct
{
uchar *base_recv_buffer; //<2F><><EFBFBD>Ž<EFBFBD><C5BD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>׵<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B9BB>
uint act_recv_buffer;//
uint recv_size;
uint to_be_recved_size;
uchar *base_send_buffer; //<2F><><EFBFBD>Ž<EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>׵<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B9BB>
uint act_send_buffer;//
uint send_size; //<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵij<DDB5><C4B3><EFBFBD>
uint flash_start; //<2F><>ʼλ<CABC>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬Ҳ<E6A3AC><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>flash<73><68><EFBFBD><EFBFBD>
uint flash_sectors;
}
pburn_trans_set_t;
typedef struct
{
char magic[16]; //<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><CCB6><EFBFBD> "usbhandshake"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int sizelo; //<2F>̷<EFBFBD><CCB7>ĵ<EFBFBD>32λ<32><CEBB><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int sizehi; //<2F>̷<EFBFBD><CCB7>ĸ<EFBFBD>32λ<32><CEBB><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int res1;
int res2;
}
__usb_handshake_t;
typedef struct
{
char magic[16]; //<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><CCB6><EFBFBD> "usbburnpart"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
char name[16]; //<2F><>д<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
unsigned int lenhi; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>С<EFBFBD><D0A1>32λ,<2C><>λ<EFBFBD>ֽ<EFBFBD>
unsigned int lenlo; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>С<EFBFBD><D0A1>32λ,<2C><>λ<EFBFBD>ֽ<EFBFBD>
char reserved[1024-40]; //<2F><><EFBFBD>ݹ<EFBFBD>1024 byte
}__attribute__ ((packed))pburn_partition_set_t;
typedef struct
{
char magic[16]; //<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><CCB6><EFBFBD> "usbburnpart"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
char name[16]; //<2F><>д<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
unsigned int check_sum; //pc<70>˼<EFBFBD><CBBC><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD>
char reserved[1024-36]; //<2F><><EFBFBD>ݹ<EFBFBD>1024 byte
}__attribute__ ((packed))pburn_verify_part_set_t;
typedef struct
{
char magic[32]; //<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><CCB6><EFBFBD> "usbhandshake"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
__usb_handshake_sec_t;
typedef struct
{
char magic[64]; //<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
int err_no;
}
__usb_handshake_ext_t;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30>û<EFBFBD>д<EFBFBD><D0B4><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(key)<29><>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32>ָ<EFBFBD><D6B8>keyλ<79>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3>Ѿ<EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(key)д<><D0B4>ʧ<EFBFBD><CAA7>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̫̫<CCAB><CCAB><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>6<EFBFBD><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ʧ<EFBFBD><CAA7>
// 7: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϢmagicУ<63><D0A3>ʧ<EFBFBD><CAA7>
#define ERR_NO_SUCCESS 0
#define ERR_NO_KEY_VERIFY_ERR 1
#define ERR_NO_KEY_HASEXIST 2
#define ERR_NO_WRITE_ERR 3
#define ERR_NO_PART_NOEXIST 4
#define ERR_NO_PART_SIZE_ERR 5
#define ERR_NO_PART_VERIFY_ERR 6
#define ERR_NO_PART_MAGIC_ERR 7
#define ERR_NO_ERASE_KEY_FAILED 8
#define ERR_NO_KEY_NOEXIST 9
#define ERR_NO_READ_KEY_NOEXIST 10
#define ERR_NO_READ_KEY_FAILED 11
typedef struct
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>ʾÿ<CABE><C3BF>key<65><79><EFBFBD><EFBFBD>Ϣ
char name[64]; //key<65><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u32 type; //0:aes 1:rsa <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ֪key
u32 len; //key<65><79><EFBFBD>ݶε<DDB6><CEB5>ܳ<EFBFBD><DCB3><EFBFBD>
u32 if_burn; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA>¼<EFBFBD><C2BC>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>1<EFBFBD><31><EFBFBD><EFBFBD>Ҫ
u32 if_replace; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>滻֮ǰ<D6AE><C7B0>key<65><79>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u32 if_crypt; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD>ҪС<D2AA><D0A1><EFBFBD>˼<EFBFBD><CBBC>ܴ洢
u8 *key_data[]; //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E9A3AC><EFBFBD><EFBFBD>key<65><79>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD><EFBFBD><EFBFBD>lenָ<6E><D6B8>
}
sunxi_usb_burn_key_info_t;
typedef struct
{
u8 magic[16]; //<2F><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"key-group-db"
u8 hash[256]; //hashֵ(<28><><EFBFBD><EFBFBD>rootkey<65><79>˽Կ<CBBD><D4BF><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>key<65><79>Ϣ<EFBFBD><CFA2><EFBFBD>м<EFBFBD><D0BC><EFBFBD>)
u32 count; //key<65>ĸ<EFBFBD><C4B8><EFBFBD>
u32 res[3]; //<2F><><EFBFBD><EFBFBD>
sunxi_usb_burn_key_info_t key_info;
}
sunxi_usb_burn_main_info_t;
#define SUNXI_PBURN_RECV_MEM_SIZE (512 * 1024)
#define SUNXI_PBURN_SEND_MEM_SIZE (512 * 1024)
#endif