Skip to content

Commit 3b3c3cc

Browse files
tpetazzoninvswarren
authored andcommitted
Use C99 uintXX_t instead of implementation-specific u_intXX_t types
The u_intXX_t types are implementation-specific and not part of a standard. As an example, they are not provided by the musl C library. Therefore, this commit switches cbootimage to use the C99 uintXX_t types. This commit has been produced by: 1. Running: find . -name '*.[ch]' | xargs sed -i 's%u_int\([0-9]*\)_t%uint\1_t%g' 2. Adding a #include <stdint.h> in cbootimage.h The result has been compile tested with the musl C library. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> (swarren, validated "objdump -d cbootimage" is identical before/after) Signed-off-by: Stephen Warren <swarren@nvidia.com>
1 parent 64045f9 commit 3b3c3cc

32 files changed

Lines changed: 2596 additions & 2595 deletions

src/aes_ref.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ REDISTRIBUTION OF THIS SOFTWARE.
4646

4747
#include "nvaes_ref.h"
4848

49-
static void shift_rows(u_int8_t *state);
50-
static void mix_sub_columns(u_int8_t *state);
51-
static void add_round_key(u_int32_t *state, u_int32_t *key);
49+
static void shift_rows(uint8_t *state);
50+
static void mix_sub_columns(uint8_t *state);
51+
static void add_round_key(uint32_t *state, uint32_t *key);
5252

53-
static u_int8_t s_Sbox[256] =
53+
static uint8_t s_Sbox[256] =
5454
{ /* forward s-box */
5555
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
5656
0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
@@ -87,7 +87,7 @@ static u_int8_t s_Sbox[256] =
8787
};
8888

8989
/* combined Xtimes2[Sbox[]] */
90-
static u_int8_t s_Xtime2Sbox[256] =
90+
static uint8_t s_Xtime2Sbox[256] =
9191
{
9292
0xc6, 0xf8, 0xee, 0xf6, 0xff, 0xd6, 0xde, 0x91,
9393
0x60, 0x02, 0xce, 0x56, 0xe7, 0xb5, 0x4d, 0xec,
@@ -124,7 +124,7 @@ static u_int8_t s_Xtime2Sbox[256] =
124124
};
125125

