Boot sector linked with ld has QEMU print "Hard Disk Boot Failed: not a bootable disk" - ld

A few friends and I are working on a very simple kernel project. At the moment, we have a bootloader (using GNU assembly) and a simple kernel (C with no stdlib). I've been tasked with setting up a QEMU simulation to test the OS, but ran into several issues along the way.
I've gotten QEMU to boot, and I have created a bootable disk image.
Makefile:
%.o: %.S
as -o $# -c $<
bootsect: boot.o
ld -o ./bin/bootsect.bin $^ -nostdlib -Ttext 0x7C00
img: bootsect
dd if=/dev/zero of=boot.img bs=512 count=2880
dd if=./bin/bootsect.bin of=boot.img conv=notrunc bs=512 count=1
I tried to run it with qemu-system-i386 -drive format=raw,file=boot.img
I have also tried various ways of booting the image, but always end up with the same error:
Booting from Hard Disk:
Boot failed: not a bootable disk
Here is the boot loader code if needed:
.code16
.org 0
.text
.global _start
_start:
cli
xorw %ax, %ax
movw %ax, %es
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movw $0x3000, %sp
sti
movw $hello, %si
call print
print:
xorb %bh, %bh
movb $0x0E, %ah
lodsb
cmpb $0, %al
je 1f
int $0x10;
jmp print
1:
ret
hello:
.asciz "HELLO WORLD\n"
.org 510
.word 0xAA55
Where is the problem?

The linker is creating an ELF executable, not a raw binary. You need to extract the raw code contained in the .text section into a stand-alone file, without any wrapping object code format. Only then you can splice that file into the disk image as the boot sector.
There are two ways you can go about doing this. One is to add an extra step to the Makefile that invokes objcopy:
bootsect: bin/bootsect.bin
bin/bootsect.elf: boot.o
ld -o $# $^ -nostdlib -Ttext=0x7c00
%.bin: %.elf
objcopy -Obinary -j.text $< $#
The other is to use a linker script. Put the following in a file named bootsect.ld:
OUTPUT_FORMAT("binary")
SECTIONS {
.image 0x7c00 : {
*(.text)
}
}
And in the Makefile:
bin/bootsect.bin: boot.o bootsect.ld
ld -o $# boot.o -nostdlib -Tbootsect.ld
To check that this works, run file bin/bootsect.bin. It should output ‘DOS/MBR boot sector’.

Related

Issue debugging a 32-bits assembly Hello world with GDB on a Raspberry Pi running a 64 bit version of Linux

