Skip to content

Commit 2d3b064

Browse files
padmanarayanalguohan
authored andcommitted
[image]: build sonic-broadcom.raw image for sonic conversion from ftos (#901)
1. "make target/sonic-broadcom.raw" will create the compressed dd'able image. 2. This will also update the grub config files (device/dell/*/nos_to_sonic_grub.cfg) with the image versions.
1 parent 0a9d60e commit 2d3b064

File tree

10 files changed

+232
-29
lines changed

10 files changed

+232
-29
lines changed

build_image.sh

+51-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414

1515
IMAGE_VERSION=$(. functions.sh && sonic_get_version)
1616

17-
if [ "$IMAGE_TYPE" = "onie" ]; then
18-
echo "Build ONIE installer"
19-
mkdir -p `dirname $OUTPUT_ONIE_IMAGE`
20-
sudo rm -f $OUTPUT_ONIE_IMAGE
21-
17+
generate_onie_installer_image()
18+
{
2219
# Copy platform-specific ONIE installer config files where onie-mk-demo.sh expects them
2320
rm -rf ./installer/x86_64/platforms/
2421
mkdir -p ./installer/x86_64/platforms/
@@ -27,6 +24,11 @@ if [ "$IMAGE_TYPE" = "onie" ]; then
2724
if [ -f ./device/$VENDOR/$PLATFORM/installer.conf ]; then
2825
cp ./device/$VENDOR/$PLATFORM/installer.conf ./installer/x86_64/platforms/$PLATFORM
2926
fi
27+
28+
if [ "$IMAGE_TYPE" = "raw" ] && [ -f ./device/$VENDOR/$PLATFORM/nos_to_sonic_grub.cfg ]; then
29+
sed -i -e "s/%%IMAGE_VERSION%%/$IMAGE_VERSION/g" ./device/$VENDOR/$PLATFORM/nos_to_sonic_grub.cfg
30+
echo "IMAGE_VERSION is $IMAGE_VERSION"
31+
fi
3032
done
3133
done
3234

@@ -35,6 +37,50 @@ if [ "$IMAGE_TYPE" = "onie" ]; then
3537
./onie-mk-demo.sh $TARGET_PLATFORM $TARGET_MACHINE $TARGET_PLATFORM-$TARGET_MACHINE-$ONIEIMAGE_VERSION \
3638
installer platform/$TARGET_MACHINE/platform.conf $OUTPUT_ONIE_IMAGE OS $IMAGE_VERSION $ONIE_IMAGE_PART_SIZE \
3739
$ONIE_INSTALLER_PAYLOAD
40+
}
41+
42+
if [ "$IMAGE_TYPE" = "onie" ]; then
43+
echo "Build ONIE installer"
44+
mkdir -p `dirname $OUTPUT_ONIE_IMAGE`
45+
sudo rm -f $OUTPUT_ONIE_IMAGE
46+
47+
generate_onie_installer_image
48+
49+
## Build a raw partition dump image using the ONIE installer that can be
50+
## used to dd' in-lieu of using the onie-nos-installer. Used while migrating
51+
## into SONiC from other NOS.
52+
elif [ "$IMAGE_TYPE" = "raw" ]; then
53+
54+
echo "Build RAW image"
55+
mkdir -p `dirname $OUTPUT_RAW_IMAGE`
56+
sudo rm -f $OUTPUT_RAW_IMAGE
57+
58+
generate_onie_installer_image
59+
60+
echo "Creating SONiC raw partition : $OUTPUT_RAW_IMAGE of size $RAW_IMAGE_DISK_SIZE MB"
61+
fallocate -l "$RAW_IMAGE_DISK_SIZE"M $OUTPUT_RAW_IMAGE
62+
63+
## Generate a compressed 8GB partition dump that can be used to 'dd' in-lieu of using the onie-nos-installer
64+
## Run the installer
65+
## The 'build' install mode of the installer is used to generate this dump.
66+
sudo chmod a+x $OUTPUT_ONIE_IMAGE
67+
sudo ./$OUTPUT_ONIE_IMAGE
68+
69+
[ -r $OUTPUT_RAW_IMAGE ] || {
70+
echo "Error : $OUTPUT_RAW_IMAGE not generated!"
71+
exit 1
72+
}
73+
74+
gzip $OUTPUT_RAW_IMAGE
75+
76+
[ -r $OUTPUT_RAW_IMAGE.gz ] || {
77+
echo "Error : gzip $OUTPUT_RAW_IMAGE failed!"
78+
exit 1
79+
}
80+
81+
mv $OUTPUT_RAW_IMAGE.gz $OUTPUT_RAW_IMAGE
82+
echo "The compressed raw image is in $OUTPUT_RAW_IMAGE"
83+
3884
## Use 'aboot' as target machine category which includes Aboot as bootloader
3985
elif [ "$IMAGE_TYPE" = "aboot" ]; then
4086
echo "Build Aboot installer"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#
2+
# Grub config to launch SONiC
3+
# with ONIE boot option
4+
5+
insmod serial
6+
# Initialize USB-Serial com2 port
7+
serial --unit=1 --speed=9600
8+
#Serial port config;Defaults: COM1,9600
9+
serial --unit=0 --speed=9600
10+
terminal_output serial_com0
11+
terminal_input serial_com0
12+
#terminfo added to prevent text wrap issue.
13+
terminfo -g 80x100 serial_com0
14+
terminfo -g 80x100 serial_com1
15+
16+
echo -n "Press Esc to stop autoboot ... "
17+
if sleep --verbose --interruptible 5 ; then
18+
insmod gzio
19+
insmod part_msdos
20+
insmod ext2
21+
set root='(hd0,gpt8)'
22+
linux /image-%%IMAGE_VERSION%%/boot/vmlinuz-3.16.0-4-amd64 root=/dev/sda8 rw console=tty0 console=ttyS1,9600n8 loop=image-%%IMAGE_VERSION%%/fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor
23+
initrd /image-%%IMAGE_VERSION%%/boot/initrd.img-3.16.0-4-amd64
24+
boot
25+
else
26+
menuentry 'SONiC' {
27+
insmod gzio
28+
insmod part_msdos
29+
insmod ext2
30+
set root='(hd0,gpt8)'
31+
linux /image-%%IMAGE_VERSION%%/boot/vmlinuz-3.16.0-4-amd64 root=/dev/sda8 rw console=tty0 console=ttyS1,9600n8 loop=image-%%IMAGE_VERSION%%/fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor
32+
initrd /image-%%IMAGE_VERSION%%/boot/initrd.img-3.16.0-4-amd64
33+
boot
34+
}
35+
36+
menuentry 'ONIE' {
37+
insmod force10
38+
onieboot
39+
}
40+
41+
menuentry 'DELL-DIAG' {
42+
delldiagboot
43+
}
44+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#
2+
# Grub config to launch SONiC
3+
# with ONIE boot option
4+
5+
insmod serial
6+
# Initialize USB-Serial com2 port
7+
serial --unit=1 --speed=9600
8+
#Serial port config;Defaults: COM1,9600
9+
serial --unit=0 --speed=9600
10+
terminal_output serial_com0
11+
terminal_input serial_com0
12+
#terminfo added to prevent text wrap issue.
13+
terminfo -g 80x100 serial_com0
14+
terminfo -g 80x100 serial_com1
15+
16+
echo -n "Press Esc to stop autoboot ... "
17+
if sleep --verbose --interruptible 5 ; then
18+
insmod gzio
19+
insmod part_msdos
20+
insmod ext2
21+
set root='(hd0,gpt8)'
22+
linux /image-%%IMAGE_VERSION%%/boot/vmlinuz-3.16.0-4-amd64 root=/dev/sda8 rw console=tty0 console=ttyS1,9600n8 loop=image-%%IMAGE_VERSION%%/fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor
23+
initrd /image-%%IMAGE_VERSION%%/boot/initrd.img-3.16.0-4-amd64
24+
boot
25+
else
26+
menuentry 'SONiC' {
27+
insmod gzio
28+
insmod part_msdos
29+
insmod ext2
30+
set root='(hd0,gpt8)'
31+
linux /image-%%IMAGE_VERSION%%/boot/vmlinuz-3.16.0-4-amd64 root=/dev/sda8 rw console=tty0 console=ttyS1,9600n8 loop=image-%%IMAGE_VERSION%%/fs.squashfs loopfstype=squashfs apparmor=1 security=apparmor
32+
initrd /image-%%IMAGE_VERSION%%/boot/initrd.img-3.16.0-4-amd64
33+
boot
34+
}
35+
36+
menuentry 'ONIE' {
37+
insmod force10
38+
onieboot
39+
}
40+
41+
menuentry 'DELL-DIAG' {
42+
delldiagboot
43+
}
44+
fi

files/image_config/platform/rc.local

+21
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@
1111
#
1212
# By default this script does nothing.
1313

14+
# If the machine.conf is absent, it indicates that the unit booted
15+
# into SONiC from another NOS. Extract the machine.conf from ONIE.
16+
if [ ! -e /host/machine.conf ]; then
17+
onie_dev=$(blkid | grep ONIE-BOOT | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//')
18+
mkdir -p /mnt/onie-boot
19+
mount $onie_dev /mnt/onie-boot
20+
onie_grub_cfg=/mnt/onie-boot/onie/grub/grub-machine.cfg
21+
22+
if [ ! -e $onie_grub_cfg ]; then
23+
echo "$onie_grub_cfg not found" >> /etc/migration.log
24+
else
25+
. ./$onie_grub_cfg
26+
grep = $onie_grub_cfg | sed -e 's/onie_//' -e 's/=.*$//' | while read var ; do
27+
eval val='$'onie_$var
28+
echo "onie_${var}=${val}" >> /host/machine.conf
29+
done
30+
fi
31+
32+
umount /mnt/onie-boot
33+
fi
34+
1435
. /host/machine.conf
1536

1637
echo "install platform dependent packages at the first boot time"

installer/sharch_body.sh

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ echo " OK."
2727

2828
# Untar and launch install script in a tmpfs
2929
cur_wd=$(pwd)
30+
export cur_wd
3031
archive_path=$(realpath "$0")
3132
tmp_dir=$(mktemp -d)
3233
if [ "$(id -u)" = "0" ] ; then

installer/x86_64/install.sh

+50-24
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,25 @@ _trap_push true
2424
set -e
2525
cd $(dirname $0)
2626

27+
if [ -d "/etc/sonic" ]; then
28+
echo "Installing SONiC in SONiC"
29+
install_env="sonic"
30+
elif grep -Fxqs "DISTRIB_ID=onie" /etc/lsb-release > /dev/null
31+
then
32+
echo "Installing SONiC in ONIE"
33+
install_env="onie"
34+
else
35+
echo "Installing SONiC in BUILD"
36+
install_env="build"
37+
fi
38+
39+
if [ -r ./machine.conf ]; then
2740
. ./machine.conf
41+
fi
42+
43+
if [ -r ./onie-image.conf ]; then
2844
. ./onie-image.conf
45+
fi
2946

3047
echo "ONIE Installer: platform: $platform"
3148

@@ -40,7 +57,7 @@ if [ -r /etc/machine.conf ]; then
4057
. /etc/machine.conf
4158
elif [ -r /host/machine.conf ]; then
4259
. /host/machine.conf
43-
else
60+
elif [ "$install_env" != "build" ]; then
4461
echo "cannot find machine.conf"
4562
exit 1
4663
fi
@@ -58,26 +75,20 @@ ONIE_PLATFORM_EXTRA_CMDLINE_LINUX=""
5875
# Default var/log device size in MB
5976
VAR_LOG_SIZE=4096
6077

61-
if [ -d "/etc/sonic" ]; then
62-
echo "Installing SONiC in SONiC"
63-
install_env="sonic"
64-
else
65-
echo "Installing SONiC in ONIE"
66-
install_env="onie"
67-
fi
68-
6978
[ -r platforms/$onie_platform ] && . platforms/$onie_platform
7079

7180
# Install demo on same block device as ONIE
72-
onie_dev=$(blkid | grep ONIE-BOOT | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//')
73-
blk_dev=$(echo $onie_dev | sed -e 's/[1-9][0-9]*$//' | sed -e 's/\([0-9]\)\(p\)/\1/')
74-
# Note: ONIE has no mount setting for / with device node, so below will be empty string
75-
cur_part=$(cat /proc/mounts | awk "{ if(\$2==\"/\") print \$1 }" | grep $blk_dev || true)
76-
77-
[ -b "$blk_dev" ] || {
78-
echo "Error: Unable to determine block device of ONIE install"
79-
exit 1
80-
}
81+
if [ "$install_env" != "build" ]; then
82+
onie_dev=$(blkid | grep ONIE-BOOT | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//')
83+
blk_dev=$(echo $onie_dev | sed -e 's/[1-9][0-9]*$//' | sed -e 's/\([0-9]\)\(p\)/\1/')
84+
# Note: ONIE has no mount setting for / with device node, so below will be empty string
85+
cur_part=$(cat /proc/mounts | awk "{ if(\$2==\"/\") print \$1 }" | grep $blk_dev || true)
86+
87+
[ -b "$blk_dev" ] || {
88+
echo "Error: Unable to determine block device of ONIE install"
89+
exit 1
90+
}
91+
fi
8192

8293
# If running in ONIE
8394
if [ "$install_env" = "onie" ]; then
@@ -108,7 +119,7 @@ else
108119
firmware="bios"
109120
fi
110121

111-
if [ "$install_env" != "sonic" ]; then
122+
if [ "$install_env" = "onie" ]; then
112123
# determine ONIE partition type
113124
onie_partition_type=$(${onie_bin} onie-sysinfo -t)
114125
# demo partition size in MB
@@ -310,6 +321,7 @@ demo_install_grub()
310321
cat $grub_install_log && rm -f $grub_install_log
311322
exit 1
312323
}
324+
313325
rm -f $grub_install_log
314326
315327
# restore immutable flag on the core.img file as discussed
@@ -374,7 +386,7 @@ demo_install_uefi_grub()
374386
375387
image_dir="image-$image_version"
376388
377-
if [ "$install_env" != "sonic" ]; then
389+
if [ "$install_env" = "onie" ]; then
378390
eval $create_demo_partition $blk_dev
379391
demo_dev=$(echo $blk_dev | sed -e 's/\(mmcblk[0-9]\)/\1p/')$demo_part
380392
@@ -391,7 +403,8 @@ if [ "$install_env" != "sonic" ]; then
391403
echo "Error: Unable to mount $demo_dev on $demo_mnt"
392404
exit 1
393405
}
394-
else
406+
407+
elif [ "$install_env" = "sonic" ]; then
395408
demo_mnt="/host"
396409
running_sonic_revision=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ")
397410
# Prevent installing existing SONiC if it is running
@@ -406,6 +419,15 @@ else
406419
rm -rf $f
407420
fi
408421
done
422+
else
423+
demo_mnt="build_raw_image_mnt"
424+
demo_dev=$cur_wd/"%%OUTPUT_RAW_IMAGE%%"
425+
426+
mkfs.ext4 $demo_dev
427+
428+
echo "Mounting $demo_dev on $demo_mnt..."
429+
mkdir $demo_mnt
430+
mount -t auto -o loop $demo_dev $demo_mnt
409431
fi
410432
411433
echo "Installing SONiC to $demo_mnt/$image_dir"
@@ -446,7 +468,7 @@ if [ "$VAR_LOG_SIZE" != "0" ]; then
446468
mkfs.ext4 -q $demo_mnt/disk-img/var-log.ext4 -F
447469
fi
448470
449-
if [ "$install_env" != "sonic" ]; then
471+
if [ "$install_env" = "onie" ]; then
450472
# Store machine description in target file system
451473
cp /etc/machine.conf $demo_mnt
452474
@@ -547,7 +569,7 @@ menuentry '$demo_grub_entry' {
547569
}
548570
EOF
549571
550-
if [ "$install_env" != "sonic" ]; then
572+
if [ "$install_env" = "onie" ]; then
551573
# Add menu entries for ONIE -- use the grub fragment provided by the
552574
# ONIE distribution.
553575
$onie_root_dir/grub.d/50_onie_grub >> $grub_cfg
@@ -559,7 +581,11 @@ $onie_menuentry
559581
EOF
560582
fi
561583
562-
cp $grub_cfg $onie_initrd_tmp/$demo_mnt/grub/grub.cfg
584+
if [ "$install_env" = "build" ]; then
585+
umount $demo_mnt
586+
else
587+
cp $grub_cfg $onie_initrd_tmp/$demo_mnt/grub/grub.cfg
588+
fi
563589
564590
cd /
565591

onie-image.conf

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ DOCKERFS_DIR=docker
2727
## Output file name for onie installer
2828
OUTPUT_ONIE_IMAGE=target/sonic-$TARGET_MACHINE.bin
2929

30+
### Output file name for raw image
31+
OUTPUT_RAW_IMAGE=target/sonic-$TARGET_MACHINE.raw
32+
33+
### Raw image size in MB
34+
RAW_IMAGE_DISK_SIZE=8192
35+
3036
## Output file name for aboot installer
3137
OUTPUT_ABOOT_IMAGE=target/sonic-aboot-$TARGET_MACHINE.swi
3238

onie-mk-demo.sh

+5
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,16 @@ cp onie-image.conf $tmp_installdir
8383
# sed. Special chars are: \ / &
8484
EXTRA_CMDLINE_LINUX=`echo $EXTRA_CMDLINE_LINUX | sed -e 's/[\/&]/\\\&/g'`
8585

86+
output_raw_image=$(cat onie-image.conf | grep OUTPUT_RAW_IMAGE | cut -f2 -d"=")
87+
[ -z "$TARGET_MACHINE" ] && output_raw_image=$(echo $output_raw_image | sed -e 's/$TARGET_MACHINE/$machine/g')
88+
output_raw_image=$(eval echo $output_raw_image)
89+
8690
# Tailor the demo installer for OS mode or DIAG mode
8791
sed -i -e "s/%%DEMO_TYPE%%/$demo_type/g" \
8892
-e "s/%%IMAGE_VERSION%%/$image_version/g" \
8993
-e "s/%%ONIE_IMAGE_PART_SIZE%%/$onie_image_part_size/" \
9094
-e "s/%%EXTRA_CMDLINE_LINUX%%/$EXTRA_CMDLINE_LINUX/" \
95+
-e "s@%%OUTPUT_RAW_IMAGE%%@$output_raw_image@" \
9196
$tmp_installdir/install.sh || clean_up 1
9297
echo -n "."
9398
cp -r $* $tmp_installdir || clean_up 1

platform/broadcom/raw-image.mk

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# sonic broadcom raw image installer
2+
3+
SONIC_RAW_IMAGE = sonic-broadcom.raw
4+
$(SONIC_RAW_IMAGE)_MACHINE = broadcom
5+
$(SONIC_RAW_IMAGE)_IMAGE_TYPE = raw
6+
$(SONIC_RAW_IMAGE)_DEPENDS += $(BRCM_OPENNSL_KERNEL)
7+
$(SONIC_RAW_IMAGE)_INSTALLS += $($(SONIC_ONE_IMAGE)_INSTALLS)
8+
$(SONIC_RAW_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_IMAGES)
9+
SONIC_INSTALLERS += $(SONIC_RAW_IMAGE)

0 commit comments

Comments
 (0)