126126
/* combined Xtimes3[Sbox[]] */
127-
static u_int8_t s_Xtime3Sbox[256] =
127+
static uint8_t s_Xtime3Sbox[256] =
128128
{
129129
0xa5, 0x84, 0x99, 0x8d, 0x0d, 0xbd, 0xb1, 0x54,
130130
0x50, 0x03, 0xa9, 0x7d, 0x19, 0x62, 0xe6, 0x9a,
@@ -165,9 +165,9 @@ static u_int8_t s_Xtime3Sbox[256] =
165165
* row2 - shifted left 2 and row3 - shifted left 3
166166
*/
167167
static void
168-
shift_rows(u_int8_t *state)
168+
shift_rows(uint8_t *state)
169169
{
170-
u_int8_t tmp;
170+
uint8_t tmp;
171171

172172
/* just substitute row 0 */
173173
state[ 0] = s_Sbox[state[ 0]];
@@ -200,9 +200,9 @@ shift_rows(u_int8_t *state)
200200

201201
/* recombine and mix each row in a column */
202202
static void
203-
mix_sub_columns(u_int8_t *state)
203+
mix_sub_columns(uint8_t *state)
204204
{
205-
u_int8_t tmp[4 * NVAES_STATECOLS];
205+
uint8_t tmp[4 * NVAES_STATECOLS];
206206

207207
/* mixing column 0 */
208208
tmp[ 0] = s_Xtime2Sbox[state[ 0]] ^ s_Xtime3Sbox[state[ 5]] ^
@@ -253,25 +253,25 @@ mix_sub_columns(u_int8_t *state)
253253
*/
254254

255255
static void
256-
add_round_key(u_int32_t *state, u_int32_t *key)
256+
add_round_key(uint32_t *state, uint32_t *key)
257257
{
258258
int idx;
259259

260260
for (idx = 0; idx < 4; idx++)
261261
state[idx] ^= key[idx];
262262
}
263263

264-
static u_int8_t s_Rcon[11] =
264+
static uint8_t s_Rcon[11] =
265265
{
266266
0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
267267
};
268268

269269
/* produce NVAES_STATECOLS bytes for each round */
270270
void
271-
nv_aes_expand_key(u_int8_t *key, u_int8_t *expkey)
271+
nv_aes_expand_key(uint8_t *key, uint8_t *expkey)
272272
{
273-
u_int8_t tmp0, tmp1, tmp2, tmp3, tmp4;
274-
u_int32_t idx;
273+
uint8_t tmp0, tmp1, tmp2, tmp3, tmp4;
274+
uint32_t idx;
275275

276276
memcpy(expkey, key, NVAES_KEYCOLS * 4);
277277

@@ -304,21 +304,21 @@ nv_aes_expand_key(u_int8_t *key, u_int8_t *expkey)
304304

305305
/* encrypt one 128 bit block */
306306
void
307-
nv_aes_encrypt(u_int8_t *in, u_int8_t *expkey, u_int8_t *out)
307+
nv_aes_encrypt(uint8_t *in, uint8_t *expkey, uint8_t *out)
308308
{
309-
u_int8_t state[NVAES_STATECOLS * 4];
310-
u_int32_t round;
309+
uint8_t state[NVAES_STATECOLS * 4];
310+
uint32_t round;
311311

312312
memcpy(state, in, NVAES_STATECOLS * 4);
313-
add_round_key((u_int32_t *)state, (u_int32_t *)expkey);
313+
add_round_key((uint32_t *)state, (uint32_t *)expkey);
314314

315315
for (round = 1; round < NVAES_ROUNDS + 1; round++) {
316316
if (round < NVAES_ROUNDS)
317317
mix_sub_columns (state);
318318
else
319319
shift_rows (state);
320320

321-
add_round_key((u_int32_t *)state, (u_int32_t *)expkey +
321+
add_round_key((uint32_t *)state, (uint32_t *)expkey +
322322
round * NVAES_STATECOLS);
323323
}
324324

src/bct_dump.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ typedef struct {
4343

4444
#define PARAM_TYPE_BINARY_DATA_MAX_SIZE 256
4545
typedef union {
46-
u_int32_t val;
47-
u_int8_t uid[16];
48-
u_int8_t binary[PARAM_TYPE_BINARY_DATA_MAX_SIZE];
46+
uint32_t val;
47+
uint8_t uid[16];
48+
uint8_t binary[PARAM_TYPE_BINARY_DATA_MAX_SIZE];
4949
} param_types;
5050

5151
#define MAX_PARAM_SIZE sizeof(param_types)
@@ -96,17 +96,17 @@ static value_data const mts_values[] = {
9696
/*****************************************************************************/
9797
static void format_u32_hex8(parse_token id, char const * message, void * data)
9898
{
99-
printf("%s0x%08x;\n", message, *((u_int32_t *) data));
99+
printf("%s0x%08x;\n", message, *((uint32_t *) data));
100100
}
101101

102102
static void format_u32(parse_token id, char const * message, void * data)
103103
{
104-
printf("%s%d;\n", message, *((u_int32_t *) data));
104+
printf("%s%d;\n", message, *((uint32_t *) data));
105105
}
106106

107107
static void format_chipuid(parse_token id, char const * message, void * data)
108108
{
109-
u_int8_t *uid = (u_int8_t *)data;
109+
uint8_t *uid = (uint8_t *)data;
110110
int byte_index;
111111
char uid_str[35] = "0x";
112112
char *s = &uid_str[2];
@@ -119,7 +119,7 @@ static void format_chipuid(parse_token id, char const * message, void * data)
119119

120120
static void format_hex_16_bytes(parse_token id, char const * message, void * data)
121121
{
122-
u_int8_t *p_byte = (u_int8_t *)data;
122+
uint8_t *p_byte = (uint8_t *)data;
123123
int byte_index;
124124

125125
printf("%s", message);
@@ -132,7 +132,7 @@ static void format_hex_16_bytes(parse_token id, char const * message, void * dat
132132
static void format_rsa_param(parse_token id, char const * message, void * data)
133133
{
134134
#define MAX_BYTE_NUMBER_PER_LINE 16
135-
u_int8_t *rsa = (u_int8_t *)data;
135+
uint8_t *rsa = (uint8_t *)data;
136136
int size, byte_index;
137137

138138
printf("%s", message);
@@ -177,7 +177,7 @@ static int max_width(field_item const * table)
177177
/*****************************************************************************/
178178
static enum_item const * find_enum_item(build_image_context *context,
179179
enum_item const * table,
180-
u_int32_t value)
180+
uint32_t value)
181181
{
182182
int i;
183183

@@ -191,7 +191,7 @@ static enum_item const * find_enum_item(build_image_context *context,
191191
/*****************************************************************************/
192192
static void display_enum_value(build_image_context *context,
193193
enum_item const * table,
194-
u_int32_t value)
194+
uint32_t value)
195195
{
196196
enum_item const * e_item = find_enum_item(context, table, value);
197197

@@ -203,7 +203,7 @@ static void display_enum_value(build_image_context *context,
203203
/*****************************************************************************/
204204
static int display_field_value(build_image_context *context,
205205
field_item const * item,
206-
u_int32_t value)
206+
uint32_t value)
207207
{
208208
switch (item->type) {
209209
case field_type_enum:
@@ -230,10 +230,10 @@ int main(int argc, char *argv[])
230230
{
231231
int e;
232232
build_image_context context;
233-
u_int32_t bootloaders_used;
234-
u_int32_t parameters_used;
235-
u_int32_t sdram_used;
236-
u_int32_t mts_used;
233+
uint32_t bootloaders_used;
234+
uint32_t parameters_used;
235+
uint32_t sdram_used;
236+
uint32_t mts_used;
237237
nvboot_dev_type type;
238238
param_types data;
239239
int i;

src/cbootimage.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ main(int argc, char *argv[])
227227

228228
/* Read the bct data from image if bct configs needs to be updated */
229229
if (context.update_image) {
230-
u_int32_t offset = 0, bct_size, actual_size;
231-
u_int8_t *data_block;
230+
uint32_t offset = 0, bct_size, actual_size;
231+
uint8_t *data_block;
232232
struct stat stats;
233233

234234
if (stat(context.input_image_filename, &stats) != 0) {

src/cbootimage.h

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <assert.h>
3131
#include <errno.h>
3232
#include <math.h>
33+
#include <stdint.h>
3334

3435
#define NVBOOT_AES_BLOCK_SIZE_LOG2 4
3536
#define MAX_BUFFER 200
@@ -86,49 +87,49 @@ typedef struct build_image_context_rec
8687
char *output_image_filename;
8788
char *input_image_filename;
8889
FILE *raw_file;
89-
u_int32_t block_size;
90-
u_int32_t block_size_log2;
91-
u_int32_t page_size;
92-
u_int32_t page_size_log2;
93-
u_int32_t pages_per_blk;
94-
u_int32_t partition_size;
95-
u_int32_t redundancy;
96-
u_int32_t version;
97-
u_int32_t bct_copy;
90+
uint32_t block_size;
91+
uint32_t block_size_log2;
92+
uint32_t page_size;
93+
uint32_t page_size_log2;
94+
uint32_t pages_per_blk;
95+
uint32_t partition_size;
96+
uint32_t redundancy;
97+
uint32_t version;
98+
uint32_t bct_copy;
9899
/*
99100
* Number of blocks at start of device to skip before the BCT.
100101
* This may be used to reserve space for a partition table, for
101102
* example, in order to write the resultant boot image to e.g. an
102103
* SD card while using the remaining space for a user filesystem.
103104
*/
104-
u_int32_t pre_bct_pad_blocks;
105+
uint32_t pre_bct_pad_blocks;
105106
/* Allocation data. */
106107
struct blk_data_rec *memory; /* Representation of memory */
107108
/* block number for the BCT block */
108-
u_int32_t next_bct_blk;
109+
uint32_t next_bct_blk;
109110

110111
char *newbl_filename;
111-
u_int32_t newbl_load_addr;
112-
u_int32_t newbl_entry_point;
113-
u_int32_t newbl_attr;
114-
u_int8_t generate_bct;
115-
u_int8_t *bct;
112+
uint32_t newbl_load_addr;
113+
uint32_t newbl_entry_point;
114+
uint32_t newbl_attr;
115+
uint8_t generate_bct;
116+
uint8_t *bct;
116117

117118
char *mts_filename;
118-
u_int32_t mts_load_addr;
119-
u_int32_t mts_entry_point;
120-
u_int32_t mts_attr;
119+
uint32_t mts_load_addr;
120+
uint32_t mts_entry_point;
121+
uint32_t mts_attr;
121122

122123
char *bct_filename;
123-
u_int32_t last_blk;
124-
u_int32_t bct_size; /* The BCT file size */
125-
u_int32_t boot_data_version; /* The boot data version of BCT */
126-
u_int8_t bct_init; /* The flag for the memory allocation of bct */
127-
u_int32_t odm_data; /* The odm data value */
128-
u_int8_t unique_chip_id[16]; /* The unique chip uid */
129-
u_int8_t secure_jtag_control; /* The flag for enabling jtag control */
130-
u_int32_t secure_debug_control; /* The flag for enabling jtag control */
131-
u_int8_t update_image; /* The flag for updating image */
124+
uint32_t last_blk;
125+
uint32_t bct_size; /* The BCT file size */
126+
uint32_t boot_data_version; /* The boot data version of BCT */
127+
uint8_t bct_init; /* The flag for the memory allocation of bct */
128+
uint32_t odm_data; /* The odm data value */
129+
uint8_t unique_chip_id[16]; /* The unique chip uid */
130+
uint8_t secure_jtag_control; /* The flag for enabling jtag control */
131+
uint32_t secure_debug_control; /* The flag for enabling jtag control */
132+
uint8_t update_image; /* The flag for updating image */
132133
} build_image_context;
133134

134135
/* Function prototypes */

src/context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cleanup_context(build_image_context *context)
3131
int
3232
init_context(build_image_context *context)
3333
{
34-
u_int32_t value;
34+
uint32_t value;
3535

3636
/* Set defaults */
3737
context->memory = new_block_list();

0 commit comments

Comments
 (0)