This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM4378: Scanf statement doesn't work

Part Number: AM4378

Hi, 

I want to get string input from the user in u-boot. When I tried by including scanf function, I am getting errors like an implicit declaration of the function and unable to get the string. Help me to give steps to get a string.

  • Hi Monish,

    One example for reading user input string from serial terminal @u-boot is listed below for your reference.

    /cmd/nvedit.c
    static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
    		       char * const argv[])
    {
    ...
    	if (cli_readline_into_buffer("edit: ", buffer, 0) < 0)
    		return 1;
    ...
    }

    Best,

    -Hong

  • Hi Guan,

    I am not using the command line argument to get the input from user. I want to get string/word input from the user through debug UART. I am able to get a character from the user using getc() function, but I want to get more  than two character from the user. So I thought of using scanf() function to get a string. But I am unable to use the function in U-Boot, it shows an error when I try to build the code in U-Boot. So kindly do the needful.

    Regards,

    Monish P

  • I uploaded a reference call flow in attachment.
    You would refer to functions listed in the attached call flow, and use/modify one of them for your specific user case.
    Alternatively you could search community for the same as it is a generic question.

    B::area_log1
    
    
    
    
    
    
    
    
    
    
    
    
    ===================================================
    26. Feb 2021
    15:16:46
    ===================================================
    B::Register
    N _  R0         60  R8          1  ^S+ ^Stack_+
    Z _  R1   44E09014  R9   BDF46EB8
    C _  R2   44E35000  R10        0A
    V _  R3          0  R11         1
    Q _  R4          1  R12  BFFD3BE0
         R5          0  R13  BDF38760
    0 _  R6   BFFCC010  R14  BFF90F6D
    1 _  R7   BFFBB242  PC   BFF90EEC
    2 _  SPSR        0  CPSR     01B3
    3 _
    4 _  USR:           FIQ:
         R8          1  R8          0
         R9   BDF46EB8  R9          0
    I I  R10        0A  R10  20000000
    F _  R11         1  R11         0
         R12  BFFD3BE0  R12         0
    T T  R13         0  R13         0
    J _  R14         0  R14         0
    svc                 SPSR        0
    nsec
         SVC:           IRQ:
    A A  R13  BDF38760  R13  00A00500
    E _  R14  BFF90F6D  R14  04100003
         SPSR        0  SPSR        0
    0 _
    1 _  UND:           ABT:
    2 _  R13  EC0280C0  R13         0
    3 _  R14  04CA8081  R14         0
         SPSR        0  SPSR        0
    
         MON:
         R13
         R14
         SPSR
    B::Var.Frame_/Locals_/Caller
    -000|serial_in_shift(inline)
    -000|ns16550_readb.isra.1(
        |  ?)
        |  addr = 0x44E09014
        |  addr = 0x44E09014
        |
    -001|ns16550_serial_pending(
        |  ?,
        |  ?)
        |
        |                return (serial_in(&com_port->lsr) & UART_LSR_DR) ? 1 : 0;
    -002|fgetc.part.0(
        |    file = 0x0)
        |
        |
    -003|cread_line(inline)
    -003|cli_readline_into_buffer(
        |    prompt = 0xBFFBB242,
        |    buffer = 0xBFFD4284,
        |    timeout = 0x0)
        |  p = 0xBFFD4284
        |  timeout = 0x0
        |  buf = 0xBFFD4284
        |  prompt = 0xBFFBB242
        |  num = 0x2
        |  eol_num = 0x2
        |  insert = 0x1
        |  esc_len = 0x0
        |  esc_save = (0x2, 0x0, 0x0, 0x0, 0x0A, 0x0, 0x0, 0x0)
        |  first = 0x1
        |
        |                        }
        |                        first = 0;
        |                }
        |
        |                ichar = getcmd_getch();
    -004|get_user_input(inline)
    -004|file_get(
        |    i = 0xBDF3884C)
        |  ch = 0x0
        |  i = 0xBDF3884C
        |  n = 0x60
        |  i = 0xBDF3884C
        |
        |...
        |#else
        |        *prompt_str = (promptmode==1)? PS1 : PS2;
        |#endif
        |        debug_printf("result %s\n",*prompt_str);
        |}
        |#endif
        |
        |#ifdef __U_BOOT__
        |static int uboot_cli_readline(struct in_str *i)
        |{
        |        char *prompt;
        |        char __maybe_unused *ps_prompt = NULL;
        |
        |        if (i->promptmode == 1)
        |...
        |        if (i->promptmode == 1)
        |                ps_prompt = env_get("PS1");
        |        else
        |                ps_prompt = env_get("PS2");
        |        if (ps_prompt)
        |                prompt = ps_prompt;
        |#endif
        |
        |        return cli_readline(prompt);
        |        n = uboot_cli_readline(i);
    -005|parse_stream(inline)
    -005|parse_stream_outer(
        |  eoinp = 0xBDF3884C,
        |  inflag = 0x2)
        |  ctx = (child = 0xBDF548F8, list_head = 0xBDF548E0, pipe = 0xBDF548E0, w = RES_NONE = 0x0, old_flag = 0x0, stack = 0x0, type = 0x2)
        |  temp = (data = 0x0, length = 0x0, maxlen = 0x0, quote = 0x0, nonnull = 0x0)
        |
        |                rcode = parse_stream(&temp, &ctx, inp,
    -006|parse_file_outer()
        |  rcode = 0x60
        |  input = (p = 0xBFFD3BE1, __promptme = 0x1, promptmode = 0x1, get = 0xBFF74D95, peek = 0xBFF74FE5)
        |
        |#endif
        |        rcode = parse_stream_outer(&input, FLAG_PARSE_SEMICOLON);
    -007|cli_loop()
        |
        |}
        |#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
        |
        |void cli_loop(void)
        |{
        |#ifdef CONFIG_HUSH_PARSER
        |        parse_file_outer();
    -008|bootstage_mark_name(inline)
    -008|main_loop()
        |  s = 0xBDF508F0
        |
        |        cli_loop();
    -009|run_main_loop()
        |#ireturn = 0x60
        |
        |        for (;;)
        |                main_loop();
        |        return 0;
        |}
        |
        |/*
    -010|initcall_run_list(
        |    init_sequence = 0xBFFCBF54)
        |  init_fnc_ptr = 0xBFFCBFEC
        |  ret = 0x60
        |
        |                if (ret) {
    -011|board_init_r(
        |  ?,
        |  ?)
        |
        |#endif
        |
        |        if (initcall_run_list(init_sequence_r))
        |                hang();
        |
        |        /* NOTREACHED - run_main_loop() does not return */
        |        hang();
    -012|board_init_r(
        |  rsnew_gd = 0x60,
        |  rcdest_addr = 0x44E09014)
        |
        |}
        |
     ---|end of frame