kernel cmdline

本文详细介绍了在Android系统中如何从LK传送到Kernel的cmdline,并解析这些参数。重点讲解了利用adb读取/proc/cmdline的过程,以及如何在/system/core/init/util.cpp中将cmdline参数转换为系统属性。

從 lk 傳送到 kerel 的 cmdline 會放在開機後的
adb
/proc/cmdline

開到 android 後,又會被讀出來

/system/core/init/util.cpp

275void import_kernel_cmdline(bool in_qemu,
276                           const std::function<void(const std::string&, const std::string&, bool)>& fn) {
277    std::string cmdline;
278    android::base::ReadFileToString("/proc/cmdline", &cmdline);
279
280    for (const auto& entry : android::base::Split(android::base::Trim(cmdline), " ")) {
281        std::vector<std::string> pieces = android::base::Split(entry, "=");
282        if (pieces.size() == 2) {
283            fn(pieces[0], pieces[1], in_qemu);
284        }
285    }
286}

/system/core/init/init.cpp

391static void import_kernel_nv(const std::string& key, const std::string& value, bool for_emulator) {
392    if (key.empty()) return;
393
394    if (for_emulator) {
395        // In the emulator, export any kernel option with the "ro.kernel." prefix.
396        property_set(android::base::StringPrintf("ro.kernel.%s", key.c_str()).c_str(), value.c_str());
397        return;
398    }
399
400    if (key == "qemu") {
401        strlcpy(qemu, value.c_str(), sizeof(qemu));
402    } else if (android::base::StartsWith(key, "androidboot.")) {
403        property_set(android::base::StringPrintf("ro.boot.%s", key.c_str() + 12).c_str(),
404                     value.c_str());
405    }
406}

转载于:https://www.cnblogs.com/youchihwang/p/7603218.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值