summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/imgtool/modules/cybiko.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/imgtool/modules/cybiko.cpp')
-rw-r--r--src/tools/imgtool/modules/cybiko.cpp104
1 files changed, 52 insertions, 52 deletions
diff --git a/src/tools/imgtool/modules/cybiko.cpp b/src/tools/imgtool/modules/cybiko.cpp
index 78dd11e4951..7a6ad8ce013 100644
--- a/src/tools/imgtool/modules/cybiko.cpp
+++ b/src/tools/imgtool/modules/cybiko.cpp
@@ -15,21 +15,21 @@
struct cybiko_file_system
{
imgtool::stream *stream;
- UINT32 page_count, page_size, block_count_boot, block_count_file;
- UINT16 write_count;
+ uint32_t page_count, page_size, block_count_boot, block_count_file;
+ uint16_t write_count;
};
struct cybiko_iter
{
- UINT16 block;
+ uint16_t block;
};
struct cfs_file
{
char name[64]; // name of the file
- UINT32 date; // date/time of the file (seconds since 1900/01/01)
- UINT32 size; // size of the file
- UINT32 blocks; // number of blocks occupied by the file
+ uint32_t date; // date/time of the file (seconds since 1900/01/01)
+ uint32_t size; // size of the file
+ uint32_t blocks; // number of blocks occupied by the file
};
enum
@@ -65,27 +65,27 @@ static cybiko_file_system *get_cfs(imgtool::image &image)
// 2208988800 is the number of seconds between 1900/01/01 and 1970/01/01
-static time_t time_crack( UINT32 cfs_time)
+static time_t time_crack( uint32_t cfs_time)
{
return (time_t)(cfs_time - 2208988800UL);
}
-static UINT32 time_setup( time_t ansi_time)
+static uint32_t time_setup( time_t ansi_time)
{
- return (UINT32)(ansi_time + 2208988800UL);
+ return (uint32_t)(ansi_time + 2208988800UL);
}
-static UINT32 buffer_read_32_be( UINT8 *buffer)
+static uint32_t buffer_read_32_be( uint8_t *buffer)
{
return (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | (buffer[3] << 0);
}
-static UINT16 buffer_read_16_be( UINT8 *buffer)
+static uint16_t buffer_read_16_be( uint8_t *buffer)
{
return (buffer[0] << 8) | (buffer[1] << 0);
}
-static void buffer_write_32_be( UINT8 *buffer, UINT32 data)
+static void buffer_write_32_be( uint8_t *buffer, uint32_t data)
{
buffer[0] = (data >> 24) & 0xFF;
buffer[1] = (data >> 16) & 0xFF;
@@ -93,7 +93,7 @@ static void buffer_write_32_be( UINT8 *buffer, UINT32 data)
buffer[3] = (data >> 0) & 0xFF;
}
-static void buffer_write_16_be( UINT8 *buffer, UINT16 data)
+static void buffer_write_16_be( uint8_t *buffer, uint16_t data)
{
buffer[0] = (data >> 8) & 0xFF;
buffer[1] = (data >> 0) & 0xFF;
@@ -101,23 +101,23 @@ static void buffer_write_16_be( UINT8 *buffer, UINT16 data)
// page = crc1 (4) + wcnt (2) + crc2 (2) + data (x) + unk (2)
-static UINT32 page_buffer_calc_checksum_1( UINT8 *buffer, UINT32 size, int block_type)
+static uint32_t page_buffer_calc_checksum_1( uint8_t *buffer, uint32_t size, int block_type)
{
return crc32( 0, buffer + 8, (block_type == BLOCK_TYPE_BOOT) ? 250 : size - 10);
}
-static UINT16 page_buffer_calc_checksum_2( UINT8 *buffer)
+static uint16_t page_buffer_calc_checksum_2( uint8_t *buffer)
{
- UINT16 val = 0xAF17;
+ uint16_t val = 0xAF17;
val ^= buffer_read_16_be( buffer + 0);
val ^= buffer_read_16_be( buffer + 2);
val ^= buffer_read_16_be( buffer + 4);
return flipendian_int16(val);
}
-static int page_buffer_verify( UINT8 *buffer, UINT32 size, int block_type)
+static int page_buffer_verify( uint8_t *buffer, uint32_t size, int block_type)
{
- UINT32 checksum_page, checksum_calc;
+ uint32_t checksum_page, checksum_calc;
// checksum 1
checksum_calc = page_buffer_calc_checksum_1( buffer, size, block_type);
checksum_page = buffer_read_32_be( buffer + 0);
@@ -130,7 +130,7 @@ static int page_buffer_verify( UINT8 *buffer, UINT32 size, int block_type)
return TRUE;
}
-static int cfs_block_to_page( cybiko_file_system *cfs, int block_type, UINT32 block, UINT32 *page)
+static int cfs_block_to_page( cybiko_file_system *cfs, int block_type, uint32_t block, uint32_t *page)
{
switch (block_type)
{
@@ -140,9 +140,9 @@ static int cfs_block_to_page( cybiko_file_system *cfs, int block_type, UINT32 bl
}
}
-static int cfs_page_to_block( cybiko_file_system *cfs, UINT32 page, int *block_type, UINT32 *block)
+static int cfs_page_to_block( cybiko_file_system *cfs, uint32_t page, int *block_type, uint32_t *block)
{
- UINT32 tmp = page;
+ uint32_t tmp = page;
// boot block
if (tmp < cfs->block_count_boot)
{
@@ -163,7 +163,7 @@ static int cfs_page_to_block( cybiko_file_system *cfs, UINT32 page, int *block_t
return FALSE;
}
-static int cfs_page_read( cybiko_file_system *cfs, UINT8 *buffer, UINT32 page)
+static int cfs_page_read( cybiko_file_system *cfs, uint8_t *buffer, uint32_t page)
{
if (page >= cfs->page_count) return FALSE;
cfs->stream->seek(page * cfs->page_size, SEEK_SET);
@@ -171,7 +171,7 @@ static int cfs_page_read( cybiko_file_system *cfs, UINT8 *buffer, UINT32 page)
return TRUE;
}
-static int cfs_page_write( cybiko_file_system *cfs, UINT8 *buffer, UINT32 page)
+static int cfs_page_write( cybiko_file_system *cfs, uint8_t *buffer, uint32_t page)
{
if (page >= cfs->page_count) return FALSE;
cfs->stream->seek(page * cfs->page_size, SEEK_SET);
@@ -179,20 +179,20 @@ static int cfs_page_write( cybiko_file_system *cfs, UINT8 *buffer, UINT32 page)
return TRUE;
}
-static int cfs_block_read( cybiko_file_system *cfs, UINT8 *buffer, int block_type, UINT32 block)
+static int cfs_block_read( cybiko_file_system *cfs, uint8_t *buffer, int block_type, uint32_t block)
{
- UINT8 buffer_page[MAX_PAGE_SIZE];
- UINT32 page;
+ uint8_t buffer_page[MAX_PAGE_SIZE];
+ uint32_t page;
if (!cfs_block_to_page( cfs, block_type, block, &page)) return FALSE;
if (!cfs_page_read( cfs, buffer_page, page)) return FALSE;
memcpy( buffer, buffer_page + 8, cfs->page_size - 10);
return TRUE;
}
-static int cfs_block_write( cybiko_file_system *cfs, UINT8 *buffer, int block_type, UINT32 block)
+static int cfs_block_write( cybiko_file_system *cfs, uint8_t *buffer, int block_type, uint32_t block)
{
- UINT8 buffer_page[MAX_PAGE_SIZE];
- UINT32 page;
+ uint8_t buffer_page[MAX_PAGE_SIZE];
+ uint32_t page;
memcpy( buffer_page + 8, buffer, cfs->page_size - 10);
buffer_write_32_be( buffer_page + 0, page_buffer_calc_checksum_1( buffer_page, cfs->page_size, block_type));
buffer_write_16_be( buffer_page + 4, cfs->write_count++);
@@ -203,9 +203,9 @@ static int cfs_block_write( cybiko_file_system *cfs, UINT8 *buffer, int block_ty
return TRUE;
}
-static int cfs_file_delete( cybiko_file_system *cfs, UINT16 file_id)
+static int cfs_file_delete( cybiko_file_system *cfs, uint16_t file_id)
{
- UINT8 buffer[MAX_PAGE_SIZE];
+ uint8_t buffer[MAX_PAGE_SIZE];
int i;
for (i=0;i<cfs->block_count_file;i++)
{
@@ -219,9 +219,9 @@ static int cfs_file_delete( cybiko_file_system *cfs, UINT16 file_id)
return TRUE;
}
-static int cfs_file_info( cybiko_file_system *cfs, UINT16 file_id, cfs_file *file)
+static int cfs_file_info( cybiko_file_system *cfs, uint16_t file_id, cfs_file *file)
{
- UINT8 buffer[MAX_PAGE_SIZE];
+ uint8_t buffer[MAX_PAGE_SIZE];
int i;
file->blocks = file->size = 0;
for (i=0;i<cfs->block_count_file;i++)
@@ -241,9 +241,9 @@ static int cfs_file_info( cybiko_file_system *cfs, UINT16 file_id, cfs_file *fil
return (file->blocks > 0) ? TRUE : FALSE;
}
-static int cfs_file_find( cybiko_file_system *cfs, const char *filename, UINT16 *file_id)
+static int cfs_file_find( cybiko_file_system *cfs, const char *filename, uint16_t *file_id)
{
- UINT8 buffer[MAX_PAGE_SIZE];
+ uint8_t buffer[MAX_PAGE_SIZE];
int i;
for (i=0;i<cfs->block_count_file;i++)
{
@@ -259,7 +259,7 @@ static int cfs_file_find( cybiko_file_system *cfs, const char *filename, UINT16
static int cfs_verify(cybiko_file_system &cfs)
{
- UINT8 buffer[MAX_PAGE_SIZE];
+ uint8_t buffer[MAX_PAGE_SIZE];
int i, block_type;
for (i = 0; i < cfs.page_count; i++)
{
@@ -288,7 +288,7 @@ static int cfs_init(cybiko_file_system &cfs, imgtool::stream::ptr &&stream, int
static int cfs_format( cybiko_file_system *cfs)
{
- UINT8 buffer[MAX_PAGE_SIZE];
+ uint8_t buffer[MAX_PAGE_SIZE];
int i;
// boot blocks
memset( buffer, 0xFF, sizeof( buffer));
@@ -307,11 +307,11 @@ static int cfs_format( cybiko_file_system *cfs)
return TRUE;
}
-static UINT16 cfs_calc_free_blocks( cybiko_file_system *cfs)
+static uint16_t cfs_calc_free_blocks( cybiko_file_system *cfs)
{
- UINT8 buffer[MAX_PAGE_SIZE];
+ uint8_t buffer[MAX_PAGE_SIZE];
int i;
- UINT16 blocks = 0;
+ uint16_t blocks = 0;
for (i=0;i<cfs->block_count_file;i++)
{
if (!cfs_block_read( cfs, buffer, BLOCK_TYPE_FILE, i)) return 0;
@@ -320,9 +320,9 @@ static UINT16 cfs_calc_free_blocks( cybiko_file_system *cfs)
return blocks;
}
-static UINT32 cfs_calc_free_space( cybiko_file_system *cfs, UINT16 blocks)
+static uint32_t cfs_calc_free_space( cybiko_file_system *cfs, uint16_t blocks)
{
- UINT32 free_space;
+ uint32_t free_space;
free_space = blocks * (cfs->page_size - 0x10);
if (free_space > 0) free_space -= FILE_HEADER_SIZE;
return free_space;
@@ -394,8 +394,8 @@ static imgtoolerr_t cybiko_image_next_enum(imgtool::directory &enumeration, imgt
imgtool::image &image(enumeration.image());
cybiko_file_system *cfs = get_cfs(image);
cybiko_iter *iter = (cybiko_iter*)enumeration.extra_bytes();
- UINT8 buffer[MAX_PAGE_SIZE];
- UINT16 file_id = INVALID_FILE_ID;
+ uint8_t buffer[MAX_PAGE_SIZE];
+ uint16_t file_id = INVALID_FILE_ID;
cfs_file file;
// find next file
while (iter->block < cfs->block_count_file)
@@ -423,7 +423,7 @@ static imgtoolerr_t cybiko_image_next_enum(imgtool::directory &enumeration, imgt
return IMGTOOLERR_SUCCESS;
}
-static imgtoolerr_t cybiko_image_free_space(imgtool::partition &partition, UINT64 *size)
+static imgtoolerr_t cybiko_image_free_space(imgtool::partition &partition, uint64_t *size)
{
imgtool::image &image(partition.image());
cybiko_file_system *cfs = get_cfs(image);
@@ -435,8 +435,8 @@ static imgtoolerr_t cybiko_image_read_file(imgtool::partition &partition, const
{
imgtool::image &image(partition.image());
cybiko_file_system *cfs = get_cfs(image);
- UINT8 buffer[MAX_PAGE_SIZE];
- UINT16 file_id, part_id = 0, old_part_id;
+ uint8_t buffer[MAX_PAGE_SIZE];
+ uint16_t file_id, part_id = 0, old_part_id;
int i;
// find file
if (!cfs_file_find( cfs, filename, &file_id)) return IMGTOOLERR_FILENOTFOUND;
@@ -462,9 +462,9 @@ static imgtoolerr_t cybiko_image_write_file(imgtool::partition &partition, const
{
imgtool::image &image(partition.image());
cybiko_file_system *cfs = get_cfs(image);
- UINT8 buffer[MAX_PAGE_SIZE];
- UINT16 file_id, part_id = 0, free_blocks;
- UINT64 bytes_left;
+ uint8_t buffer[MAX_PAGE_SIZE];
+ uint16_t file_id, part_id = 0, free_blocks;
+ uint64_t bytes_left;
cfs_file file;
int i;
// find file
@@ -522,7 +522,7 @@ static imgtoolerr_t cybiko_image_delete_file(imgtool::partition &partition, cons
{
imgtool::image &image(partition.image());
cybiko_file_system *cfs = get_cfs(image);
- UINT16 file_id;
+ uint16_t file_id;
// find file
if (!cfs_file_find( cfs, filename, &file_id)) return IMGTOOLERR_FILENOTFOUND;
// delete file
@@ -543,7 +543,7 @@ OPTION_GUIDE_END
// OPTION_INT( 'B', "boot", "Boot Flag" )
//OPTION_GUIDE_END
-void cybiko_get_info( const imgtool_class *imgclass, UINT32 state, union imgtoolinfo *info)
+void cybiko_get_info( const imgtool_class *imgclass, uint32_t state, union imgtoolinfo *info)
{
switch (state)
{