Android uses javasline to pass Parameters from preloader to kernel, and implements linepreloader

Source: Internet
Author: User

Android uses javasline to pass Parameters from preloader to kernel, and implements linepreloader
Take the definition parameter cus_param as an example, int type variable.
 
1. Preloader part
Platform. h (mediatek \ platform \ [$ platform] \ preloader \ src \ drivers \ inc \ platform. h)
Add the cus_param variable to the following struct. If it is of the char type, pay attention to it by 4 Bytes:
Typedef struct {
U32 magic;
Boot_mode_t mode;
U32 e_flag;
U32 log_port;
U32 log_baudrate;
U8 log_enable;
U8 part_num;
U8 reserved [2];
U32 dram_rank_num;
U32 dram_rank_size [4];
U32 boot_reason;
U32 meta_com_type;
U32 meta_com_id;
U32 boot_time;
Da_info_t da_info;
SEC_LIMIT sec_limit;
Part_hdr_t * part_info;
U8 md_type [4];
U32 ddr_reserve_enable;
U32 ddr_reserve_success;
U32 cus_param; // mediatek add
} Boot_arg_t;
 
Platform. c (mediatek \ platform \ [$ platform] \ preloader \ src \ drivers \ platform. c)
Add a value for cus_param to this function. Use the function or directly write the required value:
Void platform_set_boot_args ()
{
# If cmd_boot_argument
Bootarg. magic = BOOT_ARGUMENT_MAGIC;
Bootarg. mode = g_boot_mode;
Bootarg. e_flag = sp_check_platform ();
Bootarg. log_port = pai_uart_log;
Bootarg. log_baudrate = pai_log_baudrate;
Bootarg. log_enable = (u8) log_status ();
Bootarg. dram_rank_num = get_dram_rank_nr ();
Get_dram_rank_size (bootarg. dram_rank_size );
Bootarg. boot_reason = g_boot_reason;
Bootarg. meta_com_type = (u32) g_meta_com_type;
Bootarg. meta_com_id = g_meta_com_id;
Bootarg. boot_time = get_timer (g_boot_time );
 
Bootarg. part_num = g_dram_buf-> part_num;
Bootarg. part_info = g_dram_buf-> part_info;
 
Bootarg. ddr_reserve_enable = g_ddr_reserve_enable;
Bootarg. ddr_reserve_success = g_ddr_reserve_success;
 
// Mediatek add, mt_get_cus_param. This function is customized to obtain the cus_param function. Please implement it by yourself.
Bootarg. cus_param = mt_get_cus_param ();
 
2. LK part
Boot_mode.h (mediatek \ platform \ [$ platform] \ lk \ include \ platform \ boot_mode.h)
Add the cus_param variable to the following struct. If it is char type, pay attention to it by 4 Bytes:
Typedef struct {
U32 maggic_number;
BOOTMODE boot_mode;
U32 e_flag;
U32 log_port;
U32 log_baudrate;
U8 log_enable;
U8 part_num;
U8 reserved [2];
U32 dram_rank_num;
U32 dram_rank_size [4];
U32 boot_reason;
META_COM_TYPE meta_com_type;
U32 meta_com_id;
U32 boot_time;
Da_info_t da_info;
SEC_LIMIT sec_limit;
Part_hdr_t * part_info;
U8 md_type [4];
U32 ddr_reserve_enable;
U32 ddr_reserve_success;
U32 cus_param; // mediatek add, which is the same as the preloader and must be the same as the two struct.
} BOOT_ARGUMENT;
 
Mt_boot.c (bootable \ bootloader \ lk \ app \ mt_boot \ mt_boot.c)
In this function, add the information of cus_param to cmdline:
Int boot_linux_from_storage (void)
{
.....
Strlen + = sprintf (commanline, "% s fps = % 1d", commanline, mt_disp_get_ LCD _time ());
Strlen + = sprintf (commanline, "% s cus_param = % 1d", commanline, g_boot_arg-> cus_param); // mediatek add
 
3. Kernel Section
Saved_command_line this is a global variable. In the driver file where you need this parameter, extern saved_command_line variable,
Search for the string of cus_param:
Char * ptr;
Int cus_param;
Ptr = strstr (saved_command_line, "cus_param = ");
Ptr + = strlen ("cus_param = ");
Cus_param = simple_strtol (ptr, NULL, 10 );
In this case, cus_param is the initial int value.
 
How can I read/proc/cmdline content in the linux Driver (kernel state)? fp-> f_op-> read and kernel_read both report errors and cannot be used.

The code is
In kernkel/fs/proc/proc_misc.c: proc_misc_init ()-> cmdline_read_proc ()
The cmdline_read_proc () Code shows that the/proc/cmdline information is saved in saved_command_line.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.