本文主要是介绍nrf5340之pm_static.yml文件分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
pm_static.yml文件内容举例:
app:address: 0xc200 region: flash_primarysize: 0xE8E00
external_flash:address: 0region: external_flashsize: 0xF17000
mcuboot:address: 0x0 placement:before:- mcuboot_primaryregion: flash_primarysize: 0xc000
mcuboot_pad:address: 0xc000size: 0x200
mcuboot_primary:address: 0xc000orig_span: &id001 - mcuboot_pad- appregion: flash_primarysize: 0xE9000span: *id001
mcuboot_primary_app:address: 0xc200orig_span: &id002- appregion: flash_primarysize: 0xE8E00span: *id002
mcuboot_secondary:address: 0xF17000device: MX25R64region: external_flashsize: 0xE9000
otp:address: 0xff8100end_address: 0xff83fcregion: otpsize: 0x2fc
pcd_sram:address: 0x2007e000end_address: 0x20080000placement:before:- endregion: sram_primarysize: 0x2000
sram_primary:address: 0x20000000end_address: 0x2007e000region: sram_primarysize: 0x7e000
app_pad:address: 0xF5000region: flash_primarysize: 0x1000
settings_storage:address: 0xF6000end_address: 0xFF000region: flash_primarysize: 0x9000
cywee:address: 0xff000end_address: 0x100000region: flash_primaryplacement:before:- end size: 0x1000
该文件经过python处理之后变成了build_nrf5340dk_nrf5340_cpuapp\zephyr\include\generated目录下面的pm_config.h 文件
pm_config.h文件内容如下:
/* File generated by E:/aw32001/NordicNCS/v1.5.1-dev/nrf/scripts/partition_manager_output.py, do not modify */
#ifndef PM_CONFIG_H__
#define PM_CONFIG_H__
#define PM_EXTERNAL_FLASH_ADDRESS 0x0
#define PM_EXTERNAL_FLASH_END_ADDRESS 0xf17000
#define PM_EXTERNAL_FLASH_SIZE 0xf17000
#define PM_EXTERNAL_FLASH_NAME external_flash
#define PM_EXTERNAL_FLASH_ID 0
#define PM_external_flash_ID PM_EXTERNAL_FLASH_ID
#define PM_external_flash_IS_ENABLED 1
#define PM_0_LABEL EXTERNAL_FLASH
#define PM_EXTERNAL_FLASH_DEV_NAME "MX25R64"
#define PM_MCUBOOT_ADDRESS 0x0
#define PM_MCUBOOT_END_ADDRESS 0xc000
#define PM_MCUBOOT_SIZE 0xc000
#define PM_MCUBOOT_NAME mcuboot
#define PM_MCUBOOT_ID 1
#define PM_mcuboot_ID PM_MCUBOOT_ID
#define PM_mcuboot_IS_ENABLED 1
#define PM_1_LABEL MCUBOOT
#define PM_MCUBOOT_DEV_NAME "NRF_FLASH_DRV_NAME"
#define PM_MCUBOOT_PAD_ADDRESS 0xc000
#define PM_MCUBOOT_PAD_END_ADDRESS 0xc200
#define PM_MCUBOOT_PAD_SIZE 0x200
#define PM_MCUBOOT_PAD_NAME mcuboot_pad
#define PM_MCUBOOT_PAD_ID 2
#define PM_mcuboot_pad_ID PM_MCUBOOT_PAD_ID
#define PM_mcuboot_pad_IS_ENABLED 1
#define PM_2_LABEL MCUBOOT_PAD
#define PM_MCUBOOT_PAD_DEV_NAME "NRF_FLASH_DRV_NAME"
#define PM_MCUBOOT_PRIMARY_ADDRESS 0xc000
#define PM_MCUBOOT_PRIMARY_END_ADDRESS 0xf5000
#define PM_MCUBOOT_PRIMARY_SIZE 0xe9000
#define PM_MCUBOOT_PRIMARY_NAME mcuboot_primary
#define PM_MCUBOOT_PRIMARY_ID 3
#define PM_mcuboot_primary_ID PM_MCUBOOT_PRIMARY_ID
#define PM_mcuboot_primary_IS_ENABLED 1
#define PM_3_LABEL MCUBOOT_PRIMARY
#define PM_MCUBOOT_PRIMARY_DEV_NAME "NRF_FLASH_DRV_NAME"
#define PM_APP_ADDRESS 0xc200
#define PM_APP_END_ADDRESS 0xf5000
#define PM_APP_SIZE 0xe8e00
#define PM_APP_NAME app
#define PM_APP_ID 4
#define PM_app_ID PM_APP_ID
#define PM_app_IS_ENABLED 1
#define PM_4_LABEL APP
#define PM_APP_DEV_NAME "NRF_FLASH_DRV_NAME"
#define PM_MCUBOOT_PRIMARY_APP_ADDRESS 0xc200
#define PM_MCUBOOT_PRIMARY_APP_END_ADDRESS 0xf5000
#define PM_MCUBOOT_PRIMARY_APP_SIZE 0xe8e00
#define PM_MCUBOOT_PRIMARY_APP_NAME mcuboot_primary_app
#define PM_MCUBOOT_PRIMARY_APP_ID 5
#define PM_mcuboot_primary_app_ID PM_MCUBOOT_PRIMARY_APP_ID
#define PM_mcuboot_primary_app_IS_ENABLED 1
#define PM_5_LABEL MCUBOOT_PRIMARY_APP
#define PM_MCUBOOT_PRIMARY_APP_DEV_NAME "NRF_FLASH_DRV_NAME"
#define PM_APP_PAD_ADDRESS 0xf5000
#define PM_APP_PAD_END_ADDRESS 0xf6000
#define PM_APP_PAD_SIZE 0x1000
#define PM_APP_PAD_NAME app_pad
#define PM_APP_PAD_ID 6
#define PM_app_pad_ID PM_APP_PAD_ID
#define PM_app_pad_IS_ENABLED 1
#define PM_6_LABEL APP_PAD
#define PM_APP_PAD_DEV_NAME "NRF_FLASH_DRV_NAME"
#define PM_SETTINGS_STORAGE_ADDRESS 0xf6000
#define PM_SETTINGS_STORAGE_END_ADDRESS 0xff000
#define PM_SETTINGS_STORAGE_SIZE 0x9000
#define PM_SETTINGS_STORAGE_NAME settings_storage
#define PM_SETTINGS_STORAGE_ID 7
#define PM_settings_storage_ID PM_SETTINGS_STORAGE_ID
#define PM_settings_storage_IS_ENABLED 1
#define PM_7_LABEL SETTINGS_STORAGE
#define PM_SETTINGS_STORAGE_DEV_NAME "NRF_FLASH_DRV_NAME"
#define PM_CYWEE_ADDRESS 0xff000
#define PM_CYWEE_END_ADDRESS 0x100000
#define PM_CYWEE_SIZE 0x1000
#define PM_CYWEE_NAME cywee
#define PM_CYWEE_ID 8
#define PM_cywee_ID PM_CYWEE_ID
#define PM_cywee_IS_ENABLED 1
#define PM_8_LABEL CYWEE
#define PM_CYWEE_DEV_NAME "NRF_FLASH_DRV_NAME"
#define PM_MCUBOOT_SECONDARY_ADDRESS 0xf17000
#define PM_MCUBOOT_SECONDARY_END_ADDRESS 0x1000000
#define PM_MCUBOOT_SECONDARY_SIZE 0xe9000
#define PM_MCUBOOT_SECONDARY_NAME mcuboot_secondary
#define PM_MCUBOOT_SECONDARY_ID 9
#define PM_mcuboot_secondary_ID PM_MCUBOOT_SECONDARY_ID
#define PM_mcuboot_secondary_IS_ENABLED 1
#define PM_9_LABEL MCUBOOT_SECONDARY
#define PM_MCUBOOT_SECONDARY_DEV_NAME "MX25R64"
#define PM_OTP_ADDRESS 0xff8100
#define PM_OTP_END_ADDRESS 0xff83fc
#define PM_OTP_SIZE 0x2fc
#define PM_OTP_NAME otp
#define PM_SRAM_PRIMARY_ADDRESS 0x20000000
#define PM_SRAM_PRIMARY_END_ADDRESS 0x2007e000
#define PM_SRAM_PRIMARY_SIZE 0x7e000
#define PM_SRAM_PRIMARY_NAME sram_primary
#define PM_PCD_SRAM_ADDRESS 0x2007e000
#define PM_PCD_SRAM_END_ADDRESS 0x20080000
#define PM_PCD_SRAM_SIZE 0x2000
#define PM_PCD_SRAM_NAME pcd_sram
#define PM_NUM 10
#define PM_ALL_BY_SIZE "mcuboot_pad otp app_pad cywee pcd_sram settings_storage mcuboot sram_primary app mcuboot_primary_app mcuboot_secondary mcuboot_primary external_flash"
#define PM_CPUNET_B0N_ADDRESS 0x1000000
#define PM_CPUNET_B0N_END_ADDRESS 0x1008600
#define PM_CPUNET_B0N_SIZE 0x8600
#define PM_CPUNET_B0N_NAME b0n
#define PM_CPUNET_B0N_ID 10
#define PM_CPUNET_b0n_ID PM_B0N_ID
#define PM_CPUNET_b0n_IS_ENABLED 1
#define PM_10_LABEL CPUNET_B0N
#define PM_CPUNET_B0N_DEV_NAME "NRF_FLASH_DRV_NAME"
#define PM_CPUNET_B0N_CONTAINER_ADDRESS 0x1000000
#define PM_CPUNET_B0N_CONTAINER_END_ADDRESS 0x1008800
#define PM_CPUNET_B0N_CONTAINER_SIZE 0x8800
#define PM_CPUNET_B0N_CONTAINER_NAME b0n_container
#define PM_CPUNET_B0N_CONTAINER_ID 11
#define PM_CPUNET_b0n_container_ID PM_B0N_CONTAINER_ID
#define PM_CPUNET_b0n_container_IS_ENABLED 1
#define PM_11_LABEL CPUNET_B0N_CONTAINER
#define PM_CPUNET_B0N_CONTAINER_DEV_NAME "NRF_FLASH_DRV_NAME"
#define PM_CPUNET_PROVISION_ADDRESS 0x1008600
#define PM_CPUNET_PROVISION_END_ADDRESS 0x1008800
#define PM_CPUNET_PROVISION_SIZE 0x200
#define PM_CPUNET_PROVISION_NAME provision
#define PM_CPUNET_PROVISION_ID 12
#define PM_CPUNET_provision_ID PM_PROVISION_ID
#define PM_CPUNET_provision_IS_ENABLED 1
#define PM_12_LABEL CPUNET_PROVISION
#define PM_CPUNET_PROVISION_DEV_NAME "NRF_FLASH_DRV_NAME"
#define PM_CPUNET_APP_ADDRESS 0x1008800
#define PM_CPUNET_APP_END_ADDRESS 0x1040000
#define PM_CPUNET_APP_SIZE 0x37800
#define PM_CPUNET_APP_NAME app
#define PM_CPUNET_APP_ID 13
#define PM_CPUNET_app_ID PM_APP_ID
#define PM_CPUNET_app_IS_ENABLED 1
#define PM_13_LABEL CPUNET_APP
#define PM_CPUNET_APP_DEV_NAME "NRF_FLASH_DRV_NAME"
#define PM_CPUNET_HCI_RPMSG_ADDRESS 0x1008800
#define PM_CPUNET_HCI_RPMSG_END_ADDRESS 0x1040000
#define PM_CPUNET_HCI_RPMSG_SIZE 0x37800
#define PM_CPUNET_HCI_RPMSG_NAME hci_rpmsg
#define PM_CPUNET_HCI_RPMSG_ID 14
#define PM_CPUNET_hci_rpmsg_ID PM_HCI_RPMSG_ID
#define PM_CPUNET_hci_rpmsg_IS_ENABLED 1
#define PM_14_LABEL CPUNET_HCI_RPMSG
#define PM_CPUNET_HCI_RPMSG_DEV_NAME "NRF_FLASH_DRV_NAME"
#define PM_CPUNET_SRAM_PRIMARY_ADDRESS 0x21000000
#define PM_CPUNET_SRAM_PRIMARY_END_ADDRESS 0x21010000
#define PM_CPUNET_SRAM_PRIMARY_SIZE 0x10000
#define PM_CPUNET_SRAM_PRIMARY_NAME sram_primary
#define PM_CPUNET_NUM 15
#define PM_CPUNET_ALL_BY_SIZE "provision b0n b0n_container sram_primary hci_rpmsg app"
#define PM_ADDRESS 0xc200
#define PM_SIZE 0xe8e00
#define PM_SRAM_ADDRESS 0x20000000
#define PM_SRAM_SIZE 0x7e000
#endif /* PM_CONFIG_H__ */
那么我在application中如何使用这些分好的内存区域呢?
以fatfs文件系统为例:
#define PM_ID(label) PM_##label##_ID
#define PM_IS_ENABLED(label) PM_##label##_IS_ENABLED#define FLASH_AREA_ID(label) PM_ID(label)static int setup_flash(struct fs_mount_t *mnt)
{int rc = 0;
#if CONFIG_DISK_ACCESS_FLASHunsigned int id;const struct flash_area *pfa;mnt->storage_dev = (void *)FLASH_AREA_ID(external_flash);//这个宏就是获取flash IDid = (uintptr_t)mnt->storage_dev;rc = flash_area_open(id, &pfa);printk("Area %u at 0x%x on %s for %u bytes\n",id, (unsigned int)pfa->fa_off, pfa->fa_dev_name,(unsigned int)pfa->fa_size);if (rc < 0 && IS_ENABLED(CONFIG_APP_WIPE_STORAGE)) {printk("Erasing flash area ... ");rc = flash_area_erase(pfa, 0, pfa->fa_size);printk("%d\n", rc);}if (rc < 0) {flash_area_close(pfa);}
#endifreturn rc;
}static void setup_disk(void)
{struct fs_mount_t *mp = &fs_mnt;struct fs_dir_t dir = { 0 };struct fs_statvfs sbuf;int rc;if (IS_ENABLED(CONFIG_DISK_ACCESS_FLASH)) {rc = setup_flash(mp);//这个函数里面有获取flash ID的实现方法if (rc < 0) {LOG_ERR("Failed to setup flash area");return;}}if (!IS_ENABLED(CONFIG_FILE_SYSTEM_LITTLEFS) &&!IS_ENABLED(CONFIG_FAT_FILESYSTEM_ELM)) {LOG_INF("No file system selected");return;}rc = mount_app_fs(mp);if (rc < 0) {LOG_ERR("Failed to mount filesystem");return;}/* Allow log messages to flush to avoid interleaved output */k_sleep(K_MSEC(50));printk("Mount %s: %d\n", fs_mnt.mnt_point, rc);rc = fs_statvfs(mp->mnt_point, &sbuf);if (rc < 0) {printk("FAIL: statvfs: %d\n", rc);return;}printk("%s: bsize = %lu ; frsize = %lu ;"" blocks = %lu ; bfree = %lu\n",mp->mnt_point,sbuf.f_bsize, sbuf.f_frsize,sbuf.f_blocks, sbuf.f_bfree);rc = fs_opendir(&dir, mp->mnt_point);printk("%s opendir: %d\n", mp->mnt_point, rc);if (rc < 0) {LOG_ERR("Failed to open directory");}while (rc >= 0) {struct fs_dirent ent = { 0 };rc = fs_readdir(&dir, &ent);if (rc < 0) {LOG_ERR("Failed to read directory entries");break;}if (ent.name[0] == 0) {printk("End of files\n");break;}//printk(" %c %u %s\n", (ent.type == FS_DIR_ENTRY_FILE) ? 'F' : 'D', ent.size, ent.name);}(void)fs_closedir(&dir);return;
}void filesystem_init(void)
{k_sem_init(&file_system_lock, 1, 10);
}int main()
{filesystem_init();
}
FLASH_AREA_ID 宏最终获取到的就是下面这个ID
这篇关于nrf5340之pm_static.yml文件分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!