From 6bd17d47808e3889d0625e59a027c0960b82c164 Mon Sep 17 00:00:00 2001 From: "arheneus@marvell.com" <51254330+antony-rheneus@users.noreply.github.com> Date: Wed, 15 Jan 2020 21:55:01 +0530 Subject: [PATCH] [initramfs] Updated required tools for initramfs (#3734) * [initramfs] Updated reuired tools for initramfs Signed-off-by: Antony Rheneus * [initramfs] Updated required tools for initramfs Signed-off-by: Antony Rheneus * [Platform] [Marvell] Platform specific debian package for et6448m device Signed-off-by: Antony Rheneus * Removed auto-generated files Signed-off-by: Antony Rheneus * [initramfs] Added mtd and uboot firmware tools package required for arm arch Its been enabled to all arch including amd64 Signed-off-by: Antony Rheneus * [initramfs] Added mtd and uboot firmware tools package required for arm arch Its been enabled to all arch including amd64 Signed-off-by: Antony Rheneus * [initramfs] Marvell arm modules update and platform config update Signed-off-by: Antony Rheneus * [iniramfs] add initramfs uboot-utils hook script only for ARM Signed-off-by: Antony Rheneus --- build_debian.sh | 19 ++ .../armhf-marvell_et6448m_52x-r0/fancontrol | 17 +- files/initramfs-tools/modules.arm | 7 + files/initramfs-tools/uboot-utils | 21 ++ files/initramfs-tools/union-mount.j2 | 15 +- files/initramfs-tools/varlog | 10 +- installer/armhf/install.sh | 134 ++++++++++- onie-image-armhf.conf | 3 + platform/marvell-armhf/one-image.mk | 1 + platform/marvell-armhf/platform-et6448m.mk | 9 + platform/marvell-armhf/platform.conf | 226 ++++++++++-------- platform/marvell-armhf/rules.mk | 1 + .../sonic-platform-et6448m/.gitignore | 50 ++++ .../sonic-platform-et6448m/debian/changelog | 5 + .../sonic-platform-et6448m/debian/compat | 1 + .../sonic-platform-et6448m/debian/control | 15 ++ .../sonic-platform-et6448m/debian/install | 1 + .../sonic-platform-et6448m/debian/postinst | 40 ++++ .../sonic-platform-et6448m/debian/rules | 25 ++ .../et6448m_plt_setup.sh | 57 +++++ 20 files changed, 535 insertions(+), 122 deletions(-) create mode 100644 files/initramfs-tools/modules.arm create mode 100644 files/initramfs-tools/uboot-utils create mode 100644 platform/marvell-armhf/platform-et6448m.mk create mode 100644 platform/marvell-armhf/sonic-platform-et6448m/.gitignore create mode 100755 platform/marvell-armhf/sonic-platform-et6448m/debian/changelog create mode 100644 platform/marvell-armhf/sonic-platform-et6448m/debian/compat create mode 100755 platform/marvell-armhf/sonic-platform-et6448m/debian/control create mode 100644 platform/marvell-armhf/sonic-platform-et6448m/debian/install create mode 100644 platform/marvell-armhf/sonic-platform-et6448m/debian/postinst create mode 100755 platform/marvell-armhf/sonic-platform-et6448m/debian/rules create mode 100755 platform/marvell-armhf/sonic-platform-et6448m/et6448m_plt_setup.sh diff --git a/build_debian.sh b/build_debian.sh index 3ccdd3e9820a..57c85e033f58 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -176,6 +176,11 @@ sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/varlog sudo cp files/initramfs-tools/union-fsck $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/union-fsck sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/union-fsck pushd $FILESYSTEM_ROOT/usr/share/initramfs-tools/scripts/init-bottom && sudo patch -p1 < $OLDPWD/files/initramfs-tools/udev.patch; popd +if [[ $CONFIGURED_ARCH == armhf || $CONFIGURED_ARCH == arm64 ]]; then + sudo cp files/initramfs-tools/uboot-utils $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/uboot-utils + sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/uboot-utils + cat files/initramfs-tools/modules.arm | sudo tee -a $FILESYSTEM_ROOT/etc/initramfs-tools/modules > /dev/null +fi if [[ $CONFIGURED_ARCH == amd64 ]]; then ## Install latest intel ixgbe driver @@ -494,8 +499,22 @@ fi ## Remove gcc and python dev pkgs sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove gcc libpython2.7-dev +## Add mtd and uboot firmware tools package +sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install u-boot-tools mtd-utils +sudo LANG=C chroot $FILESYSTEM_ROOT apt-mark manual u-boot-tools mtd-utils + ## Update initramfs sudo chroot $FILESYSTEM_ROOT update-initramfs -u +## Convert initrd image to u-boot format +if [[ $CONFIGURED_ARCH == armhf || $CONFIGURED_ARCH == arm64 ]]; then + INITRD_FILE=initrd.img-${LINUX_KERNEL_VERSION}-${CONFIGURED_ARCH} + if [[ $CONFIGURED_ARCH == armhf ]]; then + INITRD_FILE=initrd.img-${LINUX_KERNEL_VERSION}-armmp + fi + sudo LANG=C chroot $FILESYSTEM_ROOT mkimage -A arm -O linux -T ramdisk -C gzip -d /boot/$INITRD_FILE /boot/u${INITRD_FILE} + ## Overwriting the initrd image with uInitrd + sudo LANG=C chroot $FILESYSTEM_ROOT mv /boot/u${INITRD_FILE} /boot/$INITRD_FILE +fi ## Clean up apt sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y autoremove diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/fancontrol b/device/marvell/armhf-marvell_et6448m_52x-r0/fancontrol index c2150eb45741..050e2504626c 100755 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/fancontrol +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/fancontrol @@ -1,10 +1,9 @@ INTERVAL=10 -DEVPATH=hwmon0=devices/platform/soc/soc:internal-regs/f1011000.i2c/i2c-0/0-002e hwmon1=devices/platform/soc/soc:internal-regs/f1011000.i2c/i2c-0/0-004a hwmon2=devices/platform/soc/soc:internal-regs/f1011000.i2c/i2c-0/0-004b -DEVNAME=hwmon0=adt7473 hwmon1=lm75a hwmon2=lm75a -FCTEMPS=hwmon0/device/pwm2=hwmon2/temp1_input hwmon0/device/pwm1=hwmon1/temp1_input -FCFANS=hwmon0/device/pwm2=hwmon0/device/fan2_input hwmon0/device/pwm1=hwmon0/device/fan1_input -MINTEMP=hwmon0/device/pwm2=20 hwmon0/device/pwm1=20 -MAXTEMP=hwmon0/device/pwm2=60 hwmon0/device/pwm1=60 -MINSTART=hwmon0/device/pwm2=150 hwmon0/device/pwm1=150 -MINSTOP=hwmon0/device/pwm2=0 hwmon0/device/pwm1=0 - +DEVPATH=hwmon1=devices/platform/soc/soc:internal-regs/f1011000.i2c/i2c-0/0-002e +DEVNAME=hwmon1=adt7473 +FCTEMPS=hwmon1/device/pwm1=hwmon1/device/temp1_input hwmon1/device/pwm2=hwmon1/device/temp2_input +FCFANS=hwmon1/device/pwm1= hwmon1/device/pwm2=hwmon1/device/fan1_input +MINTEMP=hwmon1/device/pwm1=20 hwmon1/device/pwm2=20 +MAXTEMP=hwmon1/device/pwm1=60 hwmon1/device/pwm2=60 +MINSTART=hwmon1/device/pwm1=150 hwmon1/device/pwm2=150 +MINSTOP=hwmon1/device/pwm1=0 hwmon1/device/pwm2=0 diff --git a/files/initramfs-tools/modules.arm b/files/initramfs-tools/modules.arm new file mode 100644 index 000000000000..a923920bb1b2 --- /dev/null +++ b/files/initramfs-tools/modules.arm @@ -0,0 +1,7 @@ +crc16 +deflate +zlib_deflate +m25p80 +ubi +ubifs +squashfs diff --git a/files/initramfs-tools/uboot-utils b/files/initramfs-tools/uboot-utils new file mode 100644 index 000000000000..a9255a37eacf --- /dev/null +++ b/files/initramfs-tools/uboot-utils @@ -0,0 +1,21 @@ +#!/bin/sh +#Part of the code is revised based on initramfs-tool is under GPL v2. + +PREREQ="" + +prereqs() +{ + echo "$PREREQ" +} + +case $1 in +prereqs) + prereqs + exit 0 + ;; +esac + +. /usr/share/initramfs-tools/hook-functions + +copy_exec /usr/sbin/ubiattach /sbin/ubiattach +copy_exec /usr/sbin/mtdinfo /sbin/mtdinfo diff --git a/files/initramfs-tools/union-mount.j2 b/files/initramfs-tools/union-mount.j2 index f6f1deff4220..2376ea490e64 100644 --- a/files/initramfs-tools/union-mount.j2 +++ b/files/initramfs-tools/union-mount.j2 @@ -45,8 +45,19 @@ mkdir -p ${rootmnt}/host/$image_dir/work mount -n -o lowerdir=${rootmnt},upperdir=${rootmnt}/host/$image_dir/rw,workdir=${rootmnt}/host/$image_dir/work -t overlay root-overlay ${rootmnt} ## Check if the root block device is still there [ -b ${ROOT} ] || mdev -s -## Mount the raw partition again -mount ${ROOT} ${rootmnt}/host +case "${ROOT}" in + ubi*) + mtd=$(cat /proc/cmdline | sed -e 's/.*ubi.mtd=\([0-9]\) .*/\1/') + if [ ! -f /dev/${ROOT}_0 ]; then + ubiattach /dev/ubi_ctrl -m $mtd || true + fi + mount -t ubifs /dev/${ROOT}_0 ${rootmnt}/host + ;; + *) + ## Mount the raw partition again + mount ${ROOT} ${rootmnt}/host + ;; +esac mkdir -p ${rootmnt}/var/lib/docker if [ -f ${rootmnt}/host/$image_dir/{{ FILESYSTEM_DOCKERFS }} ]; then diff --git a/files/initramfs-tools/varlog b/files/initramfs-tools/varlog index d1340eaa9d8b..e8063e41a59c 100644 --- a/files/initramfs-tools/varlog +++ b/files/initramfs-tools/varlog @@ -33,4 +33,12 @@ if [ -e "${rootmnt}/host/disk-img/var-log.ext4" ]; then fi # create varlog disk -mkdir -p ${rootmnt}/host/disk-img && ${rootmnt}/usr/bin/fallocate -l "$varlog_size"M ${rootmnt}/host/disk-img/var-log.ext4 && mkfs.ext4 -q -F ${rootmnt}/host/disk-img/var-log.ext4 +case "${ROOT}" in + ubi*) + # sys_fallocate is NOT supported over UBIFS + mkdir -p ${rootmnt}/host/disk-img && ${rootmnt}/usr/bin/truncate -s "$varlog_size"M ${rootmnt}/host/disk-img/var-log.ext4 && mkfs.ext4 -q -F ${rootmnt}/host/disk-img/var-log.ext4 + ;; + *) + mkdir -p ${rootmnt}/host/disk-img && ${rootmnt}/usr/bin/fallocate -l "$varlog_size"M ${rootmnt}/host/disk-img/var-log.ext4 && mkfs.ext4 -q -F ${rootmnt}/host/disk-img/var-log.ext4 + ;; +esac diff --git a/installer/armhf/install.sh b/installer/armhf/install.sh index bfd7eeef9e41..53f2fdf99661 100755 --- a/installer/armhf/install.sh +++ b/installer/armhf/install.sh @@ -3,6 +3,17 @@ # Copyright (C) Marvell Inc # +_trap_push() { + local next="$1" + eval "trap_push() { + local oldcmd='$(echo "$next" | sed -e s/\'/\'\\\\\'\'/g)' + local newcmd=\"\$1; \$oldcmd\" + trap -- \"\$newcmd\" EXIT INT TERM HUP + _trap_push \"\$newcmd\" + }" +} +_trap_push true + set -e if [ -d "/etc/sonic" ]; then @@ -26,27 +37,124 @@ if [ -r ./onie-image-armhf.conf ]; then . ./onie-image-armhf.conf fi +echo "ONIE Installer: platform: $platform" -echo "Installer: platform: $platform" +# Make sure run as root or under 'sudo' +if [ $(id -u) -ne 0 ] + then echo "Please run as root" + exit 1 +fi -# install_uimage will be overriden from platform.conf as it is non generic -install_uimage() { - echo "Copying uImage to NOR flash:" - flashcp -v demo-${platform}.itb $mtd_dev -} +if [ -r /etc/machine.conf ]; then + . /etc/machine.conf +elif [ -r /host/machine.conf ]; then + . /host/machine.conf +elif [ "$install_env" != "build" ]; then + echo "cannot find machine.conf" + exit 1 +fi + +echo "onie_platform: $onie_platform" + +# Get platform specific linux kernel command line arguments +ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="" + +# Default var/log device size in MB +VAR_LOG_SIZE=4096 + +[ -r platforms/$onie_platform ] && . platforms/$onie_platform + + +# If running in ONIE +if [ "$install_env" = "onie" ]; then + # The onie bin tool prefix + onie_bin= + # The persistent ONIE directory location + onie_root_dir=/mnt/onie-boot/onie + # The onie file system root + onie_initrd_tmp=/ +fi + +# The build system prepares this script by replacing %%DEMO-TYPE%% +# with "OS" or "DIAG". +demo_type="%%DEMO_TYPE%%" + +# The build system prepares this script by replacing %%IMAGE_VERSION%% +# with git revision hash as a version identifier +image_version="%%IMAGE_VERSION%%" +timestamp="$(date -u +%Y%m%d)" + +demo_volume_label="SONiC-${demo_type}" +demo_volume_revision_label="SONiC-${demo_type}-${image_version}" -# hw_load will be overriden from platform.conf as it is non generic -hw_load() { - echo "cp.b $img_start \$loadaddr $img_sz" -} . ./platform.conf -install_uimage +image_dir="image-$image_version" + +if [ "$install_env" = "onie" ]; then + # Create/format the flash + create_partition + mount_partition +elif [ "$install_env" = "sonic" ]; then + demo_mnt="/host" + eval running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ") + # Prevent installing existing SONiC if it is running + if [ "$image_dir" = "image-$running_sonic_revision" ]; then + echo "Not installing SONiC version $running_sonic_revision, as current running SONiC has the same version" + exit 0 + fi + # Remove extra SONiC images if any + for f in $demo_mnt/image-* ; do + if [ -d $f ] && [ "$f" != "$demo_mnt/image-$running_sonic_revision" ] && [ "$f" != "$demo_mnt/$image_dir" ]; then + echo "Removing old SONiC installation $f" + rm -rf $f + fi + done +fi + +# Create target directory or clean it up if exists +if [ -d $demo_mnt/$image_dir ]; then + echo "Directory $demo_mnt/$image_dir/ already exists. Cleaning up..." + rm -rf $demo_mnt/$image_dir/* +else + mkdir $demo_mnt/$image_dir || { + echo "Error: Unable to create SONiC directory" + exit 1 + } +fi -hw_load_str="$(hw_load)" +# Decompress the file for the file system directly to the partition +if [ x"$docker_inram" = x"on" ]; then + # when disk is small, keep dockerfs.tar.gz in disk, expand it into ramfs during initrd + unzip -o $ONIE_INSTALLER_PAYLOAD -d $demo_mnt/$image_dir +else + unzip -o $ONIE_INSTALLER_PAYLOAD -x "$FILESYSTEM_DOCKERFS" -d $demo_mnt/$image_dir + + if [ "$install_env" = "onie" ]; then + TAR_EXTRA_OPTION="--numeric-owner" + else + TAR_EXTRA_OPTION="--numeric-owner --warning=no-timestamp" + fi + mkdir -p $demo_mnt/$image_dir/$DOCKERFS_DIR + unzip -op $ONIE_INSTALLER_PAYLOAD "$FILESYSTEM_DOCKERFS" | tar xz $TAR_EXTRA_OPTION -f - -C $demo_mnt/$image_dir/$DOCKERFS_DIR +fi + + +if [ "$install_env" = "onie" ]; then + # Store machine description in target file system + if [ -f /etc/machine-build.conf ]; then + # onie_ variable are generate at runtime. + # they are no longer hardcoded in /etc/machine.conf + # also remove single quotes around the value + set | grep ^onie | sed -e "s/='/=/" -e "s/'$//" > $demo_mnt/machine.conf + else + cp /etc/machine.conf $demo_mnt + fi +fi -cd / +# Update Bootloader Menu with installed image +bootloader_menu_config # Set NOS mode if available. For manufacturing diag installers, you # probably want to skip this step so that the system remains in ONIE diff --git a/onie-image-armhf.conf b/onie-image-armhf.conf index 0d816e4a898c..bbff03f64041 100644 --- a/onie-image-armhf.conf +++ b/onie-image-armhf.conf @@ -24,6 +24,9 @@ FILESYSTEM_DOCKERFS=dockerfs.tar.gz ## docker directory on the root filesystem DOCKERFS_DIR=docker +## docker ramfs disk space +DOCKER_RAMFS_SIZE=900M + ## Output file name for onie installer OUTPUT_ONIE_IMAGE=target/sonic-$TARGET_MACHINE.bin diff --git a/platform/marvell-armhf/one-image.mk b/platform/marvell-armhf/one-image.mk index bed895d84d86..000ac9ea3e18 100644 --- a/platform/marvell-armhf/one-image.mk +++ b/platform/marvell-armhf/one-image.mk @@ -5,6 +5,7 @@ $(SONIC_ONE_IMAGE)_MACHINE = marvell-armhf $(SONIC_ONE_IMAGE)_IMAGE_TYPE = onie $(SONIC_ONE_IMAGE)_INSTALLS += $(SYSTEMD_SONIC_GENERATOR) $(SONIC_ONE_IMAGE)_INSTALLS += $(LINUX_KERNEL_DTB) +$(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(ET6448M_PLATFORM) ifeq ($(INSTALL_DEBUG_TOOLS),y) $(SONIC_ONE_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_DBG_IMAGES) $(SONIC_ONE_IMAGE)_DOCKERS += $(filter-out $(patsubst %-$(DBG_IMAGE_MARK).gz,%.gz, $(SONIC_INSTALL_DOCKER_DBG_IMAGES)), $(SONIC_INSTALL_DOCKER_IMAGES)) diff --git a/platform/marvell-armhf/platform-et6448m.mk b/platform/marvell-armhf/platform-et6448m.mk new file mode 100644 index 000000000000..eeef04a20ae7 --- /dev/null +++ b/platform/marvell-armhf/platform-et6448m.mk @@ -0,0 +1,9 @@ +# ET6448M Platform + +ET6448M_VERSION=0.1 +ET6448M_PLATFORM = sonic-platform-et6448m_$(ET6448M_VERSION)_$(CONFIGURED_ARCH).deb +$(ET6448M_PLATFORM)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-et6448m +$(ET6448M_PLATFORM)_PLATFORM = armhf-marvell_et6448m_52x-r0 +SONIC_DPKG_DEBS += $(ET6448M_PLATFORM) + +SONIC_STRETCH_DEBS += $(ET6448M_PLATFORM) diff --git a/platform/marvell-armhf/platform.conf b/platform/marvell-armhf/platform.conf index e574a8d1a0cd..7799b33d57d9 100644 --- a/platform/marvell-armhf/platform.conf +++ b/platform/marvell-armhf/platform.conf @@ -7,76 +7,133 @@ echo "Preparing for installation ... " # global defines kernel_addr=0x1100000 fdt_addr=0x1000000 +initrd_addr=0x2000000 +VAR_LOG=512 -image_name="/vmlinuz" -fdt_name="/boot/armada-385-ET6448M_4G_Nand.dtb" +kernel_fname="/boot/vmlinuz-4.9.0-9-2-armmp" +initrd_fname="/boot/initrd.img-4.9.0-9-2-armmp" +fdt_fname="/boot/armada-385-ET6448M_4G_Nand.dtb" # global mount defines demo_dev=ubi0 mtd_dev=/dev/$(cat /proc/mtd | grep "SONIC" | grep -o "mtd[0-9]") mtd_num=$(echo $mtd_dev | grep -o "[0-9]") -demo_mount=/tmp -FW_ENV='/dev/mtd0 \t\t 0x00500000 \t 0x80000 \t 0x100000 \t 8' - -BOOTARGS='setenv bootargs root='$demo_dev' rw rootwait ubi.mtd='$mtd_num' rootfstype=ubifs panic=1 console=ttyS0,115200 ${othbootargs} ${mtdparts}' -UBI_LOAD='run ubi_sonic_boot_mount_ubi; ubifsload $kernel_addr $image_name;ubifsload $fdt_addr $fdt_name' -UBIBOOTCMD='run ubi_sonic_boot_bootargs; run ubi_sonic_boot_load; bootz $kernel_addr - $fdt_addr' - -et6448m_machine_conf() { - SYSCTL_CFG=$demo_mount/usr/share/sonic/device/armhf-marvell_et6448m_52x-r0/syncd.conf - - echo "Configure platform et6448m " - rm $demo_mount/lib/udev/rules.d/73-usb-net-by-mac.rules - rm -f $demo_mount/usr/bin/reboot || true - rm -fr $demo_mount/host/machine.conf - cp /etc/machine.conf $demo_mount/host/ - - SONIC_VERSION=$(cat $demo_mount/etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d"'") - FIRST_BOOT_FILE="$demo_mount/host/image-$SONIC_VERSION/platform" - mkdir -p $FIRST_BOOT_FILE - touch $FIRST_BOOT_FILE/firsttime - - MAC_ADDR=$(fw_printenv | grep ^ethaddr= | cut -f2 -d"=") - sed -i "s/switchMacAddress=.*/switchMacAddress=$MAC_ADDR/g" $demo_mount/usr/share/sonic/device/armhf-marvell_et6448m_52x-r0/et6448m/profile.ini - - # IPv4 and IPv6 arp cache limits - echo "sysctl -w net.ipv4.neigh.default.gc_thresh1=16000" >> $SYSCTL_CFG - echo "sysctl -w net.ipv4.neigh.default.gc_thresh2=32000" >> $SYSCTL_CFG - echo "sysctl -w net.ipv4.neigh.default.gc_thresh3=48000" >> $SYSCTL_CFG - echo "sysctl -w net.ipv6.neigh.default.gc_thresh1=8000 " >> $SYSCTL_CFG - echo "sysctl -w net.ipv6.neigh.default.gc_thresh2=16000" >> $SYSCTL_CFG - echo "sysctl -w net.ipv6.neigh.default.gc_thresh3=32000" >> $SYSCTL_CFG -} - -prepare_uboot() { +demo_mnt=/tmp +FW_ENV_DEFAULT='/dev/mtd0 0x00500000 0x80000 0x100000 8' +UBOOT_FW_DEFAULT=1 + +# Skip VID Header in UBIFS +BOOTARGS='setenv bootargs root='$demo_dev' rw rootwait ubi.mtd='$mtd_num',8192 rootfstype=ubifs panic=1 console=ttyS0,115200 ${othbootargs} ${mtdparts} ${linuxargs}' +UBI_LOAD='run ubi_sonic_boot_mount_ubi; ubifsload $kernel_addr $image_name;ubifsload $fdt_addr $fdt_name; ubifsload $initrd_addr $initrd_name' +BOOTARGS_OLD='setenv bootargs root='$demo_dev' rw rootwait ubi.mtd='$mtd_num',8192 rootfstype=ubifs panic=1 console=ttyS0,115200 ${othbootargs} ${mtdparts} ${linuxargs_old}' +UBI_LOAD_OLD='run ubi_sonic_boot_mount_ubi; ubifsload $kernel_addr $image_name_old;ubifsload $fdt_addr $fdt_name_old; ubifsload $initrd_addr $initrd_name_old' +UBIBOOTCMD='run ubi_sonic_boot_bootargs; run ubi_sonic_boot_load; test -n "$boot_once" && setenv boot_once "" && saveenv; bootz $kernel_addr $initrd_addr $fdt_addr' +UBIBOOTCMD_OLD='run ubi_sonic_boot_bootargs_old; run ubi_sonic_boot_load_old; test -n "$boot_once" && setenv boot_once "" && saveenv; bootz $kernel_addr $initrd_addr $fdt_addr' +LINUX_MISC_CMD='apparmor=1 security=apparmor usbcore.autosuspend=-1' + +prepare_boot_menu() { echo "Setting up U-Boot environment..." - echo -e $FW_ENV > /etc/fw_env.config - - fw_setenv -f image_name $image_name > /dev/null - fw_setenv -f fdt_name $fdt_name > /dev/null - fw_setenv -f kernel_addr $kernel_addr > /dev/null - fw_setenv -f fdt_addr $fdt_addr > /dev/null - - #make sure ubi number (0) and ubi volume name (ubi0) are set correctly in bootargs_root: - #For example, the below command creates an 3000MiB volume on UBI device 0: - #setenv bootargs_root root=ubi0:ubi0 rw ubi.mtd=2 rootfstype=ubifs - - fw_setenv -f mtdids 'nand0=armada-nand' > /dev/null - fw_setenv -f mtdparts 'mtdparts=armada-nand:10m(U-Boot)ro,20m@10m(ONIE),-(SONIC)' > /dev/null - fw_setenv -f ubi_sonic_boot_mount_ubi 'ubi part SONIC; ubifsmount ubi0' > /dev/null + DTB_HAS_ENV_BLK=$(grep uboot-env /proc/mtd | sed -e 's/:.*$//') + if [ -c "/dev/$DTB_HAS_ENV_BLK" ]; then + PROC_ENV_FILE=$(find /proc/device-tree/ -name env_size) + if [ -n "$PROC_ENV_FILE" ] + then + UBOOT_ENV_SIZ="0x$(hd $PROC_ENV_FILE | awk 'FNR==1 {print $2 $3 $4 $5}')" + UBOOT_ENV_ERASE_SIZ="0x$(grep uboot-env /proc/mtd | awk '{print $3}')" + if [[ -n "$UBOOT_ENV_SIZ" && -n "$UBOOT_ENV_ERASE_SIZ" ]] + then + # Env info from DTB + FW_ENV_DTB="/dev/$DTB_HAS_ENV_BLK 0x00000000 $UBOOT_ENV_SIZ $UBOOT_ENV_ERASE_SIZ" + fi + fi + fi + if [ -n "$FW_ENV_DTB" ] + then + echo $FW_ENV_DTB > /etc/fw_env.config + echo "Found uboot env offset in device tree" + UBOOT_ENV_CRC=$(fw_printenv 2>&1 | grep -c 'Warning: Bad CRC') || true + if [ "$UBOOT_ENV_CRC" -eq 0 ] + then + echo "Uboot env offset in device tree is valid" + UBOOT_FW_DEFAULT=0 + fdt_fname="/boot/armada-385-ET6448M_4G_Nand_r2019.dtb" + else + echo "Uboot env offset in device tree is NOT valid" + UBOOT_FW_DEFAULT=1 + fi + fi + if [ $UBOOT_FW_DEFAULT -eq 1 ] + then + echo $FW_ENV_DEFAULT > /etc/fw_env.config + echo "Using pre-configured uboot env" + fi + image_name=${image_dir}${kernel_fname} + initrd_name=${image_dir}${initrd_fname} + fdt_name=${image_dir}${fdt_fname} + + if [ "$install_env" = "onie" ]; then + FW_ARG="-f" + image_dir_old="" + image_name_old="" + initrd_name_old="" + fdt_name_old="" + sonic_version_2="None" + else + image_dir_old=$(fw_printenv -n image_dir || true) + image_name_old=$(fw_printenv -n image_name || true) + initrd_name_old=$(fw_printenv -n initrd_name || true) + fdt_name_old=$(fw_printenv -n fdt_name || true) + sonic_version_2=$(fw_printenv -n sonic_version_1 || true) + fi - fw_setenv -f ubi_sonic_boot_bootargs $BOOTARGS > /dev/null - fw_setenv -f ubi_sonic_boot_load $UBI_LOAD > /dev/null - fw_setenv -f ubi_sonic_boot $UBIBOOTCMD > /dev/null - fw_setenv -f bootcmd 'usb start; run ubi_sonic_boot' > /dev/null + # Set boot variables + fw_setenv ${FW_ARG} image_dir $image_dir > /dev/null + fw_setenv ${FW_ARG} image_name $image_name > /dev/null + fw_setenv ${FW_ARG} initrd_name $initrd_name > /dev/null + fw_setenv ${FW_ARG} fdt_name $fdt_name > /dev/null + fw_setenv ${FW_ARG} sonic_version_1 $demo_volume_revision_label > /dev/null + fw_setenv ${FW_ARG} image_dir_old $image_dir_old > /dev/null + fw_setenv ${FW_ARG} image_name_old $image_name_old > /dev/null + fw_setenv ${FW_ARG} initrd_name_old $initrd_name_old > /dev/null + fw_setenv ${FW_ARG} fdt_name_old $fdt_name_old > /dev/null + fw_setenv ${FW_ARG} sonic_version_2 $sonic_version_2 > /dev/null + BOOT1='echo " > Boot1: $sonic_version_1 - run sonic_image_1";echo;' + BOOT2='echo " > Boot2: $sonic_version_2 - run sonic_image_2";echo;' + BOOT3='echo " > Boot3: ONIE - run onie_nand_boot";echo;' + BORDER='echo "---------------------------------------------------";echo;' + fw_setenv ${FW_ARG} print_menu $BORDER $BOOT1 $BOOT2 $BOOT3 $BORDER > /dev/null + + fw_setenv ${FW_ARG} linuxargs "net.ifnames=0 loopfstype=squashfs loop=$image_dir/$FILESYSTEM_SQUASHFS varlog_size=$VAR_LOG" > /dev/null + fw_setenv ${FW_ARG} linuxargs_old "net.ifnames=0 loopfstype=squashfs loop=$image_dir_old/$FILESYSTEM_SQUASHFS varlog_size=$VAR_LOG" > /dev/null + + # Set boot configs + fw_setenv ${FW_ARG} kernel_addr $kernel_addr > /dev/null + fw_setenv ${FW_ARG} fdt_addr $fdt_addr > /dev/null + fw_setenv ${FW_ARG} initrd_addr $initrd_addr > /dev/null + fw_setenv ${FW_ARG} mtdids 'nand0=armada-nand' > /dev/null + if [ $UBOOT_FW_DEFAULT -eq 1 ] + then + fw_setenv ${FW_ARG} mtdparts 'mtdparts=armada-nand:10m(U-Boot)ro,20m@10m(ONIE),-(SONIC)' > /dev/null + else + fw_setenv ${FW_ARG} mtdparts 'mtdparts=armada-nand:4m(uboot)ro,5m@5m(uboot-env),20m@10m(ONIE),-(SONIC)' > /dev/null + fi + fw_setenv ${FW_ARG} ubi_sonic_boot_mount_ubi 'ubi part SONIC; ubifsmount ubi0' > /dev/null + fw_setenv ${FW_ARG} ubi_sonic_boot_bootargs $BOOTARGS > /dev/null + fw_setenv ${FW_ARG} ubi_sonic_boot_load $UBI_LOAD > /dev/null + fw_setenv ${FW_ARG} sonic_image_1 "$UBIBOOTCMD" > /dev/null + fw_setenv ${FW_ARG} ubi_sonic_boot_bootargs_old $BOOTARGS_OLD > /dev/null + fw_setenv ${FW_ARG} ubi_sonic_boot_load_old $UBI_LOAD_OLD > /dev/null + fw_setenv ${FW_ARG} sonic_image_2 "$UBIBOOTCMD_OLD" > /dev/null + fw_setenv ${FW_ARG} boot_next 'run sonic_image_1'> /dev/null + fw_setenv ${FW_ARG} bootcmd 'run print_menu; usb start; test -n "$boot_once" && run boot_once; run boot_next' > /dev/null } -install_uimage() { - - ubidetach /dev/ubi_ctrl -m $mtd_num 2>/dev/null || true +create_ubi_partition() { + ubidetach /dev/ubi_ctrl -d 0 2>/dev/null || true + trap_push "${onie_bin} ubidetach -d 0 /dev/ubi_ctrl || true" echo -en "Format mtd partition '$mtd_dev' " ubiformat $mtd_dev -y -q || { echo "Failed" @@ -90,54 +147,29 @@ install_uimage() { #creates UBI volumes on UBI devices ubimkvol /dev/$demo_dev -N $demo_dev -s 3900MiB +} + +create_partition() { + # Platform speicific partition + create_ubi_partition +} + +mount_partition() { - demo_mount=$(mktemp -d) || { + demo_mnt=$(mktemp -d) || { echo "Error: Unable to create file sstem mount point" exit 1 } - echo "Mounting $demo_dev on $demo_mount " - mount -t ubifs /dev/ubi0_0 $demo_mount || { + echo "Mounting $demo_dev on $demo_mnt " + trap_push "${onie_bin} umount /dev/ubi0_0|| true" + mount -t ubifs /dev/ubi0_0 $demo_mnt || { echo "Failed" } +} - echo "Extracting NOS " - - # Decompress the file for the file system directly to the partition - unzip -o $ONIE_INSTALLER_PAYLOAD -x "$FILESYSTEM_DOCKERFS" -d $demo_mount/ - cd $demo_mount - - if [ -f fs.cpio ]; then - cpio -id < fs.cpio - if [ $? -ne 0 ]; then - echo "cpio extraction Failed" - fi - rm fs.cpio - elif [ -f fs.squashfs ]; then - unsquashfs -f -d $demo_mount $FILESYSTEM_SQUASHFS - if [ $? -ne 0 ]; then - echo "unsquashfs extraction Failed" - fi - rm -f $FILESYSTEM_SQUASHFS - fi - - cd - - TAR_EXTRA_OPTION="--numeric-owner" - mkdir -p $demo_mount/var/lib/$DOCKERFS_DIR - unzip -op $ONIE_INSTALLER_PAYLOAD "$FILESYSTEM_DOCKERFS" | tar -xpz $TAR_EXTRA_OPTION -f - -C $demo_mount/var/lib/$DOCKERFS_DIR - +bootloader_menu_config() { # Update uboot Environment - prepare_uboot - - # Platform configuration - et6448m_machine_conf - - # Unmounting mount path - umount $demo_mount - - echo "Reboot board to boot from installed OS" + prepare_boot_menu } -hw_load() { - echo "mtdpart default && ubi part SONIC && ubifsmount 'demo_dev' && ubifsload '$kernel_addr' 'image_name'" -} diff --git a/platform/marvell-armhf/rules.mk b/platform/marvell-armhf/rules.mk index 809e46bd1738..fb46b261fa06 100644 --- a/platform/marvell-armhf/rules.mk +++ b/platform/marvell-armhf/rules.mk @@ -7,6 +7,7 @@ include $(PLATFORM_PATH)/libsaithrift-dev.mk include $(PLATFORM_PATH)/docker-ptf-mrvl.mk include $(PLATFORM_PATH)/one-image.mk include $(PLATFORM_PATH)/linux-kernel-armhf.mk +include $(PLATFORM_PATH)/platform-et6448m.mk ENABLE_SYSTEM_TELEMETRY = "" ENABLE_SYNCD_RPC = "" diff --git a/platform/marvell-armhf/sonic-platform-et6448m/.gitignore b/platform/marvell-armhf/sonic-platform-et6448m/.gitignore new file mode 100644 index 000000000000..7f287d538227 --- /dev/null +++ b/platform/marvell-armhf/sonic-platform-et6448m/.gitignore @@ -0,0 +1,50 @@ +# Object files +*.o +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su + +# Kernel Module Compile Results +*.mod* +*.cmd +*.o.d +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +# Debian packaging +*.debhelper.log +*.postinst.debhelper +*.postrm.debhelper +*.prerm.debhelper +*.substvars diff --git a/platform/marvell-armhf/sonic-platform-et6448m/debian/changelog b/platform/marvell-armhf/sonic-platform-et6448m/debian/changelog new file mode 100755 index 000000000000..98934823b4f5 --- /dev/null +++ b/platform/marvell-armhf/sonic-platform-et6448m/debian/changelog @@ -0,0 +1,5 @@ +sonic-platform-et6448m (0.1) unstable; urgency=low + + * Add support for ET6448M. + + -- Marvell Mon, 11 Nov 2019 09:35:58 +0800 diff --git a/platform/marvell-armhf/sonic-platform-et6448m/debian/compat b/platform/marvell-armhf/sonic-platform-et6448m/debian/compat new file mode 100644 index 000000000000..ec635144f600 --- /dev/null +++ b/platform/marvell-armhf/sonic-platform-et6448m/debian/compat @@ -0,0 +1 @@ +9 diff --git a/platform/marvell-armhf/sonic-platform-et6448m/debian/control b/platform/marvell-armhf/sonic-platform-et6448m/debian/control new file mode 100755 index 000000000000..52c9593a1ea5 --- /dev/null +++ b/platform/marvell-armhf/sonic-platform-et6448m/debian/control @@ -0,0 +1,15 @@ +Source: sonic-platform-et6448m +Section: unknown +Priority: optional +Maintainer: Marvell +Build-Depends: debhelper (>=9) +Standards-Version: 3.9.6 +Homepage: +#Vcs-Git: git://anonscm.debian.org/collab-maint/sonic-platform-et6448m.git +#Vcs-Browser: https://anonscm.debian.org/cgit/collab-maint/sonic-platform-et6448m.git + +Package: sonic-platform-et6448m +Architecture: armhf +Depends: ${misc:Depends} +Description: + diff --git a/platform/marvell-armhf/sonic-platform-et6448m/debian/install b/platform/marvell-armhf/sonic-platform-et6448m/debian/install new file mode 100644 index 000000000000..af8265fb38ce --- /dev/null +++ b/platform/marvell-armhf/sonic-platform-et6448m/debian/install @@ -0,0 +1 @@ +et6448m_plt_setup.sh usr/sbin diff --git a/platform/marvell-armhf/sonic-platform-et6448m/debian/postinst b/platform/marvell-armhf/sonic-platform-et6448m/debian/postinst new file mode 100644 index 000000000000..a3a727c7222c --- /dev/null +++ b/platform/marvell-armhf/sonic-platform-et6448m/debian/postinst @@ -0,0 +1,40 @@ +#!/bin/sh +# postinst script for sonic-platform-et6448m +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-remove' +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see https://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + configure) + sh /usr/sbin/et6448m_plt_setup.sh + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/platform/marvell-armhf/sonic-platform-et6448m/debian/rules b/platform/marvell-armhf/sonic-platform-et6448m/debian/rules new file mode 100755 index 000000000000..2f54c4710f17 --- /dev/null +++ b/platform/marvell-armhf/sonic-platform-et6448m/debian/rules @@ -0,0 +1,25 @@ +#!/usr/bin/make -f +# See debhelper(7) (uncomment to enable) +# output every command that modifies files on the build system. +#export DH_VERBOSE = 1 + + +# see FEATURE AREAS in dpkg-buildflags(1) +#export DEB_BUILD_MAINT_OPTIONS = hardening=+all + +# see ENVIRONMENT in dpkg-buildflags(1) +# package maintainers to append CFLAGS +#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic +# package maintainers to append LDFLAGS +#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed + + +%: + dh $@ + + +# dh_make generated override targets +# This is example for Cmake (See https://bugs.debian.org/641051 ) +#override_dh_auto_configure: +# dh_auto_configure -- # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) + diff --git a/platform/marvell-armhf/sonic-platform-et6448m/et6448m_plt_setup.sh b/platform/marvell-armhf/sonic-platform-et6448m/et6448m_plt_setup.sh new file mode 100755 index 000000000000..83a0add5f005 --- /dev/null +++ b/platform/marvell-armhf/sonic-platform-et6448m/et6448m_plt_setup.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +fw_uboot_env_cfg() +{ + echo "Setting up U-Boot environment..." + FW_ENV_DEFAULT='/dev/mtd0 0x00500000 0x80000 0x100000 8' + UBOOT_FW_DFAULT=1 + + DTB_HAS_ENV_BLK=$(grep uboot-env /proc/mtd | sed -e 's/:.*$//') + if [ -c "/dev/$DTB_HAS_ENV_BLK" ]; then + PROC_ENV_FILE=$(find /proc/device-tree/ -name env_size) + if [ -n "$PROC_ENV_FILE" ] + then + UBOOT_ENV_SIZ="0x$(hd $PROC_ENV_FILE | awk 'FNR==1 {print $2 $3 $4 $5}')" + UBOOT_ENV_ERASE_SIZ="0x$(grep uboot-env /proc/mtd | awk '{print $3}')" + if [[ -n "$UBOOT_ENV_SIZ" && -n "$UBOOT_ENV_ERASE_SIZ" ]] + then + # Env info from DTB + FW_ENV_DTB="/dev/$DTB_HAS_ENV_BLK 0x00000000 $UBOOT_ENV_SIZ $UBOOT_ENV_ERASE_SIZ" + fi + fi + fi + if [ -n "$FW_ENV_DTB" ] + then + echo $FW_ENV_DTB > /etc/fw_env.config + echo "Found uboot env offset in device tree" + UBOOT_ENV_CRC=$(fw_printenv -c /etc/fw_env.config 2>&1 | grep -c 'Warning: Bad CRC') + if [ $UBOOT_ENV_CRC -eq 0 ] + then + echo "Uboot env offset in device tree is valid" + UBOOT_FW_DFAULT=0 + else + echo "Uboot env offset in device tree is NOT valid" + UBOOT_FW_DFAULT=1 + fi + fi + if [ $UBOOT_FW_DFAULT -eq 1 ] + then + echo $FW_ENV_DEFAULT > /etc/fw_env.config + echo "Using pre-configured uboot env" + fi +} + +et6448m_profile() +{ + MAC_ADDR=$(fw_printenv -n ethaddr) + sed -i "s/switchMacAddress=.*/switchMacAddress=$MAC_ADDR/g" /usr/share/sonic/device/armhf-marvell_et6448m_52x-r0/et6448m/profile.ini + echo "ET6448M: Updating switch mac address ${MAC_ADDR}" +} + +main() +{ + fw_uboot_env_cfg + et6448m_profile +} + +main $@