I am trying to setup my Raspberry Pi so I can start learning ARM, and have issues debugging 32-bits ARM files. First, some informations maybe useful to my problem:
$ uname -a
Linux raspberrypi 5.15.32-v8+ #1538 SMP PREEMPT Thu Mar 31 19:40:39 BST 2022 aarch64 GNU/Linux
$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
I can write a hello world program (in assembly) for ARM64, compile it using as and ld, then execute it and debug it with gdb without any issue. For 32 bits ARM, after installing the package binutils-arm-linux-gnueabihf, I can compile my files using arm-linux-gnueabihf-as/ld and execute them without issue. However, I have problems debugging them with gdb.
My version of gdb is :
$ gdb -v
GNU gdb (Debian 10.1-1.7) 10.1.90.20210103-git
and I am using the GEF extension. The file command for the 32-bits file gives:
$ file helloworld
helloworld: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped
After typing gdb helloworld, I can run it using the r command and it does print Hello world, but I can't debug it step by step: setting a breakpoint to the entry point (in my case, 0x10074 - obtained with info file -, which does not seem standard) makes the program run indefinitely, as if it was in an infinite loop, and stopping it with CTRL+C gives me:
$sp : 0x798fdfb4
$lr : 0xc6ac9670
$pc : 0x20
$cpsr: [negative ZERO CARRY OVERFLOW INTERRUPT FAST thumb]
────────────────────────────────────────────────────────────────────────────────────────── stack ────
[!] Unmapped address: '0x55798fdfb4'
─────────────────────────────────────────────────────────────────────────────────── code:arm:ARM ────
[!] Cannot disassemble from $PC
[!] Cannot access memory at address 0x20
──────────────────────────────────────────────────────────────────────────────────────── threads ────
[#0] Id 1, Name: "helloworld", stopped 0x20 in ?? (), reason: SIGINT
I am not sure what is going on. The address in Unmapped address: '0x55798fdfb4' looks like a standard .text address under PIE + ASLR, but I don't know why there would be mapping issues. How could I fix this ?
This answer is more an answer to the question: "How can I learn 32 bit assembly language on my raspberry Pi" than a direct answer to yours:
If your goal is to learn Aarch32 T32 or A32 assembly language on your raspberry Pi, I would strongly suggest to do so on a 32 bit distribution - I am not sure at this stage that you can debug a user mode Aarch32 program on an Aarch64 Linux system using an Aarch64 multiarch GDB or an Aarch32 version of GDB, my own attempts having been unsuccessful, and having not found to this day examples of how exactly to do this.
Another pro of this approach is that you will be able to concentrate on learning 32 bit Arm, and not asking yourself if your programs are not working because of a bug, or because off a potential problem/bug in the tools you are running on your Aarch64 system - my two cents.
If you have a spare 8GiB micro-SD card, you can install a 32 bit version of Ubuntu Server 22.04 from here.
One installed, here is what I am getting on my system:
cat /sys/firmware/devicetree/base/model
Raspberry Pi 3 Model B Rev 1.2
uname -a
Linux ubuntu 5.15.0-1005-raspi #5-Ubuntu SMP PREEMPT Mon Apr 4 12:25:49 UTC 2022 armv7l armv7l armv7l GNU/Linux
Install gcc and gdb:
sudo-apt -get install gcc gdb
Create hello-world.s, adapted from this example:
.arch armv7a
.file "hello-world.s"
.text
.global main
.syntax unified
.thumb
.thumb_func
.type main, %function
main:
mov r0, #1 # 1 = stdout
ldr r1, =hello_world # str pointer
mov r2, #13 # str len
mov r7, #4 # linux write syscall
svc 0 # software interrupt call write
exit:
mov r0, #0 # return code
mov r7, #1 # linux exit syscall
svc 0 # software interrupt call exit
.data
hello_world:
.ascii "Hello World!\n"
.end
as -g -o hello-world.o hello-world.s
gcc -g -o hello-world hello-world.o
./hello-world
Hello World!
GDB debug session:
gdb ./hello-world
GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./hello-world...
(gdb) b main
Breakpoint 1 at 0x4e0: file hello-world.s, line 10.
(gdb) run
Starting program: /home/ubuntu/hello-world
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
Breakpoint 1, main () at hello-world.s:10
10 mov r0, #1 # 1 = stdout
(gdb) step
11 ldr r1, =hello_world # str pointer
(gdb)
12 mov r2, #13 # str len
(gdb)
13 mov r7, #4 # linux write syscall
(gdb)
14 svc 0 # software interrupt call write
(gdb)
Hello World!
exit () at hello-world.s:16
16 mov r0, #0 # return code
(gdb)
17 mov r7, #1 # linux exit syscall
(gdb)
18 svc 0 # software interrupt call exit
(gdb)
[Inferior 1 (process 3043) exited normally]
(gdb) quit

Raspberry Pi 4B + U-Boot bootloader - device tree addresses (.dtb)

I compiled U-Boot (#v2022.01-rc1) with untouched rpi_4_defconfig. The U-Boot loads into shell successfuly, however
entering this sequence of commands will get stuck on "Starting kernel ...":
setenv serverip 192.168.0.1
setenv ipaddr 192.168.0.10
setenv kernel_comp_addr_r 0x0A000000
setenv kernel_comp_size 7921972
tftp ${kernel_addr_r} kernel8.img
tftp ${fdt_addr_r} bcm2711-rpi-4-b.dtb
booti ${kernel_addr_r} - ${fdt_addr_r} // Gets stuck at Starting kernel...
However, if I replace ${fdt_addr_r} with ${fdt_addr} in booti command it will load the kernel successfully. Like this:
booti ${kernel_addr_r} - ${fdt_addr} // Works fine
What is the difference between ${fdt_addr_r} and ${fdt_addr}? Why doesn't my first approach work? Why does ${fdt_addr} work?
DEBUG INFO:
RPi firmware boot logs:
Read start4.elf bytes 2228768 hnd 0x00000072
Read fixup4.dat bytes 5446 hnd 0x00000067
Firmware: d7f29d96450abfc77cd6cf011af1faf1e03e5e56 Apr 30 2021 13:45:52
0x00c03112 0x00000000 0x000000ff
MEM GPU: 76 ARM: 948 TOTAL: 1024
Starting start4.elf # 0xfec00200 partition 0
PCI reset
+
MESS:00:00:05.184648:0: arasan: arasan_emmc_open
MESS:00:00:05.332928:0: brfs: File read: /mfs/sd/config.txt
MESS:00:00:05.335639:0: brfs: File read: 81 bytes
MESS:00:00:05.402894:0: brfs: File read: /mfs/sd/config.txt
MESS:00:00:05.421071:0: brfs: File read: 81 bytes
MESS:00:00:05.902232:0: gpioman: gpioman_get_pin_num: pin DISPLAY_DSI_PORT not defined
MESS:00:00:05.909524:0: *** Restart logging
MESS:00:00:05.914477:0: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
MESS:00:00:05.923831:0: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
MESS:00:00:05.929762:0: HDMI0: hdmi_pixel_encoding: 300000000
MESS:00:00:05.935229:0: HDMI1: hdmi_pixel_encoding: 300000000
MESS:00:00:05.945421:0: dtb_file 'bcm2711-rpi-4-b.dtb'
MESS:00:00:05.952218:0: brfs: File read: /mfs/sd/bcm2711-rpi-4-b.dtb
MESS:00:00:05.955466:0: Loading 'bcm2711-rpi-4-b.dtb' to 0x100 size 0xc2a9
MESS:00:00:05.974659:0: brfs: File read: 49833 bytes
MESS:00:00:06.039897:0: brfs: File read: /mfs/sd/config.txt
MESS:00:00:06.042389:0: brfs: File read: 81 bytes
MESS:00:00:06.047663:0: brfs: File read: /mfs/sd/overlays/disable-bt.dtbo
MESS:00:00:06.067534:0: Loaded overlay 'disable-bt'
MESS:00:00:06.107041:0: brfs: File read: 1073 bytes
MESS:00:00:06.108885:0: Failed to open command line file 'cmdline.txt'
MESS:00:00:07.249713:0: brfs: File read: /mfs/sd/u-boot.bin
MESS:00:00:07.252181:0: Loading 'u-boot.bin' to 0x80000 size 0x8f720
MESS:00:00:07.258265:0: Device tree loaded to 0x2eff3800 (size 0xc743)
MESS:00:00:07.266568:0: uart: Set PL011 baud rate to 103448.300000 Hz
MESS:00:00:07.273628:0: uart: Baud rate change done...
MESS:00:00:07.275688:0: uart: Baud rate change done...
MESS:00:00:07.281220:0: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined
U-Boot log:
U-Boot 2022.01-rc1 (Nov 11 2021 - 15:59:50 +0100)
DRAM: 3.9 GiB
RPI 4 Model B (0xc03112)
MMC: mmcnr#7e300000: 1, mmc#7e340000: 0
Loading Environment from FAT... Unable to read "uboot.env" from mmc0:1... In: serial
Out: serial
Err: serial
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: 2
U-boot environment (without entering any commands, or modifying env in any way):
arch=arm
baudrate=115200
board=rpi
board_name=4 Model B
board_rev=0x11
board_rev_scheme=1
board_revision=0xC03112
boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr}
boot_efi_binary=load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} efi/boot/bootaa64.efi; if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r};else bootefi ${kernel_addr_r} ${fdtcontroladdr};fi
boot_efi_bootmgr=if fdt addr ${fdt_addr_r}; then bootefi bootmgr ${fdt_addr_r};else bootefi bootmgr;fi
boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} ${prefix}${boot_syslinux_conf}
boot_net_usb_start=usb start
boot_pci_enum=pci enum
boot_prefixes=/ /boot/
boot_script_dhcp=boot.scr.uimg
boot_scripts=boot.scr.uimg boot.scr
boot_syslinux_conf=extlinux/extlinux.conf
boot_targets=mmc0 mmc1 usb0 pxe dhcp
bootcmd=run distro_bootcmd
bootcmd_dhcp=devtype=dhcp; run boot_net_usb_start; run boot_pci_enum; if dhcp ${scriptaddr} ${boot_script_dhcp}; then source ${scriptaddr}; fi;setenv efi_fdtfile ${fdtfile}; setenv efi_old_vci ${bootp_vci};setenv efi_old_arch ${bootp_arch};setenv bootp_vci PXEClient:Arch:00011:UNDI:003000;setenv bootp_arch 0xb;if dhcp ${kernel_addr_r}; then tftpboot ${fdt_addr_r} dtb/${efi_fdtfile};if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r}; else bootefi ${kernel_addr_r} ${fdtcontroladdr};fi;fi;setenv bootp_vci ${efi_old_vci};setenv bootp_arch ${efi_old_arch};setenv efi_fdtfile;setenv efi_old_arch;setenv efi_old_vci;
bootcmd_mmc0=devnum=0; run mmc_boot
bootcmd_mmc1=devnum=1; run mmc_boot
bootcmd_pxe=run boot_net_usb_start; run boot_pci_enum; dhcp; if pxe get; then pxe boot; fi
bootcmd_usb0=devnum=0; run usb_boot
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
distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done
efi_dtb_prefixes=/ /dtb/ /dtb/current/
ethaddr=dc:a6:32:5f:91:f4
fdt_addr=2eff3800
fdt_addr_r=0x02600000
fdt_high=ffffffffffffffff
fdtcontroladdr=3af44630
fdtfile=broadcom/bcm2711-rpi-4-b.dtb
initrd_high=ffffffffffffffff
kernel_addr_r=0x00080000
load_efi_dtb=load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} ${prefix}${efi_fdtfile}
loadaddr=0x1000000
mmc_boot=if mmc dev ${devnum}; then devtype=mmc; run scan_dev_for_boot_part; fi
preboot=pci enum; usb start;
pxefile_addr_r=0x02500000
ramdisk_addr_r=0x02700000
scan_dev_for_boot=echo Scanning ${devtype} ${devnum}:${distro_bootpart}...; for prefix in ${boot_prefixes}; do run scan_dev_for_extlinux; run scan_dev_for_scripts; done;run scan_dev_for_efi;
scan_dev_for_boot_part=part list ${devtype} ${devnum} -bootable devplist; env exists devplist || setenv devplist 1; for distro_bootpart in ${devplist}; do if fstype ${devtype} ${devnum}:${distro_bootpart} bootfstype; then run scan_dev_for_boot; fi; done; setenv devplist
scan_dev_for_efi=setenv efi_fdtfile ${fdtfile}; for prefix in ${efi_dtb_prefixes}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${efi_fdtfile}; then run load_efi_dtb; fi;done;run boot_efi_bootmgr;if test -e ${devtype} ${devnum}:${distro_bootpart} efi/boot/bootaa64.efi; then echo Found EFI removable media binary efi/boot/bootaa64.efi; run boot_efi_binary; echo EFI LOAD FAILED: continuing...; fi; setenv efi_fdtfile
scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${boot_syslinux_conf}; then echo Found ${prefix}${boot_syslinux_conf}; run boot_extlinux; echo SCRIPT FAILED: continuing...; fi
scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${script}; then echo Found U-Boot script ${prefix}${script}; run boot_a_script; echo SCRIPT FAILED: continuing...; fi; done
scriptaddr=0x02400000
serial#=100000009b911a03
soc=bcm283x
stderr=serial,vidconsole
stdin=serial,usbkbd
stdout=serial,vidconsole
usb_boot=usb start; if usb dev ${devnum}; then devtype=usb; run scan_dev_for_boot_part; fi
usbethaddr=dc:a6:32:5f:91:f4
vendor=raspberrypi
Environment size: 4113/16380 bytes
U-boot process of entering commands and booting the kernel:
U-Boot> setenv serverip 192.168.0.1
U-Boot> setenv ipaddr 192.168.0.10
U-Boot> setenv kernel_comp_addr_r 0x0A000000
U-Boot> setenv kernel_comp_size 7921972
U-Boot> tftp ${kernel_addr_r} kernel8.img
Using ethernet#7d580000 device
TFTP from server 192.168.0.1; our IP address is 192.168.0.10
Filename 'kernel8.img'.
Load address: 0x80000
Loading: *################################################## 7.6 MiB
13.9 MiB/s
done
Bytes transferred = 7921972 (78e134 hex)
U-Boot> tftp ${fdt_addr_r} bcm2711-rpi-4-b.dtb
Using ethernet#7d580000 device
TFTP from server 192.168.0.1; our IP address is 192.168.0.10
Filename 'bcm2711-rpi-4-b.dtb'.
Load address: 0x2600000
Loading: *################################################## 48.7 KiB
5.3 MiB/s
done
Bytes transferred = 49833 (c2a9 hex)
U-Boot> booti ${kernel_addr_r} - ${fdt_addr_r}
Uncompressing Kernel Image
Moving Image from 0x80000 to 0x200000, end=17f0000
## Flattened Device Tree blob at 02600000
Booting using the fdt blob at 0x2600000
Using Device Tree in place at 0000000002600000, end 000000000260f2a8
Starting kernel ... // <------ !!!! stuck here forever
Regarding ${fdt_addr} and ${fdt_addr_r}:
The u-boot rpi_4_defconfig configures CONFIG_OF_BOARD. By this option u-boot does not use its own device tree, but it receives the device tree which is provided by the eeprom bootloader of the Raspberry Pi 4. The RPi bootloader already prepares the device tree depending on the options in the file config.txt of the boot partition, including dt-overlays and including bootargs specified in cmdline.txt.
So the device tree located at address ${fdt_addr} is the device tree prepared by the Raspberry Pi bootloader. This might be the reason why booting using ${fdt_addr} works. As a consequence, you don't have to necessarily prepare and load a device tree on your own on the Raspberry Pi. You could just reuse ${fdt_addr} in the u-boot booti command as it is already loaded.
If you choose to load your own device tree, compare its contents with the configuration in config.txt (especially the dtoverlay=..). Also check cmdline.txt for bootargs. In your u-boot command list you did not set any bootargs with setenv bootargs ....
As mentioned by sawdust you could use setenv bootargs 'earlycon=uart8250,mmio32,0xfe215040 console=serial0,115200 ...' for getting debug infos on the miniuart serial line.

Buildroot + U-Boot + Rpi4 : Error zImage Bad Magic

I am working on a project where I want to create my own embedded linux with U-Boot. Therefore I am working with buildroot, which i recently start learning. After successfully creating my own rasberrypi4_defconfig i am currently struggling at the problem to get u-boot work correctly.
What versions I am working with:
Rpi 4
buildroot-2019.11
u-boot (therefore i pull everyday the new changes)
Current State of the work:
I build on a Ubuntu(32bit). I configure buildroot with the raspberrypi4_defconfig and make it without changes. Then i make a u-boot defconfig for rpi_4_32b_defconfig and create the u-boot.bin with make CROSS_COMPILE=arm-linux-gnueabihf- u-boot.bin
Now my next step was to configure the config.txt and exchange the content with following:
enalbe_uart=1
kernel=u-boot.bin
In addition i copyied my u-boot.bin into my sd-card.
The last step that i actually did is to build my own boot.scr.uimg with following content
fatload mmc O:1 ${fdt_addr_r} bcm2711-rpi-4-b.dtb
fatload mmc 0:1 ${kernel_addr_r} Image.4.8
setenv bootargs console=ttyS0, 115200 \
root=/dev/mmcblk0p2 rootfstype=ext4 rootwait rw
bootz ${kernel_addr_r} - ${fdt_addr_r}
Problem
So far i am archieving to reach the U-boot menu but on booting i get the error: zimage Bad Magic
I actually thing that my boot.scr.uimg is maybe not correct but dont get it.
Boot Log
After calling boot following is printed:
U-Boot 2020.01-rc4-00066-g7e5ee346fc (Dec 05 2019 - 16:55:27 +0100)
DRAM: 948 MiB
RPI 4 Model B (0xc03111)
MMC: emmc2#7e340000: 0, mmcnr#7e300000: 1
Loading Environment from FAT... *** Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
Net: Net Initialization Skipped
No ethernet found.
Hit any key to stop autoboot: 0
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found U-Boot script /boot.scr.uimg
291 bytes read in 17 ms (16.6 KiB/s)
## Executing script at 02400000
40559 bytes read in 33 ms (1.2 MiB/s)
zimage: Bad magic!
SCRIPT FAILED: continuing...
40559 bytes read in 29 ms (1.3 MiB/s)
Card did not respond to voltage select!
No ethernet found.
missing environment variable: pxeuuid
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/00000000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/0000000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/000000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/00000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/0000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/00
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/0
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/default-arm-bcm283x-rpi
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/default-arm-bcm283x
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/default-arm
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/default
No ethernet found.
Config file not found
No ethernet found.
No ethernet found.
Environment
arch=arm
baudrate=115200
board=rpi
board_name=4 Model B
board_rev=0x11
board_rev_scheme=1
board_revision=0xC03111
boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr}
boot_efi_binary=if fdt addr ${fdt_addr_r}; then bootefi bootmgr ${fdt_addr_r};else bootefi bootmgr ${fdtcontroladdr};fi;load ${devty
pe} ${devnum}:${distro_bootpart} ${kernel_addr_r} efi/boot/bootarm.efi; if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${f
dt_addr_r};else bootefi ${kernel_addr_r} ${fdtcontroladdr};fi
boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} ${prefix}${boot_syslinux_conf}
boot_prefixes=/ /boot/
boot_script_dhcp=boot.scr.uimg
boot_scripts=boot.scr.uimg boot.scr
boot_syslinux_conf=extlinux/extlinux.conf
boot_targets=mmc0 mmc1 pxe dhcp
bootargs=console=ttyS0,115200 \
root=/dev/mmcblk0p2 rootfstype=ext4 rootwait rw
bootcmd=run distro_bootcmd
bootcmd_dhcp=if dhcp ${scriptaddr} ${boot_script_dhcp}; then source ${scriptaddr}; fi;setenv efi_fdtfile ${fdtfile}; if test -z "${f
dtfile}" -a -n "${soc}"; then setenv efi_fdtfile ${soc}-${board}${boardver}.dtb; fi; setenv efi_old_vci ${bootp_vci};setenv efi_old_
arch ${bootp_arch};setenv bootp_vci PXEClient:Arch:00010:UNDI:003000;setenv bootp_arch 0xa;if dhcp ${kernel_addr_r}; then tftpboot $
{fdt_addr_r} dtb/${efi_fdtfile};if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r}; else bootefi ${kernel_addr_r
} ${fdtcontroladdr};fi;fi;setenv bootp_vci ${efi_old_vci};setenv bootp_arch ${efi_old_arch};setenv efi_fdtfile;setenv efi_old_arch;s
etenv efi_old_vci;
bootcmd_mmc0=devnum=0; run mmc_boot
bootcmd_mmc1=devnum=1; run mmc_boot
bootcmd_pxe=dhcp; if pxe get; then pxe boot; fi
bootdelay=2
bootfstype=fat
cpu=armv7
dhcpuboot=usb start; dhcp u-boot.uimg; bootm
distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done
efi_dtb_prefixes=/ /dtb/ /dtb/current/
ethaddr=dc:a6:32:45:1f:d1
fdt_addr=2eff5d00
fdt_addr_r=0x02600000
fdt_high=ffffffff
fdtcontroladdr=3af6ac98
fdtfile=bcm2711-rpi-4-b.dtb
fileaddr=2600000
filesize=9e6f
initrd_high=ffffffff
kernel_addr_r=0x00080000
load_efi_dtb=load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} ${prefix}${efi_fdtfile}
loadaddr=0x00200000
mmc_boot=if mmc dev ${devnum}; then devtype=mmc; run scan_dev_for_boot_part; fi
pxefile_addr_r=0x02500000
ramdisk_addr_r=0x02700000
scan_dev_for_boot=echo Scanning ${devtype} ${devnum}:${distro_bootpart}...; for prefix in ${boot_prefixes}; do run scan_dev_for_extlinux; run scan_dev_for_scripts; done;run scan_dev_for_efi;
scan_dev_for_boot_part=part list ${devtype} ${devnum} -bootable devplist; env exists devplist || setenv devplist 1; for distro_bootpart in ${devplist}; do if fstype ${devtype} ${devnum}:${distro_bootpart} bootfstype; then run scan_dev_for_boot; fi; done; setenv devplist
scan_dev_for_efi=setenv efi_fdtfile ${fdtfile}; if test -z "${fdtfile}" -a -n "${soc}"; then setenv efi_fdtfile ${soc}-${board}${boardver}.dtb; fi; for prefix in ${efi_dtb_prefixes}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${efi_fdtfile}; then run load_efi_dtb; fi;done;if test -e ${devtype} ${devnum}:${distro_bootpart} efi/boot/bootarm.efi; then echo Found EFI removable media binary efi/boot/bootarm.efi; run boot_efi_binary; echo EFI LOAD FAILED: continuing...; fi; setenv efi_fdtfile
scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${boot_syslinux_conf}; then echo Found ${prefix}${boot_syslinux_conf}; run boot_extlinux; echo SCRIPT FAILED: continuing...; fi
scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${script}; then echo Found U-Boot script ${prefix}${script}; run boot_a_script; echo SCRIPT FAILED: continuing...; fi; done
scriptaddr=0x02400000
serial#=10000000f58b842c
soc=bcm283x
stderr=serial,vidconsole
stdin=serial,usbkbd
stdout=serial,vidconsole
usbethaddr=dc:a6:32:45:1f:d1
vendor=raspberrypi
Environment size: 3996/16380 bytes
So far i am archieving to reach the U-boot menu but on booting i get the error: zimage Bad Magic I actually thing that my boot.scr.uimg is maybe not correct but dont get it.
That error message traces back to the contents of your boot.scr.uimg:
fatload mmc 0:1 ${kernel_addr_r} Image.4.8
...
bootz ${kernel_addr_r} - ${fdt_addr_r}
The bootz command expects a zImage file at the first memory address.
But the prior fatload command has copied a file named Image.4.8 into memory.
By convention an Image file is the generic Linux kernel binary image file, whereas a zImage file is a compressed version of the Linux kernel image that is self-extracting.
You need to install the zImage that you built (instead of the Image file) to the SD card. Edit your boot.scr.uimg to indicate the proper file type/name.
ADDENDUM
U-Boot does have a booti command for the generic Linux kernel binary Image file, but that command is intended only for ARM64, e.g. the built-in help text is boot arm64 Linux Image image from memory.
See the patch that configures that command.

Binutils LD creates huge files

I'm trying to create as small ELF as possible. I created a test file like this (NASM syntax):
SECTION .text
dd 0xdeadbeef
With this linker script:
SECTIONS {
.text : {
*(.text)
}
}
Then I checked sizes of flat binary and ELFs built two ways:
nasm -f bin -o test test.asm
It's flat binary, so 4 bytes.
nasm -f elf -o test.o test.asm
i686-elf-ld -Tlinker.ld test.o -o test
I'd expect something like 500 bytes max, but the resulting file is 4396 bytes long! There is an option however, named --strip-all, that could make this file smaller.
i686-elf-ld -Tlinker.ld test.o -o test --strip-all
4244 bytes. Still huge.
Why is LD generating so big files? Is there a way to make it smaller?
The linker is page aligning your text section to the nearest page boundary so that demand paging can be used.
$ objdump --headers -f test
test: file format elf32-i386
architecture: i386, flags 0x00000102:
EXEC_P, D_PAGED
start address 0x00000000
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000004 00000000 00000000 00001000 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
Notice the "Align" column of the text section is set to 4KB. Because of the alignment is set to 4Kb and demand paging is in use (D_PAGED), the .text section is located 4Kb into the file. Your text section is only 4 bytes long.
Link with -n to disable demand paging:
$ ld -Tlinker.ld test.o -o test --strip-all -n
$ objdump --headers -f test
test: file format elf32-i386
architecture: i386, flags 0x00000002:
EXEC_P
start address 0x00000000
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000004 00000000 00000000 00000060 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
$ ls -l test
-rwxrwxr-x 1 mikel mikel 240 Apr 15 12:31 test

