2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #define SIZE_HASH_BUFFER 4096
45 uint8_t pBuf[SIZE_HASH_BUFFER];
47 //unsigned short m_crc16ccitt;
51 printf("\n\rThis utility is used to prefix a header to the patch code!\n\r");
52 printf("For loading into the bootcode and the integrity crc header!\n\r");
53 printf(" - patch_hdr [patch binary] [load address]\n\r");
54 printf("\n\r e.g. patch_hdr patch.bin 0x8e0000\n\r");
58 #define _ROMP_SIZE_ 64
60 int main(int argc, char* argv[] )
65 struct rom_patch_st patch_item;
66 uint8_t *pBufPtr = NULL;
67 uint32_t ran_patch_size = 0;
70 uint8_t name_of_patch[32];
73 _patch_init(&patch_item);
77 _patch_oepn(pBuf, argv[1]);
85 printf("%s %s %s\n\r", argv[0], argv[1], argv[2]);
89 /***************************************************************/
90 // allocate the buffer space for func address
91 if( !(patch_item.fun = (uint8_t *)malloc(SIZE_HASH_BUFFER)) )
94 // check the function address of the patch code
96 if( db_ascii_to_hex((ld_addr+2), &(patch_item.ld_addr))!=0 )
99 // check the function address of the patch code
101 if( db_ascii_to_hex((fun_addr+2), &(patch_item.fun_addr))!=0 )
104 /***************************************************************/
106 if( gen_patch_item(&patch_item, argv[1])!=TRUE )
109 printf(" - prefix to the patch binary -\n\r");
110 _patch_dump(&patch_item);
112 sprintf(name_of_patch, "h_%s", argv[1]);
114 printf("%s is to be outputed\n\r", name_of_patch);
116 _patch_append(pBuf, &patch_item);
118 out = fopen(name_of_patch, "wb");
120 // ( struct size -4 ) + patch_code size + 4-%4( make it alignment )
121 printf(" write %d bytes to h_%s as an output file", (sizeof(struct rom_patch_st)-4)+patch_item.len+(4-(patch_item.len%4)), argv[1]);
122 fwrite((uint8_t *)pBuf, sizeof(uint8_t), (sizeof(struct rom_patch_st)-4)+patch_item.len+(4-(patch_item.len%4)), out);
133 free(patch_item.fun);