From 7f46bd00bc338f8ef6074f13c972c5a42a6266cf Mon Sep 17 00:00:00 2001 From: luka177 Date: Sat, 25 Sep 2021 11:26:11 +0300 Subject: [PATCH] Implement config parsing, and fix lwext4 --- Abm.dec | 90 ++++++++++ Abm.dsc | 3 +- Include/Library/abm_base.h | 2 +- Include/ext4_debug.h | 21 +-- Include/string.h | 15 ++ Library/AbmLib/AbmLib.inf | 31 ++++ Library/AbmLib/abm_base.c | 45 ++++- Library/AbmLib/abm_base.h | 2 +- Library/AbmLib/abm_fs.c | 174 ++++++++++++++++++++ Library/AbmLib/abm_fs.h | 16 ++ Library/AbmLib/config.c | 202 +++++++++++++++++++++++ Library/AbmLib/config.h | 32 ++++ Library/AbmLib/fs_utils.c | 40 +++++ Library/AbmLib/fs_utils.h | 1 + Library/MicroLibC/Include/stdio.h | 8 + Library/MicroLibC/Include/string.h | 15 ++ Library/MicroLibC/stdio.c | 236 +++++++++++++++++++++++++++ Library/lwext4/include/ext4_config.h | 4 +- Library/lwext4/include/ext4_debug.h | 15 +- Library/lwext4/src/ext4_blockdev.c | 3 +- Library/lwext4/src/ext4_dir.c | 21 +++ Library/lwext4/src/ext4_mkfs.c | 10 +- abm/abm.c | 18 +- 23 files changed, 958 insertions(+), 46 deletions(-) create mode 100644 Library/AbmLib/abm_fs.c create mode 100644 Library/AbmLib/abm_fs.h create mode 100644 Library/AbmLib/config.c create mode 100644 Library/AbmLib/config.h create mode 100644 Library/AbmLib/fs_utils.c create mode 100644 Library/AbmLib/fs_utils.h diff --git a/Abm.dec b/Abm.dec index 24e328d..fc6a102 100644 --- a/Abm.dec +++ b/Abm.dec @@ -4,6 +4,96 @@ PACKAGE_GUID = aba6ea83-69e9-4345-b074-01f3626b389f PACKAGE_VERSION = 0.0.1 +[Guids.common] + gQcomTokenSpaceGuid = { 0x882f8c2b, 0x9646, 0x435f, { 0x8d, 0xe5, 0xf2, 0x08, 0xff, 0x80, 0xc1, 0xbd } } + gEfiPartitionTypeGuid = { 0x6848de61, 0xeb61, 0x4def, { 0x9a, 0x8e, 0x38, 0x17, 0xcb, 0xeb, 0x8f, 0x1c } } + gEfiEmmcUserPartitionGuid = { 0xb615f1f5, 0x5088, 0x43cd, { 0x80, 0x9c, 0xa1, 0x6e, 0x52, 0x48, 0x7d, 0x00 } } + gEfiEmmcBootPartition1Guid = { 0x12c55b20, 0x25d3, 0x41c9, { 0x8e, 0x06, 0x28, 0x2d, 0x94, 0xc6, 0x76, 0xad } } + gEfiEmmcBootPartition2Guid = { 0x6b76a6db, 0x0257, 0x48a9, { 0xaa, 0x99, 0xf6, 0xb1, 0x65, 0x5f, 0x7b, 0x00 } } + gEfiEmmcRpmbPartitionGuid = { 0xc49551ea, 0xd6bc, 0x4966, { 0x94, 0x99, 0x87, 0x1e, 0x39, 0x31, 0x33, 0xcd } } + gEfiEmmcGppPartition1Guid = { 0xb9251ea5, 0x3462, 0x4807, { 0x86, 0xc6, 0x89, 0x48, 0xb1, 0xb3, 0x61, 0x63 } } + gEfiEmmcGppPartition2Guid = { 0x24f906cd, 0xee11, 0x43e1, { 0x84, 0x27, 0xdc, 0x7a, 0x36, 0xf4, 0xc0, 0x59 } } + gEfiEmmcGppPartition3Guid = { 0x5a5709a9, 0xac40, 0x4f72, { 0x88, 0x62, 0x5b, 0x01, 0x04, 0x16, 0x6e, 0x76 } } + gEfiEmmcGppPartition4Guid = { 0xa44e27c9, 0x258e, 0x406e, { 0xbf, 0x33, 0x77, 0xf5, 0xf2, 0x44, 0xc4, 0x87 } } + gEfiSdRemovableGuid = { 0xd1531d41, 0x3f80, 0x4091, { 0x8d, 0x0a, 0x54, 0x1f, 0x59, 0x23, 0x6d, 0x66 } } + gEfiUfsLU0Guid = { 0x860845c1, 0xbe09, 0x4355, { 0x8b, 0xc1, 0x30, 0xd6, 0x4f, 0xf8, 0xe6, 0x3a } } + gEfiUfsLU1Guid = { 0x8d90d477, 0x39a3, 0x4a38, { 0xab, 0x9e, 0x58, 0x6f, 0xf6, 0x9e, 0xd0, 0x51 } } + gEfiUfsLU2Guid = { 0xedf85868, 0x87ec, 0x4f77, { 0x9c, 0xda, 0x5f, 0x10, 0xdf, 0x2f, 0xe6, 0x01 } } + gEfiUfsLU3Guid = { 0x1ae69024, 0x8aeb, 0x4df8, { 0xbc, 0x98, 0x00, 0x32, 0xdb, 0xdf, 0x50, 0x24 } } + gEfiUfsLU4Guid = { 0xd33f1985, 0xf107, 0x4a85, { 0xbe, 0x38, 0x68, 0xdc, 0x7a, 0xd3, 0x2c, 0xea } } + gEfiUfsLU5Guid = { 0x4ba1d05f, 0x088e, 0x483f, { 0xa9, 0x7e, 0xb1, 0x9b, 0x9c, 0xcf, 0x59, 0xb0 } } + gEfiUfsLU6Guid = { 0x4acf98f6, 0x26fa, 0x44d2, { 0x81, 0x32, 0x28, 0x2f, 0x2d, 0x19, 0xa4, 0xc5 } } + gEfiUfsLU7Guid = { 0x8598155f, 0x34de, 0x415c, { 0x8b, 0x55, 0x84, 0x3e, 0x33, 0x22, 0xd3, 0x6f } } + gEfiUfsRPMBGuid = { 0x5397474e, 0xf75d, 0x44b3, { 0x8e, 0x57, 0xd9, 0x32, 0x4f, 0xcf, 0x6f, 0xe1 } } + gEfiNandUserPartitionGuid = { 0x03ef84a9, 0x60ce, 0x4371, { 0x97, 0xcf, 0x04, 0x84, 0x5a, 0x86, 0x5b, 0x79 } } + + gEfiPlatPartitionTypeGuid = { 0x543c031a, 0x4cb6, 0x4897, { 0xbf, 0xfe, 0x4b, 0x48, 0x57, 0x68, 0xa8, 0xad } } + gQcomKeypadDeviceGuid = { 0xd7f58a0e, 0xbed2, 0x4b5a, { 0xbb, 0x43, 0x8a, 0xb2, 0x3d, 0xd0, 0xe2, 0xb0 } } + gEfiPlatformInfoGuid= { 0x3351baf7, 0x0820, 0x40df, { 0xb3, 0xfd, 0x4b, 0x7a, 0x3d, 0x43, 0x81, 0x88 } } + gEfiLogFSPartitionGuid = { 0xBC0330EB, 0x3410, 0x4951, { 0xA6, 0x17, 0x03, 0x89, 0x8D, 0xBE, 0x33, 0x72 } } + gEfiAblFvNameGuid= { 0x046fae99, 0xcf2e, 0x49ed, { 0xA6, 0xA8, 0xA1, 0x48, 0x8b, 0x7E, 0x80, 0xd3 } } + gEfiMiscPartitionGuid = { 0x82ACC91F, 0x357C, 0x4A68, { 0x9C, 0x8F, 0x68, 0x9E, 0x1B, 0x1A, 0x23, 0xA1 } } + gEfiBootImgPartitionGuid = { 0x20117f86, 0xe985, 0x4357, { 0xb9, 0xee, 0x37, 0x4b, 0xc1, 0xd8, 0x48, 0x7d } } + gEfiRecoveryImgPartitionGuid = { 0x9D72D4E4, 0x9958, 0x42DA, { 0xAC, 0x26, 0xBE, 0xA7, 0xA9, 0x0B, 0x04, 0x34 } } + gEfiSystemPartitionGuid = { 0x97D7B011, 0x54DA, 0x4835, { 0xB3, 0xC4, 0x91, 0x7A, 0xD6, 0xE7, 0x3D, 0x74 } } + gEfiVbmetaPartitionGuid = { 0x4b7a15d6, 0x322c, 0x42ac, { 0x81, 0x10, 0x88, 0xb7, 0xda, 0x0c, 0x5d, 0x77 } } + gEfiDtboPartitionGuid = { 0x24d0d418, 0xd31d, 0x4d8d, { 0xac, 0x2c, 0x4d, 0x43, 0x05, 0x18, 0x84, 0x50 } } + gEfiDipPartitionGuid = { 0x4114B077, 0x005D, 0x4E12, { 0xAC, 0x8C, 0xB4, 0x93, 0xBD, 0xA6, 0x84, 0xFB } } + gEfiMdtpPartitionGuid = { 0x3878408A, 0xE263, 0x4B67, { 0xB8, 0x78, 0x63, 0x40, 0xB3, 0x5B, 0x11, 0xE3 } } + gBlockIoRefreshGuid = { 0xb1eb3d10, 0x9d67, 0x40ca, { 0x95, 0x59, 0xf1, 0x48, 0x8b, 0x1b, 0x2d, 0xdb } } + gEfiRNGAlgRawGuid = { 0xe43176d7, 0xb6e8, 0x4827, { 0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61 } } + +[Protocols] + # SCM + gQcomScmProtocolGuid = { 0x77ed108d, 0x8524, 0x4b8b, { 0x9d, 0x2e, 0x34, 0x98, 0x7a, 0xec, 0xb9, 0xc1 } } + # PlatformInfo + gEfiPlatformInfoProtocolGuid = { 0x157a5c45, 0x21b2, 0x43c5, { 0xba, 0x7c, 0x82, 0x2f, 0xee, 0x5f, 0xe5, 0x99 } } + # Sdcc Card Info + gEfiMemCardInfoProtocolGuid = { 0x85c1f7d2, 0xbce6, 0x4f31, { 0x8f, 0x4d, 0xd3, 0x7e, 0x03, 0xd0, 0x5e, 0xaa } } + # USB Function + gEfiUsbfnIoProtocolGuid = { 0x32d2963a, 0xfe5d, 0x4f30, { 0xb6, 0x33, 0x6e, 0x5d, 0xc5, 0x58, 0x3, 0xcc } } + # ChipInfo + gEfiChipInfoProtocolGuid = { 0xb0760469, 0x970c, 0x487a, { 0xa4, 0xb5, 0x28, 0xdb, 0x7b, 0x45, 0xce, 0xf1 } } + gEfiPartitionRecordGuid = { 0xfe2555be, 0xd716, 0x4686, { 0xb9, 0xd0, 0x79, 0xdb, 0x59, 0x21, 0xb7, 0x0d } } + # PMIC VERSION + gQcomPmicVersionProtocolGuid = { 0x4684800a, 0x2755, 0x4edc, { 0xb4, 0x43, 0x7f, 0x8c, 0xeb, 0x32, 0x39, 0xd3 } } + # Guid for Fastboot + gEfiUsbDeviceProtocolGuid = { 0xd9d9ce48, 0x44b8, 0x4f49, { 0x8e, 0x3e, 0x2a, 0x3b, 0x92, 0x7d, 0xc6, 0xc1 } } + #RAM Partitions Protocol + gEfiRamPartitionProtocolGuid = { 0x5172FFB5, 0x4253, 0x7D51, { 0xC6, 0x41, 0xA7, 0x01, 0xF9, 0x73, 0x10, 0x3C } } + #Erase Block Protocol + gEfiEraseBlockProtocolGuid = { 0x95A9A93E, 0xA86E, 0x4926, { 0xaa, 0xef, 0x99, 0x18, 0xe7, 0x72, 0xd9, 0x87 } } + # ResetReasonProtocol + gEfiResetReasonProtocolGuid = { 0xA022155A, 0x4828, 0x4535, { 0xA4, 0x99, 0x11, 0xF1, 0x52, 0x40, 0xB9, 0x1B } } + # Charger Detection Protocol + gChargerExProtocolGuid = { 0x6edc8a6d, 0x2663, 0x43cd, { 0x90, 0xff, 0x46, 0x21, 0xff, 0xd1, 0x0d, 0xf5 } } + # Pon Reason Protocol + gQcomPmicPonProtocolGuid = { 0x97044b58, 0xfea4, 0x4ad0, { 0x9d, 0xb, 0xe4, 0x17, 0xd6, 0xf, 0x11, 0xa1 }} + # Throttle limit Protocol + gEfiLimitsProtocolGuid = { 0x79d6c879, 0x725e, 0x489e, { 0xa0, 0xa9, 0x27, 0xef, 0xa5, 0xdf, 0xcb, 0x35 } } + # VerifiedBoot Protocol + gEfiQcomVerifiedBootProtocolGuid = { 0x8e5eff91, 0x21b6, 0x47d3, { 0xaf, 0x2b, 0xc1, 0x5a, 0x1, 0xe0, 0x20, 0xec } } + # Scm mode switch Protocol + gQcomScmModeSwithProtocolGuid = { 0xf57f73ed, 0x0afc, 0x4723, { 0x93, 0x74, 0x2c, 0xeb, 0xc0, 0x19, 0x8e, 0xf9 } } + # Qseecom Protocol + gQcomQseecomProtocolGuid = { 0xa74862ce, 0x680f, 0x4fe1, { 0xa3, 0x11, 0xdf, 0x41, 0xf4, 0x3, 0x3, 0x91 } } + # Mdtp Protocol + gQcomMdtpProtocolGuid = { 0x71746E63, 0x65F9, 0x41EC, { 0xAC, 0x08, 0xCD, 0xD1, 0xF2, 0xD0, 0x22, 0x98 } } + # Partition Type Protocol + gEfiPartitionTypeGuid = { 0x6848de61, 0xeb61, 0x4def, { 0x9a, 0x8e, 0x38, 0x17, 0xcb, 0xeb, 0x8f, 0x1c } } + # Sha256 Protocol + gEfiHashAlgorithmSha256Guid = { 0x51aa59de, 0xfdf2, 0x4ea3, {0xbc, 0x63, 0x87, 0x5f, 0xb7, 0x84, 0x2e, 0xe9 } } + #Nand Partition GUID Protocol + gEfiNandPartiGuidProtocolGuid = { 0xd68edce2, 0xa314, 0x457b, { 0x96, 0x2a, 0x1d, 0x99, 0xbb, 0xfc, 0xbb, 0xfb } } + # Rng Protocol guid + gQcomRngProtocolGuid = { 0x3152bca5, 0xeade, 0x433d, { 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 } } + #UBI flasher protocol Guid + gEfiUbiFlasherProtocolGuid = { 0xe3eef434, 0x22c9, 0xe33b, { 0x8f, 0x5d, 0x0e, 0x81, 0x68, 0x6a, 0x68, 0xcb } } + + gEfiQcomASN1X509ProtocolGuid = { 0x408ec123, 0x134e, 0x4b80, { 0x91, 0x42, 0xb8, 0x9a, 0xe, 0x08, 0xf8, 0xb3 } } + + gEfiQcomSecRSAProtocolGuid = { 0xeb7a442a, 0xcef4, 0x40a7, {0xa8, 0xae, 0x5a, 0x2e, 0x7f, 0x48, 0xe1, 0x72 } } + #[Includes] # StdLib/Include [Includes.common] diff --git a/Abm.dsc b/Abm.dsc index f13d835..88fe908 100644 --- a/Abm.dsc +++ b/Abm.dsc @@ -83,7 +83,8 @@ AbmLib|AbmPkg/Library/AbmLib/AbmLib.inf lwext4Lib|AbmPkg/Library/lwext4Lib/lwext4Lib.inf - + FastbootLib|QcomModulePkg/Library/FastbootLib/FastbootLib.inf + [LibraryClasses.AARCH64] CompilerIntrinsicsLib|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf diff --git a/Include/Library/abm_base.h b/Include/Library/abm_base.h index 1f9dabc..068e88f 100644 --- a/Include/Library/abm_base.h +++ b/Include/Library/abm_base.h @@ -1 +1 @@ -void test_lvgl(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable); +void test_lvgl (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable, EFI_BLOCK_IO_PROTOCOL *BlockIo); diff --git a/Include/ext4_debug.h b/Include/ext4_debug.h index 10c581e..926d479 100644 --- a/Include/ext4_debug.h +++ b/Include/ext4_debug.h @@ -141,7 +141,7 @@ void ext4_dmask_clr(uint32_t m); * @return debug mask*/ uint32_t ext4_dmask_get(void); -#if CONFIG_DEBUG_PRINTF + #include /**@brief Debug printf.*/ @@ -153,32 +153,21 @@ uint32_t ext4_dmask_get(void); printf("l: %d ", __LINE__); \ } \ printf(__VA_ARGS__); \ - fflush(stdout); \ } \ } while (0) -#else -#define ext4_dbg(m, ...) do { } while (0) -#endif + #if CONFIG_DEBUG_ASSERT /**@brief Debug assertion.*/ #if CONFIG_HAVE_OWN_ASSERT #include -#define ext4_assert(_v) \ - do { \ - if (!(_v)) { \ - printf("assertion failed:\nfile: %s\nline: %d\n", \ - __FILE__, __LINE__); \ - while (1) \ - ; \ - } \ - } while (0) +#define ext4_assert(_v) #else -#define ext4_assert(_v) assert(_v) +#define ext4_assert(_v) #endif #else -#define ext4_assert(_v) ((void)(_v)) +#define ext4_assert(_v) #endif #ifdef __cplusplus diff --git a/Include/string.h b/Include/string.h index 2c15ae5..38d9315 100644 --- a/Include/string.h +++ b/Include/string.h @@ -16,6 +16,21 @@ #define memset(s, c, n) SetMem((s), (UINTN)(n), (UINT8)(c)) #define memcpy(s1, s2, n) CopyMem((s1), (s2), (n)) +static inline char * +strcat (char *dest, const char *src) +{ + char *p = dest; + while (*p) + p++; + while ((*p = *src) != '\0') + { + p++; + src++; + } + + return dest; +} + static inline char *strncpy(char *dest, const char *src, size_t n) { RETURN_STATUS Status = AsciiStrCpyS(dest, n, src); diff --git a/Library/AbmLib/AbmLib.inf b/Library/AbmLib/AbmLib.inf index ccefd73..4d6cfa9 100644 --- a/Library/AbmLib/AbmLib.inf +++ b/Library/AbmLib/AbmLib.inf @@ -32,7 +32,38 @@ BootLib EfiFileLib lwext4Lib + FastbootLib + +[Protocols] + gEfiSimpleTextInProtocolGuid + gEfiDevicePathToTextProtocolGuid + gEfiSimpleTextOutProtocolGuid + gEfiBlockIoProtocolGuid + gEfiDiskIoProtocolGuid + gEfiPartitionRecordGuid + gEfiUsbDeviceProtocolGuid + gEfiUsbfnIoProtocolGuid + gEfiMemCardInfoProtocolGuid + gEfiEraseBlockProtocolGuid + +[Guids] + gEfiUfsLU0Guid + gEfiUfsLU1Guid + gEfiUfsLU2Guid + gEfiUfsLU3Guid + gEfiUfsLU4Guid + gEfiUfsLU5Guid + gEfiUfsLU6Guid + gEfiUfsLU7Guid + gEfiBootImgPartitionGuid + gEfiRecoveryImgPartitionGuid + gQcomTokenSpaceGuid + gBlockIoRefreshGuid [Sources.common] abm_base.h abm_base.c + abm_fs.h + abm_fs.c + config.c + fs_utils.c diff --git a/Library/AbmLib/abm_base.c b/Library/AbmLib/abm_base.c index 0b9700d..05ebdfe 100644 --- a/Library/AbmLib/abm_base.c +++ b/Library/AbmLib/abm_base.c @@ -1,11 +1,20 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include + //TODO: fix this include #include <../Include/lvgl.h> #include <../Include/lv_misc/lv_log.h> #include - +#include EFI_SYSTEM_TABLE *gST1; EFI_BOOT_SERVICES *gBS1; EFI_GRAPHICS_OUTPUT_PROTOCOL *mGop; @@ -13,6 +22,21 @@ lv_disp_drv_t mDispDrv; lv_indev_drv_t mFakeInputDrv; lv_disp_t * disp; bool abm_running=true; +#include +#include "abm_fs.h" +#include +#include "config.h" + +struct boot_entry *entry_list; + +static struct ext4_mkfs_info info = { + .block_size = 4096, + .journal = false, +}; +static int fs_type = F_SET_EXT2; +static struct ext4_fs fs; +static struct ext4_blockdev *bd; + static void event_handler(lv_obj_t * obj, lv_event_t event) { if(event == LV_EVENT_CLICKED) { @@ -65,13 +89,22 @@ bool key_read(lv_indev_drv_t * drv, lv_indev_data_t*data) // EFI_STATUS EFIAPI -test_lvgl (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) +test_lvgl (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable, EFI_BLOCK_IO_PROTOCOL *BlockIo) { gST1 = SystemTable; gBS1 = gST1->BootServices; gBS1->LocateProtocol( &gEfiGraphicsOutputProtocolGuid, NULL, (VOID **)&mGop); + // Setup lwext4 lib, based on UEFI BlockIo protocol + uefi_dev_set(BlockIo); + bd = uefi_dev_get(); + if (!bd) { + DebugAssert("abm_base.c", 92, "open_filedev: fail\n"); + } + + mount_meta(bd); + entry_list = parse_boot_entries(&entry_list); // Prepare LittleVGL lv_init(); @@ -104,11 +137,11 @@ test_lvgl (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) lv_obj_t * list_btn; lv_obj_set_state(list1, LV_STATE_DEFAULT); - list_btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, "Example 1"); - lv_obj_set_event_cb(list_btn, event_handler); - list_btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, "Example 2"); - lv_obj_set_event_cb(list_btn, event_handler); + for(int i=0; ititle); + } list_btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, "Extras"); + lv_obj_set_event_cb(list_btn, event_handler); lv_list_set_anim_time(list1, 500); while (abm_running) { diff --git a/Library/AbmLib/abm_base.h b/Library/AbmLib/abm_base.h index 3c52264..068e88f 100644 --- a/Library/AbmLib/abm_base.h +++ b/Library/AbmLib/abm_base.h @@ -1 +1 @@ -void test_lvgl(IN EFI_SYSTEM_TABLE *SystemTable); +void test_lvgl (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable, EFI_BLOCK_IO_PROTOCOL *BlockIo); diff --git a/Library/AbmLib/abm_fs.c b/Library/AbmLib/abm_fs.c new file mode 100644 index 0000000..cec1b08 --- /dev/null +++ b/Library/AbmLib/abm_fs.c @@ -0,0 +1,174 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct ext4_mkfs_info info = { + .block_size = 4096, + .journal = false, +}; +static int fs_type = F_SET_EXT2; +static struct ext4_fs fs; + + +int uefi_dev_open (struct ext4_blockdev *bdev); +EFI_BLOCK_IO_PROTOCOL *BlockIo = NULL; + +void DumpHex(const void* data, size_t size) { + char ascii[17]; + size_t i, j; + ascii[16] = '\0'; + for (i = 0; i < size; ++i) { + DEBUG ((EFI_D_INFO,"%02X ", ((unsigned char*)data)[i])); + if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~') { + ascii[i % 16] = ((unsigned char*)data)[i]; + } else { + ascii[i % 16] = '.'; + } + if ((i+1) % 8 == 0 || i+1 == size) { + DEBUG ((EFI_D_INFO," ")); + if ((i+1) % 16 == 0) { + DEBUG ((EFI_D_INFO,"| %s \n", ascii)); + } else if (i+1 == size) { + ascii[(i+1) % 16] = '\0'; + if ((i+1) % 16 <= 8) { + DEBUG ((EFI_D_INFO," ")); + } + for (j = (i+1) % 16; j < 16; ++j) { + DEBUG ((EFI_D_INFO," ")); + } + DEBUG ((EFI_D_INFO,"| %s \n", ascii)); + } + } + } +} +static char *entry_to_str(uint8_t type) +{ + switch (type) { + case EXT4_DE_UNKNOWN: + return "[unk] "; + case EXT4_DE_REG_FILE: + return "[fil] "; + case EXT4_DE_DIR: + return "[dir] "; + case EXT4_DE_CHRDEV: + return "[cha] "; + case EXT4_DE_BLKDEV: + return "[blk] "; + case EXT4_DE_FIFO: + return "[fif] "; + case EXT4_DE_SOCK: + return "[soc] "; + case EXT4_DE_SYMLINK: + return "[sym] "; + default: + break; + } + return "[???]"; +} + +void uefi_dev_set(EFI_BLOCK_IO_PROTOCOL *BlockIo1) +{ + BlockIo=BlockIo1; +} + +int uefi_dev_close (struct ext4_blockdev *bdev){ + return EOK; +} + +static int uefi_dev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id, + uint32_t blk_cnt){ + DEBUG ((EFI_D_INFO, "Reading %d blocks from UFS at block: %d \n",blk_cnt, blk_id)); + BlockIo->ReadBlocks(BlockIo, BlockIo->Media->MediaId,blk_id, blk_cnt*4096, buf); + //DumpHex(buf, 4096); + return EOK; +} +// Debugging is here too +int uefi_dev_bwrite(struct ext4_blockdev *bdev, const void *buf, + uint64_t blk_id, uint32_t blk_cnt){ + EFI_STATUS Status; + DEBUG ((EFI_D_INFO, "Writing %d blocks to UFS at block: %d \n",blk_cnt, blk_id)); + Status=BlockIo->WriteBlocks(BlockIo, BlockIo->Media->MediaId,blk_id, blk_cnt*4096, buf); + BlockIo->FlushBlocks(BlockIo); + if(Status!=EFI_SUCCESS){ + DEBUG ((EFI_D_INFO, "Writing %d blocks to UFS at block: %d failed, error: %d, block size: %d\n",blk_cnt, blk_id, Status, BlockIo->Media->BlockSize)); + } + return EOK; +} + +EXT4_BLOCKDEV_STATIC_INSTANCE(ufs_dev, 4096, 65536, uefi_dev_open, + uefi_dev_bread, uefi_dev_bwrite, uefi_dev_close, 0, 0); +int uefi_dev_open (struct ext4_blockdev *bdev){ + ufs_dev.part_offset = 0; + ufs_dev.part_size = 65536; + ufs_dev.bdif->ph_bcnt = ufs_dev.part_size / 4096; + return EOK; +} + + +struct ext4_blockdev *uefi_dev_get(void) +{ + return &ufs_dev; +} + +void mount_meta(struct ext4_blockdev *bd){ + + int r, s; + r=ext4_device_register(bd, "ext4_fs"); + if (!bd){ + DEBUG ((EFI_D_INFO, "BD is broken :(\n")); + } + if (r != EOK) { + DebugAssert("abm_fs.c", 96, "ext4_device_register: fail\n"); + } + + + r=ext4_mount("ext4_fs", "/meta/", false); + if (r != EOK) { + DEBUG ((EFI_D_INFO, "ext4_mount: %d, status: %d\n", r,s)); + + } + + r=ext4_cache_write_back("/meta/", 1); + if (r != EOK) { + DebugAssert("abm_fs.c", 115, "ext4_cache_write_back: fail\n"); + } + + char sss[255]; + ext4_dir d; + const ext4_direntry *de; + + DEBUG ((EFI_D_INFO, "ls %s", "/meta/")); + + ext4_dir_open(&d, "/meta/db/entries"); + de = ext4_dir_entry_next(&d); + + while (de) { + memcpy(sss, de->name, de->name_length); + sss[de->name_length] = 0; + if(de->inode_type==EXT4_DE_REG_FILE){ + DEBUG ((EFI_D_INFO, "File file file\n")); + } + DEBUG ((EFI_D_INFO, "Found file or dir: %a\n", sss)); + de = ext4_dir_entry_next(&d); + } + ext4_dir_close(&d); +} + + diff --git a/Library/AbmLib/abm_fs.h b/Library/AbmLib/abm_fs.h new file mode 100644 index 0000000..27b117b --- /dev/null +++ b/Library/AbmLib/abm_fs.h @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + +struct ext4_blockdev *uefi_dev_get(void); +void uefi_dev_set(EFI_BLOCK_IO_PROTOCOL *BlockIo1); +int uefi_dev_bwrite(struct ext4_blockdev *bdev, const void *buf, uint64_t blk_id, uint32_t blk_cnt); diff --git a/Library/AbmLib/config.c b/Library/AbmLib/config.c new file mode 100644 index 0000000..8dd6214 --- /dev/null +++ b/Library/AbmLib/config.c @@ -0,0 +1,202 @@ +// SPDX-License-Identifier: GPL-2.0+ +// © 2019 Mis012 +// © 2020-2021 luka177 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include "config.h" +#include "fs_utils.h" +#include +#include + +#define ENTRIES_DIR "/meta/db/entries" +#define GLOBAL_CONFIG_FILE "/meta/db/db.conf" + +static int config_parse_option(char **_dest, const char *option, const char *buffer) { + char *temp = strstr(buffer, option); + if(!temp) + return -1; + + temp += strlen(option); + while (*temp == ' ') + temp++; + char *newline = strchr(temp, '\n'); + if(newline) + *newline = '\0'; + char *dest = malloc(strlen(temp) + 1); + if(!dest) + return 1; + strcpy(dest, temp); + *_dest = dest; + + //restore the buffer + *newline = '\n'; + + return 0; +} + +static int parse_boot_entry_file(struct boot_entry *entry, char *file) { + int ret; + ext4_file fp; + unsigned char *buf; + size_t rb; + char *path = malloc(strlen(file) + strlen(ENTRIES_DIR) + strlen("/") + 1); + strcpy(path, ENTRIES_DIR); + strcat(path, "/"); + strcat(path, file); + + DEBUG ((EFI_D_INFO, "parse_boot_entry_file: open file: %a\n", path)); + ret=ext4_fopen (&fp, path, "r"); + if(ret!=EOK){ + DEBUG ((EFI_D_INFO, "parse_boot_entry_file: open file: %a failed\n", path)); + } + DEBUG ((EFI_D_INFO, "parse_boot_entry_file: open file: %a OK\n", path)); + + ext4_fseek(&fp, 0, SEEK_END); + DEBUG ((EFI_D_INFO, "parse_boot_entry_file: fseek end OK\n")); + long fsize = ext4_ftell(&fp); + DEBUG ((EFI_D_INFO, "parse_boot_entry_file: ftell OK\n")); + ext4_fseek(&fp, 0, SEEK_SET); /* same as rewind(f); */ + DEBUG ((EFI_D_INFO, "parse_boot_entry_file: fseek set OK\n")); + + buf = malloc(fsize + 1); + DEBUG ((EFI_D_INFO, "parse_boot_entry_file: malloc OK\n")); + + ext4_fread(&fp, buf, fsize, &rb); + DEBUG ((EFI_D_INFO, "parse_boot_entry_file: fread OK\n")); + ext4_fclose(&fp); + DEBUG ((EFI_D_INFO, "parse_boot_entry_file: file operations done\n")); + buf[fsize] = '\0'; + + ret = config_parse_option(&entry->title, "title", (const char *)buf); + if(ret < 0) { + free(buf); + return ret; + } + + ret = config_parse_option(&entry->linux_kernel, "linux", (const char *)buf); + if(ret < 0) { + free(buf); + return ret; + } + + ret = config_parse_option(&entry->initrd, "initrd", (const char *)buf); + if(ret < 0) { + free(buf); + return ret; + } + + ret = config_parse_option(&entry->dtb, "dtb", (const char *)buf); + if(ret < 0) { + free(buf); + return ret; + } + + ret = config_parse_option(&entry->options, "options", (const char *)buf); + if(ret < 0) { + free(buf); + return ret; + } + + free(buf); + + entry->error = false; + + return 0; +} + +int entry_count; + +int get_entry_count(void) { + return entry_count; +} + +struct boot_entry *parse_boot_entries(struct boot_entry **_entry_list) { + int ret; + + struct boot_entry *entry_list=malloc(sizeof(struct boot_entry)*dir_count_entries(ENTRIES_DIR)); + + ret = entry_count = dir_count_entries(ENTRIES_DIR); + if (ret < 0) { + entry_count = 0; + } + + const ext4_direntry *de; + ext4_dir d; + + ret=ext4_dir_open (&d, ENTRIES_DIR); + + de = ext4_dir_entry_next(&d); + int i = 0; + while(de) { + DEBUG ((EFI_D_INFO, "Looping in parse_boot_entries, iteration: %d, inode_type: %d, name of file: %a", i, de->inode_type, de->name)); + if(de->inode_type==1){ + struct boot_entry *entry = (entry_list+i); + DEBUG ((EFI_D_INFO, "Call parse_boot_entry_file\n")); + ret = parse_boot_entry_file(entry, de->name); + DEBUG ((EFI_D_INFO, "Call parse_boot_entry_file done\n")); + if(ret < 0) { + entry->error = true; + entry->title = "SYNTAX ERROR"; + } + DEBUG ((EFI_D_INFO, "New entry found, id %d, title: %a\n", i, entry->title)); + i++; + } + de = ext4_dir_entry_next(&d); + } + + ext4_dir_close(&d); + + //*_entry_list = entry_list; + //printf("First entry is: %s\n", entry_list->title); + return entry_list; +} + +int parse_global_config(struct global_config *global_config) { + int ret; + ext4_file fp; + unsigned char *buf; + + ext4_fopen (&fp, GLOBAL_CONFIG_FILE, "r"); + + ext4_fseek(&fp, 0, SEEK_END); + long fsize = ext4_ftell(&fp); + ext4_fseek(&fp, 0, SEEK_SET); /* same as rewind(f); */ + + buf = malloc(fsize + 1); + + ext4_fread(&fp, buf, 1, fsize); + + ext4_fclose(&fp); + + ret = config_parse_option(&global_config->default_entry_title, "default", (const char *)buf); + if(ret < 0) { + + + global_config->default_entry_title = NULL; + global_config->timeout = 0; + + return 0; + } + + char *timeout = NULL; + ret = config_parse_option(&timeout, "timeout", (const char *)buf); + + global_config->timeout = atoi(timeout); + + return 0; +} diff --git a/Library/AbmLib/config.h b/Library/AbmLib/config.h new file mode 100644 index 0000000..ff52c66 --- /dev/null +++ b/Library/AbmLib/config.h @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include + +#ifndef CONFIG_H +#define CONFIG_H +struct global_config { + char *default_entry_title; + struct boot_entry *default_entry; + int timeout; +}; + + +struct boot_entry { + char *title; + char *linux_kernel; + char *initrd; + char *dtb; + char *options; + bool is_android; + bool error; +}; + +int get_entry_count(void); + +struct boot_entry *parse_boot_entries(struct boot_entry **_entry_list); + +int parse_global_config(struct global_config *global_config); + +#endif diff --git a/Library/AbmLib/fs_utils.c b/Library/AbmLib/fs_utils.c new file mode 100644 index 0000000..f0d1b08 --- /dev/null +++ b/Library/AbmLib/fs_utils.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "fs_utils.h" +#include + +int dir_count_entries(const char *path) { + const ext4_direntry *de; + ext4_dir d; + + // Ensure we can open directory. + + ext4_dir_open (&d, path); + + // Process each entry. + int res=0; + de = ext4_dir_entry_next(&d); + + while (de) { + DEBUG ((EFI_D_INFO, "Looping in dir_count_entries\n")); + if(de->inode_type==EXT4_DE_REG_FILE){ + res+=1; + } + de = ext4_dir_entry_next(&d); + } + ext4_dir_close(&d); + return res; +} diff --git a/Library/AbmLib/fs_utils.h b/Library/AbmLib/fs_utils.h new file mode 100644 index 0000000..18381a5 --- /dev/null +++ b/Library/AbmLib/fs_utils.h @@ -0,0 +1 @@ +int dir_count_entries(const char *path); diff --git a/Library/MicroLibC/Include/stdio.h b/Library/MicroLibC/Include/stdio.h index 18b2b22..8be9a7d 100644 --- a/Library/MicroLibC/Include/stdio.h +++ b/Library/MicroLibC/Include/stdio.h @@ -9,5 +9,13 @@ int snprintf(char *str, size_t size, const char *format, ...); int vprintf(const char *format, va_list ap); int printf(const char *format, ...); +int __printf_chk(const char *format, ...); + +VOID *malloc(UINTN size); +VOID *malloc_rt(UINTN Size); +VOID *memalign(UINTN boundary, UINTN size); +VOID *memalign2(UINTN boundary, UINTN size, BOOLEAN runtime); +VOID *calloc(UINTN count, UINTN size); +VOID free(VOID *ptr); #endif diff --git a/Library/MicroLibC/Include/string.h b/Library/MicroLibC/Include/string.h index 5d63db8..4c4171c 100644 --- a/Library/MicroLibC/Include/string.h +++ b/Library/MicroLibC/Include/string.h @@ -15,6 +15,21 @@ #define memset(s, c, n) SetMem((s), (UINTN)(n), (UINT8)(c)) #define memcpy(s1, s2, n) CopyMem((s1), (s2), (n)) +static inline char * +strcat (char *dest, const char *src) +{ + char *p = dest; + while (*p) + p++; + while ((*p = *src) != '\0') + { + p++; + src++; + } + + return dest; +} + static inline char *strncpy(char *dest, const char *src, size_t n) { RETURN_STATUS Status = AsciiStrCpyS(dest, n, src); diff --git a/Library/MicroLibC/stdio.c b/Library/MicroLibC/stdio.c index e510d87..0eae7d0 100644 --- a/Library/MicroLibC/stdio.c +++ b/Library/MicroLibC/stdio.c @@ -2,9 +2,22 @@ #include #include #include +#include +#include + +#include +#include #include +#define WT size_t +#define WS (sizeof(WT)) + +#define ARRAY_SIZE(a) \ + ((sizeof(a) / sizeof(*(a))) / \ + (size_t)(!(sizeof(a) % sizeof(*(a))))) + +typedef unsigned uintptr_t; int vsnprintf(char *str, size_t size, const char *format, va_list ap) { CHAR8 localfmt[100]; @@ -46,6 +59,18 @@ int vprintf(const char *format, va_list ap) } int printf(const char *format, ...) +{ + int err; +DEBUG ((EFI_D_INFO, format)); + VA_LIST ap; + VA_START(ap, format); + err = vprintf(format, ap); + VA_END(ap); + + return err; +} + +int __printf_chk(const char *format, ...) { int err; @@ -56,3 +81,214 @@ int printf(const char *format, ...) return err; } + +#define CPOOL_HEAD_SIGNATURE SIGNATURE_32('C', 'p', 'h', 'd') + +typedef enum { + ALLOCTYPE_POOL, + ALLOCTYPE_ALIGNED_PAGES, + ALLOCTYPE_POOL_RUNTIME, +} ALLOCATION_TYPE; + +typedef struct { + UINT32 Signature; + UINTN Size; + UINTN Boundary; + ALLOCATION_TYPE Type; + + UINT8 Data[0]; +} CPOOL_HEAD; + +VOID *memalign(UINTN Boundary, UINTN Size) +{ + return memalign2(Boundary, Size, FALSE); +} + +VOID *memalign2(UINTN Boundary, UINTN Size, BOOLEAN runtime) +{ + VOID * BaseMemory = NULL; + CPOOL_HEAD * Head; + VOID * RetVal; + UINTN HeadSize; + UINTN NodeSize; + ALLOCATION_TYPE Type = ALLOCTYPE_POOL; + + if (Size == 0) { + DEBUG((DEBUG_ERROR, "ERROR memalign: Zero Size\n")); + return NULL; + } + + if (Boundary == 8 && runtime) { + Type = ALLOCTYPE_POOL_RUNTIME; + } + else if (Boundary == 8) { + Type = ALLOCTYPE_POOL; + } + else { + Type = ALLOCTYPE_ALIGNED_PAGES; + } + + HeadSize = ALIGN_VALUE(sizeof(CPOOL_HEAD), Boundary); + NodeSize = HeadSize + Size; + + DEBUG((DEBUG_POOL, "memalign(%d): NodeSz: %d", Size, NodeSize)); + + if (Type == ALLOCTYPE_POOL) { + BaseMemory = AllocatePool(NodeSize); + } + else if (Type == ALLOCTYPE_POOL_RUNTIME) { + BaseMemory = AllocateRuntimePool(NodeSize); + } + else if (Type == ALLOCTYPE_ALIGNED_PAGES) { + BaseMemory = AllocateAlignedPages(EFI_SIZE_TO_PAGES(NodeSize), Boundary); + DEBUG((DEBUG_POOL, "Allocated at 0x%llx\n", BaseMemory)); + } + else { + ASSERT(FALSE); + } + + if (BaseMemory == NULL) { + RetVal = NULL; + DEBUG((DEBUG_ERROR, "\nERROR memalign: alloc failed\n")); + } + else { + ASSERT(BaseMemory != NULL); + Head = BaseMemory + HeadSize - sizeof(CPOOL_HEAD); + + // Fill out the pool header + Head->Signature = CPOOL_HEAD_SIGNATURE; + Head->Size = Size; + Head->Boundary = Boundary; + Head->Type = Type; + + // Return a pointer to the data + RetVal = (VOID *)Head->Data; + DEBUG((DEBUG_POOL, " Head: %p, Returns %p\n", Head, RetVal)); + } + + return RetVal; +} + +VOID *malloc(UINTN Size) { return memalign(8, Size); } + +VOID *malloc_rt(UINTN Size) { return memalign2(8, Size, TRUE); } + +VOID *calloc(UINTN Count, UINTN Size) +{ + VOID *Ptr; + + Ptr = malloc(Count * Size); + if (Ptr) + SetMem(Ptr, Count * Size, 0); + + return Ptr; +} + +VOID free(VOID *Ptr) +{ + CPOOL_HEAD *Head; + UINTN HeadSize; + UINTN NodeSize; + VOID * BaseMemory; + + if (Ptr != NULL) { + Head = BASE_CR(Ptr, CPOOL_HEAD, Data); + ASSERT(Head != NULL); + DEBUG((DEBUG_POOL, "free(%p): Head: %p\n", Ptr, Head)); + + if (Head->Signature == CPOOL_HEAD_SIGNATURE) { + HeadSize = ALIGN_VALUE(sizeof(CPOOL_HEAD), Head->Boundary); + NodeSize = HeadSize + Head->Size; + BaseMemory = Ptr - HeadSize + 0x4; + + if (Head->Type == ALLOCTYPE_POOL || + Head->Type == ALLOCTYPE_POOL_RUNTIME) { + FreePool(BaseMemory); + } + else if (Head->Type == ALLOCTYPE_ALIGNED_PAGES) { + DEBUG( + (DEBUG_POOL, "About to free %p, head size 0x%llx\n", BaseMemory, + HeadSize)); + FreeAlignedPages(BaseMemory, EFI_SIZE_TO_PAGES(NodeSize)); + } + else { + ASSERT(FALSE); + } + } + else { + DEBUG(( + DEBUG_ERROR, "ERROR free(0x%p): Signature is 0x%8X, expected 0x%8X\n", + Ptr, Head->Signature, CPOOL_HEAD_SIGNATURE)); + } + } + + DEBUG((DEBUG_POOL, "free Done\n")); +} +void *memmove(void *dest, const void *src, size_t n) +{ + +CopyMem(dest, src, n); + return dest; +} + +VOID *realloc(VOID *Ptr, UINTN NewSize) +{ + VOID * RetVal = NULL; + CPOOL_HEAD *Head = NULL; + UINTN OldSize = 0; + UINTN NumCpy; + BOOLEAN IsRuntimePool = FALSE; + + // Find out the size of the OLD memory region + if (Ptr != NULL) { + Head = BASE_CR(Ptr, CPOOL_HEAD, Data); + ASSERT(Head != NULL); + if (Head->Signature != CPOOL_HEAD_SIGNATURE) { + DEBUG( + (DEBUG_ERROR, + "ERROR realloc(0x%p): Signature is 0x%8X, expected 0x%8X\n", Ptr, + Head->Signature, CPOOL_HEAD_SIGNATURE)); + return NULL; + } + if (Head->Type != ALLOCTYPE_POOL && Head->Type != ALLOCTYPE_POOL_RUNTIME) { + DEBUG( + (DEBUG_ERROR, + "ERROR realloc(0x%p): Only malloc pointers are supported\n", Ptr)); + } + OldSize = Head->Size; + IsRuntimePool = Head->Type == ALLOCTYPE_POOL_RUNTIME; + } + + // At this point, Ptr is either NULL or a valid pointer to an allocated space + + if (NewSize == OldSize) { + RetVal = Ptr; + } + else if (NewSize > 0) { + if (IsRuntimePool) { + RetVal = malloc_rt(NewSize); // Get the NEW memory region for runtime pool + } + else { + RetVal = malloc(NewSize); // Get the NEW memory region + } + + if (Ptr != NULL) { + // If there is an OLD region... + if (RetVal != NULL) { + // and the NEW region was successfully allocated + NumCpy = MIN(OldSize, NewSize); + CopyMem(RetVal, Ptr, NumCpy); // Copy old data to the new region. + free(Ptr); // and reclaim the old region. + } + } + } + else { + free(Ptr); // Reclaim the old region. + } + + DEBUG( + (DEBUG_POOL, "0x%p = realloc(%p, %d): Head: %p\n", RetVal, Ptr, NewSize, + Head)); + + return RetVal; +} diff --git a/Library/lwext4/include/ext4_config.h b/Library/lwext4/include/ext4_config.h index 810df4c..b92591a 100644 --- a/Library/lwext4/include/ext4_config.h +++ b/Library/lwext4/include/ext4_config.h @@ -101,12 +101,12 @@ extern "C" { /**@brief Debug printf enable (stdout)*/ #ifndef CONFIG_DEBUG_PRINTF -#define CONFIG_DEBUG_PRINTF 1 +#define CONFIG_DEBUG_PRINTF 0 #endif /**@brief Assert printf enable (stdout)*/ #ifndef CONFIG_DEBUG_ASSERT -#define CONFIG_DEBUG_ASSERT 1 +#define CONFIG_DEBUG_ASSERT 0 #endif /**@brief Include assert codes from ext4_debug or standard library.*/ diff --git a/Library/lwext4/include/ext4_debug.h b/Library/lwext4/include/ext4_debug.h index 10c581e..9a4b1e8 100644 --- a/Library/lwext4/include/ext4_debug.h +++ b/Library/lwext4/include/ext4_debug.h @@ -153,7 +153,6 @@ uint32_t ext4_dmask_get(void); printf("l: %d ", __LINE__); \ } \ printf(__VA_ARGS__); \ - fflush(stdout); \ } \ } while (0) #else @@ -165,20 +164,12 @@ uint32_t ext4_dmask_get(void); #if CONFIG_HAVE_OWN_ASSERT #include -#define ext4_assert(_v) \ - do { \ - if (!(_v)) { \ - printf("assertion failed:\nfile: %s\nline: %d\n", \ - __FILE__, __LINE__); \ - while (1) \ - ; \ - } \ - } while (0) +#define ext4_assert(_v) #else -#define ext4_assert(_v) assert(_v) +#define ext4_assert(_v) #endif #else -#define ext4_assert(_v) ((void)(_v)) +#define ext4_assert(_v) #endif #ifdef __cplusplus diff --git a/Library/lwext4/src/ext4_blockdev.c b/Library/lwext4/src/ext4_blockdev.c index c01093a..ac344a9 100644 --- a/Library/lwext4/src/ext4_blockdev.c +++ b/Library/lwext4/src/ext4_blockdev.c @@ -120,8 +120,9 @@ int ext4_block_bind_bcache(struct ext4_blockdev *bdev, struct ext4_bcache *bc) void ext4_block_set_lb_size(struct ext4_blockdev *bdev, uint32_t lb_bsize) { /*Logical block size has to be multiply of physical */ + // breakpoint ok ext4_assert(!(lb_bsize % bdev->bdif->ph_bsize)); - +// breakpoint bad bdev->lg_bsize = lb_bsize; bdev->lg_bcnt = bdev->part_size / lb_bsize; } diff --git a/Library/lwext4/src/ext4_dir.c b/Library/lwext4/src/ext4_dir.c index 29a51c5..b2683a5 100644 --- a/Library/lwext4/src/ext4_dir.c +++ b/Library/lwext4/src/ext4_dir.c @@ -54,6 +54,27 @@ #include +// HACK: declare memcmp here, TODO: move it to libc +static int memcmp(const void *s1, const void *s2, UINTN n) +{ + const unsigned char *c1 = s1, *c2 = s2; + int d = 0; + + if (!s1 && !s2) + return 0; + if (s1 && !s2) + return 1; + if (!s1 && s2) + return -1; + + while (n--) { + d = (int)*c1++ - (int)*c2++; + if (d) + break; + } + return d; +} + /****************************************************************************/ /* Walk through a dirent block to find a checksum "dirent" at the tail */ diff --git a/Library/lwext4/src/ext4_mkfs.c b/Library/lwext4/src/ext4_mkfs.c index 0dfc91f..4be862a 100644 --- a/Library/lwext4/src/ext4_mkfs.c +++ b/Library/lwext4/src/ext4_mkfs.c @@ -776,7 +776,7 @@ int ext4_mkfs(struct ext4_fs *fs, struct ext4_blockdev *bd, } info->bg_desc_reserve_blocks = 0; - +//breakpoint ok ext4_dbg(DEBUG_MKFS, DBG_INFO "Creating filesystem with parameters:\n"); ext4_dbg(DEBUG_MKFS, DBG_NONE "Size: %"PRIu64"\n", info->len); ext4_dbg(DEBUG_MKFS, DBG_NONE "Block size: %"PRIu32"\n", @@ -805,15 +805,17 @@ int ext4_mkfs(struct ext4_fs *fs, struct ext4_blockdev *bd, ext4_dbg(DEBUG_MKFS, DBG_NONE "Label: %s\n", info->label); struct ext4_bcache bc; - +// breakpoint ok memset(&bc, 0, sizeof(struct ext4_bcache)); +// breakpoint ok ext4_block_set_lb_size(bd, info->block_size); - + +//breakpoint bad r = ext4_bcache_init_dynamic(&bc, CONFIG_BLOCK_DEV_CACHE_SIZE, info->block_size); if (r != EOK) goto block_fini; - +//breakpoint bad /*Bind block cache to block device*/ r = ext4_block_bind_bcache(bd, &bc); if (r != EOK) diff --git a/abm/abm.c b/abm/abm.c index 8eab24a..68cdab6 100644 --- a/abm/abm.c +++ b/abm/abm.c @@ -5,7 +5,17 @@ #include <../Include/lvgl.h> #include <../Include/lv_misc/lv_log.h> #include - +#include +#include "abm_fs.h" +#include + +static struct ext4_mkfs_info info = { + .block_size = 4096, + .journal = false, +}; +static int fs_type = F_SET_EXT2; +static struct ext4_fs fs; +static struct ext4_blockdev *bd; EFI_SYSTEM_TABLE *gST1; EFI_BOOT_SERVICES *gBS1; EFI_GRAPHICS_OUTPUT_PROTOCOL *mGop; @@ -67,12 +77,16 @@ EFI_STATUS EFIAPI efi_main_init (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { +#error gST1 = SystemTable; gBS1 = gST1->BootServices; gBS1->LocateProtocol( &gEfiGraphicsOutputProtocolGuid, NULL, (VOID **)&mGop); - + // Format cache test + bd = uefi_dev_get(); + ext4_mkfs(&fs, bd, &info, fs_type); + // Prepare LittleVGL lv_init(); static lv_disp_buf_t disp_buf;