cdb/windbg output too large

We are using cdb (command line version of winDBG) to resolve a cab.
For getting the output in a file we are using the -logo output to specify the output file.
For a certain cab we are getting "CvRegToMachine(x86) conversion failure for 0x7536" more than a million times.
Basically we get a huge resolved code log, nearly 1GB, and all of it filled with the above string on each line.
We are using the following cdb command
cdb -z "abc.cab" -y "SymbolsPath" -G -logo "outputfile" -lines -c ".kframes 100;!analyze -v;!load msec.dll;!exploitable -v;vertarget;lmv;q"
Does anyone have any clue about what could be wrong here?
you cannot use -c and -G at the same time -c needs the first break to read the initial
command and act upon it if you need to run the code use g; at the end of -c commands
also many times -c commands need to be provided first and the debugee needs
to be at the end of commandline
cdb -c "<some cmd;someother cmd;g>" -z foo.cab
.load not !load should be used to load third party extensions
the string emitted "CvReg.........." seems to be related to Either SYMFLAG_NULL or SYMFLAG_REGISTER in the Flags member of SYMBOLINFO Struct .
a sample trial didnt cross that code path in my machine so either the corrupt dmp or more information regarding the dmp file may be needed to find the reason for the spew
creating dump
C:\>dir /b *.cab
File Not Found
C:\>cdb -c ".dump /ma /b foo.cab;q" calc | grep -i -E "dmp|dump|wr"
0:000> cdb: Reading initial command '.dump /ma /b foo.cab;q'
Creating C:\DOCUME~1\Admin\LOCALS~1\Temp\foo.cab.dmp - mini user dump
Dump successfully written
Adding C:\DOCUME~1\Admin\LOCALS~1\Temp\foo.cab.dmp - added
Wrote foo.cab
C:\>dir /b *.cab
foo.cab
**loading dump as debugees(cdb) debuggee (foo.cab) and looking around **
C:\>cdb cdb -z foo.cab
0:000> s -u dbgeng l?39b000 "CvReg"
020341f8 0043 0076 0052 0065 0067 0054 006f 004d C.v.R.e.g.T.o.M.
0:000> # *(*20341f8 dbgeng l?39b000
dbgeng!MachineInfo::CvRegToMachine+0xfe:
021bf8ae 68f8410302 push offset dbgeng!`string' (020341f8)
0:000> # call*dbgeng!MachineInfo::CvRegToMachine dbgeng l?39b000
dbgeng!ImageInfo::CvRegToMachine+0x22:
021b62f2 e8b9940000 call dbgeng!MachineInfo::CvRegToMachine (021bf7b0)
0:000> # call*CvRegToMachine dbgeng l?39b000
dbgeng!ImageInfo::CvRegToMachine+0x22:
021b62f2 e8b9940000 call dbgeng!MachineInfo::CvRegToMachine (021bf7b0)
dbgeng!TypeInfoValueFromSymInfo+0x4b:
022541ab e82021f6ff call dbgeng!ImageInfo::CvRegToMachine (021b62d0)
dbgeng!TypedData::SetToSymbol+0x25f:
02285edf e8ec03f3ff call dbgeng!ImageInfo::CvRegToMachine (021b62d0)
dbgeng!TypedData::SetToSymbol+0x2da:
02285f5a e87103f3ff call dbgeng!ImageInfo::CvRegToMachine (021b62d0)
0:000> ln 0x21bf8ae
(021bf7b0) dbgeng!MachineInfo::CvRegToMachine+0xfe | (021bf8d0) dbgeng!Ma
chineInfo::GetContextState
doing and uf on this function yields the check where SymbolInfo->Flags is
checked and decided my sample dump above doesnt enter the path