Step 6 : Boot the OS
====================

.. tab-set::

   .. tab-item:: Boot the OS

        * In this program, you are going to learn


        .. panels::
                :container: container pb-4
                :column: col-lg-12 p-2
                :card: shadow

                * How to ?


.. panels::
        :container: container pb-4
        :column: col-lg-12 p-2
        :card: shadow

        Topics in this section,

                * :ref:`Booting Steps <freertos_rpi_4b_step6_0>`


.. _freertos_rpi_4b_step6_0:

.. tab-set::

   .. tab-item:: Booting Steps

        * Disconnect the micro SD Card reader from Linux Desktop machine.

        * Insert SD Card to the RPI Board 

        * Then, use serial usb cable to connect the RPI board and Linux Desktop machine.

        * After connecting, check whether ``/dev/ttyUSB0`` created or not.

        .. code-block:: c

                $ ls /dev/ttyUSB0

        * Run minicom to access RPI board using following command:

        .. code-block:: c

                $ sudo minicom -s

.. tab-set::

    .. tab-item:: Set Minicom Fig.6.1:

        * Once the above minicom command is given, below configuration options will be displayed:

                              .. image:: Step1_FreeRTOS_RPI4B.png
                                :alt: Diagram
                                :width: 468
                                :height: 466

.. tab-set::

    .. tab-item:: Set Minicom Fig.6.2:

        * Scroll down to "Serial port setup" and press "Enter":

                              .. image:: Step2_FreeRTOS_RPI4B.png
                                :alt: Diagram
                                :width: 352
                                :height: 270

.. tab-set::

    .. tab-item:: Set Minicom Fig.6.3:

        * Inside "Serial port setup", the option "Serial Device" should be set as shown below:

                              .. image:: Step3_FreeRTOS_RPI4B.png
                                :alt: Diagram
                                :width: 671
                                :height: 378

.. tab-set::

    .. tab-item:: Set Minicom Fig.6.4:

        * Now come back to [configuration] option, scroll down and select "Save setup as dfl":

                              .. image:: Step4_FreeRTOS_RPI4B.png
                                :alt: Diagram
                                :width: 351
                                :height: 270

