起因
今天項(xiàng)目有個(gè)新需求就是讓屏幕亮度在上電以后保持上次最后設(shè)置的值
我們的項(xiàng)目屏幕的初始化是在kernel里而不是uboot,kernel的驅(qū)動(dòng)的加載是在根文件系統(tǒng)之前,所以我們無(wú)法從配置文件中讀取亮度。
首先大家能想到的就是讓讓他存儲(chǔ)到內(nèi)核能讀取到的rom中去,到底哪里合適的,方便讀寫(xiě)
經(jīng)過(guò)查資料,發(fā)現(xiàn)uboot的環(huán)境變量的更改是直接保存到rom中,區(qū)別于kernel的環(huán)境變量保存到rom中。而且我們知道kernel啟動(dòng)后會(huì)讀取uboot傳入的bootargs,那說(shuō)明kernel就有對(duì)應(yīng)的函數(shù)去讀。
接下來(lái)就說(shuō)明下接口的調(diào)用
使用
首先是對(duì)bootargs的一些操作
我是在bootargs添加一個(gè)backlight,他的屬性值等于另外一個(gè)參數(shù),這樣做的話就可以減少bootargs的變動(dòng)
backlight=20
#set kernel cmdline if boot.img or recovery.img has no cmdline we will use this
setargs_nand=setenv bootargs console=${console} root=${nand_root} rootwait init=${init} rdinit=${rdinit} loglevel=${loglevel} earlyprintk=${earlyprintk} initcall_debug=${initcall_debug} loglevel=${loglevel} partitions=${partitions} cma=${cma} gpt=1 backlight=${backlight}
setargs_mmc=setenv bootargs console=${console} root=${mmc_root} rootwait init=${init} rdinit=${rdinit} loglevel=${loglevel} earlyprintk=${earlyprintk} initcall_debug=${initcall_debug} loglevel=${loglevel} partitions=${partitions} cma=${cma} gpt=1 backlight=${backlight}
在驅(qū)動(dòng)中使用的函數(shù)是__setup(str, fn)?
__setup宏在定義如下:
/*
* Only for really core code. See moduleparam.h for the normal way.
*
* Force the alignment so the compiler doesn't space elements of the
* obs_kernel_param "array" too far apart in .init.setup.
*/
#define __setup_param(str, unique_id, fn, early)
static const char __setup_str_##unique_id[] __initconst
__aligned(1) = str;
static struct obs_kernel_param __setup_##unique_id
__used __section(.init.setup)
__attribute__((aligned((sizeof(long)))))
= { __setup_str_##unique_id, fn, early }
#define __setup(str, fn)
__setup_param(str, fn, fn, 0)
第一個(gè)參數(shù)是bootargs的屬性,第二個(gè)參數(shù)是要把屬性值作為參數(shù)的函數(shù)的指針,說(shuō)白了就是函數(shù)
函數(shù)的要求是 static int __init?類型,下面是我使用的時(shí)候的一個(gè)demo
kstrtoint是用于將讀取到的值從字符數(shù)字轉(zhuǎn)換成數(shù)值
kstrtoint和標(biāo)準(zhǔn)的c庫(kù)有些去別,請(qǐng)注意看!!!
第一個(gè)參數(shù)是要被轉(zhuǎn)化的字符串,第二個(gè)參數(shù)是保存的進(jìn)制,第三個(gè)參數(shù)才是int類型的數(shù)據(jù)的地址
static int __init get_env_backlight(char * backlight)
{
kstrtoint(backlight, 10, &backlight_value);
// printk("%s:num:%dn",__FUNCTION__,backlight_value);
return 0;
}
-
Linux
+關(guān)注
關(guān)注
88文章
11758瀏覽量
219009 -
Linux系統(tǒng)
+關(guān)注
關(guān)注
4文章
614瀏覽量
29904 -
Uboot
+關(guān)注
關(guān)注
4文章
131瀏覽量
29937 -
Linux驅(qū)動(dòng)
+關(guān)注
關(guān)注
0文章
47瀏覽量
10480 -
掉電記憶
+關(guān)注
關(guān)注
0文章
3瀏覽量
2191
發(fā)布評(píng)論請(qǐng)先 登錄
linux驅(qū)動(dòng)開(kāi)發(fā)_文件系統(tǒng)本地掛載
請(qǐng)問(wèn)linux下uboot怎么實(shí)現(xiàn)u***下載?
zynq arm移植uboot和Linux,使用setenv設(shè)置環(huán)境變量,顯示無(wú)這個(gè)指令
基于HL開(kāi)發(fā)板的密碼鎖掉電記憶密碼
在Linux運(yùn)行期間升級(jí)Linux系 統(tǒng)Uboot+kernel+Rootfs
UBOOT命令總結(jié)
基于ARM9和NANDFlash對(duì)uboot和Linux內(nèi)核進(jìn)行修改
你了解Embeded linux中的Uboot參數(shù)與內(nèi)核?
linux內(nèi)核中percpu變量的實(shí)現(xiàn)
嵌入式Linux環(huán)境變量分區(qū)制作
嵌入式linux學(xué)習(xí) Day1 uboot基礎(chǔ)
linux驅(qū)動(dòng)通過(guò)uboot的變量實(shí)現(xiàn)掉電記憶
評(píng)論