Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlashDriver中的函数如何与地址对应? #1

Closed
zangege opened this issue Apr 29, 2021 · 2 comments
Closed

FlashDriver中的函数如何与地址对应? #1

zangege opened this issue Apr 29, 2021 · 2 comments
Assignees
Labels
good first issue Good for newcomers question Further information is requested

Comments

@zangege
Copy link

zangege commented Apr 29, 2021

大神你好,我想问下FlashDriver中的函数是如何与地址对应的?是下面这个代码么?没看太懂。。对应关系还是没理太清楚,麻烦有空了解释一下。。谢谢大神。。
static const tFlashDriverAPIInfo gs_FlashDriverAPI NVM_DRIVER_SECTION = {
#if defined (S32K116) || defined (S32K142)
(tpfFLASH_DRV_EraseSector) CAL_OFFSET(FLASH_DRV_EraseSector),
(tpfFLASH_DRV_Program) CAL_OFFSET(FLASH_DRV_Program),
(tpfFLASH_DRV_VerifySection) CAL_OFFSET(FLASH_DRV_VerifySection),
(tpfFLASH_DRV_GetDefaultConfig) CAL_OFFSET(FLASH_DRV_GetDefaultConfig),
#elif defined (S32K144) || defined (S32K118)
// (tpfFLASH_DRV_EraseAllBlock) CAL_OFFSET(FLASH_DRV_EraseAllBlock),
// (tpfFLASH_DRV_VerifyAllBlock) CAL_OFFSET(FLASH_DRV_VerifyAllBlock),
(tpfFLASH_DRV_EraseSector) CAL_OFFSET(FLASH_DRV_EraseSector),
(tpfFLASH_DRV_VerifySection) CAL_OFFSET(FLASH_DRV_VerifySection),
// (tpfFLASH_DRV_EraseSuspend) CAL_OFFSET(FLASH_DRV_EraseSuspend),
// (tpfFLASH_DRV_EraseResume) CAL_OFFSET(FLASH_DRV_EraseResume),
(tpfFLASH_DRV_Program) CAL_OFFSET(FLASH_DRV_Program),
(tpfFLASH_DRV_ProgramCheck) CAL_OFFSET(FLASH_DRV_ProgramCheck),
// (tpfFLASH_DRV_ProgramSection) CAL_OFFSET(FLASH_DRV_ProgramSection),
// (tpfFLASH_DRV_EraseBlock) CAL_OFFSET(FLASH_DRV_EraseBlock),
// (tpfFLASH_DRV_CommandSequence) CAL_OFFSET(FLASH_DRV_CommandSequence),
// (tpfFLASH_DRV_VerifyBlock) CAL_OFFSET(FLASH_DRV_VerifyBlock),
#endif

@SummerFalls
Copy link
Owner

@zangege 你好,没收到邮件通知回复晚了。

我在 .ld 链接文件中,将相关的 Flash 操作函数放在了 m_NVM_Driver MEMORY 空间区域,即位于 Flash 0x10000 处,在你编译本工程后,将 Debug_FLASH 文件夹下的 hex 文件用 J-Flash 打开,你可以看到在 0x10000 开始看到有数据存在,这里的数据就包含了本数组和 Flash 操作函数。即如下数组当中的数据,即为 4 个 32位的函数偏移量和 4 个函数的数据:

/* TODO S32K_FlashDrv: #04 Flash 驱动函数表:包含前16(0x10)字节的指针映射偏移表以及相应的4个驱动函数
 * 编译后,通过 J-Flash 打开 Hex 文件提取对应地址处的内容,粘贴到以下数组即可测试
 */
uint8_t g_flashDriverRAM[] = {
    0x11, 0x00, 0x00, 0x00, 0x49, 0x01, 0x00, 0x00, 0x65, 0x02, 0x00, 0x00, 0xB1, 0x03, 0x00, 0x00,
    0x80, 0xB5, 0x88, 0xB0, 0x00, 0xAF, 0xF8, 0x60, 0xB9, 0x60, 0x7A, 0x60, 0x00, 0x23, 0x7B, 0x82,
    0x7B, 0x68, 0xBB, 0x61, 0xFB, 0x68, 0x9B, 0x68, 0x7B, 0x61, 0xBA, 0x68, 0x7B, 0x69, 0x9A, 0x42,
    0x10, 0xD3, 0xFB, 0x68, 0xDA, 0x68, 0x7B, 0x69, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42, 0x09, 0xD9,
    0xBA, 0x68, 0x7B, 0x69, 0xD3, 0x1A, 0x03, 0xF5, 0x00, 0x03, 0xBB, 0x60, 0x4F, 0xF4, 0x00, 0x63,
    0xFB, 0x61, 0x1B, 0xE0, 0xFB, 0x68, 0x1B, 0x68, 0x7B, 0x61, 0xBA, 0x68, 0x7B, 0x69, 0x9A, 0x42,
    0x0E, 0xD3, 0xFB, 0x68, 0x5A, 0x68, 0x7B, 0x69, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42, 0x07, 0xD9,
    0xBA, 0x68, 0x7B, 0x69, 0xD3, 0x1A, 0xBB, 0x60, 0x4F, 0xF4, 0x80, 0x53, 0xFB, 0x61, 0x05, 0xE0,
    0x01, 0x23, 0x7B, 0x82, 0x00, 0x23, 0xBB, 0x61, 0x00, 0x23, 0xFB, 0x61, 0xFB, 0x69, 0x5A, 0x1E,
    0xBB, 0x69, 0x13, 0x40, 0x00, 0x2B, 0x49, 0xD0, 0x01, 0x23, 0x7B, 0x82, 0x46, 0xE0, 0x29, 0x4B,
    0x1B, 0x78, 0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0x02, 0xDB, 0x02, 0x23, 0x7B, 0x82, 0x3D, 0xE0,
    0x24, 0x4B, 0x70, 0x22, 0x1A, 0x70, 0x23, 0x4B, 0x09, 0x22, 0xDA, 0x71, 0x21, 0x4A, 0xBB, 0x68,
    0x1B, 0x0C, 0xDB, 0xB2, 0x93, 0x71, 0x1F, 0x4A, 0xBB, 0x68, 0x1B, 0x0A, 0xDB, 0xB2, 0x53, 0x71,
    0x1C, 0x4B, 0xBA, 0x68, 0xD2, 0xB2, 0x1A, 0x71, 0x00, 0x23, 0x7B, 0x82, 0x19, 0x4A, 0x19, 0x4B,
    0x1B, 0x78, 0xDB, 0xB2, 0x63, 0xF0, 0x7F, 0x03, 0xDB, 0xB2, 0x13, 0x70, 0x07, 0xE0, 0xFB, 0x68,
    0x9B, 0x69, 0xB3, 0xF1, 0xFF, 0x3F, 0x02, 0xD0, 0xFB, 0x68, 0x9B, 0x69, 0x98, 0x47, 0x11, 0x4B,
    0x1B, 0x78, 0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0xF1, 0xDA, 0x0E, 0x4B, 0x1B, 0x78, 0xDB, 0xB2,
    0x03, 0xF0, 0x71, 0x03, 0x00, 0x2B, 0x01, 0xD0, 0x01, 0x23, 0x7B, 0x82, 0xBA, 0x69, 0xFB, 0x69,
    0xD3, 0x1A, 0xBB, 0x61, 0xBA, 0x68, 0xFB, 0x69, 0x13, 0x44, 0xBB, 0x60, 0xBB, 0x69, 0x00, 0x2B,
    0x02, 0xD0, 0x7B, 0x8A, 0x00, 0x2B, 0xB2, 0xD0, 0x7B, 0x8A, 0x18, 0x46, 0x20, 0x37, 0xBD, 0x46,
    0x80, 0xBD, 0x00, 0xBF, 0x00, 0x00, 0x02, 0x40, 0x80, 0xB5, 0x86, 0xB0, 0x00, 0xAF, 0xF8, 0x60,
    0xB9, 0x60, 0x11, 0x46, 0x1A, 0x46, 0x0B, 0x46, 0xFB, 0x80, 0x13, 0x46, 0x7B, 0x71, 0x00, 0x23,
    0x7B, 0x82, 0xFB, 0x68, 0x9B, 0x68, 0x7B, 0x61, 0xBA, 0x68, 0x7B, 0x69, 0x9A, 0x42, 0x0D, 0xD3,
    0xFB, 0x68, 0xDA, 0x68, 0x7B, 0x69, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42, 0x06, 0xD9, 0xBA, 0x68,
    0x7B, 0x69, 0xD3, 0x1A, 0x03, 0xF5, 0x00, 0x03, 0xBB, 0x60, 0x14, 0xE0, 0xFB, 0x68, 0x1B, 0x68,
    0x7B, 0x61, 0xBA, 0x68, 0x7B, 0x69, 0x9A, 0x42, 0x0B, 0xD3, 0xFB, 0x68, 0x5A, 0x68, 0x7B, 0x69,
    0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42, 0x04, 0xD9, 0xBA, 0x68, 0x7B, 0x69, 0xD3, 0x1A, 0xBB, 0x60,
    0x01, 0xE0, 0x01, 0x23, 0x7B, 0x82, 0x7B, 0x8A, 0x00, 0x2B, 0x4B, 0xD1, 0x28, 0x4B, 0x1B, 0x78,
    0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0x02, 0xDB, 0x02, 0x23, 0x7B, 0x82, 0x42, 0xE0, 0x24, 0x4B,
    0x70, 0x22, 0x1A, 0x70, 0x22, 0x4B, 0x01, 0x22, 0xDA, 0x71, 0x21, 0x4A, 0xBB, 0x68, 0x1B, 0x0C,
    0xDB, 0xB2, 0x93, 0x71, 0x1E, 0x4A, 0xBB, 0x68, 0x1B, 0x0A, 0xDB, 0xB2, 0x53, 0x71, 0x1C, 0x4B,
    0xBA, 0x68, 0xD2, 0xB2, 0x1A, 0x71, 0x1A, 0x4A, 0xFB, 0x88, 0x1B, 0x0A, 0x9B, 0xB2, 0xDB, 0xB2,
    0xD3, 0x72, 0x17, 0x4B, 0xFA, 0x88, 0xD2, 0xB2, 0x9A, 0x72, 0x15, 0x4A, 0x7B, 0x79, 0x53, 0x72,
    0x00, 0x23, 0x7B, 0x82, 0x12, 0x4A, 0x12, 0x4B, 0x1B, 0x78, 0xDB, 0xB2, 0x63, 0xF0, 0x7F, 0x03,
    0xDB, 0xB2, 0x13, 0x70, 0x07, 0xE0, 0xFB, 0x68, 0x9B, 0x69, 0xB3, 0xF1, 0xFF, 0x3F, 0x02, 0xD0,
    0xFB, 0x68, 0x9B, 0x69, 0x98, 0x47, 0x0A, 0x4B, 0x1B, 0x78, 0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B,
    0xF1, 0xDA, 0x07, 0x4B, 0x1B, 0x78, 0xDB, 0xB2, 0x03, 0xF0, 0x71, 0x03, 0x00, 0x2B, 0x01, 0xD0,
    0x01, 0x23, 0x7B, 0x82, 0x7B, 0x8A, 0x18, 0x46, 0x18, 0x37, 0xBD, 0x46, 0x80, 0xBD, 0x00, 0xBF,
    0x00, 0x00, 0x02, 0x40, 0x80, 0xB5, 0x88, 0xB0, 0x00, 0xAF, 0xF8, 0x60, 0xB9, 0x60, 0x7A, 0x60,
    0x3B, 0x60, 0x00, 0x23, 0xFB, 0x82, 0x7B, 0x68, 0x03, 0xF0, 0x07, 0x03, 0x00, 0x2B, 0x02, 0xD0,
    0x01, 0x23, 0xFB, 0x82, 0x8B, 0xE0, 0xFB, 0x68, 0x9B, 0x68, 0xBB, 0x61, 0xBA, 0x68, 0xBB, 0x69,
    0x9A, 0x42, 0x0D, 0xD3, 0xFB, 0x68, 0xDA, 0x68, 0xBB, 0x69, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42,
    0x06, 0xD9, 0xBA, 0x68, 0xBB, 0x69, 0xD3, 0x1A, 0x03, 0xF5, 0x00, 0x03, 0xBB, 0x60, 0x14, 0xE0,
    0xFB, 0x68, 0x1B, 0x68, 0xBB, 0x61, 0xBA, 0x68, 0xBB, 0x69, 0x9A, 0x42, 0x0B, 0xD3, 0xFB, 0x68,
    0x5A, 0x68, 0xBB, 0x69, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42, 0x04, 0xD9, 0xBA, 0x68, 0xBB, 0x69,
    0xD3, 0x1A, 0xBB, 0x60, 0x01, 0xE0, 0x01, 0x23, 0xFB, 0x82, 0x5A, 0xE0, 0x32, 0x4B, 0x1B, 0x78,
    0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0x02, 0xDB, 0x02, 0x23, 0xFB, 0x82, 0x51, 0xE0, 0x2E, 0x4B,
    0x70, 0x22, 0x1A, 0x70, 0x2C, 0x4B, 0x07, 0x22, 0xDA, 0x71, 0x2B, 0x4A, 0xBB, 0x68, 0x1B, 0x0C,
    0xDB, 0xB2, 0x93, 0x71, 0x28, 0x4A, 0xBB, 0x68, 0x1B, 0x0A, 0xDB, 0xB2, 0x53, 0x71, 0x26, 0x4B,
    0xBA, 0x68, 0xD2, 0xB2, 0x1A, 0x71, 0x00, 0x23, 0xFB, 0x77, 0x0C, 0xE0, 0xFA, 0x7F, 0x23, 0x4B,
    0x13, 0x44, 0xBB, 0x61, 0xBB, 0x69, 0xFA, 0x7F, 0x39, 0x68, 0x0A, 0x44, 0x12, 0x78, 0x1A, 0x70,
    0xFB, 0x7F, 0x01, 0x33, 0xFB, 0x77, 0xFB, 0x7F, 0x07, 0x2B, 0xEF, 0xD9, 0x00, 0x23, 0xFB, 0x82,
    0x19, 0x4A, 0x19, 0x4B, 0x1B, 0x78, 0xDB, 0xB2, 0x63, 0xF0, 0x7F, 0x03, 0xDB, 0xB2, 0x13, 0x70,
    0x07, 0xE0, 0xFB, 0x68, 0x9B, 0x69, 0xB3, 0xF1, 0xFF, 0x3F, 0x02, 0xD0, 0xFB, 0x68, 0x9B, 0x69,
    0x98, 0x47, 0x11, 0x4B, 0x1B, 0x78, 0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0xF1, 0xDA, 0x0E, 0x4B,
    0x1B, 0x78, 0xDB, 0xB2, 0x03, 0xF0, 0x71, 0x03, 0x00, 0x2B, 0x01, 0xD0, 0x01, 0x23, 0xFB, 0x82,
    0xBB, 0x68, 0x08, 0x33, 0xBB, 0x60, 0x7B, 0x68, 0x08, 0x3B, 0x7B, 0x60, 0x3B, 0x68, 0x08, 0x33,
    0x3B, 0x60, 0x7B, 0x68, 0x00, 0x2B, 0x02, 0xD0, 0xFB, 0x8A, 0x00, 0x2B, 0x9E, 0xD0, 0xFB, 0x8A,
    0x18, 0x46, 0x20, 0x37, 0xBD, 0x46, 0x80, 0xBD, 0x00, 0x00, 0x02, 0x40, 0x08, 0x00, 0x02, 0x40,
    0x80, 0xB5, 0x8A, 0xB0, 0x00, 0xAF, 0xF8, 0x60, 0xB9, 0x60, 0x7A, 0x60, 0x3B, 0x60, 0x00, 0x23,
    0xFB, 0x82, 0x7B, 0x68, 0x03, 0xF0, 0x03, 0x03, 0x00, 0x2B, 0x02, 0xD0, 0x01, 0x23, 0xFB, 0x82,
    0xA8, 0xE0, 0x7B, 0x68, 0x3B, 0x62, 0xFB, 0x68, 0x9B, 0x68, 0x7B, 0x62, 0xBA, 0x68, 0x7B, 0x6A,
    0x9A, 0x42, 0x0D, 0xD3, 0xFB, 0x68, 0xDA, 0x68, 0x7B, 0x6A, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42,
    0x06, 0xD9, 0xBA, 0x68, 0x7B, 0x6A, 0xD3, 0x1A, 0x03, 0xF5, 0x00, 0x03, 0xBB, 0x60, 0x16, 0xE0,
    0xFB, 0x68, 0x1B, 0x68, 0x7B, 0x62, 0xBA, 0x68, 0x7B, 0x6A, 0x9A, 0x42, 0x0B, 0xD3, 0xFB, 0x68,
    0x5A, 0x68, 0x7B, 0x6A, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42, 0x04, 0xD9, 0xBA, 0x68, 0x7B, 0x6A,
    0xD3, 0x1A, 0xBB, 0x60, 0x03, 0xE0, 0x01, 0x23, 0xFB, 0x82, 0x00, 0x23, 0x3B, 0x62, 0x73, 0xE0,
    0x3F, 0x4B, 0x1B, 0x78, 0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0x02, 0xDB, 0x02, 0x23, 0xFB, 0x82,
    0x6A, 0xE0, 0x3B, 0x4B, 0x70, 0x22, 0x1A, 0x70, 0x39, 0x4B, 0x02, 0x22, 0xDA, 0x71, 0x38, 0x4A,
    0xBB, 0x68, 0x1B, 0x0C, 0xDB, 0xB2, 0x93, 0x71, 0x35, 0x4A, 0xBB, 0x68, 0x1B, 0x0A, 0xDB, 0xB2,
    0x53, 0x71, 0x33, 0x4B, 0xBA, 0x68, 0xD2, 0xB2, 0x1A, 0x71, 0x31, 0x4A, 0x97, 0xF8, 0x34, 0x30,
    0xD3, 0x72, 0x00, 0x23, 0xFB, 0x77, 0x0C, 0xE0, 0xFA, 0x7F, 0x2E, 0x4B, 0x13, 0x44, 0xBB, 0x61,
    0xBB, 0x69, 0xFA, 0x7F, 0x39, 0x68, 0x0A, 0x44, 0x12, 0x78, 0x1A, 0x70, 0xFB, 0x7F, 0x01, 0x33,
    0xFB, 0x77, 0xFB, 0x7F, 0x03, 0x2B, 0xEF, 0xD9, 0x00, 0x23, 0xFB, 0x82, 0x24, 0x4A, 0x24, 0x4B,
    0x1B, 0x78, 0xDB, 0xB2, 0x63, 0xF0, 0x7F, 0x03, 0xDB, 0xB2, 0x13, 0x70, 0x07, 0xE0, 0xFB, 0x68,
    0x9B, 0x69, 0xB3, 0xF1, 0xFF, 0x3F, 0x02, 0xD0, 0xFB, 0x68, 0x9B, 0x69, 0x98, 0x47, 0x1C, 0x4B,
    0x1B, 0x78, 0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0xF1, 0xDA, 0x19, 0x4B, 0x1B, 0x78, 0xDB, 0xB2,
    0x03, 0xF0, 0x71, 0x03, 0x00, 0x2B, 0x01, 0xD0, 0x01, 0x23, 0xFB, 0x82, 0xFB, 0x8A, 0x00, 0x2B,
    0x11, 0xD0, 0xBB, 0x68, 0xB3, 0xF5, 0x00, 0x0F, 0x07, 0xD3, 0xBA, 0x68, 0x7B, 0x6A, 0x13, 0x44,
    0xA3, 0xF5, 0x00, 0x02, 0x3B, 0x6B, 0x1A, 0x60, 0x0E, 0xE0, 0xBA, 0x68, 0x7B, 0x6A, 0x1A, 0x44,
    0x3B, 0x6B, 0x1A, 0x60, 0x08, 0xE0, 0x3B, 0x6A, 0x04, 0x3B, 0x3B, 0x62, 0x3B, 0x68, 0x04, 0x33,
    0x3B, 0x60, 0xBB, 0x68, 0x04, 0x33, 0xBB, 0x60, 0x3B, 0x6A, 0x00, 0x2B, 0x02, 0xD0, 0xFB, 0x8A,
    0x00, 0x2B, 0x85, 0xD0, 0xFB, 0x8A, 0x18, 0x46, 0x28, 0x37, 0xBD, 0x46, 0x80, 0xBD, 0x00, 0xBF,
    0x00, 0x00, 0x02, 0x40, 0x0C, 0x00, 0x02, 0x40
};

结构体数组 gs_FlashDriverAPI 的内部成员变量(这里都是函数指针)的排列顺序需要与 Bootloader 工程内的数组一一对应,并且该数组后面跟了 NVM_DRIVER_SECTION ,会将此数组放在 m_NVM_Driver 区域内,另外,因为次数组会和 Flash 操作函数一起放到 m_NVM_Driver 区域内,所以必须保证本数组放在那些函数的前面,这我在 README.md 当中也有截图说明。

/* TODO S32K_FlashDrv: #02 本偏移量需与 .ld 链接文件中的 m_NVM_Driver 起始地址保持一致 */
#define FLASH_DRV_OFFSET    (0x10000u)
#define CAL_OFFSET(funcPtr) ((uint32_t)(funcPtr) - FLASH_DRV_OFFSET)

CAL_OFFSET 这个宏是用于计算相对地址偏移量的,在这里,会将对应函数的地址减去 0x10000 后作为各函数指针的初值存储于数组内。为何要减去 0x10000 ?,因为 Flash Driver 最终是加载到 Bootloader 中预留的 RAM 空间地址运行的,起始地址不一样,所以 Flash Driver UDS_S32K144_FlashDriverExtracted.hex 在下载到 Bootloader 的 RAM 0x1FFF8000 处之后,需要将开头的 4 个 32位地址偏移量分别再加上 0x1FFF8000,这样,就得到了 4 个函数在 Bootloader 的 RAM 中的真实地址,之后,就可以在 Bootloader 中通过函数指针的方式进行调用。相关计算函数位于 Bootloader 的 flash.c,函数名:void InitFlashAPI(void),在此我也贴出该函数内容:

/* Init falsh g_stFlashOptInfo pointer */
void InitFlashAPI(void)
{
    //caculate offset
    uint32_t *tmp = NULL;
    uint32_t flashDriverStartAdd = 0;
    uint32_t flashDriverEndAdd = 0;

    FLASH_HAL_GetFlashDriverInfo(&flashDriverStartAdd, &flashDriverEndAdd);
    tmp = (uint32 *)flashDriverStartAdd;

    for (uint32_t i = 0; i < sizeof(tFlashOptInfo) / 4; i++) {
        /* XXX Bootloader: #01 此处 tmp[i] 用来给 Flash Driver 头部的函数偏移量偏移到目前 Bootloader 中实际的 RAM 地址
         * 官方 Bootloader 例程配合官方编译好的 12 个 Flash Driver 函数,为何要减去(向左偏移) 0x410 原因不明,
         * 自己编译出的 4 个 Flash Driver 函数不需要减 0x410
         */
        //        tmp[i] -= 0x410;
        tmp[i] += (uint32_t) flashDriverStartAdd;
    }

    g_pstFlashOptInfo = (tFlashOptInfo *)flashDriverStartAdd;

    /* Disable cache to ensure that all flash operations will take effect instantly,
       this is device dependent */
#ifdef S32K144_SERIES
    //  MSCM->OCMDR[0u] |= MSCM_OCMDR_OCM1(0xFu);
    //  MSCM->OCMDR[1u] |= MSCM_OCMDR_OCM1(0xFu);
    //  MSCM->OCMDR[2u] |= MSCM_OCMDR_OCM1(0xFu);
#endif /* S32K144_SERIES */
}

从以上数组可以看到 4 个函数的相对偏移量:

0x11, 0x00, 0x00, 0x00, 0x49, 0x01, 0x00, 0x00, 0x65, 0x02, 0x00, 0x00, 0xB1, 0x03, 0x00, 0x00,

// 对应的函数相对偏移量为:
// FLASH_DRV_EraseSector          0x00000011
// FLASH_DRV_VerifySection        0x00000149
// FLASH_DRV_Program              0x00000265
// FLASH_DRV_ProgramCheck         0x000003B1

在 Bootloader 中经过计算,该部分内容会变成:

0x11, 0x80, 0xFF, 0x1F, 0x49, 0x81, 0xFF, 0x1F, 0x65, 0x82, 0xFF, 0x1F, 0xB1, 0x83, 0xFF, 0x1F,

// 对应的函数相对偏移量为:
// FLASH_DRV_EraseSector          0x1FFF8011
// FLASH_DRV_VerifySection        0x1FFF8149
// FLASH_DRV_Program              0x1FFF8265
// FLASH_DRV_ProgramCheck         0x1FFF83B1

即,最后,存储于 Bootloader RAM 中 0x1FFF8000 处的数据变成了如下情况:

uint8_t g_flashDriverRAM[] = {
    0x11, 0x80, 0xFF, 0x1F, 0x49, 0x81, 0xFF, 0x1F, 0x65, 0x82, 0xFF, 0x1F, 0xB1, 0x83, 0xFF, 0x1F,
    0x80, 0xB5, 0x88, 0xB0, 0x00, 0xAF, 0xF8, 0x60, 0xB9, 0x60, 0x7A, 0x60, 0x00, 0x23, 0x7B, 0x82,
    0x7B, 0x68, 0xBB, 0x61, 0xFB, 0x68, 0x9B, 0x68, 0x7B, 0x61, 0xBA, 0x68, 0x7B, 0x69, 0x9A, 0x42,
    0x10, 0xD3, 0xFB, 0x68, 0xDA, 0x68, 0x7B, 0x69, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42, 0x09, 0xD9,
    0xBA, 0x68, 0x7B, 0x69, 0xD3, 0x1A, 0x03, 0xF5, 0x00, 0x03, 0xBB, 0x60, 0x4F, 0xF4, 0x00, 0x63,
    0xFB, 0x61, 0x1B, 0xE0, 0xFB, 0x68, 0x1B, 0x68, 0x7B, 0x61, 0xBA, 0x68, 0x7B, 0x69, 0x9A, 0x42,
    0x0E, 0xD3, 0xFB, 0x68, 0x5A, 0x68, 0x7B, 0x69, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42, 0x07, 0xD9,
    0xBA, 0x68, 0x7B, 0x69, 0xD3, 0x1A, 0xBB, 0x60, 0x4F, 0xF4, 0x80, 0x53, 0xFB, 0x61, 0x05, 0xE0,
    0x01, 0x23, 0x7B, 0x82, 0x00, 0x23, 0xBB, 0x61, 0x00, 0x23, 0xFB, 0x61, 0xFB, 0x69, 0x5A, 0x1E,
    0xBB, 0x69, 0x13, 0x40, 0x00, 0x2B, 0x49, 0xD0, 0x01, 0x23, 0x7B, 0x82, 0x46, 0xE0, 0x29, 0x4B,
    0x1B, 0x78, 0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0x02, 0xDB, 0x02, 0x23, 0x7B, 0x82, 0x3D, 0xE0,
    0x24, 0x4B, 0x70, 0x22, 0x1A, 0x70, 0x23, 0x4B, 0x09, 0x22, 0xDA, 0x71, 0x21, 0x4A, 0xBB, 0x68,
    0x1B, 0x0C, 0xDB, 0xB2, 0x93, 0x71, 0x1F, 0x4A, 0xBB, 0x68, 0x1B, 0x0A, 0xDB, 0xB2, 0x53, 0x71,
    0x1C, 0x4B, 0xBA, 0x68, 0xD2, 0xB2, 0x1A, 0x71, 0x00, 0x23, 0x7B, 0x82, 0x19, 0x4A, 0x19, 0x4B,
    0x1B, 0x78, 0xDB, 0xB2, 0x63, 0xF0, 0x7F, 0x03, 0xDB, 0xB2, 0x13, 0x70, 0x07, 0xE0, 0xFB, 0x68,
    0x9B, 0x69, 0xB3, 0xF1, 0xFF, 0x3F, 0x02, 0xD0, 0xFB, 0x68, 0x9B, 0x69, 0x98, 0x47, 0x11, 0x4B,
    0x1B, 0x78, 0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0xF1, 0xDA, 0x0E, 0x4B, 0x1B, 0x78, 0xDB, 0xB2,
    0x03, 0xF0, 0x71, 0x03, 0x00, 0x2B, 0x01, 0xD0, 0x01, 0x23, 0x7B, 0x82, 0xBA, 0x69, 0xFB, 0x69,
    0xD3, 0x1A, 0xBB, 0x61, 0xBA, 0x68, 0xFB, 0x69, 0x13, 0x44, 0xBB, 0x60, 0xBB, 0x69, 0x00, 0x2B,
    0x02, 0xD0, 0x7B, 0x8A, 0x00, 0x2B, 0xB2, 0xD0, 0x7B, 0x8A, 0x18, 0x46, 0x20, 0x37, 0xBD, 0x46,
    0x80, 0xBD, 0x00, 0xBF, 0x00, 0x00, 0x02, 0x40, 0x80, 0xB5, 0x86, 0xB0, 0x00, 0xAF, 0xF8, 0x60,
    0xB9, 0x60, 0x11, 0x46, 0x1A, 0x46, 0x0B, 0x46, 0xFB, 0x80, 0x13, 0x46, 0x7B, 0x71, 0x00, 0x23,
    0x7B, 0x82, 0xFB, 0x68, 0x9B, 0x68, 0x7B, 0x61, 0xBA, 0x68, 0x7B, 0x69, 0x9A, 0x42, 0x0D, 0xD3,
    0xFB, 0x68, 0xDA, 0x68, 0x7B, 0x69, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42, 0x06, 0xD9, 0xBA, 0x68,
    0x7B, 0x69, 0xD3, 0x1A, 0x03, 0xF5, 0x00, 0x03, 0xBB, 0x60, 0x14, 0xE0, 0xFB, 0x68, 0x1B, 0x68,
    0x7B, 0x61, 0xBA, 0x68, 0x7B, 0x69, 0x9A, 0x42, 0x0B, 0xD3, 0xFB, 0x68, 0x5A, 0x68, 0x7B, 0x69,
    0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42, 0x04, 0xD9, 0xBA, 0x68, 0x7B, 0x69, 0xD3, 0x1A, 0xBB, 0x60,
    0x01, 0xE0, 0x01, 0x23, 0x7B, 0x82, 0x7B, 0x8A, 0x00, 0x2B, 0x4B, 0xD1, 0x28, 0x4B, 0x1B, 0x78,
    0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0x02, 0xDB, 0x02, 0x23, 0x7B, 0x82, 0x42, 0xE0, 0x24, 0x4B,
    0x70, 0x22, 0x1A, 0x70, 0x22, 0x4B, 0x01, 0x22, 0xDA, 0x71, 0x21, 0x4A, 0xBB, 0x68, 0x1B, 0x0C,
    0xDB, 0xB2, 0x93, 0x71, 0x1E, 0x4A, 0xBB, 0x68, 0x1B, 0x0A, 0xDB, 0xB2, 0x53, 0x71, 0x1C, 0x4B,
    0xBA, 0x68, 0xD2, 0xB2, 0x1A, 0x71, 0x1A, 0x4A, 0xFB, 0x88, 0x1B, 0x0A, 0x9B, 0xB2, 0xDB, 0xB2,
    0xD3, 0x72, 0x17, 0x4B, 0xFA, 0x88, 0xD2, 0xB2, 0x9A, 0x72, 0x15, 0x4A, 0x7B, 0x79, 0x53, 0x72,
    0x00, 0x23, 0x7B, 0x82, 0x12, 0x4A, 0x12, 0x4B, 0x1B, 0x78, 0xDB, 0xB2, 0x63, 0xF0, 0x7F, 0x03,
    0xDB, 0xB2, 0x13, 0x70, 0x07, 0xE0, 0xFB, 0x68, 0x9B, 0x69, 0xB3, 0xF1, 0xFF, 0x3F, 0x02, 0xD0,
    0xFB, 0x68, 0x9B, 0x69, 0x98, 0x47, 0x0A, 0x4B, 0x1B, 0x78, 0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B,
    0xF1, 0xDA, 0x07, 0x4B, 0x1B, 0x78, 0xDB, 0xB2, 0x03, 0xF0, 0x71, 0x03, 0x00, 0x2B, 0x01, 0xD0,
    0x01, 0x23, 0x7B, 0x82, 0x7B, 0x8A, 0x18, 0x46, 0x18, 0x37, 0xBD, 0x46, 0x80, 0xBD, 0x00, 0xBF,
    0x00, 0x00, 0x02, 0x40, 0x80, 0xB5, 0x88, 0xB0, 0x00, 0xAF, 0xF8, 0x60, 0xB9, 0x60, 0x7A, 0x60,
    0x3B, 0x60, 0x00, 0x23, 0xFB, 0x82, 0x7B, 0x68, 0x03, 0xF0, 0x07, 0x03, 0x00, 0x2B, 0x02, 0xD0,
    0x01, 0x23, 0xFB, 0x82, 0x8B, 0xE0, 0xFB, 0x68, 0x9B, 0x68, 0xBB, 0x61, 0xBA, 0x68, 0xBB, 0x69,
    0x9A, 0x42, 0x0D, 0xD3, 0xFB, 0x68, 0xDA, 0x68, 0xBB, 0x69, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42,
    0x06, 0xD9, 0xBA, 0x68, 0xBB, 0x69, 0xD3, 0x1A, 0x03, 0xF5, 0x00, 0x03, 0xBB, 0x60, 0x14, 0xE0,
    0xFB, 0x68, 0x1B, 0x68, 0xBB, 0x61, 0xBA, 0x68, 0xBB, 0x69, 0x9A, 0x42, 0x0B, 0xD3, 0xFB, 0x68,
    0x5A, 0x68, 0xBB, 0x69, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42, 0x04, 0xD9, 0xBA, 0x68, 0xBB, 0x69,
    0xD3, 0x1A, 0xBB, 0x60, 0x01, 0xE0, 0x01, 0x23, 0xFB, 0x82, 0x5A, 0xE0, 0x32, 0x4B, 0x1B, 0x78,
    0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0x02, 0xDB, 0x02, 0x23, 0xFB, 0x82, 0x51, 0xE0, 0x2E, 0x4B,
    0x70, 0x22, 0x1A, 0x70, 0x2C, 0x4B, 0x07, 0x22, 0xDA, 0x71, 0x2B, 0x4A, 0xBB, 0x68, 0x1B, 0x0C,
    0xDB, 0xB2, 0x93, 0x71, 0x28, 0x4A, 0xBB, 0x68, 0x1B, 0x0A, 0xDB, 0xB2, 0x53, 0x71, 0x26, 0x4B,
    0xBA, 0x68, 0xD2, 0xB2, 0x1A, 0x71, 0x00, 0x23, 0xFB, 0x77, 0x0C, 0xE0, 0xFA, 0x7F, 0x23, 0x4B,
    0x13, 0x44, 0xBB, 0x61, 0xBB, 0x69, 0xFA, 0x7F, 0x39, 0x68, 0x0A, 0x44, 0x12, 0x78, 0x1A, 0x70,
    0xFB, 0x7F, 0x01, 0x33, 0xFB, 0x77, 0xFB, 0x7F, 0x07, 0x2B, 0xEF, 0xD9, 0x00, 0x23, 0xFB, 0x82,
    0x19, 0x4A, 0x19, 0x4B, 0x1B, 0x78, 0xDB, 0xB2, 0x63, 0xF0, 0x7F, 0x03, 0xDB, 0xB2, 0x13, 0x70,
    0x07, 0xE0, 0xFB, 0x68, 0x9B, 0x69, 0xB3, 0xF1, 0xFF, 0x3F, 0x02, 0xD0, 0xFB, 0x68, 0x9B, 0x69,
    0x98, 0x47, 0x11, 0x4B, 0x1B, 0x78, 0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0xF1, 0xDA, 0x0E, 0x4B,
    0x1B, 0x78, 0xDB, 0xB2, 0x03, 0xF0, 0x71, 0x03, 0x00, 0x2B, 0x01, 0xD0, 0x01, 0x23, 0xFB, 0x82,
    0xBB, 0x68, 0x08, 0x33, 0xBB, 0x60, 0x7B, 0x68, 0x08, 0x3B, 0x7B, 0x60, 0x3B, 0x68, 0x08, 0x33,
    0x3B, 0x60, 0x7B, 0x68, 0x00, 0x2B, 0x02, 0xD0, 0xFB, 0x8A, 0x00, 0x2B, 0x9E, 0xD0, 0xFB, 0x8A,
    0x18, 0x46, 0x20, 0x37, 0xBD, 0x46, 0x80, 0xBD, 0x00, 0x00, 0x02, 0x40, 0x08, 0x00, 0x02, 0x40,
    0x80, 0xB5, 0x8A, 0xB0, 0x00, 0xAF, 0xF8, 0x60, 0xB9, 0x60, 0x7A, 0x60, 0x3B, 0x60, 0x00, 0x23,
    0xFB, 0x82, 0x7B, 0x68, 0x03, 0xF0, 0x03, 0x03, 0x00, 0x2B, 0x02, 0xD0, 0x01, 0x23, 0xFB, 0x82,
    0xA8, 0xE0, 0x7B, 0x68, 0x3B, 0x62, 0xFB, 0x68, 0x9B, 0x68, 0x7B, 0x62, 0xBA, 0x68, 0x7B, 0x6A,
    0x9A, 0x42, 0x0D, 0xD3, 0xFB, 0x68, 0xDA, 0x68, 0x7B, 0x6A, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42,
    0x06, 0xD9, 0xBA, 0x68, 0x7B, 0x6A, 0xD3, 0x1A, 0x03, 0xF5, 0x00, 0x03, 0xBB, 0x60, 0x16, 0xE0,
    0xFB, 0x68, 0x1B, 0x68, 0x7B, 0x62, 0xBA, 0x68, 0x7B, 0x6A, 0x9A, 0x42, 0x0B, 0xD3, 0xFB, 0x68,
    0x5A, 0x68, 0x7B, 0x6A, 0x1A, 0x44, 0xBB, 0x68, 0x9A, 0x42, 0x04, 0xD9, 0xBA, 0x68, 0x7B, 0x6A,
    0xD3, 0x1A, 0xBB, 0x60, 0x03, 0xE0, 0x01, 0x23, 0xFB, 0x82, 0x00, 0x23, 0x3B, 0x62, 0x73, 0xE0,
    0x3F, 0x4B, 0x1B, 0x78, 0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0x02, 0xDB, 0x02, 0x23, 0xFB, 0x82,
    0x6A, 0xE0, 0x3B, 0x4B, 0x70, 0x22, 0x1A, 0x70, 0x39, 0x4B, 0x02, 0x22, 0xDA, 0x71, 0x38, 0x4A,
    0xBB, 0x68, 0x1B, 0x0C, 0xDB, 0xB2, 0x93, 0x71, 0x35, 0x4A, 0xBB, 0x68, 0x1B, 0x0A, 0xDB, 0xB2,
    0x53, 0x71, 0x33, 0x4B, 0xBA, 0x68, 0xD2, 0xB2, 0x1A, 0x71, 0x31, 0x4A, 0x97, 0xF8, 0x34, 0x30,
    0xD3, 0x72, 0x00, 0x23, 0xFB, 0x77, 0x0C, 0xE0, 0xFA, 0x7F, 0x2E, 0x4B, 0x13, 0x44, 0xBB, 0x61,
    0xBB, 0x69, 0xFA, 0x7F, 0x39, 0x68, 0x0A, 0x44, 0x12, 0x78, 0x1A, 0x70, 0xFB, 0x7F, 0x01, 0x33,
    0xFB, 0x77, 0xFB, 0x7F, 0x03, 0x2B, 0xEF, 0xD9, 0x00, 0x23, 0xFB, 0x82, 0x24, 0x4A, 0x24, 0x4B,
    0x1B, 0x78, 0xDB, 0xB2, 0x63, 0xF0, 0x7F, 0x03, 0xDB, 0xB2, 0x13, 0x70, 0x07, 0xE0, 0xFB, 0x68,
    0x9B, 0x69, 0xB3, 0xF1, 0xFF, 0x3F, 0x02, 0xD0, 0xFB, 0x68, 0x9B, 0x69, 0x98, 0x47, 0x1C, 0x4B,
    0x1B, 0x78, 0xDB, 0xB2, 0x5B, 0xB2, 0x00, 0x2B, 0xF1, 0xDA, 0x19, 0x4B, 0x1B, 0x78, 0xDB, 0xB2,
    0x03, 0xF0, 0x71, 0x03, 0x00, 0x2B, 0x01, 0xD0, 0x01, 0x23, 0xFB, 0x82, 0xFB, 0x8A, 0x00, 0x2B,
    0x11, 0xD0, 0xBB, 0x68, 0xB3, 0xF5, 0x00, 0x0F, 0x07, 0xD3, 0xBA, 0x68, 0x7B, 0x6A, 0x13, 0x44,
    0xA3, 0xF5, 0x00, 0x02, 0x3B, 0x6B, 0x1A, 0x60, 0x0E, 0xE0, 0xBA, 0x68, 0x7B, 0x6A, 0x1A, 0x44,
    0x3B, 0x6B, 0x1A, 0x60, 0x08, 0xE0, 0x3B, 0x6A, 0x04, 0x3B, 0x3B, 0x62, 0x3B, 0x68, 0x04, 0x33,
    0x3B, 0x60, 0xBB, 0x68, 0x04, 0x33, 0xBB, 0x60, 0x3B, 0x6A, 0x00, 0x2B, 0x02, 0xD0, 0xFB, 0x8A,
    0x00, 0x2B, 0x85, 0xD0, 0xFB, 0x8A, 0x18, 0x46, 0x28, 0x37, 0xBD, 0x46, 0x80, 0xBD, 0x00, 0xBF,
    0x00, 0x00, 0x02, 0x40, 0x0C, 0x00, 0x02, 0x40
};

另外,本工程的 flash_driver.h 和 flash_driver.c 是进行了更改的,请自行观察。

flash_driver.h
flash_driver.c

另外,flash_driver.h 中的宏开关可用于验证本工程的 Flash Driver 操作函数是否有效、工作正常。

#define EN_FLASH_DRIVER_DEBUG

除了你的问题,也有其它人提出了与 Flash Driver 相关的 Issue,位于另一个工程,我在此引用过来,如有需要,可以查看了解:

Flash的操作函数 #1 @zangege @wwwying9

@SummerFalls SummerFalls pinned this issue May 9, 2021
@SummerFalls SummerFalls self-assigned this May 9, 2021
@SummerFalls SummerFalls added good first issue Good for newcomers question Further information is requested labels May 9, 2021
@zangege
Copy link
Author

zangege commented May 11, 2021

大概明白了,我自己再理一下,谢谢大佬!

@zangege zangege closed this as completed May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants