NAS542 bootloop after Debian/OMV (get a new firmware) (solved)

Options
1246710

Comments

  • Triu
    Triu Posts: 46  Freshman Member
    edited June 2019
    Options
    Depends on the tool you use to show the content

    Oh, didn't know that, will go through all files again. Thought it depends on the monitor itselft and it would scroll automatically when i mark it with the mouse. Thank you. Unfortunately i have no vi, nano etc. All i have is "edit".

    Oh yeah, there is alot more to see now. I post everything here so no need to scroll to the earlier post. Hope i didn't miss something.

    /env/config:

    #!/bin/sh

    # use 'dhcp' to do dhcp in barebox and in kernel
    # use 'none' if you want to skip kernel ip autoconfiguration
    ip=dhcp

    # or set your networking parameters here
    #eth0.ipaddr=192.168.2.22
    #eth0.netmask=255.255.255.0
    eth0.serverip=192.168.1.70
    #eth0.gateway=192.168.2.1
    #eth0.ethaddr=00:0A:0B:0C:0D:0E
    #eth1.ethaddr=00:1A:1B:1C:1D:1E
    #eth2.ethaddr=00:2A:2B:2C:2D:2E

    # can be either 'nfs', 'tftp' , 'nor' , 'nand' and 'sata'
    kernel_loc=nand
    #kernel_loc=nor
    #kernel_loc=sata
    # can be either 'net', 'nor' ,'initrd' , 'nand' and 'sata'
    rootfs_loc=nand
    #rootfs_loc=nor
    #rootfs_loc=sata

    # barebox images
    uloaderimage=microloader-c2kevm.bin
    bareboximage=barebox-c2kevm.bin

    # MFG images for NAND flash
    mfg_kernel_img=uImage_MFG
    mfg_rootfs_img=rootfs_ubi.img_MFG

    # can be either 'jffs2' , 'ubifs' or 'ext4
    #rootfs_type=jffs2
    rootfs_type=ubifs
    #rootfs_type=ext4
    rootfsimage=root.$rootfs_type-128k

    # The image type of the kernel. Can be uimage, zimage, raw, or raw_lzo
    kernelimage_type=uimage
    kernelimage=uImage

    #nfsroot="$eth0.serverip:/opt/work/busybox/rootfs_arm"

    spi_parts="256k(uloader)ro,512k(barebox)ro,256k(env)"
    spi_device="spi0.0"

    nand_device="comcertonand"
    #nand_parts="1024k(barebox)ro,1024k(bareboxenv),4M(kernel),-(rootfs)"
    nand_parts="10M(config),10M(kernel1),110M(rootfs1),10M(kernel2),110M(rootfs2),-(
    #rootfs_mtdblock_nand=8
    rootfs_mtdblock_nand=2

    #nor_parts="128k(uloader)ro,512k(barebox)ro,128k(env),4M(kernel),48M(rootfs)"
    #nor_device="comcertoflash.0"
    #rootfs_mtdblock_nor=4

    autoboot_timeout=3

    usb3_internal_clk="yes"

    bootargs="console=ttyS0,115200n8, init=/etc/preinit pcie_gen1_only=yes "
    bootargs="$bootargs mac_addr=$eth0.ethaddr,$eth1.ethaddr,$eth2.ethaddr"

    # boot partition
    next_bootfrom="1"
    curr_bootfrom="2"

    # partition layout
    kernel_mtd_1=4
    sysimg_mtd_1=5
    kernel_mtd_2=6
    sysimg_mtd_2=7

    # MODEL ID for STG-540
    MODEL_ID="B403"
    fwversion_1="V5.20(ABAG.1)"
    revision_1="50683"
    modelid_1="B403"
    core_checksum_1="2d4c3dbbbcb5ba8d40f7ed3591c1f3cc"
    zld_checksum_1="db2960ca9ac1c1d09ea54ef3dc836989"
    romfile_checksum_1="21E7"
    img_checksum_1="7b31cf25f28a0a40d1463cdd5c3d35b9"
    fwversion_2="V5.20(ABAG.1)"
    revision_2="50683"
    modelid_2="B403"
    core_checksum_2="2d4c3dbbbcb5ba8d40f7ed3591c1f3cc"
    zld_checksum_2="db2960ca9ac1c1d09ea54ef3dc836989"
    romfile_checksum_2="21E7"
    img_checksum_2="7b31cf25f28a0a40d1463cdd5c3d35b9"
    ethaddr="5C:F4:AB:67:B1:BC"
    eth2addr="5C:F4:AB:67:B1:BD"
    serial_number="S150Z47005461"
    change_boot_part="0"
    /env/bin/update:
    #!/bin/sh

    type=""
    device_type=""
    check=n
    mode=tftp

    . /env/config

    while getopt "ht:d:f:a:s:m:c" Option
    do
    if [ ${Option} = t ]; then
            type=${OPTARG}
    elif [ ${Option} = d ]; then
            device_type=${OPTARG}
    elif [ ${Option} = f ]; then
            imagename=${OPTARG}
    elif [ ${Option} = a ]; then
            address=${OPTARG}
    elif [ ${Option} = s ]; then
            size=${OPTARG}
    elif [ ${Option} = c ]; then
            check=y
    elif [ ${Option} = m ]; then
            mode=${OPTARG}
    else
            . /env/bin/_update_help
            exit 0
    fi
    done

    if [ x${type} = xkernel ]; then
            image=$kernelimage
    elif [ x${type} = xkernel1 ]; then
            image=$kernelimage
    elif [ x${type} = xkernel2 ]; then
            image=$kernelimage
    elif [ x${type} = xrootfs ]; then
            image=$rootfsimage
    elif [ x${type} = xrootfs1 ]; then
            image=$rootfsimage
    elif [ x${type} = xrootfs2 ]; then
            image=$rootfsimage
    elif [ x${type} = xbarebox ]; then
            image=$bareboximage
            if [ x${image} = x ]; then
                    image=barebox.bin
            fi
    elif [ x${type} = xuloader ]; then
            image=$uloaderimage
    elif [ x${type} = xbareboxenv ]; then
            image=$bareboxenvimage
            if [ x${image} = x ]; then
                    image=bareboxenv.bin
            fi
            type=env
    else
            . /env/bin/_update_help
            exit 1
    fi

    if [ x${imagename} != x ]; then
            image=${imagename}
    fi

    if [ x${device_type} = xnand ]; then
            part=/dev/nand0.${type}.bb
    elif [ x${device_type} = xnor ]; then
            part=/dev/nor0.${type}
    else
            . /env/bin/_update_help
            exit 1
    fi

    if [ x${mode} != xtftp ] && [ x${mode} != xxmodem ] && [ x${mode} != xddr ]; the
            echo "unsupported mode ${mode}."
            . /env/bin/_update_help
            exit 1
    fi

    . /env/bin/_update || exit 1

    if [ x${check} = xy ]; then
            if [ x${mode} = xddr ]; then
                    crc32 -f $part
                    crc32 $address+$size
            elif [ x${mode} = xtftp ]; then
                    crc32 -f $part
            else
                    crc32 -f $image -F $part
            fi
    else
            true
    fi
    /env/bin/update_rootfs
    #!/bin/sh

    . /env/bin/update -t rootfs -d $1
    /env/bin/_update
    #!/bin/sh

    uloader 2011.06.0 (May 20 2014 - 16:36:41)
            if [ -z "$part" -o -z "$address" -o -z "$size" ]; then
    Board: Mindspeed C2000define \$part, \$address and \$size"
    c2k_spi_probe   exit 1
            fi
    Copying Barebox from SPI Flash(bootopt=0)
            if [ -z "$part" -o -z "$image" ]; then
                    echo "define \$part and \$image"
                    exit 1
            fi
    fi

    if [ ! -e "$part" ]; then
            echo "Partition $part does not exist"
            exit 1
    fi

    if [ x$mode = xtftp ]; then
            if [ x$ip = xdhcp ]; then
                    dhcp
            fi

            ping $eth0.serverip
            if [ $? -ne 0 ] ; then
                    echo "Server did not reply! Update aborted."
                    exit 1
            fi

    elif [ x$mode = xxmodem ]; then
            loadb -f $image -c
            if [ $? -ne 0 ] ; then
                    echo "loadb failed or cancelled! Update aborted."
                    exit 1
            fi
    fi

    unprotect $part

    echo
    echo "erasing partition $part"
    echo
    erase $part

    if [ x$mode = xddr ]; then
            echo
            echo "flashing $size@$address to $part"
            echo
    else
            echo
            echo "flashing $image to $part"
            echo
    fi

    if [ x$mode = xtftp ]; then
            tftp $image $part
            if [ $? -ne 0 ] ; then
                    echo "!!!Probable use of old NAND layout.!!!"
                    echo "Use 'erase_old_nand_fmt' command to clean NAND."
                    exit 1
            fi
    elif [ x$mode = xddr ]; then
            memcpy $address -d $part 0 $size
    else
            cp $image $part
    fi

    protect $part
    /env/bin/update_uloader
    #!/bin/sh

    . /env/bin/update -t uloader -d $1

  • Triu
    Triu Posts: 46  Freshman Member
    edited June 2019
    Options
    /env/bin/b0
    #!/bin/sh

    . /env/config

    if [ x$1 = xnand ]; then
            rootfs_loc=nand
            kernel_loc=nand
    #elif [ x$1 = xnor ]; then
    #       rootfs_loc=nor
    #       kernel_loc=nor
    #elif [ x$1 = xsata ]; then
    #       rootfs_loc=sata
    #       kernel_loc=sata
    #elif [ x$1 = xnfs ]; then
    #       rootfs_loc=net
    #       kernel_loc=nfs
    elif [ x$1 = xtftp ]; then
            rootfs_loc=net
            kernel_loc=tftp
    fi

    if [ x$ip = xdhcp ]; then
            bootargs="$bootargs ip=dhcp"
    elif [ x$ip = xnone ]; then
            bootargs="$bootargs ip=none"
    else
            bootargs="$bootargs ip=$eth0.ipaddr::$eth0.gateway:$eth0.netmask:::"
    fi


    if [ x$rootfs_loc = xnet ]; then
            bootargs="$bootargs root=/dev/nfs nfsroot=$nfsroot,v3,tcp noinitrd"
    elif [ x$rootfs_loc = xinitrd ]; then
            bootargs="$bootargs root=/dev/ram0 rdinit=/sbin/init"
    elif [ x$rootfs_loc = xsata ]; then
            bootargs="$bootargs root=/dev/sda2 rootfstype=$rootfs_type rw noinitrd"
    else
            if [ x$rootfs_loc = xnand ]; then
                    rootfs_mtdblock=$rootfs_mtdblock_nand
            else
                    rootfs_mtdblock=$rootfs_mtdblock_nor
            fi

            if [ x$rootfs_type = xubifs ]; then
                    if [ -z $ubiroot ]; then
                            ubiroot="rootfs"
                    fi
                    if [ x$rootfs_loc = xnand ]; then
                            bootargs="$bootargs root=ubi0:$ubiroot ubi.mtd=$rootfs_m
                    else
                            bootargs="$bootargs root=ubi0:$ubiroot ubi.mtd=$rootfs_m
                    fi
            else
                    bootargs="$bootargs root=/dev/mtdblock$rootfs_mtdblock"
            fi

            bootargs="$bootargs rootfstype=$rootfs_type rw noinitrd"
    fi

    #if [ -n $nor_parts ]; then
    #       mtdparts="${mtdparts}${nor_device}:${nor_parts}"
    #fi

    if [ -n $spi_parts ]; then
            mtdparts="${mtdparts}${spi_device}:${spi_parts}"
    fi

    if [ -n $nand_parts ]; then
            if [ -n ${mtdparts} ]; then
                    mtdparts="${mtdparts};"
            fi
            mtdparts="${mtdparts}${nand_device}:${nand_parts}"
    fi

    if [ -n $mtdparts ]; then
            bootargs="${bootargs} mtdparts=${mtdparts}"
    fi

    if [ -e /dev/ram0 ]; then
    if [ ! -e /dev/ram0.kernelraw ]; then
            # arm raw kernel images are usually located at sdram start + 0x8000
            addpart /dev/ram0 8M@0x8000(kernelraw)
    fi

    if [ ! -e /dev/ram0.kernel ]; then
            # Here we can safely put the kernel without risking of overwriting it
            # while extracting
            addpart /dev/ram0 8M@8M(kernel)
    fi
    fi

    # update curr_bootfrom according to next_bootfrom
    if [ x$next_bootfrom != x$curr_bootfrom ]; then
            curr_bootfrom=$next_bootfrom
    fi
    if [ x$kernel_loc = xnfs ] || [ x$kernel_loc = xtftp ]; then
            if [ x$ip = xdhcp ]; then
                    dhcp
            fi
            if [ $kernelimage_type = uimage ]; then
                    netload="/dev/ram0.kernel"
            elif [ $kernelimage_type = zimage ]; then
                    netload="/dev/ram0.kernel"
            elif [ $kernelimage_type = raw ]; then
                    netload="/dev/ram0.kernelraw"
            elif [ $kernelimage_type = raw_lzo ]; then
                    netload="/dev/ram0.kernel"
            else
                    echo "error: set kernelimage_type to one of 'uimage', 'zimage',
                    exit 1
            fi
            $kernel_loc $kernelimage $netload || exit 1
            kdev="$netload"
    elif [ x$kernel_loc = xnor ]; then
            kdev="/dev/nor0.kernel"
    elif [ x$kernel_loc = xnand ]; then
            kdev="/dev/nand0.kernel${curr_bootfrom}.bb"
    elif [ x$kernel_loc = xsata ]; then
            addpart /dev/mem 3M@0x3008000(uImage)
            sata read 3008000 1 5000
            kdev="/dev/mem.uImage"
            sata stop
    else
            echo "error: set kernel_loc to one of 'nfs', 'tftp', 'nand' or 'nor'"
            exit 1
    fi

    if [ -n $usb3_internal_clk ]; then
            bootargs="$bootargs usb3_internal_clk=$usb3_internal_clk"
    fi

    # set fan speed to 20% to avoid the irregular jitter
    mw 0x90470058 0x05000000
    mw 0x90458000 0x80000001
    mw 0x90458028 0x80001388
    mw 0x9045802C 0x00000fa0


    echo "booting kernel of type $kernelimage_type from $kdev"

    if [ x$kernelimage_type = xuimage ]; then
            bootm $kdev

            echo " Failed."

            # change partition and retry it
            if [ "$curr_bootfrom" = "1" ]; then
                    curr_bootfrom=2
            elif [ "$curr_bootfrom" = "2" ]; then
                    curr_bootfrom=1
            else
                    curr_bootfrom=1
            fi
            kdev="/dev/nand0.kernel${curr_bootfrom}.bb"
            echo "booting kernel of type $kernelimage_type from $kdev"
            bootm $kdev

    elif [ x$kernelimage_type = xzimage ]; then
            bootz $kdev
    elif [ x$kernelimage_type = xraw ]; then
            if [ $kernel_loc != net ]; then
                    cp $kdev /dev/ram0.kernelraw
            fi
            bootu /dev/ram0.kernelraw
    elif [ x$kernelimage_type = xraw_lzo ]; then
            unlzo $kdev /dev/ram0.kernelraw
            bootu /dev/ram0.kernelraw
    fi




    ####### do error handling here (for MFG process) ######
    # stop watchdog timer of MCU (37: MCU normal mode(not burning), 39: MCU sys boot
    mw 0x904700D0 0x010000A0

    # get ip address from dhcp server
    dhcp

    # update kernel1 partition
    /env/bin/update -t kernel1 -d nand -f $mfg_kernel_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi

    # update kernel2 partition
    /env/bin/update -t kernel2 -d nand -f $mfg_kernel_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi

    if [ 0 -eq 1 ]; then    # rootfs should not be downloaded here, use rootfs key i
    # update rootfs1 partition
    /env/bin/update -t rootfs1 -d nand -f $mfg_rootfs_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi

    # update rootfs2 partition
    /env/bin/update -t rootfs2 -d nand -f $mfg_rootfs_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi
    fi

    #/env/bin/blink_sys_led
    while [ 1 ]
    do
            # turn off sys led
            mw 0x904700D0 0x000000A0
            sleep 1

            # turn on sys led
            mw 0x904700D0 0x010000A0
            sleep 1
    done
    /env/bin/hush_hack
    nand -a /dev/nand0.*
    /env/bin/_update_help
    #!/bin/sh

    echo "usage: update -t <kernel|rootfs|barebox|bareboxenv> -d <nor|nand> [-m tftp
    echo "update tools."
    echo ""
    echo "options"
    echo " -c     to check the crc32 for the image and flashed one"
    echo ""
    echo "default mode is tftp"
    echo "type update -t uloader -d <nor|nand> [-m tftp|xmodem|ddr] [-f imagename|-a
    echo "type update -t barebox -d <nor|nand> [-m tftp|xmodem|ddr] [-f imagename|-a
    echo "type update -t kernel -d <nor|nand> [-m tftp|xmodem|ddr] [-f imagename|-a
    echo "type update -t rootfs -d <nor|nand> [-m tftp|xmodem|ddr] [-f imagename|-a
    echo "type update -t bareboxenv -d <nor|nand> [-m tftp|xmodem|ddr] [-f imagename
    /env/bin/init
    #!/bin/sh

    PATH=/env/bin
    export PATH

    . /env/config
    #if [ -e /dev/nor0 -a -n "$nor_parts" ]; then
    #       addpart /dev/nor0 $nor_parts
    #fi

    #if [ -e /dev/disk0 -a -n "$disk_parts" ]; then
    #       addpart /dev/disk0 $disk_parts
    #fi

    if [ -e /dev/spi0 -a -n "$spi_parts" ]; then
            addpart /dev/spi0 $spi_parts
    fi

    if [ -e /dev/nand0 -a -n "$nand_parts" ]; then
            addpart /dev/nand0 $nand_parts

            # Uh, oh, hush first expands wildcards and then starts executing
            # commands. What a bug!
            source /env/bin/hush_hack
    fi

    if [ -f /env/bin/init_board ]; then
            /env/bin/init_board
    fi

    echo "Disabling eee function of phy 4 ..."
    phy write 4 0x1F 0x0000
    phy write 4 0x00 0x8000
    #Wait 20ms for PHY reset
    sleep 1
    phy write 4 0x1F 0x0005
    phy write 4 0x05 0x8b85
    phy write 4 0x06 0x0ae2
    phy write 4 0x1F 0x0007
    phy write 4 0x1E 0x0020
    phy write 4 0x15 0x1008
    phy write 4 0x1F 0x0000
    phy write 4 0x0D 0x0007
    phy write 4 0x0E 0x003c
    phy write 4 0x0D 0x4007
    phy write 4 0x0E 0x0000

    echo "Disabling eee function of phy 6 ..."
    phy write 6 0x1F 0x0000
    phy write 6 0x00 0x8000
    #Wait 20ms for PHY reset
    sleep 1
    phy write 6 0x1F 0x0005
    phy write 6 0x05 0x8b85
    phy write 6 0x06 0x0ae2
    phy write 6 0x1F 0x0007
    phy write 6 0x1E 0x0020
    phy write 6 0x15 0x1008
    phy write 6 0x1F 0x0000
    phy write 6 0x0D 0x0007
    phy write 6 0x0E 0x003c
    phy write 6 0x0D 0x4007
    phy write 6 0x0E 0x0000

    echo
    echo -n "Hit any key to stop autoboot: "
    timeout -a $autoboot_timeout
    if [ $? != 0 ]; then
            . /env/bin/_update_help
            exit
    fi

    boot
    /env/bin/update_barebox
    #!/bin/sh

    . /env/bin/update -t barebox -d $1

  • Triu
    Triu Posts: 46  Freshman Member
    Options
    /env/bin/b2
    #!/bin/sh

    . /env/config
    next_bootfrom="2"

    if [ x$1 = xnand ]; then
            rootfs_loc=nand
            kernel_loc=nand
    #elif [ x$1 = xnor ]; then
    #       rootfs_loc=nor
    #       kernel_loc=nor
    #elif [ x$1 = xsata ]; then
    #       rootfs_loc=sata
    #       kernel_loc=sata
    #elif [ x$1 = xnfs ]; then
    #       rootfs_loc=net
    #       kernel_loc=nfs
    elif [ x$1 = xtftp ]; then
            rootfs_loc=net
            kernel_loc=tftp
    fi

    if [ x$ip = xdhcp ]; then
            bootargs="$bootargs ip=dhcp"
    elif [ x$ip = xnone ]; then
            bootargs="$bootargs ip=none"
    else
            bootargs="$bootargs ip=$eth0.ipaddr::$eth0.gateway:$eth0.netmask:::"
    fi


    if [ x$rootfs_loc = xnet ]; then
            bootargs="$bootargs root=/dev/nfs nfsroot=$nfsroot,v3,tcp noinitrd"
    elif [ x$rootfs_loc = xinitrd ]; then
            bootargs="$bootargs root=/dev/ram0 rdinit=/sbin/init"
    elif [ x$rootfs_loc = xsata ]; then
            bootargs="$bootargs root=/dev/sda2 rootfstype=$rootfs_type rw noinitrd"
    else
            if [ x$rootfs_loc = xnand ]; then
                    rootfs_mtdblock=$rootfs_mtdblock_nand
            else
                    rootfs_mtdblock=$rootfs_mtdblock_nor
            fi

            if [ x$rootfs_type = xubifs ]; then
                    if [ -z $ubiroot ]; then
                            ubiroot="rootfs"
                    fi
                    if [ x$rootfs_loc = xnand ]; then
                            bootargs="$bootargs root=ubi0:$ubiroot ubi.mtd=$rootfs_m
                    else
                            bootargs="$bootargs root=ubi0:$ubiroot ubi.mtd=$rootfs_m
                    fi
            else
                    bootargs="$bootargs root=/dev/mtdblock$rootfs_mtdblock"
            fi

            bootargs="$bootargs rootfstype=$rootfs_type rw noinitrd"
    fi

    #if [ -n $nor_parts ]; then
    #       mtdparts="${mtdparts}${nor_device}:${nor_parts}"
    #fi

    if [ -n $spi_parts ]; then
            mtdparts="${mtdparts}${spi_device}:${spi_parts}"
    fi

    if [ -n $nand_parts ]; then
            if [ -n ${mtdparts} ]; then
                    mtdparts="${mtdparts};"
            fi
            mtdparts="${mtdparts}${nand_device}:${nand_parts}"
    fi

    if [ -n $mtdparts ]; then
            bootargs="${bootargs} mtdparts=${mtdparts}"
    fi

    if [ -e /dev/ram0 ]; then
    if [ ! -e /dev/ram0.kernelraw ]; then
            # arm raw kernel images are usually located at sdram start + 0x8000
            addpart /dev/ram0 8M@0x8000(kernelraw)
    fi

    if [ ! -e /dev/ram0.kernel ]; then
            # Here we can safely put the kernel without risking of overwriting it
            # while extracting
            addpart /dev/ram0 8M@8M(kernel)
    fi
    fi

    # update curr_bootfrom according to next_bootfrom
    if [ x$next_bootfrom != x$curr_bootfrom ]; then
            curr_bootfrom=$next_bootfrom
    fi

    if [ x$kernel_loc = xnfs ] || [ x$kernel_loc = xtftp ]; then
            if [ x$ip = xdhcp ]; then
                    dhcp
            fi
            if [ $kernelimage_type = uimage ]; then
                    netload="/dev/ram0.kernel"
            elif [ $kernelimage_type = zimage ]; then
                    netload="/dev/ram0.kernel"
            elif [ $kernelimage_type = raw ]; then
                    netload="/dev/ram0.kernelraw"
            elif [ $kernelimage_type = raw_lzo ]; then
                    netload="/dev/ram0.kernel"
            else
                    echo "error: set kernelimage_type to one of 'uimage', 'zimage',
                    exit 1
            fi
            $kernel_loc $kernelimage $netload || exit 1
            kdev="$netload"
    elif [ x$kernel_loc = xnor ]; then
            kdev="/dev/nor0.kernel"
    elif [ x$kernel_loc = xnand ]; then
            kdev="/dev/nand0.kernel${curr_bootfrom}.bb"
    elif [ x$kernel_loc = xsata ]; then
            addpart /dev/mem 3M@0x3008000(uImage)
            sata read 3008000 1 5000
            kdev="/dev/mem.uImage"
            sata stop
    else
            echo "error: set kernel_loc to one of 'nfs', 'tftp', 'nand' or 'nor'"
            exit 1
    fi

    if [ -n $usb3_internal_clk ]; then
            bootargs="$bootargs usb3_internal_clk=$usb3_internal_clk"
    fi

    # set fan speed to 20% to avoid the irregular jitter
    mw 0x90470058 0x05000000
    mw 0x90458000 0x80000001
    mw 0x90458028 0x80001388
    mw 0x9045802C 0x00000fa0


    echo "booting kernel of type $kernelimage_type from $kdev"

    if [ x$kernelimage_type = xuimage ]; then
            bootm $kdev

            echo " Failed."

            # change partition and retry it
            if [ "$curr_bootfrom" = "1" ]; then
                    curr_bootfrom=2
            elif [ "$curr_bootfrom" = "2" ]; then
                    curr_bootfrom=1
            else
                    curr_bootfrom=1
            fi
            kdev="/dev/nand0.kernel${curr_bootfrom}.bb"
            echo "booting kernel of type $kernelimage_type from $kdev"
            bootm $kdev

    elif [ x$kernelimage_type = xzimage ]; then
            bootz $kdev
    elif [ x$kernelimage_type = xraw ]; then
            if [ $kernel_loc != net ]; then
                    cp $kdev /dev/ram0.kernelraw
            fi
            bootu /dev/ram0.kernelraw
    elif [ x$kernelimage_type = xraw_lzo ]; then
            unlzo $kdev /dev/ram0.kernelraw
            bootu /dev/ram0.kernelraw
    fi




    ####### do error handling here (for MFG process) ######
    # stop watchdog timer of MCU (37: MCU normal mode(not burning), 39: MCU sys boot
    mw 0x904700D0 0x010000A0

    # get ip address from dhcp server
    dhcp

    # update kernel1 partition
    /env/bin/update -t kernel1 -d nand -f $mfg_kernel_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi

    # update kernel2 partition
    /env/bin/update -t kernel2 -d nand -f $mfg_kernel_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi

    if [ 0 -eq 1 ]; then    # rootfs should not be downloaded here, use rootfs key i
    # update rootfs1 partition
    /env/bin/update -t rootfs1 -d nand -f $mfg_rootfs_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi

    # update rootfs2 partition
    /env/bin/update -t rootfs2 -d nand -f $mfg_rootfs_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi
    fi

    #/env/bin/blink_sys_led
    while [ 1 ]
    do
            # turn off sys led
            mw 0x904700D0 0x000000A0
            sleep 1

            # turn on sys led
            mw 0x904700D0 0x010000A0
            sleep 1
    done


  • Triu
    Triu Posts: 46  Freshman Member
    Options
    /env/bin/b1
    #!/bin/sh

    . /env/config
    next_bootfrom="1"

    if [ x$1 = xnand ]; then
            rootfs_loc=nand
            kernel_loc=nand
    #elif [ x$1 = xnor ]; then
    #       rootfs_loc=nor
    #       kernel_loc=nor
    #elif [ x$1 = xsata ]; then
    #       rootfs_loc=sata
    #       kernel_loc=sata
    #elif [ x$1 = xnfs ]; then
    #       rootfs_loc=net
    #       kernel_loc=nfs
    elif [ x$1 = xtftp ]; then
            rootfs_loc=net
            kernel_loc=tftp
    fi

    if [ x$ip = xdhcp ]; then
            bootargs="$bootargs ip=dhcp"
    elif [ x$ip = xnone ]; then
            bootargs="$bootargs ip=none"
    else
            bootargs="$bootargs ip=$eth0.ipaddr::$eth0.gateway:$eth0.netmask:::"
    fi


    if [ x$rootfs_loc = xnet ]; then
            bootargs="$bootargs root=/dev/nfs nfsroot=$nfsroot,v3,tcp noinitrd"
    elif [ x$rootfs_loc = xinitrd ]; then
            bootargs="$bootargs root=/dev/ram0 rdinit=/sbin/init"
    elif [ x$rootfs_loc = xsata ]; then
            bootargs="$bootargs root=/dev/sda2 rootfstype=$rootfs_type rw noinitrd"
    else
            if [ x$rootfs_loc = xnand ]; then
                    rootfs_mtdblock=$rootfs_mtdblock_nand
            else
                    rootfs_mtdblock=$rootfs_mtdblock_nor
            fi

            if [ x$rootfs_type = xubifs ]; then
                    if [ -z $ubiroot ]; then
                            ubiroot="rootfs"
                    fi
                    if [ x$rootfs_loc = xnand ]; then
                            bootargs="$bootargs root=ubi0:$ubiroot ubi.mtd=$rootfs_m
                    else
                            bootargs="$bootargs root=ubi0:$ubiroot ubi.mtd=$rootfs_m
                    fi
            else
                    bootargs="$bootargs root=/dev/mtdblock$rootfs_mtdblock"
            fi

            bootargs="$bootargs rootfstype=$rootfs_type rw noinitrd"
    fi

    #if [ -n $nor_parts ]; then
    #       mtdparts="${mtdparts}${nor_device}:${nor_parts}"
    #fi

    if [ -n $spi_parts ]; then
            mtdparts="${mtdparts}${spi_device}:${spi_parts}"
    fi

    if [ -n $nand_parts ]; then
            if [ -n ${mtdparts} ]; then
                    mtdparts="${mtdparts};"
            fi
            mtdparts="${mtdparts}${nand_device}:${nand_parts}"
    fi

    if [ -n $mtdparts ]; then
            bootargs="${bootargs} mtdparts=${mtdparts}"
    fi

    if [ -e /dev/ram0 ]; then
    if [ ! -e /dev/ram0.kernelraw ]; then
            # arm raw kernel images are usually located at sdram start + 0x8000
            addpart /dev/ram0 8M@0x8000(kernelraw)
    fi

    if [ ! -e /dev/ram0.kernel ]; then
            # Here we can safely put the kernel without risking of overwriting it
            # while extracting
            addpart /dev/ram0 8M@8M(kernel)
    fi
    fi

    # update curr_bootfrom according to next_bootfrom
    if [ x$next_bootfrom != x$curr_bootfrom ]; then
            curr_bootfrom=$next_bootfrom
    fi

    if [ x$kernel_loc = xnfs ] || [ x$kernel_loc = xtftp ]; then
            if [ x$ip = xdhcp ]; then
                    dhcp
            fi
            if [ $kernelimage_type = uimage ]; then
                    netload="/dev/ram0.kernel"
            elif [ $kernelimage_type = zimage ]; then
                    netload="/dev/ram0.kernel"
            elif [ $kernelimage_type = raw ]; then
                    netload="/dev/ram0.kernelraw"
            elif [ $kernelimage_type = raw_lzo ]; then
                    netload="/dev/ram0.kernel"
            else
                    echo "error: set kernelimage_type to one of 'uimage', 'zimage',
                    exit 1
            fi
            $kernel_loc $kernelimage $netload || exit 1
            kdev="$netload"
    elif [ x$kernel_loc = xnor ]; then
            kdev="/dev/nor0.kernel"
    elif [ x$kernel_loc = xnand ]; then
            kdev="/dev/nand0.kernel${curr_bootfrom}.bb"
    elif [ x$kernel_loc = xsata ]; then
            addpart /dev/mem 3M@0x3008000(uImage)
            sata read 3008000 1 5000
            kdev="/dev/mem.uImage"
            sata stop
    else
            echo "error: set kernel_loc to one of 'nfs', 'tftp', 'nand' or 'nor'"
            exit 1
    fi

    if [ -n $usb3_internal_clk ]; then
            bootargs="$bootargs usb3_internal_clk=$usb3_internal_clk"
    fi

    # set fan speed to 20% to avoid the irregular jitter
    mw 0x90470058 0x05000000
    mw 0x90458000 0x80000001
    mw 0x90458028 0x80001388
    mw 0x9045802C 0x00000fa0


    echo "booting kernel of type $kernelimage_type from $kdev"

    if [ x$kernelimage_type = xuimage ]; then
            bootm $kdev

            echo " Failed."

            # change partition and retry it
            if [ "$curr_bootfrom" = "1" ]; then
                    curr_bootfrom=2
            elif [ "$curr_bootfrom" = "2" ]; then
                    curr_bootfrom=1
            else
                    curr_bootfrom=1
            fi
            kdev="/dev/nand0.kernel${curr_bootfrom}.bb"
            echo "booting kernel of type $kernelimage_type from $kdev"
            bootm $kdev

    elif [ x$kernelimage_type = xzimage ]; then
            bootz $kdev
    elif [ x$kernelimage_type = xraw ]; then
            if [ $kernel_loc != net ]; then
                    cp $kdev /dev/ram0.kernelraw
            fi
            bootu /dev/ram0.kernelraw
    elif [ x$kernelimage_type = xraw_lzo ]; then
            unlzo $kdev /dev/ram0.kernelraw
            bootu /dev/ram0.kernelraw
    fi




    ####### do error handling here (for MFG process) ######
    # stop watchdog timer of MCU (37: MCU normal mode(not burning), 39: MCU sys boot
    mw 0x904700D0 0x010000A0

    # get ip address from dhcp server
    dhcp

    # update kernel1 partition
    /env/bin/update -t kernel1 -d nand -f $mfg_kernel_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi

    # update kernel2 partition
    /env/bin/update -t kernel2 -d nand -f $mfg_kernel_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi

    if [ 0 -eq 1 ]; then    # rootfs should not be downloaded here, use rootfs key i
    # update rootfs1 partition
    /env/bin/update -t rootfs1 -d nand -f $mfg_rootfs_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi

    # update rootfs2 partition
    /env/bin/update -t rootfs2 -d nand -f $mfg_rootfs_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi
    fi

    #/env/bin/blink_sys_led
    while [ 1 ]
    do
            # turn off sys led
            mw 0x904700D0 0x000000A0
            sleep 1

            # turn on sys led
            mw 0x904700D0 0x010000A0
            sleep 1
    done
  • Triu
    Triu Posts: 46  Freshman Member
    edited June 2019
    Options
    /env/bin/boot
    #!/bin/sh

    . /env/config

    if [ x$1 = xnand ]; then
            rootfs_loc=nand
            kernel_loc=nand
    #elif [ x$1 = xnor ]; then
    #       rootfs_loc=nor
    #       kernel_loc=nor
    #elif [ x$1 = xsata ]; then
    #       rootfs_loc=sata
    #       kernel_loc=sata
    #elif [ x$1 = xnfs ]; then
    #       rootfs_loc=net
    #       kernel_loc=nfs
    elif [ x$1 = xtftp ]; then
            rootfs_loc=net
            kernel_loc=tftp
    fi

    if [ x$ip = xdhcp ]; then
            bootargs="$bootargs ip=dhcp"
    elif [ x$ip = xnone ]; then
            bootargs="$bootargs ip=none"
    else
            bootargs="$bootargs ip=$eth0.ipaddr::$eth0.gateway:$eth0.netmask:::"
    fi


    if [ x$rootfs_loc = xnet ]; then
            bootargs="$bootargs root=/dev/nfs nfsroot=$nfsroot,v3,tcp noinitrd"
    elif [ x$rootfs_loc = xinitrd ]; then
            bootargs="$bootargs root=/dev/ram0 rdinit=/sbin/init"
    elif [ x$rootfs_loc = xsata ]; then
            bootargs="$bootargs root=/dev/sda2 rootfstype=$rootfs_type rw noinitrd"
    else
            if [ x$rootfs_loc = xnand ]; then
                    rootfs_mtdblock=$rootfs_mtdblock_nand
            else
                    rootfs_mtdblock=$rootfs_mtdblock_nor
            fi

            if [ x$next_bootfrom = x2 ]; then
                    bootargs="$bootargs drive_bays=4 syno_hw_version=NAS542v10 ihd_n
                    rootfs_type=ext4
            elif [ x$rootfs_type = xubifs ]; then
                    if [ -z $ubiroot ]; then
                            ubiroot="rootfs"
                    fi
                    if [ x$rootfs_loc = xnand ]; then
                            bootargs="$bootargs root=ubi0:$ubiroot ubi.mtd=$rootfs_m
                    else
                            bootargs="$bootargs root=ubi0:$ubiroot ubi.mtd=$rootfs_m
                    fi
            else
                    bootargs="$bootargs root=/dev/mtdblock$rootfs_mtdblock"
            fi

            bootargs="$bootargs rootfstype=$rootfs_type rw noinitrd"
    fi

    #if [ -n $nor_parts ]; then
    #       mtdparts="${mtdparts}${nor_device}:${nor_parts}"
    #fi

    if [ -n $spi_parts ]; then
            mtdparts="${mtdparts}${spi_device}:${spi_parts}"
    fi

    if [ -n $nand_parts ]; then
            if [ -n ${mtdparts} ]; then
                    mtdparts="${mtdparts};"
            fi
            mtdparts="${mtdparts}${nand_device}:${nand_parts}"
    fi

    if [ -n $mtdparts ]; then
            bootargs="${bootargs} mtdparts=${mtdparts}"
    fi

    if [ -e /dev/ram0 ]; then
    if [ ! -e /dev/ram0.kernelraw ]; then
            # arm raw kernel images are usually located at sdram start + 0x8000
            addpart /dev/ram0 8M@0x8000(kernelraw)
    fi

    if [ ! -e /dev/ram0.kernel ]; then
            # Here we can safely put the kernel without risking of overwriting it
            # while extracting
            addpart /dev/ram0 8M@8M(kernel)
    fi
    fi

    # update curr_bootfrom according to next_bootfrom
    if [ x$next_bootfrom != x$curr_bootfrom ]; then
            curr_bootfrom=$next_bootfrom
    fi

    if [ x$kernel_loc = xnfs ] || [ x$kernel_loc = xtftp ]; then
            if [ x$ip = xdhcp ]; then
                    dhcp
            fi
            if [ $kernelimage_type = uimage ]; then
                    netload="/dev/ram0.kernel"
            elif [ $kernelimage_type = zimage ]; then
                    netload="/dev/ram0.kernel"
            elif [ $kernelimage_type = raw ]; then
                    netload="/dev/ram0.kernelraw"
            elif [ $kernelimage_type = raw_lzo ]; then
                    netload="/dev/ram0.kernel"
            else
                    echo "error: set kernelimage_type to one of 'uimage', 'zimage',
                    exit 1
            fi
            $kernel_loc $kernelimage $netload || exit 1
            kdev="$netload"
    elif [ x$kernel_loc = xnor ]; then
            kdev="/dev/nor0.kernel"
    elif [ x$kernel_loc = xnand ]; then
            kdev="/dev/nand0.kernel${curr_bootfrom}.bb"
    elif [ x$kernel_loc = xsata ]; then
            addpart /dev/mem 3M@0x3008000(uImage)
            sata read 3008000 1 5000
            kdev="/dev/mem.uImage"
            sata stop
    else
            echo "error: set kernel_loc to one of 'nfs', 'tftp', 'nand' or 'nor'"
            exit 1
    fi

    if [ -n $usb3_internal_clk ]; then
            bootargs="$bootargs usb3_internal_clk=$usb3_internal_clk"
    fi

    # set fan speed to 20% to avoid the irregular jitter
    mw 0x90470058 0x05000000
    mw 0x90458000 0x80000001
    mw 0x90458028 0x80001388
    mw 0x9045802C 0x00000fa0


    echo "booting kernel of type $kernelimage_type from $kdev"

    if [ x$kernelimage_type = xuimage ]; then
            bootm $kdev

            echo " Failed."

            # change partition and retry it
            if [ "$curr_bootfrom" = "1" ]; then
                    curr_bootfrom=2
            elif [ "$curr_bootfrom" = "2" ]; then
                    curr_bootfrom=1
            else
                    curr_bootfrom=1
            fi
            kdev="/dev/nand0.kernel${curr_bootfrom}.bb"
            echo "booting kernel of type $kernelimage_type from $kdev"
            bootm $kdev

    elif [ x$kernelimage_type = xzimage ]; then
            bootz $kdev
    elif [ x$kernelimage_type = xraw ]; then
            if [ $kernel_loc != net ]; then
                    cp $kdev /dev/ram0.kernelraw
            fi
            bootu /dev/ram0.kernelraw
    elif [ x$kernelimage_type = xraw_lzo ]; then
            unlzo $kdev /dev/ram0.kernelraw
            bootu /dev/ram0.kernelraw
    fi




    ####### do error handling here (for MFG process) ######
    # stop watchdog timer of MCU (37: MCU normal mode(not burning), 39: MCU sys boot
    mw 0x904700D0 0x010000A0

    # get ip address from dhcp server
    dhcp

    # update kernel1 partition
    /env/bin/update -t kernel1 -d nand -f $mfg_kernel_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi

    # update kernel2 partition
    /env/bin/update -t kernel2 -d nand -f $mfg_kernel_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi

    if [ 0 -eq 1 ]; then    # rootfs should not be downloaded here, use rootfs key i
    # update rootfs1 partition
    /env/bin/update -t rootfs1 -d nand -f $mfg_rootfs_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi

    # update rootfs2 partition
    /env/bin/update -t rootfs2 -d nand -f $mfg_rootfs_img
    if [ $? != 0 ]; then
            mw 0x904700D0 0x020000A0
            exit
    fi
    fi

    #/env/bin/blink_sys_led
    while [ 1 ]
    do
            # turn off sys led
            mw 0x904700D0 0x000000A0
            sleep 1

            # turn on sys led
            mw 0x904700D0 0x010000A0
            sleep 1
    done
    /env/bin/update_kernel
    #!/bin/sh

    . /env/bin/update -t kernel -d $1
  • Mijzelf
    Mijzelf Posts: 2,607  Guru Member
    First Anniversary 10 Comments Friend Collector First Answer
    Options
    Hmm. Reading that /env/config file, I wonder if 'setenv' is as easy as editing that file? There I read
    <div># boot partition<br>next_bootfrom="1"<br>curr_bootfrom="2"</div><div></div>
    and I can nowhere find that it's overwritten by a readenv, or something like that.

  • Triu
    Triu Posts: 46  Freshman Member
    edited June 2019
    Options
    WOHOOOO.......a little bit.
    After alot of trying i found out how to save in the "edit" tool (this is stored till a reboot). Close window with "CTRL+C" and save with "CTRL+D". Now i need a little hint what to do with that, cause simply "boot" is the same as before (cause he already switches to the second one).
    I tried this change with loading the uImage.521 but this gives me an "ubiattach error" (wasn't that before? attached uImage.txt)
    After that i tried with my SDcard and "boot". It booted to the debian login prompt. I am happy about that but this doesn't really help to get the original firmware back.
  • Mijzelf
    Mijzelf Posts: 2,607  Guru Member
    First Anniversary 10 Comments Friend Collector First Answer
    Options
    (this is stored till a reboot).

    saveenv might help.


    Combining your debian bootlog with the bootscripts, I'd try

    <p>bootargs="console=ttyS0,115200n8, init=/etc/preinit pcie_gen1_only=yes&nbsp; mac_addr=,, ip=dhcp root=ubi0:rootfs ubi.mtd=2,2048 rootfstype=ubifs rw noinitrd mtdparts=spi0.0:256k(uloader)ro,512k(barebox)ro,256k(env);comcertonand:10M(config),10M(kernel1),110M(rootfs1),10M(kernel2),110M(rootfs2),-(reserved) usb3_internal_clk=yes"</p><p><br></p><p><insert tftp boot commands></p>




  • Triu
    Triu Posts: 46  Freshman Member
    edited June 2019
    Options
    Saveenv works here, great.
    I exchanged the first bootargs line in the config file with yours, the second bootargs line i didn't touch. Unfortunately it seems i had problems with the line length, output after "Starting kernel" was:
    commandline: console=ttyS0,115200n8, init=/etc/preinit pcie_gen1_only=yes  mac_addr=,,<br>
    So i split your line in parts, but i am not shure if i have done it right.
    bootargs="console=ttyS0,115200n8, init=/etc/preinit pcie_gen1_only=yes  ,"
    bootargs="mac_addr=,, ip=dhcp root=ubi0:rootfs ubi.mtd=2,"
    bootargs="2048 rootfstype=ubifs rw noinitrd"
    bootargs="mtdparts=spi0.0:256k(uloader)ro,512k(barebox)ro,256k(env);"
    bootargs="comcertonand:10M(config),10M(kernel1),110M(rootfs1),10M(kernel2),"
    bootargs="110M(rootfs2),-(reserved) usb3_internal_clk=yes"
    The result was the same to me. Log of the second try with all the lines is attached.
    Log.txt 25.9K
  • Mijzelf
    Mijzelf Posts: 2,607  Guru Member
    First Anniversary 10 Comments Friend Collector First Answer
    Options
    So i split your line in parts, but i am not shure if i have done it right.

    Eh, no. Have a look in /env/bin/boot, there you can see how the bootargs is build. Something like

    <p>bootargs="key=value"</p><p><br></p><p>bootargs="${bootargs} key2=value2"</p><p><br></p><p>bootargs="${bootargs} key3=value3"<br></p>

    Here each time the old bootargs argument is injected in the new one. If you split a value, like you did in the insanely long 'mtdparts' key, make sure you don't add a space:

    <p>bootargs="key=firstpartofvalue"</p><p><br></p><p>bootargs="${bootargs}nextpartofvalue"</p><p></p>

    I think you can look at the result with 'echo ${bootparts}'. (That's equal to 'echo $bootparts, but by use of curly braces the statement doesn't have to end with a space or newline)

    Yet your commandline is different than I would expect. Seeing your commands above I'd expect it to be

    <p>110M(rootfs2),-(reserved) usb3_internal_clk=yes <br></p><p></p>

    but instead it's not changed at all.

    Reading your bootlog I see your bootargs commands, followed by

    <p>bootargs="$bootargs mac_addr=$eth0.ethaddr,$eth1.ethaddr,$eth2.ethaddr"<br></p><p></p>

    Where does that come from? Did you type it?

    Anyway, somehow it's reset. I searched for an old version of the barebox documentation, and found it here. The 'global' keyword suggests that variables in scripts are handled differently than variables on the command line. So I thought of 2 options. First prepare everything:

    <p>dhcp<br></p><p>eth0.serverip=192.168.178.11<br></p><p>addpart /dev/mem 8M@0x8000(kernelraw)<br></p><p>addpart /dev/mem 8M@8M(kernel)<br></p><p>netload="/dev/mem.kernel"<br></p><p>tftp uImage.521 $netload<br><br></p><p>bootargs="console=ttyS0,115200n8, init=/etc/preinit pcie_gen1_only=yes&nbsp; ,"<br></p><p>bootargs="${bootargs} mac_addr=,, ip=dhcp root=ubi0:rootfs ubi.mtd=2,"<br></p><p>bootargs="${bootargs}2048 rootfstype=ubifs rw noinitrd"<br></p><p>bootargs="${bootargs} mtdparts=spi0.0:256k(uloader)ro,512k(barebox)ro,256k(env);"<br></p><p>bootargs="${bootargs}comcertonand:10M(config),10M(kernel1),110M(rootfs1),10M(kernel2),"<br></p><p>bootargs="${bootargs}110M(rootfs2),-(reserved) usb3_internal_clk=yes"<br></p>

    Check if bootargs is ok:

    echo ${bootargs}
    Then there are 2 options:

    <p>bootargs=${bootargs} bootm ${netload}</p>

    or


    <p>global bootargs=${bootargs}</p><p><br></p><p>bootm ${netload}<br></p>



Consumer Product Help Center