怎么样在persist 分区写值
时间: 2024-02-05 21:14:00 浏览: 37
在 Android 系统中,persist 分区是一个特殊的分区,它可以用来保存一些系统设置和配置信息。在 Android 应用程序中,如果需要在 persist 分区中写入值,可以通过 SystemProperties.set() 方法来实现。具体步骤如下:
1. 导入 SystemProperties 类
```
import android.os.SystemProperties;
```
2. 使用 SystemProperties.set() 方法来设置属性值
```
SystemProperties.set("persist.mysetting", "myvalue");
```
其中,第一个参数是属性名,第二个参数是属性值。
注意:要写入 persist 分区,需要具有 root 权限。
相关问题
android如何从persist分区读取序列号赋值给ro.serialno属性
Android系统的ro.serialno属性是由bootloader在启动时生成并写入到persist分区中的。如果需要从persist分区读取序列号并赋值给ro.serialno属性,可以按照以下步骤进行:
1. 通过adb shell命令进入到Android系统的shell环境中;
2. 使用cat命令读取persist分区中的序列号,具体命令如下:
```
cat /mnt/vendor/persist/serialno
```
注意:不同设备的persist分区路径可能不同,需要根据实际情况进行调整。
3. 将上一步读取到的序列号赋值给ro.serialno属性,具体命令如下:
```
setprop ro.serialno <serialno>
```
其中,<serialno>是从persist分区中读取到的序列号。
4. 验证ro.serialno属性是否已经被赋值成功,具体命令如下:
```
getprop ro.serialno
```
如果输出与从persist分区中读取到的序列号相同,则表示赋值成功。
注意:在进行以上操作时,需要确保已经获取了足够的权限,例如root权限。另外,修改ro.serialno属性可能会影响某些应用程序的正常运行,因此需要谨慎操作。
写一个高通8295芯片的分区代码
以下是一个简单的高通8295芯片的分区代码,其中包含了一些物理分区的信息,用于控制设备的分区行为。这个代码使用了GPT分区表,其中包含了一些基本的分区,如boot、recovery、system、userdata等等。此外,代码中还包含了一些附加分区,如cache、persist、misc等等。请注意,这只是一个简单的示例,实际的分区代码可能会更复杂和详细。
```
#define SECTOR_SIZE 512
#define PARTITION_TABLE_SIZE 34 * SECTOR_SIZE
struct partition_entry {
uint8_t partition_guid[16];
uint64_t starting_lba;
uint64_t ending_lba;
uint64_t attributes;
uint16_t partition_name[36];
};
struct partition_table {
uint64_t signature;
uint32_t revision;
uint32_t header_size;
uint32_t crc32;
uint32_t reserved;
uint64_t current_lba;
uint64_t backup_lba;
uint64_t first_usable_lba;
uint64_t last_usable_lba;
uint8_t disk_guid[16];
uint64_t partition_entry_lba;
uint32_t num_partition_entries;
uint32_t sizeof_partition_entry;
uint32_t partition_entry_array_crc32;
struct partition_entry partition_entries[128];
};
int main() {
struct partition_table gpt = {0};
gpt.signature = 0x5452415020494645ULL;
gpt.revision = 0x00010000;
gpt.header_size = 92;
gpt.current_lba = 1;
gpt.backup_lba = 65535;
gpt.first_usable_lba = 34;
gpt.last_usable_lba = 65502;
memcpy(gpt.disk_guid, "\x8f\x00\x00\x00\x00\x00\x10\x00\x80\x00\x00\xaa\x00\x38\x9b\x71", 16);
gpt.partition_entry_lba = 2;
gpt.num_partition_entries = 128;
gpt.sizeof_partition_entry = 128;
// boot partition
struct partition_entry boot = {0};
memcpy(boot.partition_guid, "\x40\x0c\x52\x6a\x8d\x4e\x4f\x5d\x84\x65\x5a\x3e\x3f\xbd\x6c\x3f", 16);
boot.starting_lba = 34;
boot.ending_lba = 1601;
boot.attributes = 0;
memcpy(boot.partition_name, L"boot", 8 * sizeof(wchar_t));
gpt.partition_entries[0] = boot;
// recovery partition
struct partition_entry recovery = {0};
memcpy(recovery.partition_guid, "\x9e\x6d\xc5\x8e\x3b\x3d\x4a\x4b\x9f\x6a\x92\x9d\x8b\xfa\x8a\x13", 16);
recovery.starting_lba = 1602;
recovery.ending_lba = 3137;
recovery.attributes = 0;
memcpy(recovery.partition_name, L"recovery", 16 * sizeof(wchar_t));
gpt.partition_entries[1] = recovery;
// system partition
struct partition_entry system = {0};
memcpy(system.partition_guid, "\x7a\x26\x8c\x2e\x5d\x91\x4c\x45\xa1\x4b\x7e\x69\xb6\x6f\x1f\x9f", 16);
system.starting_lba = 3138;
system.ending_lba = 44289;
system.attributes = 0;
memcpy(system.partition_name, L"system", 12 * sizeof(wchar_t));
gpt.partition_entries[2] = system;
// userdata partition
struct partition_entry userdata = {0};
memcpy(userdata.partition_guid, "\xc5\x9a\x34\xd2\x64\x4d\x4c\x4d\x80\x0b\x67\xc0\x5c\x1b\xf3\x96", 16);
userdata.starting_lba = 44290;
userdata.ending_lba = 65502;
userdata.attributes = 0;
memcpy(userdata.partition_name, L"userdata", 14 * sizeof(wchar_t));
gpt.partition_entries[3] = userdata;
// cache partition
struct partition_entry cache = {0};
memcpy(cache.partition_guid, "\xbf\x0a\x1b\x2e\xd2\x1d\x4c\x4f\xa6\xdb\x2a\xef\x43\x7c\xdf\x3b", 16);
cache.starting_lba = 3138;
cache.ending_lba = 3377;
cache.attributes = 0;
memcpy(cache.partition_name, L"cache", 10 * sizeof(wchar_t));
gpt.partition_entries[4] = cache;
// persist partition
struct partition_entry persist = {0};
memcpy(persist.partition_guid, "\x6d\x55\x8e\xea\x6f\x36\x4c\x4d\xbb\x1c\x95\x7d\x5c\x5b\x12\x45", 16);
persist.starting_lba = 3378;
persist.ending_lba = 3649;
persist.attributes = 0;
memcpy(persist.partition_name, L"persist", 12 * sizeof(wchar_t));
gpt.partition_entries[5] = persist;
// misc partition
struct partition_entry misc = {0};
memcpy(misc.partition_guid, "\x5d\x07\x7d\x41\x6c\x77\x4e\x4f\xa9\x5e\x9c\x7d\x5c\x5b\x12\x45", 16);
misc.starting_lba = 3650;
misc.ending_lba = 3777;
misc.attributes = 0;
memcpy(misc.partition_name, L"misc", 8 * sizeof(wchar_t));
gpt.partition_entries[6] = misc;
// write partition table to disk
FILE* fp = fopen("/dev/block/mmcblk0", "wb");
fwrite(&gpt, 1, PARTITION_TABLE_SIZE, fp);
fclose(fp);
return 0;
}
```
相关推荐
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)