Skip to content

Commit

Permalink
[initramfs] Updated required tools for initramfs (sonic-net#3734)
Browse files Browse the repository at this point in the history
* [initramfs] Updated reuired tools for initramfs

Signed-off-by: Antony Rheneus <[email protected]>

* [initramfs] Updated required tools for initramfs

Signed-off-by: Antony Rheneus <[email protected]>

* [Platform] [Marvell] Platform specific debian package for et6448m device

Signed-off-by: Antony Rheneus <[email protected]>

* Removed auto-generated files

Signed-off-by: Antony Rheneus <[email protected]>

* [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 <[email protected]>

* [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 <[email protected]>

* [initramfs] Marvell arm modules update and platform config update

Signed-off-by: Antony Rheneus <[email protected]>

* [iniramfs] add initramfs uboot-utils hook script only for ARM

Signed-off-by: Antony Rheneus <[email protected]>
  • Loading branch information
antony-rheneus authored and lguohan committed Jan 15, 2020
1 parent 9a089c2 commit 6bd17d4
Show file tree
Hide file tree
Showing 20 changed files with 535 additions and 122 deletions.
19 changes: 19 additions & 0 deletions build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions device/marvell/armhf-marvell_et6448m_52x-r0/fancontrol
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions files/initramfs-tools/modules.arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
crc16
deflate
zlib_deflate
m25p80
ubi
ubifs
squashfs
21 changes: 21 additions & 0 deletions files/initramfs-tools/uboot-utils
Original file line number Diff line number Diff line change
@@ -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
15 changes: 13 additions & 2 deletions files/initramfs-tools/union-mount.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion files/initramfs-tools/varlog
Original file line number Diff line number Diff line change
Expand Up @@ -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
134 changes: 121 additions & 13 deletions installer/armhf/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions onie-image-armhf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions platform/marvell-armhf/one-image.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 9 additions & 0 deletions platform/marvell-armhf/platform-et6448m.mk
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit 6bd17d4

Please sign in to comment.