VirtualBox vs. Udoo x86

Discussion in 'UDOO X86' started by Snakebyte, Mar 20, 2018.

  1. Snakebyte

    Snakebyte Member

    Joined:
    Mar 19, 2018
    Messages:
    90
    Likes Received:
    9
    Hello,
    Is there any place to obtain some documentation on potential differences between a VirtualBox virtual machine and the Udoo x86 SBC? In particular, reading and writing to the USB flash drive and the serial console via BIOS does not work on the Udoo board but these work fine with BIOS calls in VB.

    Thank you.
     
  2. ccs_hello

    ccs_hello UDOOer

    Joined:
    Apr 15, 2017
    Messages:
    536
    Likes Received:
    194
    In what exec environment you are calling BIOS (e.g., post-boot assembler)? That exec env's support on BIOS (or UEFI and CSM under it)
    <-- probably direct thru bare-metal is the issue

    The VirtualBox has to run under a underlay OS (say Linux.)
    VirtualBox (passing thru hypervisor layer then down to) OS would take care of the software BIOS call.
     
    LDighera likes this.
  3. Snakebyte

    Snakebyte Member

    Joined:
    Mar 19, 2018
    Messages:
    90
    Likes Received:
    9
    The OS uses a two stage bootloader. The first stage finds the second stage on the disk and near jumps into it. The second stage notes where it was entered and then does a far jump into the next step. I can't explain why this is important but I do know this helps clarify the context (I know it invokes the correct segment).

    The second stage bootloader prints to video with printf from libc, which as far as I can tell eventually makes its way to

    putc: movb ah, #0x0E ! Print character in teletype mode
    mov bx, #0x0001 ! Page 0, foreground color
    int 0x10

    If serial communication is enabled, the following code is executed

    1: lea dx, 5(bx) ! Line Status Register
    ...
    mov dx, bx ! Transmit Holding Register
    outb dx ! Send character down the serial line

    This code works perfectly fine in both VirtualBox video and serial, and on the Udoo video. Serial does not work. It is unusably slow.

    Once the kernel is entered, it prints to the video screen with kprintf:

    #define printf kprintf
    #define count_kputc(c) do { charcount++; kputc(c); } while(0)
    printf()
    ...
    if (c != '%') {
    /* Ordinary character. */
    count_kputc(c);
    continue;
    }
    ...
    The kernel has its own kputc. As far as I can tell, that code eventually ends up writing directly to video memory. It works in VirtualBox and Udoo, to the point that the OS stops working (see below).

    If serial communication is enabled, it also executes the following code:
    ser_putc(c);
    #define COM1_BASE 0x3F8
    PUBLIC void ser_putc(char c)
    {
    int i;
    int lsr, thr;

    lsr= COM1_LSR;
    thr= COM1_THR;
    for (i= 0; i<100000; i++)
    {
    if (inb( lsr) & LSR_THRE)
    break;
    }
    outb( thr, c);
    }

    (Strike through start here)
    This code is not working on VirtualBox nor Udoo.
    If I use

    #define COM1_BASE 0x400

    to access COM1 in the BIOS data area, the OS writes to serial in VirtualBox and gets farther before ceasing communication via video (suggesting there is no BIOS data area in Udoo). Serial does not work.
    (end strike through)

    (There was another flag that needed to be enabled in the OS for the serial out to fully work. It now does in VirtualBox.)


    For the USB flash drive, the bootloader is able to load the kernel image into memory using the following code:

    movb ah, #0x87 ! Code for extended memory move
    int 0x15

    Once in the kernel, the following code is used to further access the USB flash drive:

    /* Set up an ordinary read or write BIOS call. */
    unsigned cylinder = block / secspcyl;
    unsigned sector = (block % wn->sectors) + 1;
    unsigned head = (block % secspcyl) / wn->sectors;

    reg86.u.b.intno = 0x13;
    ...

    This works just fine in VirtualBox, but is near where the OS is no longer communicating. In both VB and Udoo, the OS is successfully able to identify the number of sectors on the flash drive with the following code:

    reg86.u.b.intno = 0x13;
    reg86.u.b.ah = 0x08; /* Get drive parameters. */
    reg86.u.b.dl = drive_id;
    r= sys_int86(&reg86);

    So, in summary, accessing BIOS via interrupts works fine in VirtualBox but not Udoo. If this is due to the differences in UEFI's BIOS legacy mode, I would appreciate a pointer towards some documentation where I can make adjustments.

    Thanks!
     
    Last edited: Mar 21, 2018
  4. Snakebyte

    Snakebyte Member

    Joined:
    Mar 19, 2018
    Messages:
    90
    Likes Received:
    9
    An update:

    I have documented an error I made in the above analysis at the thread serial port and console redirection. I have been able to get the Udoo x86 SBC to boot, read and write to a USB stick using BIOS calls. I am still working on some of the details, but I wanted to issue a correction as soon as I sure about my mistake and the correct code. The linked thread does document a discrepancy between Braswell documentation and standard COM1 addressing. I would still like to know if there is any documentation or help on identifying differences between VirtualBox and Udoo x86 SBC (as in, it'd be really great if we could boot an image in VB and know it'd work exactly the same way on the Udoo x86).

    Thank you.
     

Share This Page