需要在各层如:bootloader、kernel、framework、system-app获取uboot的Env需要如下步骤
以905平台设置控制台日志等级为例
- 将Env环境变量预置并且作为bootargs(传递给内核的启动参数)
--- a/uboot-repo/bl33/board/amlogic/configs/g12a_u202_v1.h
+++ b/uboot-repo/bl33/board/amlogic/configs/g12a_u202_v1.h
@@ -149,6 +149,14 @@
#define CONFIG_LOGO_FB "setenv fb_width 800; setenv fb_height 1280;"
#endif
+#ifndef CONFIG_CONSOLE_LOGLEVEL
+#define CONFIG_CONSOLE_LOGLEVEL "console_loglevel=7\0"
+#endif
+
/* args/envs */
#define CONFIG_SYS_MAXARGS 64
#define CONFIG_EXTRA_ENV_SETTINGS \
@@ -193,6 +201,8 @@
"lock=10001000\0"\
"active_slot=normal\0"\
"boot_part=boot\0"\
+ CONFIG_CONSOLE_LOGLEVEL \
"reboot_mode_android=""normal""\0"\
"Irq_check_en=0\0"\
"fs_type=""rootfstype=ramfs""\0"\
@@ -206,7 +216,7 @@
"else fi;"\
"\0"\
"storeargs="\
- "setenv bootargs ${initargs} ${fs_type} otg_device=${otg_device} reboot_mode_android=${reboot_mode_android} logo=${display_layer},loaded,${fb_addr} fb_width=${fb_width} fb_height=${fb_height} vout2=${outputmode2},enable vout=${outputmode},enable panel_type=${panel_type} lcd_ctrl=${lcd_ctrl} hdmitx=${cecconfig},${colorattribute} hdmimode=${hdmimode} frac_rate_policy=${frac_rate_policy} hdmi_read_edid=${hdmi_read_edid} cvbsmode=${cvbsmode} osd_reverse=${osd_reverse} video_reverse=${video_reverse} irq_check_en=${Irq_check_en} androidboot.selinux=${EnableSelinux} androidboot.firstboot=${firstboot} jtag=${jtag}; "\
+ "setenv bootargs ${initargs} ${fs_type} otg_device=${otg_device} console_loglevel=${console_loglevel} reboot_mode_android=${reboot_mode_android} logo=${display_layer},loaded,${fb_addr} fb_width=${fb_width} fb_height=${fb_height} vout2=${outputmode2},enable vout=${outputmode},enable panel_type=${panel_type} lcd_ctrl=${lcd_ctrl} hdmitx=${cecconfig},${colorattribute} hdmimode=${hdmimode} frac_rate_policy=${frac_rate_policy} hdmi_read_edid=${hdmi_read_edid} cvbsmode=${cvbsmode} osd_reverse=${osd_reverse} video_reverse=${video_reverse} irq_check_en=${Irq_check_en} androidboot.selinux=${EnableSelinux} androidboot.firstboot=${firstboot} jtag=${jtag}; "\
- 各层如何获取和设置
- booloader层
setenv("console_loglevel", 0); //设置Env
getenv("console_loglevel"); //获取Env
- kernel层获取Env
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -124,6 +124,21 @@ static int __control_devkmsg(char *str)
return -EINVAL;
}
+static int __init console_loglevel_setup(char *str)
+{
+ int level;
+ pr_info("Peter [console_loglevel_setup] str:%s",str);
+ if(kstrtoint(str, 10, &level))
+ return -1;
+ if(level >= 0 && level <= 15)
+ console_printk[0] = level;
+ else
+ return -1;
+ return 0;
+}
+__setup("console_loglevel=", console_loglevel_setup);
+
+
- system-app层
可以通过原厂提供的类 com.droidlogic.app.SystemControlManager,获取Env已经进行广播接收封装,在Wiki--内部接口有说明
public class SystemControlManager {
public String getBootenv(String prop, String def);
public void setBootenv(String prop, String val);
}