.. tab-set::

    .. tab-item:: Set Minicom Fig.6.5:

        * Finally select "Exit" from the main configuration as shown below:

                              .. image:: Step5_FreeRTOS_RPI4B.png
                                :alt: Diagram
                                :width: 364
                                :height: 364




        * Power on RPI board, and you would see the following prints:

        .. code-block:: shell

                Welcome to minicom 2.8

                OPTIONS: I18n                                                                
                Port /dev/ttyUSB0, 19:57:47                                                  
                                                                             
                Press CTRL-A Z for help on special keys                                      
                                                                             
                                                                             
                Read start4.elf bytes  2257024 hnd 0x00000064                        
                Missing/empty 'fixup4.dat' continuing                                        
                Firmware: fef7849c350cb250be836afc6d43c742f9ebc97a May  3 2024 19:32:18      
                0x00c03114 0x00000000 0x00001fff                                             
                MEM GPU: 76 ARM: 948 TOTAL: 1024                                             
                Starting start4.elf @ 0xcec00200 partition 0                                 
                PCI reset                                                                    
                +                                                                            

                MESS:00:00:04.025365:0: arasan: arasan_emmc_open
                MESS:00:00:04.027022:0: arasan: arasan_emmc_set_clock C0: 0x00800000 C1: 0x000e0047 emmc: 200000000 actual: 390625 div: 0x00000100 target: 400000 min: 400000 max: 400000 delay: 5
                MESS:00:00:04.147244:0: arasan: arasan_emmc_set_clock C0: 0x00800000 C1: 0x000e0047 emmc: 200000000 actual: 390625 div: 0x00000100 target: 400000 min: 400000 max: 400000 delay: 5
                MESS:00:00:04.160114:0: arasan: arasan_emmc_set_clock C0: 0x00800f00 C1: 0x000e0047 emmc: 200000000 actual: 390625 div: 0x00000100 target: 400000 min: 390000 max: 400000 delay: 5
                MESS:00:00:04.200706:0: arasan: arasan_emmc_set_clock C0: 0x00800f02 C1: 0x000e0407 emmc: 200000000 actual: 25000000 div: 0x00000004 target: 25000000 min: 0 max: 25000000 delay: 1
                MESS:00:00:04.215981:0: brfs: File read: /mfs/sd/config.txt
                MESS:00:00:04.219118:0: brfs: File read: 60 bytes
                MESS:00:00:04.244785:0: HDMI0:EDID error reading EDID block 0 attempt 0
                MESS:00:00:04.249293:0: HDMI0:EDID giving up on reading EDID block 0
                MESS:00:00:04.266231:0: HDMI1:EDID error reading EDID block 0 attempt 0
                MESS:00:00:04.270731:0: HDMI1:EDID giving up on reading EDID block 0
                MESS:00:00:04.276369:0: brfs: File read: /mfs/sd/config.txt
                MESS:00:00:04.810922:0: gpioman: gpioman_get_pin_num: pin DISPLAY_DSI_PORT not defined
                MESS:00:00:04.817884:0: *** Restart logging
                MESS:00:00:04.819640:0: brfs: File read: 60 bytes
                MESS:00:00:04.829216:0: hdmi: HDMI0:EDID error reading EDID block 0 attempt 0
                MESS:00:00:04.834238:0: hdmi: HDMI0:EDID giving up on reading EDID block 0
                MESS:00:00:04.844862:0: hdmi: HDMI0:EDID error reading EDID block 0 attempt 0
                MESS:00:00:04.849891:0: hdmi: HDMI0:EDID giving up on reading EDID block 0
                MESS:00:00:04.855490:0: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
                MESS:00:00:04.869280:0: hdmi: HDMI1:EDID error reading EDID block 0 attempt 0
                MESS:00:00:04.874310:0: hdmi: HDMI1:EDID giving up on reading EDID block 0
                MESS:00:00:04.884932:0: hdmi: HDMI1:EDID error reading EDID block 0 attempt 0
                MESS:00:00:04.889952:0: hdmi: HDMI1:EDID giving up on reading EDID block 0
                MESS:00:00:04.895551:0: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
                MESS:00:00:04.904315:0: HDMI0: hdmi_pixel_encoding: 300000000
                MESS:00:00:04.909783:0: HDMI1: hdmi_pixel_encoding: 300000000
                MESS:00:00:04.925108:0: dtb_file 'bcm2711-rpi-4-b.dtb'
                MESS:00:00:04.937573:0: brfs: File read: /mfs/sd/bcm2711-rpi-4-b.dtb
                MESS:00:00:04.940816:0: Loaded 'bcm2711-rpi-4-b.dtb' to 0x100 size 0xd9f4
                MESS:00:00:04.961040:0: brfs: File read: 55796 bytes
                MESS:00:00:04.982593:0: brfs: File read: /mfs/sd/config.txt
                MESS:00:00:04.998377:0: brfs: File read: 60 bytes
                MESS:00:00:05.000054:0: Failed to open command line file 'cmdline.txt'
                MESS:00:00:05.518838:0: brfs: File read: /mfs/sd/u-boot.bin
                MESS:00:00:05.521309:0: Loaded 'u-boot.bin' to 0x200000 size 0x9e958
                MESS:00:00:05.528060:0: Kernel relocated to 0x80000
                MESS:00:00:05.531980:0: Device tree loaded to 0x7fe2100 (size 0xde62)
                MESS:00:00:05.540281:0: uart: Set PL011 baud rate to 103448.300000 Hz
                MESS:00:00:05.547222:0: uart: Baud rate change done...
                MESS:00:00:05.549241:0:

                U-Boot 2024.07-rc2-00066-g5c5565cfec-dirty (May 08 2024 - 15:46:45 +0530)

                DRAM:  128 MiB (effective 3.1 GiB)
                RPI 4 Model B (0xc03114)
                Core:  212 devices, 16 uclasses, devicetree: board
                MMC:   mmcnr@7e300000: 1, mmc@7e340000: 0
                Loading Environment from FAT... Unable to read "uboot.env" from mmc0:1... 
                In:    serial,usbkbd
                Out:   serial,vidconsole
                Err:   serial,vidconsole
                Net:   eth0: ethernet@7d580000

                PCIe BRCM: link up, 5.0 Gbps x1 (SSC)
                starting USB...
                Bus xhci_pci: Register 5000420 NbrPorts 5
                Starting the controller
                USB XHCI 1.00
                scanning bus xhci_pci for devices... 2 USB Device(s) found
                scanning usb for storage devices... 0 Storage Device(s) found
                Hit any key to stop autoboot:  0 
                Card did not respond to voltage select! : -110
                No EFI system partition
                No EFI system partition
                Failed to persist EFI variables
                No EFI system partition
                Failed to persist EFI variables
                No EFI system partition
                Failed to persist EFI variables
                ** Booting bootflow '<NULL>' with efi_mgr
                Loading Boot0000 'mmc 0' failed
                EFI boot manager: Cannot load any image
                Boot failed (err=-14)
                Card did not respond to voltage select! : -110
                ethernet@7d580000 Waiting for PHY auto negotiation to complete......... TIMEOUT !
                bcmgenet: PHY startup failed: -110
                ethernet@7d580000 Waiting for PHY auto negotiation to complete......... TIMEOUT !
                bcmgenet: PHY startup failed: -110
                U-Boot> 
                U-Boot> 
                U-Boot> 


        * Print the u-boot environment

        .. code-block:: shell

                u-boot > printenv
                arch=arm
                baudrate=115200
                board=rpi
                board_name=4 Model B
                board_rev=0x11
                board_rev_scheme=1
                board_revision=0xC03114
                boot_targets=mmc usb pxe dhcp
                bootcmd=bootflow scan
                bootdelay=2
                cpu=armv8
                dfu_alt_info=u-boot.bin fat 0 1;uboot.env fat 0 1; config.txt fat 0 1;Image fat 0 1
                dhcpuboot=usb start; dhcp u-boot.uimg; bootm
                ethact=ethernet@7d580000
                ethaddr=e4:5f:01:3c:f4:4f
                fdt_addr=7fe2100
                fdt_addr_r=0x02600000
                fdt_high=ffffffffffffffff
                fdtcontroladdr=7b14ee0
                fdtfile=broadcom/bcm2711-rpi-4-b.dtb
                initrd_high=ffffffffffffffff
                kernel_addr_r=0x00080000
                loadaddr=0x1000000
                preboot=pci enum; usb start;
                pxefile_addr_r=0x02500000
                ramdisk_addr_r=0x02700000
                scriptaddr=0x02400000
                serial#=100000000f75b945
                soc=bcm283x
                stderr=serial,vidconsole
                stdin=serial,usbkbd
                stdout=serial,vidconsole
                usb_ignorelist=0x1050:'*',
                usbethaddr=e4:5f:01:3c:f4:4f
                vendor=raspberrypi

                Environment size: 850/16380 bytes


        * Load the OS/Application image from SD Card, using the below commands.

        .. code-block:: c

                u-boot> setenv autostart yes
                u-boot> dcache off
		u-boot> fatload mmc 0:1 0x1000000 freertos.elf
		u-boot> dcache flush
		u-boot> bootelf 0x1000000

        * Code flow is as below

        .. code-block:: c

                do_bootelf                      ---> Source code in "u-boot"
                        entry == _bootd         
                                _boot           ---> Source code in "uart"
                                        main
                
        * Output is as shown below,

        .. code-block:: c

                ****************************
 
                    FreeRTOS UART Sample
                  (This sample uses UART2)
 
                **************************** 

.. panels::
        :container: container pb-4
        :column: col-lg-12 p-2
        :card: shadow

        What is /.bashrc file?

        .. dropdown:: See Answer

                * ??