Martin Str|mberg
2017-Mar-21 06:52 UTC
[syslinux] "isolinux.bin missing or corrupt" when booting USB flash drive in old PC
Thomas Schmitt wrote:> My main point of interest is which block is really loaded as first one > of isolinux.bin.[Program snipped.]> (It could be shorter if i did not insist in big endian words.)Why insisting? Anyway appended is a dumper version. I could put up a binery version if needed. Let me know if so. -- MartinS /* ----------------------------------------------------------------------- * * Copyright 2007-2009 H. Peter Anvin - All Rights Reserved * Copyright 2009 Intel Corporation; author: H. Peter Anvin * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom * the Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall * be included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * ----------------------------------------------------------------------- */ /* * Modified MBR code used on an ISO image in hybrid mode. * * This doesn't follow the El Torito spec at all -- it is just a stub * loader of a hard-coded offset, but that's good enough to load * ISOLINUX. */ #define DEBUG_PRINT 1 #include "adjust.h" .code16 .text HYBRID_MAGIC = 0x7078c0fb isolinux_hybrid_signature = 0x7c00+64 isolinux_start_hybrid = 0x7c00+64+4 .globl bootsec /* Important: the top 6 words on the stack are passed to isolinux.bin */ stack = 0x7c00 partoffset = (stack-8) driveno = (stack-14) heads = (stack-16) sectors = (stack-18) ebios_flag = (stack-20) secpercyl = (stack-24) BIOS_kbdflags = 0x417 BIOS_page = 0x462 /* gas/ld has issues with doing this as absolute addresses... */ .section ".bootsec", "a", @nobits .globl bootsec bootsec: .space 512 .text .globl _start _start: .byte 0x33, 0xed /* xorw %bp, %bp */ cli movw %bp, %ss movw $stack, %sp sti cld /* Check to see if we have a partition table entry */ xorl %ebx, %ebx xorl %ecx, %ecx #ifdef PARTITION_SUPPORT andw %si, %si /* %si == 0 -> no partition data */ jz 1f testb $0x7f, (%si) /* Invalid active flag field? */ jnz 1f cmpb %cl, 4(%si) /* Partition type zero == invalid? */ je 1f cmpl $0x58504721, %eax /* !GPT signature in EAX? */ jne 2f cmpb $0xed, 4(%si) /* EFI partition type? */ jne 2f /* We have GPT partition information */ movl (32+20)(%si), %ecx movl (36+20)(%si), %ebx #ifdef DEBUG_PRINT push %si call print_string .ascii "G\r\n" pop %si #endif jmp 1f /* We have non-GPT partition information */ 2: #ifdef DEBUG_PRINT push %si call print_string .ascii "M\r\n" pop %si #endif movl 8(%si), %ecx #endif 1: /* We have no partition information */ pushl %ebx /* -4: partoffset_hi */ pushl %ecx /* -8: partoffset_lo */ pushw %es /* -10: es:di -> $PnP header */ pushw %di /* -12: es:di -> $PnP header */ movw %bp, %ds movw %bp, %es ADJUST_DRIVE pushw %dx /* -14: dl -> drive number */ /* Copy down to 0:0x600 */ movw $0x7c00, %si movw $_start, %di movw $(512/2), %cx rep; movsw ljmpw $0, $next next: /* Check to see if we have EBIOS */ pushw %dx /* drive number */ movb $0x41, %ah /* %al == 0 already */ movw $0x55aa, %bx xorw %cx, %cx xorb %dh, %dh stc int $0x13 jc 1f cmpw $0xaa55, %bx jne 1f andw $1,%cx /* Bit 0 = fixed disk subset */ jz 1f /* We have EBIOS; patch in the following code at read_sector_cbios: movb $0x42, %ah ; jmp read_common */ movl $0xeb42b4+((read_common-read_sector_cbios-4) << 24), \ (read_sector_cbios) #ifdef DEBUG_PRINT push %si call print_string .ascii "E\r\n" jmp 2f 1: push %si call print_string .ascii "C\r\n" 2: pop %si #else 1: #endif popw %dx pushw %cx /* EBIOS flag */ /* Get (C)HS geometry */ movb $0x08, %ah int $0x13 /* here we computer CHS values or just do some dummy computation for EBIOS */ andw $0x3f, %cx /* Sector count */ popw %bx /* EBIOS flag */ pushw %cx /* -16: Save sectors on the stack */ movzbw %dh, %ax /* dh = max head */ incw %ax /* From 0-based max to count */ pushw %ax /* -18: Save heads on the stack */ mulw %cx /* Heads*sectors -> sectors per cylinder */ pushw %bx /* -20: EBIOS flag */ /* Save sectors/cylinder on the stack */ pushw %dx /* -22: High word */ pushw %ax /* -24: Low word */ /* * Load sectors. We do this one at a time mostly to avoid * pitfalls and to share code with the stock MBR code. */ movw $0x7c00, %bx movw $4, %cx /* Sector count */ movl (lba_offset), %eax 2: call read_sector jc disk_error incl %eax addb $(512 >> 8), %bh loopw 2b /* Dump out the bytes of the first sector. */ pusha mov $0x7c00, %di mov $16, %dx 2: mov $16, %cx 1: mov (%di), %al inc %di call print_al loop 1b call print_string .ascii "\r\n" dec %dx jnz 2b call print_string .ascii "Key?\r\n" xor %ax, %ax int $0x16 popa /* * Okay, that actually worked... update the stack pointer * and jump into isolinux.bin... */ cmpl $HYBRID_MAGIC,(isolinux_hybrid_signature) jne bad_signature cli movw $ebios_flag, %sp /* * Use a ljmpw here to work around a bug in some unknown version * of gas or ld when it comes to jumping to an absolute symbol... * * Look more closely into it if we ever are short on space. */ ljmpw $0, $isolinux_start_hybrid bad_signature: call print_string .ascii "isolinux.bin missing or corrupt.\r\n" boot_failure: int $0x18 /* Boot failure */ die: hlt jmp die /* * read_sector: read a single sector pointed to by %eax to %es:%bx. * CF is set on error. All registers saved. */ read_sector: pushal xorl %edx, %edx addl (partoffset), %eax adcl (partoffset+4), %edx pushl %edx /* MSW of LBA */ pushl %eax /* LSW of LBA */ pushw %es /* Buffer segment */ pushw %bx /* Buffer offset */ pushw $1 /* Sector count */ pushw $16 /* Size of packet */ movw %sp, %si /* This chunk is skipped if we have ebios */ /* Do not clobber %eax before this chunk! */ /* This also relies on %bx and %edx as set up above. */ read_sector_cbios: divl (secpercyl) shlb $6, %ah movb %ah, %cl movb %al, %ch xchgw %dx, %ax divb (sectors) movb %al, %dh orb %ah, %cl incw %cx /* Sectors are 1-based */ movw $0x0201, %ax read_common: movb (driveno), %dl int $0x13 leaw 16(%si), %sp /* Drop DAPA */ popal ret disk_error: call print_string .ascii "Operating system load error.\r\n" jmp boot_failure /* * Prints char in al. * Destroys AH. Possibly BP. */ wrchr: push %bx movb $0x0e, %ah movb (BIOS_page), %bh movb $0x07, %bl int $0x10 /* May destroy %bp */ pop %bx ret /* * Prints byte in AL as hex (e. g. 255 prints FF). * Destroys AX. */ print_al: push %ax shr $4, %al call print_nibble pop %ax print_nibble: and $0x0F, %al cmp $9, %al jbe .wc add $('A'-'0'-10), %al .wc: add $'0', %al call wrchr ret /* * Print message. This is invoked with "call", with the message at the * return address. * Destroys SI. */ print_string: pop %si push %bp push %ax push %bx 2: lodsb call wrchr cmpb $10, %al /* Newline? */ jne 2b pop %bx pop %ax pop %bp push %si ret end_of_code: /* Address of pointer to isolinux.bin */ lba_offset = _start+432
Thomas Schmitt
2017-Mar-21 08:03 UTC
[syslinux] "isolinux.bin missing or corrupt" when booting USB flash drive in old PC
Hi, MartinS wrote:> appended is a dumper version. I could put up a binery version > if needed. Let me know if so.I think we should offer David a binary which he can combine with the MBR of the ISO and the image with the recognizable blocks. I will later today upload a binary version of my block producer and post the URL. The combination will be: 432 bytes from Martin's MBR 80 bytes from the Debian ISO with isolinux block address 647 MiB from my block producer -------------------------------------------------------------------- Looking at the assembler code: What's the meaning of call print_string .ascii "Key?\r\n" How large is the binary currently ? Would there be room to print the (Cylinder, Head, Sector) address in case of CBIOS ? Have a nice day :) Thomas
Thomas Schmitt
2017-Mar-21 08:41 UTC
[syslinux] "isolinux.bin missing or corrupt" when booting USB flash drive in old PC
Hi, i have uploaded a little gz compressed tarball http://scdbackup.webframe.org/block_seq.tgz containing -rwxr-xr-x thomas/thomas 4552 2017-03-21 09:23 block_seq -rw-r--r-- thomas/thomas 315 2017-03-21 09:22 block_seq.c To be unpacked in a suitable directory by tar xvzf block_seq.tgz The binary "block_seq" was compiled on Debian Jessie. If it does not run, do cc -o block_seq block_seq.c to get a locally compiled binary. When Martin posted his MBR binary, the test stick shall be composed by: dd if=martins_mbr.bin bs=1 count=432 of=/dev/sdc dd if=debian-8.7.1-i386-xfce-CD-1.iso bs=1 count=80 seek=432 of=/dev/sdc ./block_seq | dd bs=512 skip=1 count=1325055 seek=1 of=/dev/sdc You will have to copy the screen output by hand or by photo camera. The hopefully lengish hex output of the block content can be truncated to 4 bytes, if all groups of 4 bytes are the same. If you see a change in the 4 byte pattern in the reported text, then all different groups of 4 bytes are of interest. Have a nice day :) Thomas
Martin Str|mberg
2017-Mar-22 07:01 UTC
[syslinux] "isolinux.bin missing or corrupt" when booting USB flash drive in old PC
On Tue, Mar 21, 2017 at 09:03:35AM +0100, Thomas Schmitt via Syslinux wrote:> I think we should offer David a binary which he can combine with > the MBR of the ISO and the image with the recognizable blocks. > I will later today upload a binary version of my block producer > and post the URL. > > The combination will be: > 432 bytes from Martin's MBR > 80 bytes from the Debian ISO with isolinux block address > 647 MiB from my block producer > > -------------------------------------------------------------------- > Looking at the assembler code: > > What's the meaning of > call print_string > .ascii "Key?\r\n"It's waiting for a key because the debian iso displays some graphics stuff so you won't have time to see any of the debug printing.> How large is the binary currently ? > Would there be room to print the (Cylinder, Head, Sector) address in > case of CBIOS ?Yes. It becoming very tight now, so I shortened the error messages. First though I want to say I've managed to simulate David's error in qemu by forcing isohdpfx.bin to fail the EBIOS test. /* Check to see if we have EBIOS */ pushw %dx /* drive number */ movb $0x41, %ah /* %al == 0 already */ movw $0x55aa, %bx xorw %cx, %cx xorb %dh, %dh stc int $0x13 //XXX jc 1f jnc 1f cmpw $0xaa55, %bx jne 1f andw $1,%cx /* Bit 0 = fixed disk subset */ jz 1f With that jc changed to jnc you will invert the result of the EBIOS test and my qemu always has EBIOS. Download the resulting isohdpfx here: <http://www.ludd.ltu.se/~ams/tmp/isohdpfx.force_cbios.bin> Back to Thomas' debug prints. You can download my logger version of isohdpfx called isohdpfd here: <http://www.ludd.ltu.se/~ams/tmp/isohdpfd.bin> <http://www.ludd.ltu.se/~ams/tmp/isohdpfd.S> In the EBIOS case it will print: E<LBA0>/<LBA1>/<LBA2>/<LBA3>/ <Big dump of first loaded sector> Key? and wait for a key press. In the CBIOS case it will print C<LBA0>/<C0>/<H0>/<S0> <LBA1>/<C1>/<H1>/<S1> <LBA2>/<C2>/<H2>/<S2> <LBA3>/<C3>/<H3>/<S3> <Big dump of first loaded sector> Key? and wait for a key press. -- MartinS