diff options
author | Arve Hjønnevåg <arve@android.com> | 2020-11-11 16:23:45 -0800 |
---|---|---|
committer | Arve Hjønnevåg <arve@android.com> | 2020-11-11 16:35:14 -0800 |
commit | a83546bda0e22cc8bdb8144dd2f2968c6e4fe719 (patch) | |
tree | 5399a4782bff9c256701b6a0b88d1b2c49265f5f /block_device_tipc.c | |
parent | c1b01acff8f7159a99d4d11aa370c56434e18c2f (diff) | |
download | storage-a83546bda0e22cc8bdb8144dd2f2968c6e4fe719.tar.gz |
[storage] Add support for TDP fs in non secure proxy file
If the STORAGE_HAS_FS_TDP build flag is set a filesystem will be created
in a file under persist/ in the data directory passed to the non-secure
proxy. A file-system that is not wiped with userdata should must be
mounted or linked there.
Bug: 173032298
Change-Id: I254f98a4fca28114b74a7183e463096d86f78860
Diffstat (limited to 'block_device_tipc.c')
-rw-r--r-- | block_device_tipc.c | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/block_device_tipc.c b/block_device_tipc.c index 7b31c4b..61f61ee 100644 --- a/block_device_tipc.c +++ b/block_device_tipc.c @@ -395,14 +395,17 @@ int block_device_tipc_init(struct block_device_tipc* state, uint8_t probe; uint16_t rpmb_key_part_base = 0; uint32_t rpmb_block_count; - uint32_t rpmb_part1_block_count = 2; + uint32_t rpmb_part_sb_ns_block_count = 2; /* * First block is reserved for rpmb key derivation data, whose base is * rpmb_key_part_base */ uint16_t rpmb_part1_base = 1; - uint16_t rpmb_part2_base = rpmb_part1_base + rpmb_part1_block_count; - + uint16_t rpmb_part2_base = rpmb_part1_base + rpmb_part_sb_ns_block_count; +#if HAS_FS_TDP + uint16_t rpmb_part_sb_tdp_base = rpmb_part2_base; + rpmb_part2_base += rpmb_part_sb_ns_block_count; +#endif state->ipc_handle = ipc_handle; /* init rpmb */ @@ -474,15 +477,38 @@ int block_device_tipc_init(struct block_device_tipc* state, return 0; } +#if HAS_FS_TDP + block_device_tipc_init_dev_ns(&state->dev_ns_tdp, state); + + ret = ns_open_file(state->ipc_handle, "persist/0", + &state->dev_ns_tdp.ns_handle, true); + if (ret < 0) { + goto err_open_tdp; + } + + state->fs_tdp.tr_state = &state->tr_state_ns_tdp; + + block_device_tipc_init_dev_rpmb(&state->dev_ns_tdp_rpmb, state, + rpmb_part_sb_tdp_base, + rpmb_part_sb_ns_block_count); + + ret = fs_init(&state->tr_state_ns_tdp, fs_key, &state->dev_ns_tdp.dev, + &state->dev_ns_tdp_rpmb.dev, false /* Don't allow wiping */); + if (ret < 0) { + goto err_init_fs_ns_tdp_tr_state; + } + +#else /* * Create STORAGE_CLIENT_TDP_PORT alias after we know the backing file for - * STORAGE_CLIENT_TD_PORT is available. On future devices + * STORAGE_CLIENT_TD_PORT is available. On future devices, using HAS_FS_TDP, * STORAGE_CLIENT_TDP_PORT will not be available when the bootloader is * running, so we limit access to this alias as well to prevent apps * developed on old devices from relying on STORAGE_CLIENT_TDP_PORT being * available early. */ state->fs_tdp.tr_state = &state->tr_state_rpmb; +#endif ret = client_create_port(&state->fs_tdp.client_ctx, STORAGE_CLIENT_TDP_PORT); @@ -498,7 +524,7 @@ int block_device_tipc_init(struct block_device_tipc* state, state->fs_ns.tr_state = &state->tr_state_ns; block_device_tipc_init_dev_rpmb(&state->dev_ns_rpmb, state, rpmb_part1_base, - rpmb_part1_block_count); + rpmb_part_sb_ns_block_count); ret = fs_init(&state->tr_state_ns, fs_key, &state->dev_ns.dev, &state->dev_ns_rpmb.dev, new_ns_fs); @@ -518,6 +544,12 @@ err_fs_ns_create_port: err_init_fs_ns_tr_state: ipc_port_destroy(&state->fs_tdp.client_ctx); err_fs_rpmb_tdp_create_port: +#if HAS_FS_TDP + /* undo fs_init */ +err_init_fs_ns_tdp_tr_state: + ns_close_file(state->ipc_handle, state->dev_ns_tdp.ns_handle); +err_open_tdp: +#endif ns_close_file(state->ipc_handle, state->dev_ns.ns_handle); ipc_port_destroy(&state->fs_rpmb_boot.client_ctx); err_fs_rpmb_boot_create_port: @@ -539,6 +571,10 @@ void block_device_tipc_uninit(struct block_device_tipc* state) { ns_close_file(state->ipc_handle, state->dev_ns.ns_handle); ipc_port_destroy(&state->fs_tdp.client_ctx); +#if HAS_FS_TDP + /* undo fs_init */ + ns_close_file(state->ipc_handle, state->dev_ns_tdp.ns_handle); +#endif } ipc_port_destroy(&state->fs_rpmb_boot.client_ctx); ipc_port_destroy(&state->fs_rpmb.client_ctx); |