nrf5340之pm_static.yml文件分析

pm_static.yml文件内容举例:

app:
  address: 0xc200  
  region: flash_primary
  size: 0xE8E00
external_flash:
  address: 0
  region: external_flash
  size: 0xF17000 
mcuboot:
  address: 0x0  
  placement:
    before:
    - mcuboot_primary
  region: flash_primary
  size: 0xc000
mcuboot_pad:
  address: 0xc000
  size: 0x200
mcuboot_primary:
  address: 0xc000
  orig_span: &id001  
  - mcuboot_pad
  - app
  region: flash_primary
  size: 0xE9000
  span: *id001
mcuboot_primary_app:
  address: 0xc200
  orig_span: &id002
  - app
  region: flash_primary
  size: 0xE8E00
  span: *id002
mcuboot_secondary:
  address: 0xF17000
  device: MX25R64
  region: external_flash
  size: 0xE9000
otp:
  address: 0xff8100
  end_address: 0xff83fc
  region: otp
  size: 0x2fc
pcd_sram:
  address: 0x2007e000
  end_address: 0x20080000
  placement:
    before:
    - end
  region: sram_primary
  size: 0x2000
sram_primary:
  address: 0x20000000
  end_address: 0x2007e000
  region: sram_primary
  size: 0x7e000
app_pad:
  address: 0xF5000
  region: flash_primary
  size: 0x1000
settings_storage:
  address: 0xF6000
  end_address: 0xFF000
  region: flash_primary
  size: 0x9000
cywee:
  address: 0xff000
  end_address: 0x100000
  region: flash_primary
  placement:
    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_FLASH
	unsigned int id;
	const struct flash_area *pfa;

	mnt->storage_dev = (void *)FLASH_AREA_ID(external_flash);//这个宏就是获取flash ID
	id = (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);
	}
#endif
	return 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值