diff --git a/configure.py b/configure.py index bc8d7f0e..66cb69f3 100644 --- a/configure.py +++ b/configure.py @@ -1853,10 +1853,10 @@ config.libs = [ Object(NonMatching, "fa/kernel/pfk_api.c"), - Object(Matching, "fa/driver/nand_drv.c"), + Object(NonMatching, "fa/driver/nand_drv.c"), Object(NonMatching, "fa/driver/sd_drv.c"), Object(NonMatching, "fa/driver/pfd_cmn.c"), - Object(Matching, "fa/driver/msc_drv.c"), + Object(NonMatching, "fa/driver/msc_drv.c"), Object(NonMatching, "fa/msc/puh_msc.c"), Object(NonMatching, "fa/msc/puh_msc_cmd.c"), diff --git a/libs/RVL_SDK/src/fa/driver/msc_drv.c b/libs/RVL_SDK/src/fa/driver/msc_drv.c index 2b65eaf2..5b07f714 100644 --- a/libs/RVL_SDK/src/fa/driver/msc_drv.c +++ b/libs/RVL_SDK/src/fa/driver/msc_drv.c @@ -1,7 +1,7 @@ #include -static FAEjectCallback g_detach_func; static FAInsertCallback g_attach_func; +static FAEjectCallback g_detach_func; extern s32 uhf_msc_is_media_insert(void); diff --git a/libs/RVL_SDK/src/fa/driver/nand_drv.c b/libs/RVL_SDK/src/fa/driver/nand_drv.c index a322fdb9..8202e42b 100644 --- a/libs/RVL_SDK/src/fa/driver/nand_drv.c +++ b/libs/RVL_SDK/src/fa/driver/nand_drv.c @@ -24,16 +24,9 @@ char NAND_Org_Path[64]; NAND_DISK_INFO nanddisk_info[23]; NAND_SEMAPHORE csem; NAND_SEMAPHORE osem; -u32 fa_nanddrv_bss_tail[4]; -__declspec(export) u32 fa_nanddrv_work0; -__declspec(export) u32 fa_nanddrv_work1; -__declspec(export) u32 fa_nanddrv_work2; -__declspec(export) u32 fa_nanddrv_work3; -__declspec(export) u32 fa_nanddrv_work4; -s32 fa_nanad_semid; -s32 NAND_Init; s32 Nanddisk_Internal_Info_Init; - +s32 NAND_Init; +s32 fa_nanad_semid; static inline s32 find_disk(PDM_DISK* disk, NAND_DISK_INFO** result) { NAND_DISK_INFO* info; @@ -171,21 +164,18 @@ static s32 fa_nanddrv_ParseCreateNANDFile(NAND_DISK_INFO* info) { return error; } if (length > 11) { return -20; } - if (pf_strcmp(name, "..\0") != 0) { error = NANDCreateDir(name, 0x30, 0); } + if (pf_strcmp(name, "..") != 0) { error = NANDCreateDir(name, 0x30, 0); } else { error = 0; } if (error == 0 || error == -6 || error == -1) { error = NANDChangeDir(name); if (error != 0) { return error; } - else { goto success; } - } else { - return error; + path++; + pf_memset(name, 0, 16); + next = name; + length = 0; + break; } - success: - path++; - pf_memset(name, 0, 16); - next = name; - length = 0; - break; + return error; case 0: if (length > 12) { return -20; } error = NANDCreate(name, 0x30, 0); @@ -203,7 +193,6 @@ static s32 fa_nanddrv_ParseCreateNANDFile(NAND_DISK_INFO* info) { } } static s32 fa_nanddrv_VerifyBPB(u8* buf, u32* clusters) { - u8 sector_log = 0; u8 cluster_log; u16 value = 512; @@ -414,6 +403,7 @@ s32 fa_nanddrv_init_drv_tbl(PDM_DISK_TBL* table, u32 extension) { return 0; } s32 fa_nanddrv_NotifyNANDFile(const char* path, u32 size) { + NAND_DISK_INFO* info; u16 index; if (pf_strlen(path) >= 76) { return -20; } if (Nanddisk_Internal_Info_Init == 0) { @@ -426,9 +416,10 @@ s32 fa_nanddrv_NotifyNANDFile(const char* path, u32 size) { if (fa_nanad_semid == 0) { return -21; } } for (index = 0; index < 23; index++) { - if (pf_strcmp(nanddisk_info[index].path, path) == 0) { return 0; } + info = &nanddisk_info[index]; + if (pf_strcmp(info->path, path) == 0) { return 0; } if (nanddisk_info[index].disk == 0) { - pf_strcpy(nanddisk_info[index].path, path); + pf_strcpy(info->path, path); nanddisk_info[index].file_size = size; break; } @@ -490,14 +481,14 @@ static s32 fa_nanddrv_physical_read(u32 count, u8* buf, u32 block, u32 bps, u32* return error; } static s32 fa_nanddrv_physical_write(u32 count, const u8* buf, u32 block, u32 bps, u32* success, PDM_DISK* disk) { - u32 file_size; - u32 wanted; u32 remaining; - s32 error; + u32 wanted; + u32 file_size; + NAND_DISK_INFO* info = 0; u16 index; u32 offset; u32 position; - NAND_DISK_INFO* info = 0; + s32 error; u8 work[512] __attribute__((aligned(32))); for (index = 0; index < 23; index++) { if (nanddisk_info[index].disk == disk) { info = &nanddisk_info[index]; break; } @@ -542,4 +533,3 @@ static s32 fa_nanddrv_physical_write(u32 count, const u8* buf, u32 block, u32 bp store_disk_error(disk, error); return error; } - diff --git a/libs/RVL_SDK/src/fa/driver/pfd_cmn.c b/libs/RVL_SDK/src/fa/driver/pfd_cmn.c index 8565d805..8197d041 100644 --- a/libs/RVL_SDK/src/fa/driver/pfd_cmn.c +++ b/libs/RVL_SDK/src/fa/driver/pfd_cmn.c @@ -6,11 +6,11 @@ extern pf_s32 pdm_part_is_attached_partition(PDM_PARTITION* partition); pf_u8 pfd_get_media_drv_char(PDM_DISK* disk, pf_s8* drives, pf_u32 capacity) { pf_u32 partition_index; - pf_u32 volume_index; + PDM_PARTITION* partition; PF_VOLUME* volume; pf_u8 count; pf_s8* next_drive; - PDM_PARTITION* partition; + pf_u32 volume_index; if (drives == NULL || capacity == 0) { return 0; } @@ -20,7 +20,8 @@ pf_u8 pfd_get_media_drv_char(PDM_DISK* disk, pf_s8* drives, pf_u32 capacity) { for (partition_index = 0; partition_index < 26; partition_index++, partition++) { if (pdm_part_is_attached_partition(partition) && partition->p_disk == disk) { volume = pf_vol_set.volumes; - for (volume_index = 0; volume_index < 26; volume_index++, volume++) { + for (volume_index = 0; volume_index < 26; volume++) { + volume_index++; if (volume->p_part == partition) { count++; *next_drive++ = volume->drv_char; diff --git a/libs/RVL_SDK/src/fa/driver/sd_drv.c b/libs/RVL_SDK/src/fa/driver/sd_drv.c index 037009e7..866ec34f 100644 --- a/libs/RVL_SDK/src/fa/driver/sd_drv.c +++ b/libs/RVL_SDK/src/fa/driver/sd_drv.c @@ -3,14 +3,13 @@ #include typedef struct PFD_SDDRV_INFO { - volatile u32 flags; + u32 flags; u32 bytes_per_sector; - SDDev* volatile device; + SDDev* device; FADisk* disk; - volatile u32 media_inserted; + u32 media_inserted; u32 media_ejected; s8 drive; - u32 reserved; } PFD_SDDRV_INFO; typedef union PFD_SDDEV_STORAGE { @@ -33,16 +32,9 @@ PFD_SDDRV_INFO g_pfd_sddrv_info; PFD_SDDEV_STORAGE g_pfd_sddev; u8 g_pfd_sddrv_buf[0x200]; -u32 pfd_sddrv_reserved; -u32 g_event; -u32 pfd_sddrv_work0; -u32 pfd_sddrv_work1; -u32 pfd_sddrv_work2; -u32 pfd_sddrv_work3; -u32 pfd_sddrv_work4; -u32 pfd_sddrv_work5; -static FAEjectCallback g_detach_func; static FAInsertCallback g_attach_func; +static FAEjectCallback g_detach_func; +u32 g_event; extern u8 pfd_get_media_drv_char(FADisk*, s8*, u32); extern void pdm_disk_notify_media_insert(FADisk*); @@ -241,12 +233,12 @@ const PFD_SDDRV_SIZE_DEPEND sddrv_size_depend_tbl[14] = { static inline void update_media_drive(void) { s8 drive; - if (g_pfd_sddrv_info.drive == 0 && pfd_get_media_drv_char(*(FADisk* volatile*)&g_pfd_sddrv_info.disk, &drive, 1) == 1) { + if (g_pfd_sddrv_info.drive == 0 && pfd_get_media_drv_char(g_pfd_sddrv_info.disk, &drive, 1) == 1) { g_pfd_sddrv_info.drive = drive; } } -static void clear_mount_flag(void) { +static inline void clear_mount_flag(void) { g_pfd_sddrv_info.flags &= ~2; } @@ -267,7 +259,7 @@ s32 pfd_st_inter_callback(s32 status, void* data) { update_media_drive(); pdm_disk_notify_media_insert(g_pfd_sddrv_info.disk); if (g_pfd_sddrv_info.drive != 0 && g_attach_func != 0) { - g_attach_func(*(s8 volatile*)&g_pfd_sddrv_info.drive); + g_attach_func(g_pfd_sddrv_info.drive); } } g_pfd_sddrv_info.media_inserted = 1; @@ -293,7 +285,7 @@ s32 pfd_st_removal_callback(s32 status, void* data) { update_media_drive(); pdm_disk_notify_media_eject(g_pfd_sddrv_info.disk); if (g_pfd_sddrv_info.drive != 0 && g_detach_func != 0) { - g_detach_func(*(s8 volatile*)&g_pfd_sddrv_info.drive); + g_detach_func(g_pfd_sddrv_info.drive); } } return 0; @@ -304,16 +296,15 @@ s32 pfd_sddrv_init(FADisk* disk) { SDDev* device; u32 status; - if (disk == (FADisk*)(status = 0)) { + if (disk == 0) { return -30; } if ((g_pfd_sddrv_info.flags & 1) != 0) { OSReport("INFO SD Card driver is already initialize. pfd_sddrv_init()\n"); - sd_result = 0; - if (disk != g_pfd_sddrv_info.disk) { - sd_result = -44; + if (disk == g_pfd_sddrv_info.disk) { + return 0; } - return sd_result; + return -44; } if ((g_pfd_sddrv_info.flags & 4) == 0) { g_pfd_sddrv_info.bytes_per_sector = 0x200; @@ -337,11 +328,11 @@ s32 pfd_sddrv_init(FADisk* disk) { OSReport("ERR Failed to get sd card status. [ret = 0x%x]\n", sd_result); return 21; } - if ((status & 1) != 0) { + if ((status & 1) == 1) { g_pfd_sddrv_info.media_inserted = 1; } g_pfd_sddrv_info.device = device; - if (g_pfd_sddrv_info.media_inserted != 0) { + if (g_pfd_sddrv_info.media_inserted == 1) { g_event = 2; sd_result = ISD_RegisterDeviceIntrHandler(device, (SDDevIntrCallback)pfd_st_removal_callback, &g_event); if (sd_result != 0) { @@ -360,7 +351,7 @@ s32 pfd_sddrv_init(FADisk* disk) { return -42; } } - *(FADisk* volatile*)&g_pfd_sddrv_info.disk = disk; + g_pfd_sddrv_info.disk = disk; g_pfd_sddrv_info.flags |= 1; return 0; } @@ -472,14 +463,15 @@ s32 pfd_sddrv_unmount(FADisk* disk) { } s32 pfd_sddrv_finalize(FADisk* disk) { + s32 result; + if (disk == 0) { return -30; } - if ((g_pfd_sddrv_info.flags & 2) != 0) { + if ((g_pfd_sddrv_info.flags & 2) == 2) { clear_mount_flag(); } if ((g_pfd_sddrv_info.flags & 1) != 0) { - s32 result; result = ISD_UnregisterDeviceIntrHandler(g_pfd_sddrv_info.device); if (result != 0) { OSReport("WARNING Faild to UnregisterDeviceIntrHandler sd card [ret = %d]\n", result); @@ -490,10 +482,10 @@ s32 pfd_sddrv_finalize(FADisk* disk) { } g_pfd_sddrv_info.device = 0; } - g_pfd_sddrv_info.flags = g_pfd_sddrv_info.flags & ~1; - g_pfd_sddrv_info.media_inserted = 0; - *(FADisk* volatile*)&g_pfd_sddrv_info.disk = 0; - *(s8 volatile*)&g_pfd_sddrv_info.drive = 0; + g_pfd_sddrv_info.flags = g_pfd_sddrv_info.flags & 0xfffffffe; + g_pfd_sddrv_info.media_inserted = g_pfd_sddrv_info.media_ejected = 0; + g_pfd_sddrv_info.disk = 0; + g_pfd_sddrv_info.drive = 0; return 0; } @@ -565,7 +557,7 @@ s32 pfd_sddrv_is_media_insert(void) { s8 drive; if ((g_pfd_sddrv_info.flags & 1) != 0) { - if (g_pfd_sddrv_info.drive == 0 && pfd_get_media_drv_char(*(FADisk* volatile*)&g_pfd_sddrv_info.disk, &drive, 1) == 1) { + if (g_pfd_sddrv_info.drive == 0 && pfd_get_media_drv_char(g_pfd_sddrv_info.disk, &drive, 1) == 1) { g_pfd_sddrv_info.drive = drive; } if (g_pfd_sddrv_info.media_inserted != 0) { @@ -581,8 +573,8 @@ s32 pfd_sddrv_is_media_insert(void) { } static s32 pfd_sddrv_physical_read(u32 blocks, u8* buffer, u32 sector, u32 bytes_per_sector, u32* blocks_read) { - u32 current_sector; s32 result; + u32 current_sector; u32 completed; u8* current_buffer; if ((g_pfd_sddrv_info.flags & 2) == 0) { @@ -646,8 +638,8 @@ static s32 pfd_sddrv_physical_read(u32 blocks, u8* buffer, u32 sector, u32 bytes } s32 pfd_sddrv_physical_write(u32 blocks, u8* buffer, u32 sector, u32 bytes_per_sector, u32* blocks_written) { - u32 current_sector; s32 result; + u32 current_sector; u32 completed; u8* current_buffer; if ((g_pfd_sddrv_info.flags & 2) == 0) { @@ -739,7 +731,7 @@ s32 pfd_sddrv_get_total_sectors(u32* sectors, u16* bytes_per_sector) { multiplier = (csd[2] >> 8) & 0xf; minimum_multiplier = multiplier >= 9 ? multiplier : 9; max_multiplier = minimum_multiplier <= 11 ? minimum_multiplier : 11; - multiplier_factor = (u16)1 << (u16)(max_multiplier - 9); + multiplier_factor = 1 << (u16)(max_multiplier - 9); *sectors = cluster_blocks * multiplier_factor; } else { *sectors = ((csd[1] >> 8 & 0x3fffff) + 1) * 0x400; @@ -852,7 +844,7 @@ s32 pfd_sddrv_calc_mbr_bpb(PFD_SDDRV_FORMAT_DATA* format_data) { format_data->sectors_per_fat = fat_sectors; format_data->partition_start_sector = start_sector; format_data->partition_sector_count = format_data->total_sectors - start_sector; - clusters = (format_data->partition_sector_count - (next_fat_sectors * 2 + 0x21)) / format_data->sectors_per_cluster + 1; + clusters = (format_data->partition_sector_count - (fat_sectors * 2 + 0x21)) / format_data->sectors_per_cluster + 1; if (clusters < 0xff5) { format_data->fat_type = 0; } else if (clusters >= 0xff5) { @@ -861,12 +853,12 @@ s32 pfd_sddrv_calc_mbr_bpb(PFD_SDDRV_FORMAT_DATA* format_data) { return -31; } OSTicksToCalendarTime(OSGetTime(), ¤t_time); - format_data->volume_serial_number = ((current_time.mday & 0x1f) | + format_data->volume_serial_number = ((((current_time.year - 1900) & 0x7f) << 9) | ((current_time.mon & 0xf) << 5) | - (((current_time.year - 1900) & 0x7f) << 9)) * 0x10000 + - ((current_time.sec & 0x1f) | + (current_time.mday & 0x1f)) * 0x10000 + + (((current_time.hour & 0x1f) << 11) | ((current_time.min & 0x3f) << 5) | - ((current_time.hour & 0x1f) << 11)); + (current_time.sec & 0x1f)); return 0; }