head	1.95;
access;
symbols
	netbsd-11-0-RC4:1.92
	netbsd-11-0-RC3:1.92
	netbsd-11-0-RC2:1.92
	netbsd-11-0-RC1:1.92
	perseant-exfatfs-base-20250801:1.92
	netbsd-11:1.92.0.2
	netbsd-11-base:1.92
	netbsd-10-1-RELEASE:1.78.2.1
	perseant-exfatfs-base-20240630:1.82
	perseant-exfatfs:1.82.0.2
	perseant-exfatfs-base:1.82
	netbsd-8-3-RELEASE:1.64.4.1
	netbsd-9-4-RELEASE:1.69.6.1
	netbsd-10-0-RELEASE:1.78.2.1
	netbsd-10-0-RC6:1.78.2.1
	netbsd-10-0-RC5:1.78.2.1
	netbsd-10-0-RC4:1.78.2.1
	netbsd-10-0-RC3:1.78
	netbsd-10-0-RC2:1.78
	netbsd-10-0-RC1:1.78
	netbsd-10:1.78.0.2
	netbsd-10-base:1.78
	netbsd-9-3-RELEASE:1.69.6.1
	cjep_sun2x-base1:1.77
	cjep_sun2x:1.77.0.4
	cjep_sun2x-base:1.77
	cjep_staticlib_x-base1:1.77
	netbsd-9-2-RELEASE:1.69.6.1
	cjep_staticlib_x:1.77.0.2
	cjep_staticlib_x-base:1.77
	netbsd-9-1-RELEASE:1.69.6.1
	phil-wifi-20200421:1.71
	phil-wifi-20200411:1.71
	is-mlppp:1.71.0.2
	is-mlppp-base:1.71
	phil-wifi-20200406:1.71
	netbsd-8-2-RELEASE:1.64.4.1
	netbsd-9-0-RELEASE:1.69.6.1
	netbsd-9-0-RC2:1.69.6.1
	netbsd-9-0-RC1:1.69.6.1
	phil-wifi-20191119:1.71
	netbsd-9:1.69.0.6
	netbsd-9-base:1.69
	phil-wifi-20190609:1.69
	netbsd-8-1-RELEASE:1.64.4.1
	netbsd-8-1-RC1:1.64.4.1
	pgoyette-compat-merge-20190127:1.69
	pgoyette-compat-20190127:1.69
	pgoyette-compat-20190118:1.69
	pgoyette-compat-1226:1.69
	pgoyette-compat-1126:1.69
	pgoyette-compat-1020:1.69
	pgoyette-compat-0930:1.69
	pgoyette-compat-0906:1.69
	netbsd-7-2-RELEASE:1.48.4.7
	pgoyette-compat-0728:1.69
	netbsd-8-0-RELEASE:1.64.4.1
	phil-wifi:1.69.0.4
	phil-wifi-base:1.69
	pgoyette-compat-0625:1.69
	netbsd-8-0-RC2:1.64.4.1
	pgoyette-compat-0521:1.69
	pgoyette-compat-0502:1.69
	pgoyette-compat-0422:1.69
	netbsd-8-0-RC1:1.64.4.1
	pgoyette-compat-0415:1.69
	pgoyette-compat-0407:1.69
	pgoyette-compat-0330:1.69
	pgoyette-compat-0322:1.69
	pgoyette-compat-0315:1.69
	netbsd-7-1-2-RELEASE:1.48.4.6
	pgoyette-compat:1.69.0.2
	pgoyette-compat-base:1.69
	netbsd-7-1-1-RELEASE:1.48.4.6
	matt-nb8-mediatek:1.64.4.1.0.2
	matt-nb8-mediatek-base:1.64.4.1
	perseant-stdc-iso10646:1.66.0.2
	perseant-stdc-iso10646-base:1.66
	netbsd-8:1.64.0.4
	netbsd-8-base:1.64
	prg-localcount2-base3:1.64
	prg-localcount2-base2:1.64
	prg-localcount2-base1:1.64
	prg-localcount2:1.64.0.2
	prg-localcount2-base:1.64
	pgoyette-localcount-20170426:1.64
	bouyer-socketcan-base1:1.64
	pgoyette-localcount-20170320:1.62
	netbsd-7-1:1.48.4.6.0.6
	netbsd-7-1-RELEASE:1.48.4.6
	netbsd-7-1-RC2:1.48.4.6
	netbsd-7-nhusb-base-20170116:1.48.4.6
	bouyer-socketcan:1.61.0.4
	bouyer-socketcan-base:1.61
	pgoyette-localcount-20170107:1.61
	netbsd-7-1-RC1:1.48.4.6
	pgoyette-localcount-20161104:1.61
	netbsd-7-0-2-RELEASE:1.48.4.6
	localcount-20160914:1.61
	netbsd-7-nhusb:1.48.4.6.0.4
	netbsd-7-nhusb-base:1.48.4.6
	pgoyette-localcount-20160806:1.61
	pgoyette-localcount-20160726:1.61
	pgoyette-localcount:1.61.0.2
	pgoyette-localcount-base:1.61
	netbsd-7-0-1-RELEASE:1.48.4.6
	netbsd-7-0:1.48.4.6.0.2
	netbsd-7-0-RELEASE:1.48.4.6
	netbsd-7-0-RC3:1.48.4.6
	netbsd-7-0-RC2:1.48.4.5
	netbsd-7-0-RC1:1.48.4.5
	netbsd-6-0-6-RELEASE:1.2
	netbsd-6-1-5-RELEASE:1.2
	netbsd-7:1.48.0.4
	netbsd-7-base:1.48
	yamt-pagecache-base9:1.48
	yamt-pagecache-tag8:1.3.2.3
	netbsd-6-1-4-RELEASE:1.2
	netbsd-6-0-5-RELEASE:1.2
	tls-earlyentropy:1.48.0.2
	tls-earlyentropy-base:1.48
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.47
	riastradh-drm2-base3:1.44
	netbsd-6-1-3-RELEASE:1.2
	netbsd-6-0-4-RELEASE:1.2
	netbsd-6-1-2-RELEASE:1.2
	netbsd-6-0-3-RELEASE:1.2
	netbsd-6-1-1-RELEASE:1.2
	riastradh-drm2-base2:1.43
	riastradh-drm2-base1:1.43
	riastradh-drm2:1.43.0.2
	riastradh-drm2-base:1.43
	netbsd-6-1:1.2.0.8
	netbsd-6-0-2-RELEASE:1.2
	netbsd-6-1-RELEASE:1.2
	khorben-n900:1.38.0.2
	netbsd-6-1-RC4:1.2
	netbsd-6-1-RC3:1.2
	agc-symver:1.36.0.2
	agc-symver-base:1.36
	netbsd-6-1-RC2:1.2
	netbsd-6-1-RC1:1.2
	yamt-pagecache-base8:1.15
	netbsd-6-0-1-RELEASE:1.2
	yamt-pagecache-base7:1.3
	matt-nb6-plus-nbase:1.2
	yamt-pagecache-base6:1.3
	netbsd-6-0:1.2.0.6
	netbsd-6-0-RELEASE:1.2
	netbsd-6-0-RC2:1.2
	tls-maxphys:1.3.0.4
	tls-maxphys-base:1.48
	matt-nb6-plus:1.2.0.4
	matt-nb6-plus-base:1.2
	netbsd-6-0-RC1:1.2
	yamt-pagecache-base5:1.3
	yamt-pagecache:1.3.0.2
	yamt-pagecache-base4:1.3
	netbsd-6:1.2.0.2
	netbsd-6-base:1.2;
locks; strict;
comment	@# @;


1.95
date	2026.03.22.20.11.36;	author kre;	state Exp;
branches;
next	1.94;
commitid	MsGKmLDBdZijE0zG;

1.94
date	2026.02.15.21.07.36;	author riastradh;	state Exp;
branches;
next	1.93;
commitid	F3YkgceqP8vI3wuG;

1.93
date	2026.02.07.20.07.19;	author riastradh;	state Exp;
branches;
next	1.92;
commitid	RmY8DHVDBbXm0utG;

1.92
date	2025.04.01.00.04.00;	author gutteridge;	state Exp;
branches;
next	1.91;
commitid	FXShllREZwgn8hPF;

1.91
date	2025.03.22.09.25.14;	author hgutch;	state Exp;
branches;
next	1.90;
commitid	c4Cs3lkS38emJ2OF;

1.90
date	2025.01.24.21.47.51;	author jmcneill;	state Exp;
branches;
next	1.89;
commitid	FCBsg6IkW2P2LMGF;

1.89
date	2025.01.17.12.11.53;	author jmcneill;	state Exp;
branches;
next	1.88;
commitid	xLG6mvyp7jzJNPFF;

1.88
date	2025.01.11.14.33.31;	author jmmv;	state Exp;
branches;
next	1.87;
commitid	JNXUfYPidtyOL4FF;

1.87
date	2024.12.29.09.46.44;	author jmmv;	state Exp;
branches;
next	1.86;
commitid	SMRsHmmHTKgOBnDF;

1.86
date	2024.12.28.18.13.29;	author christos;	state Exp;
branches;
next	1.85;
commitid	C8v0SUNdiqpHriDF;

1.85
date	2024.12.27.19.02.19;	author christos;	state Exp;
branches;
next	1.84;
commitid	lUKdBalraoedKaDF;

1.84
date	2024.08.12.18.45.51;	author skrll;	state Exp;
branches;
next	1.83;
commitid	jDnH9jLN2YJO3zlF;

1.83
date	2024.08.12.10.55.51;	author skrll;	state Exp;
branches;
next	1.82;
commitid	yptj3PKbdU6BrwlF;

1.82
date	2024.04.09.15.17.24;	author nia;	state Exp;
branches
	1.82.2.1;
next	1.81;
commitid	JExbVLp22BtkVt5F;

1.81
date	2024.02.12.11.30.33;	author mlelstv;	state Exp;
branches;
next	1.80;
commitid	EIcPg3k9X9yDu8YE;

1.80
date	2024.02.11.17.29.50;	author christos;	state Exp;
branches;
next	1.79;
commitid	qzgDGegUMG2jw2YE;

1.79
date	2024.01.20.21.35.59;	author jmcneill;	state Exp;
branches;
next	1.78;
commitid	5dWkrVi2Bg7eAeVE;

1.78
date	2021.09.25.08.54.30;	author maya;	state Exp;
branches
	1.78.2.1;
next	1.77;
commitid	BGRNzDrS01VoBjaD;

1.77
date	2020.12.23.10.35.18;	author rin;	state Exp;
branches;
next	1.76;
commitid	UjUL16IWXrm42RAC;

1.76
date	2020.12.21.16.38.02;	author riastradh;	state Exp;
branches;
next	1.75;
commitid	9fkeseNipGx76DAC;

1.75
date	2020.07.17.15.16.34;	author jmcneill;	state Exp;
branches;
next	1.74;
commitid	UXZW2Dqo4F3mHrgC;

1.74
date	2020.05.24.18.43.39;	author jmcneill;	state Exp;
branches;
next	1.73;
commitid	2JeAxTaL5QV7Aw9C;

1.73
date	2020.05.24.14.45.49;	author jmcneill;	state Exp;
branches;
next	1.72;
commitid	D62nZek5KhWxgv9C;

1.72
date	2020.05.18.21.19.34;	author jmcneill;	state Exp;
branches;
next	1.71;
commitid	LEg8TRe3NPw0DL8C;

1.71
date	2019.10.30.14.16.15;	author martin;	state Exp;
branches;
next	1.70;
commitid	GhARECm1wbgyKTIB;

1.70
date	2019.10.02.11.16.00;	author maya;	state Exp;
branches;
next	1.69;
commitid	7L8j32uFc906EhFB;

1.69
date	2017.11.28.02.56.44;	author kre;	state Exp;
branches
	1.69.4.1
	1.69.6.1;
next	1.68;
commitid	YyX28ObBtFaovKgA;

1.68
date	2017.11.28.00.24.08;	author kre;	state Exp;
branches;
next	1.67;
commitid	QkzNaFrZMcBrGJgA;

1.67
date	2017.11.28.00.14.30;	author kre;	state Exp;
branches;
next	1.66;
commitid	E0ZoL0eoA1O2DJgA;

1.66
date	2017.07.06.00.17.04;	author jmcneill;	state Exp;
branches;
next	1.65;
commitid	IghW9X1dbyjRi6Yz;

1.65
date	2017.06.10.23.26.32;	author christos;	state Exp;
branches;
next	1.64;
commitid	mXblIxvjhYfxPSUz;

1.64
date	2017.04.11.21.06.30;	author jmcneill;	state Exp;
branches
	1.64.4.1;
next	1.63;
commitid	2KAB6Nzx5XyGY9Nz;

1.63
date	2017.04.11.18.04.08;	author jmcneill;	state Exp;
branches;
next	1.62;
commitid	vP3imaQ0NMn0Y8Nz;

1.62
date	2017.03.14.06.37.39;	author skrll;	state Exp;
branches;
next	1.61;
commitid	82tvUqWAl1WC4uJz;

1.61
date	2015.08.01.10.05.51;	author jmcneill;	state Exp;
branches
	1.61.2.1
	1.61.4.1;
next	1.60;
commitid	1l6tfbe3afi3eyvy;

1.60
date	2015.07.15.11.27.13;	author martin;	state Exp;
branches;
next	1.59;
commitid	iLfS8q6kJCiCdnty;

1.59
date	2015.05.24.17.08.21;	author christos;	state Exp;
branches;
next	1.58;
commitid	p3K4v0RdsRPrMImy;

1.58
date	2015.04.19.17.56.57;	author hubertf;	state Exp;
branches;
next	1.57;
commitid	aTZCXKdEmSOMaeiy;

1.57
date	2015.04.18.22.06.48;	author hubertf;	state Exp;
branches;
next	1.56;
commitid	2GCpzD15iaQcA7iy;

1.56
date	2015.04.06.22.20.52;	author jmcneill;	state Exp;
branches;
next	1.55;
commitid	cuym36jfvXhn3Agy;

1.55
date	2015.04.06.20.19.28;	author jmcneill;	state Exp;
branches;
next	1.54;
commitid	tOifK7pY9bjAnzgy;

1.54
date	2015.04.06.17.59.36;	author jmcneill;	state Exp;
branches;
next	1.53;
commitid	ju5jkcpS4aQtBygy;

1.53
date	2015.04.05.17.05.45;	author jmcneill;	state Exp;
branches;
next	1.52;
commitid	4dp3e2dPsqYmkqgy;

1.52
date	2015.01.29.14.54.06;	author skrll;	state Exp;
branches;
next	1.51;
commitid	dFnZUnkpzEf2JV7y;

1.51
date	2015.01.23.15.17.58;	author skrll;	state Exp;
branches;
next	1.50;
commitid	LaUSni46C5eI2a7y;

1.50
date	2015.01.18.17.37.54;	author skrll;	state Exp;
branches;
next	1.49;
commitid	1FayMbIz58QtZw6y;

1.49
date	2014.12.14.00.28.46;	author christos;	state Exp;
branches;
next	1.48;
commitid	QIiWDOWYpAbdqW1y;

1.48
date	2014.04.03.22.51.38;	author christos;	state Exp;
branches
	1.48.4.1;
next	1.47;
commitid	o6Rx9iTuR9Jd3ivx;

1.47
date	2014.03.31.18.18.29;	author christos;	state Exp;
branches;
next	1.46;
commitid	7W7APLbS4VVuDSux;

1.46
date	2014.03.31.17.05.03;	author christos;	state Exp;
branches;
next	1.45;
commitid	s5fzrHt1nRsieSux;

1.45
date	2014.03.31.16.20.48;	author christos;	state Exp;
branches;
next	1.44;
commitid	zkF6OiMVD9sVYRux;

1.44
date	2013.09.14.12.51.27;	author ast;	state Exp;
branches;
next	1.43;
commitid	4EyAOx5TgyYMbp5x;

1.43
date	2013.06.27.14.51.30;	author christos;	state Exp;
branches;
next	1.42;
commitid	wPOpsKhecGKzogVw;

1.42
date	2013.06.27.03.03.16;	author christos;	state Exp;
branches;
next	1.41;
commitid	zoDpGcQEubYBtcVw;

1.41
date	2013.06.27.03.00.53;	author christos;	state Exp;
branches;
next	1.40;
commitid	VS6AmuMOIDJMscVw;

1.40
date	2013.06.16.13.47.42;	author jakllsch;	state Exp;
branches;
next	1.39;
commitid	2pv6LI47pWuWnQTw;

1.39
date	2013.05.20.19.27.17;	author christos;	state Exp;
branches;
next	1.38;
commitid	rU8zYSv0EhmO8pQw;

1.38
date	2013.04.03.19.37.43;	author htodd;	state Exp;
branches;
next	1.37;

1.37
date	2013.03.28.00.20.02;	author jmcneill;	state Exp;
branches;
next	1.36;

1.36
date	2013.03.19.22.16.53;	author garbled;	state Exp;
branches;
next	1.35;

1.35
date	2013.02.15.00.13.06;	author christos;	state Exp;
branches;
next	1.34;

1.34
date	2013.02.12.12.45.12;	author jmcneill;	state Exp;
branches;
next	1.33;

1.33
date	2013.02.11.18.11.20;	author jmcneill;	state Exp;
branches;
next	1.32;

1.32
date	2013.02.10.21.51.05;	author jmcneill;	state Exp;
branches;
next	1.31;

1.31
date	2013.02.10.16.56.38;	author jmcneill;	state Exp;
branches;
next	1.30;

1.30
date	2013.02.10.16.56.01;	author jmcneill;	state Exp;
branches;
next	1.29;

1.29
date	2013.02.10.16.13.23;	author christos;	state Exp;
branches;
next	1.28;

1.28
date	2013.02.10.16.12.37;	author christos;	state Exp;
branches;
next	1.27;

1.27
date	2013.02.10.15.51.59;	author christos;	state Exp;
branches;
next	1.26;

1.26
date	2013.02.10.15.45.33;	author christos;	state Exp;
branches;
next	1.25;

1.25
date	2013.02.10.15.35.34;	author jmcneill;	state Exp;
branches;
next	1.24;

1.24
date	2013.02.10.03.09.07;	author christos;	state Exp;
branches;
next	1.23;

1.23
date	2013.02.10.02.09.47;	author christos;	state Exp;
branches;
next	1.22;

1.22
date	2013.02.10.01.28.42;	author christos;	state Exp;
branches;
next	1.21;

1.21
date	2013.02.09.18.50.11;	author christos;	state Exp;
branches;
next	1.20;

1.20
date	2013.02.09.11.20.56;	author jmcneill;	state Exp;
branches;
next	1.19;

1.19
date	2013.02.09.11.15.14;	author jmcneill;	state Exp;
branches;
next	1.18;

1.18
date	2013.02.08.19.14.14;	author christos;	state Exp;
branches;
next	1.17;

1.17
date	2013.02.03.09.16.24;	author christos;	state Exp;
branches;
next	1.16;

1.16
date	2013.01.30.07.40.34;	author skrll;	state Exp;
branches;
next	1.15;

1.15
date	2013.01.21.16.49.49;	author skrll;	state Exp;
branches;
next	1.14;

1.14
date	2013.01.21.16.47.23;	author skrll;	state Exp;
branches;
next	1.13;

1.13
date	2013.01.16.23.27.34;	author christos;	state Exp;
branches;
next	1.12;

1.12
date	2013.01.16.15.58.19;	author christos;	state Exp;
branches;
next	1.11;

1.11
date	2013.01.15.21.04.41;	author christos;	state Exp;
branches;
next	1.10;

1.10
date	2013.01.15.03.26.27;	author christos;	state Exp;
branches;
next	1.9;

1.9
date	2013.01.15.02.50.08;	author jmcneill;	state Exp;
branches;
next	1.8;

1.8
date	2013.01.14.12.12.19;	author jmcneill;	state Exp;
branches;
next	1.7;

1.7
date	2013.01.13.21.51.47;	author christos;	state Exp;
branches;
next	1.6;

1.6
date	2013.01.13.20.59.22;	author christos;	state Exp;
branches;
next	1.5;

1.5
date	2013.01.13.20.58.38;	author christos;	state Exp;
branches;
next	1.4;

1.4
date	2013.01.13.20.57.18;	author christos;	state Exp;
branches;
next	1.3;

1.3
date	2012.02.29.04.49.50;	author agc;	state Exp;
branches
	1.3.2.1
	1.3.4.1;
next	1.2;

1.2
date	2012.01.20.02.19.47;	author agc;	state Exp;
branches;
next	1.1;

1.1
date	2012.01.15.02.01.02;	author agc;	state Exp;
branches;
next	;

1.82.2.1
date	2025.08.02.05.20.40;	author perseant;	state Exp;
branches;
next	;
commitid	23j6GFaDws3O875G;

1.78.2.1
date	2024.02.03.11.47.08;	author martin;	state Exp;
branches;
next	;
commitid	ut73eiinJNBPSYWE;

1.69.4.1
date	2020.04.13.07.45.36;	author martin;	state Exp;
branches;
next	;
commitid	X01YhRUPVUDaec4C;

1.69.6.1
date	2019.11.17.07.04.36;	author martin;	state Exp;
branches;
next	;
commitid	fmdLX9M716eYMaLB;

1.64.4.1
date	2017.07.18.19.13.07;	author snj;	state Exp;
branches;
next	;
commitid	xwp7839uh5fpcKZz;

1.61.2.1
date	2017.03.20.06.52.10;	author pgoyette;	state Exp;
branches;
next	1.61.2.2;
commitid	jjw7cAwgyKq7RfKz;

1.61.2.2
date	2017.04.26.02.52.17;	author pgoyette;	state Exp;
branches;
next	;
commitid	ojV02aOSdzvBqZOz;

1.61.4.1
date	2017.04.21.16.51.15;	author bouyer;	state Exp;
branches;
next	;
commitid	dUG7nkTKALCadqOz;

1.48.4.1
date	2015.01.20.09.50.46;	author martin;	state Exp;
branches;
next	1.48.4.2;
commitid	p8UjqAUo1VpvlK6y;

1.48.4.2
date	2015.01.28.11.27.03;	author martin;	state Exp;
branches;
next	1.48.4.3;
commitid	0H3hSwdbxpwACM7y;

1.48.4.3
date	2015.01.29.15.12.48;	author martin;	state Exp;
branches;
next	1.48.4.4;
commitid	VmbBB67APv43QV7y;

1.48.4.4
date	2015.04.06.01.59.36;	author snj;	state Exp;
branches;
next	1.48.4.5;
commitid	MiQZTwVZIk9mitgy;

1.48.4.5
date	2015.04.06.18.47.54;	author snj;	state Exp;
branches;
next	1.48.4.6;
commitid	Fw2H7MsqGIlfSygy;

1.48.4.6
date	2015.08.06.21.13.43;	author snj;	state Exp;
branches;
next	1.48.4.7;
commitid	8DiUh5BbT1XZKfwy;

1.48.4.7
date	2017.05.12.05.12.58;	author snj;	state Exp;
branches;
next	;
commitid	IxcgFlrd31s8I3Rz;

1.3.2.1
date	2012.02.29.04.49.50;	author yamt;	state dead;
branches;
next	1.3.2.2;

1.3.2.2
date	2012.04.17.00.02.49;	author yamt;	state Exp;
branches;
next	1.3.2.3;

1.3.2.3
date	2013.01.23.00.04.28;	author yamt;	state Exp;
branches;
next	1.3.2.4;

1.3.2.4
date	2014.05.22.12.01.34;	author yamt;	state Exp;
branches;
next	;
commitid	yqlfOuaAhYmASwBx;

1.3.4.1
date	2013.02.25.00.24.47;	author tls;	state Exp;
branches;
next	1.3.4.2;

1.3.4.2
date	2013.06.23.06.26.19;	author tls;	state Exp;
branches;
next	1.3.4.3;
commitid	OnlO1cBgtQRcIHUw;

1.3.4.3
date	2014.08.19.23.45.45;	author tls;	state Exp;
branches;
next	;
commitid	jTnpym9Qu0o4R1Nx;


desc
@@


1.95
log
@PR 60119 - don't set -o pipefail (revert previous)

I was going to make the setting of the pipefail option check if
the executing shell supports the option or not (all should really,
and up to date dash does - it is a standard option) - but then I
looked at the script, and couldn't find a pipe used anywhere.

The option is useless here.   So, bye-bye pipefail.
@
text
@#!/bin/sh
# $NetBSD: mkimage,v 1.93 2026/02/07 20:07:19 riastradh Exp $
#
# Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Christos Zoulas.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. Neither the name of The NetBSD Foundation nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

#
# Makes a bootable image for the host architecture given.
# The host-specific functions are pulled in from a /bin/sh script in the
# "conf" directory, which is expected to provide the following shell
# functions, which are called in the following order:
#
#  - make_fstab: Creates the host's /etc/fstab with / on ${rootdev}.
#    If -m is given, a number of directories are put on a tmpfs RAM disk
#  - customize: After unpacking the sets, this gets the system to
#    a working state, e.g., by setting up /etc/rc.conf and /dev
#  - populate: Add common goods like kernel and bootloader
#  - make_label: Prints disklabel to stdout
#

set -e

DIR="$(cd "$(dirname "$0")" && pwd)"
PROG="$(basename "$0")"

MAKE=${TOOL_MAKE:-make}
DISKLABEL=${TOOL_DISKLABEL:-disklabel}
FDISK=${TOOL_FDISK:-fdisk}
GPT=${TOOL_GPT:-gpt}
MAKEFS=${TOOL_MAKEFS:-makefs}
MTREE=${TOOL_MTREE:-mtree}
INSTALLBOOT=${TOOL_INSTALLBOOT:-installboot}
MKUBOOTIMAGE=${TOOL_MKUBOOTIMAGE:-mkubootimage}
GZIP_CMD=${TOOL_GZIP:-gzip} # ${GZIP} is special to gzip(1)
SED=${TOOL_SED:-sed}
PWD_MKDB=${TOOL_PWD_MKDB:-pwd_mkdb}

postfix=false
[ "${MKPOSTFIX:-yes}" = no ] || postfix=true

src="/usr/src"
sets="base comp etc games gpufw man manhtml misc modules rescue tests text"
xsets="xbase xcomp xetc xfont xserver"
minfree="10%"
bar="==="

tmp="$(mktemp -d "${TMPDIR:-/tmp}/$PROG.XXXXXX")"
mnt="${tmp}/mnt"
mkdir -p "${mnt}/etc" "${mnt}/dev"

trap "cleanup" 0 1 2 3 15

cleanup() {
	case "$tmp" in
	"${TMPDIR:-/tmp}/$PROG."*)	rm -fr "$tmp";;
	esac
}

fail() {
	IFS=' '
	echo >&2 "${PROG}: $*"
	exit 1
}

getsize() {
	set -- $(ls -l $1)
	echo $5
}

getsectors() {
	case "$1" in
	*g)
		m=1073741824
		v=${1%g}
		;;
	*m)
		m=1048576
		v=${1%m}
		;;
	*k)
		m=1024
		v=${1%k}
		;;
	*[0-9b])
		m=1
		v=${1%b}
		;;
	esac
	echo $((m * v / 512))
}

minwrites_fstab_entries() {
	$minwrites || return 0
	cat << EOF
tmpfs		/var/log		tmpfs	rw,union,-s32M
tmpfs		/var/run		tmpfs	rw,union,-s1M
tmpfs		/var/mail		tmpfs	rw,union,-s10M
tmpfs		/var/chroot		tmpfs	rw,union,-s10M
EOF
	if $postfix; then
	cat << EOF
tmpfs		/var/spool/postfix	tmpfs	rw,union,-s20M
tmpfs		/var/db/postfix		tmpfs	rw,union,-s1M
EOF
	fi
}

make_fstab_gpt() {
	local boot=$1
	local rootopts=
	if $minwrites; then
		rootopts=,log,nodevmtime
	fi

	cat > ${mnt}/etc/fstab << EOF
# NetBSD /etc/fstab
# See /usr/share/examples/fstab/ for more examples.
NAME=${gpt_label_ffs:-netbsd-root}	/		ffs	rw,noatime${rootopts}	1 1
NAME=${gpt_label_boot:-$boot}		/boot		msdos	rw	1 1
ptyfs		/dev/pts	ptyfs	rw
procfs		/proc		procfs	rw
tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
EOF
	minwrites_fstab_entries >> ${mnt}/etc/fstab
}

# From Richard Neswold's:
# http://rich-tbp.blogspot.com/2013/03/netbsd-on-rpi-minimizing-disk-writes.html
# Also for the postfix stuff below
make_fstab_normal() {
	local rootopts=
	if $minwrites; then
		rootopts=,nodevmtime
	fi
	cat > ${mnt}/etc/fstab << EOF
# NetBSD /etc/fstab
# See /usr/share/examples/fstab/ for more examples.
ROOT.a		/			ffs	rw,noatime${rootopts}	1 1
ROOT.e		/boot			msdos	rw				1 1
ptyfs		/dev/pts		ptyfs	rw
procfs		/proc			procfs	rw
tmpfs		/tmp			tmpfs	rw,-s32M
tmpfs		/var/shm		tmpfs	rw,-m1777,-sram%25
EOF
	minwrites_fstab_entries >> ${mnt}/etc/fstab
}

make_fstab_default() {
	if $gpt; then
		make_fstab_gpt "$@@"
	else
		make_fstab_normal
	fi
	echo "./etc/fstab type=file uname=root gname=wheel mode=0644" \
	    >> "$tmp/selected_sets"

	# Missing mount points from fstab
	echo "./proc type=dir uname=root gname=wheel mode=0755" \
	    >> "$tmp/selected_sets"
}

usage() {
	cat << EOF 1>&2
Usage: $PROG -h <host-arch> [-bdmx] [-B <byte-order>] [-K <kerneldir>] [-S <srcdir>] [-D <destdir>] [-c <custom-files-dir>] [-s <Mb size>] [<image>]

-b	Boot only, no sets loaded
-r	root device kind (sd, wd, ld)
-d	Add the debug sets
-m	Optimize the OS installation to mimimize disk writes for SSDs
-x	Load the X sets too, not just the base ones
EOF
	exit 1
}

# First pass for options to get the host and src directories
OPTS="B:D:K:S:bc:dh:mr:s:x"
while getopts "$OPTS" f
do
	case $f in
	h)	h="$OPTARG";;
	S)	src="$OPTARG";;
	*)	;;
	esac
done

if [ -z "$h" ]
then
	usage
fi

if [ ! -f "${DIR}/conf/${h}.conf" ]
then
	echo $PROG: ${DIR}/conf/${h}.conf is not present 1>&2
	exit 1
fi

resize=false
gpt=false
gpt_hybrid=false
fsize=8192
bsize=65536
ffsversion=1

. "${DIR}/conf/${h}.conf"
release="/usr/obj/${MACHINE}/release"

selected_sets="$sets"
dsets_p=false
xsets_p=false
minwrites=false
rootdev=ld
endian=

OPTIND=1
while getopts "$OPTS" f
do
	case $f in
	B)	endian="-B $OPTARG";;
	D)	release="$OPTARG";;
	K)	kernel="$OPTARG";;
	S)	;;
	b)	bootonly=true;;
	d)	dsets_p=true
		selected_sets="$selected_sets debug"
		if $xsets_p; then
			selected_sets="$selected_sets xdebug"
		fi
		;;
	c)	custom="$OPTARG";;
	h)	;;
	m)	minwrites=true;;
	r)	rootdev="$OPTARG";;
	s)	size="$OPTARG";;
	x)	xsets_p=true
		selected_sets="$selected_sets $xsets"
		if $dsets_p; then
		    selected_sets="$selected_sets xdebug"
		fi
		;;
	*)	usage;;
	esac
done
if [ -n "${MKREPRO_TIMESTAMP}" ]; then
	timestamp_opt="-T ${MKREPRO_TIMESTAMP}"
	volume_opt=",volume_id=$((${MKREPRO_TIMESTAMP} & 0xffff))"
fi

shift $(( $OPTIND - 1 ))
if [ -n "$1" ]; then
	# take the next argument as being the image name
	image="$1"
	shift
fi

case "$image" in
*.gz)	compress=true; image="${image%.gz}";;
*)	compress=false;;
esac

if [ -z "${bootonly}" ]; then
	echo ${bar} configuring sets ${bar}
	(cat "${release}/etc/mtree/NetBSD.dist"
	for i in $selected_sets; do
		s="${release}/etc/mtree/set.$i"
		if [ -f "$s" ]; then
			cat "$s"
		fi
	done) > "$tmp/selected_sets"
fi

make_fstab
customize
populate

if [ ! "${MKDTB}" = "no" ]; then
	#
	# Part of the dtb set resides on the FAT partition (/boot/dtb/*), and
	# the rest on FFS. Split it up here.
	#
	echo ${bar} Installing devicetree blobs ${bar}
	mkdir -p "${mnt}/boot"
	cp -r "${release}/boot/dtb" "${mnt}/boot/dtb"

	mkdir -p "${mnt}/etc/mtree"
	cp "${release}/etc/mtree/set.dtb" "${mnt}/etc/mtree/set.dtb"
	echo "./etc/mtree/set.dtb type=file uname=root gname=wheel mode=0444" >> "$tmp/selected_sets"

	mkdir -p "${mnt}/var/db/obsolete"
	cp "${release}/var/db/obsolete/dtb" "${mnt}/var/db/obsolete/dtb"
	echo "./var/db/obsolete/dtb type=file uname=root gname=wheel mode=0644" >>"$tmp/selected_sets"
fi

if [ -n "${msdosid}" ]; then
	echo ${bar} Populating msdos filesystem ${bar}

	case $(( ${msdosid} )) in
	1)	fat_opt=",fat_type=12";;
	4|6|14)	fat_opt=",fat_type=16";;
	11|12)	fat_opt=",fat_type=32";;
	*)	fat_opt=;;
	esac
	${MAKEFS} -N ${release}/etc -t msdos \
	    -o "volume_label=NETBSD${fat_opt}${volume_opt}" ${timestamp_opt} \
	    -O $((${init} / 2))m -s $((${boot} / 2))m \
	    ${image} ${mnt}/boot
fi

if [ -z "${bootonly}" ]; then
	echo ${bar} Populating ffs filesystem ${bar}
	${MAKEFS} -rx ${endian} -N ${release}/etc -t ffs \
	    -O ${ffsoffset} ${timestamp_opt} \
	    -o d=4096,f=${fsize},b=${bsize},v=${ffsversion} -b $((${extra}))m \
	    -F "$tmp/selected_sets" ${image} "${release}" "${mnt}"
fi

if [ "${size}" = 0 ]; then
	size="$(getsize "${image}")"
	# Round up to a multiple of 4m and add 1m of slop.
	alignunit=$((4*1024*1024))
	alignsize=$((alignunit*((size + alignunit - 1)/alignunit)))
	alignsize=$((alignsize + 1024*1024))
	if [ "${size}" -lt "${alignsize}" ]; then
		dd bs="$((alignsize - size))" count=1 if=/dev/zero conv=sync \
			>> "${image}" 2> /dev/null
		size="${alignsize}"
	fi
fi

if $gpt; then
	if $gpt_hybrid; then
		gpt_flags="-H"
	fi
	gpt_flags="${gpt_flags} ${timestamp_opt}"
	initsecs=$((${init} * 1024))
	bootsecs=$((${boot} * 1024))
	ffsstart="$(getsectors ${ffsoffset})"

	echo ${bar} Clearing existing partitions ${bar}
	${GPT} ${gpt_flags} ${image} destroy || true

	echo ${bar} Creating partitions ${bar}
	${GPT} ${gpt_flags} ${image} create ${gpt_create_flags}
	${GPT} ${gpt_flags} ${image} add -b ${initsecs} -s ${bootsecs} -l ${gpt_label_boot:-EFI} -t ${gpt_boot_type:-efi}
	${GPT} ${gpt_flags} ${image} set -a required -i 1
	${GPT} ${gpt_flags} ${image} add -a 4m -b ${ffsstart} -l ${gpt_label_ffs:-netbsd-root} -t ffs
	${GPT} ${gpt_flags} ${image} show
	if $gpt_hybrid; then
		echo ${bar} Creating hybrid MBR ${bar}
		${FDISK} -f -g -u -0 -a -s ${msdosid}/${initsecs}/${bootsecs} -F ${image}
		${FDISK} -f -g -u -3 -s 238/1/$((${initsecs} - 1)) -F ${image}
		${FDISK} -F ${image}
	fi
else
	if [ -n "${msdosid}" ]; then
		echo ${bar} Running fdisk ${bar}
		initsecs=$((${init} * 1024))
		bootsecs=$((${boot} * 1024))
		${FDISK} -f -i ${image}
		${FDISK} -f -a -u -0 -s ${msdosid}/${initsecs}/${bootsecs} -F ${image}
		if [ -z "${bootonly}" ]; then
			ffsstart="$(getsectors ${ffsoffset})"
			imagesize="$(getsize "${image}")"
			imagesecs="$(getsectors ${imagesize})"
			ffssize="$(expr ${imagesecs} - ${ffsstart})"
			${FDISK} -f -u -1 -s 169/${ffsstart}/${ffssize} -F ${image}
		fi

		echo ${bar} Adding label ${bar}
		make_label > ${tmp}/label
		${DISKLABEL} -m -R -F ${image} ${tmp}/label
	elif [ -n "${netbsdid}" ]; then
		echo ${bar} Adding label ${bar}
		make_label > ${tmp}/label
		${DISKLABEL} -m -R -F ${image} ${tmp}/label

		echo ${bar} Running fdisk ${bar}
		${FDISK} -f -i ${image}
		${FDISK} -f -a -u -0 -s 169/${init} ${image}
		${INSTALLBOOT} -f -v ${image} ${release}/usr/mdec/bootxx_ffsv1
	fi
fi

if $compress; then
	echo ${bar} Compressing image ${bar}
	rm -f "${image}.gz"
	${GZIP_CMD} -n -9 ${image}
	image="${image}.gz"
fi

cd "${IMAGEDIR}"
${CKSUM} -a MD5 "$(basename "${image}")" > MD5
${CKSUM} -a SHA512 "$(basename "${image}")" > SHA512

echo ${bar} Image is ${image} ${bar}
@


1.94
log
@mkimage: Use `-o pipefail' to improve early error detection.
@
text
@d49 1
a49 1
set -e -o pipefail
@


1.93
log
@mkimage: Write one block of padding up to 4MB.

Previously we wrote padding one byte at a time, which takes a while
when it's nearly 4MB of padding!

I believe these dd(1) options are POSIX-compliant.  If the read from
/dev/zero is truncated, then conv=sync means it will be padded with
NUL bytes rather than reading more -- but that's fine; that's what we
would get by reading from /dev/zero anyway!

(Why did I make this round to a multiple of 4MB and _then_ add 1MB,
rather than the other way around of adding 1MB and then rounding to a
multiple of 4MB?)

No correctness change intended -- but this should improve performance
of the image build a little bit!
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.92 2025/04/01 00:04:00 gutteridge Exp $
d49 1
a49 1
set -e
@


1.92
log
@mkimage: fix grammar in comments
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.91 2025/03/22 09:25:14 hgutch Exp $
d351 1
a351 1
		dd bs=1 count="$((alignsize - size))" if=/dev/zero \
@


1.91
log
@Also generate hashes for files in gzimg directories.

At one point this should probably be unified at least a bit with the hash
generation of regular sets, so that there is a single place that defines
the types of hashes generated for sets and gzimg.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.90 2025/01/24 21:47:51 jmcneill Exp $
d37 2
a38 2
# The host specific functions are pulled in from a /bin/sh script in the
# "conf" directory, and is expected to provide the following shell
d44 1
a44 1
#    a working state, e. g. by setting up /etc/rc.conf and /dev
@


1.90
log
@Fix resize_root.

Revision 1.85 added the 'log' option to "normal" fstabs, which is
incompatible with resize_ffs. Restore the previous behaviour.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.89 2025/01/17 12:11:53 jmcneill Exp $
d418 4
@


1.89
log
@mkimage: Allow configs to override fsize/bsize/ffs version
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.88 2025/01/11 14:33:31 jmmv Exp $
d166 1
a166 1
ROOT.a		/			ffs	rw,log,noatime${rootopts}	1 1
@


1.88
log
@Inject TOOL_SED and TOOL_PWD_MKDB into mkimage

The configuration files used for mkimage might want to customize the passwd
database of the generated image (as is the case for an out-of-tree config
file I have) and passing in these tools helps to execute those modifications.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.87 2024/12/29 09:46:44 jmmv Exp $
d228 3
d340 1
a340 1
	    -o d=4096,f=8192,b=65536 -b $((${extra}))m \
@


1.87
log
@Recognize MKPOSTFIX=no in mkimage
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.86 2024/12/28 18:13:29 christos Exp $
d63 2
@


1.86
log
@avoid extra comma, add braces
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.85 2024/12/27 19:02:19 christos Exp $
d64 3
d124 4
a129 1
tmpfs		/var/chroot		tmpfs	rw,union,-s10M
d131 1
@


1.85
log
@Remove duplicated code, handle minwrites in _normal the same way we handle
it in _gpt. Initial patch from jmmv@@.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.84 2024/08/12 18:45:51 skrll Exp $
d157 1
a157 1
ROOT.a		/			ffs	rw,log,noatime,$rootopts	1 1
@


1.84
log
@Undo accidental commit.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.83 2024/08/12 10:55:51 skrll Exp $
d115 66
@


1.83
log
@Import Linux 6.10.3 DTS for RISC-V

This has the side effect of pulling in 5 arm64 renesas and a few other
dt-bindings files which didn't exist before so there are no conflicts.

Hopefully arm/arm64/mips can catch up soon.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.82 2024/04/09 15:17:24 nia Exp $
d65 1
a65 1
sets="base comp debug etc games gpufw man manhtml misc modules rescue tests text"
@


1.82
log
@Add new sets: base32, debug32, manhtml

- base32 contains (when MKCOMPAT=yes) shared libraries for 32-bit
  compatibility, previously included in base

- debug32 contains (when MKCOMPAT=yes) debug symbols and static libraries
  containing debug symbols for 32-bit compatiblity, previously included
  in debug

- manhtml contains (when MKHTML=yes) the HTML files previously included
  in 'man', which are of limited utility without third-party software.

The motivation for this change is to be able to easily exclude sets
from CD-ROM images that go over the size limit without xz compression
(which many NetBSD platforms struggle to extract at acceptable speeds).
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.81 2024/02/12 11:30:33 mlelstv Exp $
d65 2
a66 2
sets="base comp etc games gpufw man manhtml misc modules rescue tests text"
xsets="xbase xcomp xetc xfont xserver" 
@


1.82.2.1
log
@Sync with HEAD
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.92 2025/04/01 00:04:00 gutteridge Exp $
d37 2
a38 2
# The host-specific functions are pulled in from a /bin/sh script in the
# "conf" directory, which is expected to provide the following shell
d44 1
a44 1
#    a working state, e.g., by setting up /etc/rc.conf and /dev
a62 5
SED=${TOOL_SED:-sed}
PWD_MKDB=${TOOL_PWD_MKDB:-pwd_mkdb}

postfix=false
[ "${MKPOSTFIX:-yes}" = no ] || postfix=true
d66 1
a66 1
xsets="xbase xcomp xetc xfont xserver"
a114 70
minwrites_fstab_entries() {
	$minwrites || return 0
	cat << EOF
tmpfs		/var/log		tmpfs	rw,union,-s32M
tmpfs		/var/run		tmpfs	rw,union,-s1M
tmpfs		/var/mail		tmpfs	rw,union,-s10M
tmpfs		/var/chroot		tmpfs	rw,union,-s10M
EOF
	if $postfix; then
	cat << EOF
tmpfs		/var/spool/postfix	tmpfs	rw,union,-s20M
tmpfs		/var/db/postfix		tmpfs	rw,union,-s1M
EOF
	fi
}

make_fstab_gpt() {
	local boot=$1
	local rootopts=
	if $minwrites; then
		rootopts=,log,nodevmtime
	fi

	cat > ${mnt}/etc/fstab << EOF
# NetBSD /etc/fstab
# See /usr/share/examples/fstab/ for more examples.
NAME=${gpt_label_ffs:-netbsd-root}	/		ffs	rw,noatime${rootopts}	1 1
NAME=${gpt_label_boot:-$boot}		/boot		msdos	rw	1 1
ptyfs		/dev/pts	ptyfs	rw
procfs		/proc		procfs	rw
tmpfs		/var/shm	tmpfs	rw,-m1777,-sram%25
EOF
	minwrites_fstab_entries >> ${mnt}/etc/fstab
}

# From Richard Neswold's:
# http://rich-tbp.blogspot.com/2013/03/netbsd-on-rpi-minimizing-disk-writes.html
# Also for the postfix stuff below
make_fstab_normal() {
	local rootopts=
	if $minwrites; then
		rootopts=,nodevmtime
	fi
	cat > ${mnt}/etc/fstab << EOF
# NetBSD /etc/fstab
# See /usr/share/examples/fstab/ for more examples.
ROOT.a		/			ffs	rw,noatime${rootopts}	1 1
ROOT.e		/boot			msdos	rw				1 1
ptyfs		/dev/pts		ptyfs	rw
procfs		/proc			procfs	rw
tmpfs		/tmp			tmpfs	rw,-s32M
tmpfs		/var/shm		tmpfs	rw,-m1777,-sram%25
EOF
	minwrites_fstab_entries >> ${mnt}/etc/fstab
}

make_fstab_default() {
	if $gpt; then
		make_fstab_gpt "$@@"
	else
		make_fstab_normal
	fi
	echo "./etc/fstab type=file uname=root gname=wheel mode=0644" \
	    >> "$tmp/selected_sets"

	# Missing mount points from fstab
	echo "./proc type=dir uname=root gname=wheel mode=0755" \
	    >> "$tmp/selected_sets"
}

a152 3
fsize=8192
bsize=65536
ffsversion=1
d262 1
a262 1
	    -o d=4096,f=${fsize},b=${bsize},v=${ffsversion} -b $((${extra}))m \
a339 4
cd "${IMAGEDIR}"
${CKSUM} -a MD5 "$(basename "${image}")" > MD5
${CKSUM} -a SHA512 "$(basename "${image}")" > SHA512

@


1.81
log
@Quote argument to -n as required. [ -n ] is not a syntax error but
evaluates to true.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.80 2024/02/11 17:29:50 christos Exp $
d65 1
a65 1
sets="base comp etc games gpufw man misc modules rescue tests text"
@


1.80
log
@PR/57925: Jan-Benedict Glaw: Honor $MKREPRO_TIMESTAMP, don't embed name and
stamp in gzip.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.79 2024/01/20 21:35:59 jmcneill Exp $
d193 1
a193 1
if [ -n ${MKREPRO_TIMESTAMP} ]; then
@


1.79
log
@evbppc: Add initial support for the Nintendo Wii
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.78 2021/09/25 08:54:30 maya Exp $
d193 4
d253 1
a253 1
	    -o "volume_label=NETBSD${fat_opt}" \
d261 1
a261 1
	    -O ${ffsoffset} \
d283 1
d336 1
a336 1
	${GZIP_CMD} -9 ${image}
@


1.78
log
@Move DRM-driver firmware from base to its own set, gpufw

This set is only installed on amd64,i386,evbarm.
This set is installed on minimal installs and on install media, in
case someone needs it for basic driver functionality.

Comments:
Switched to a single MK tunable for it - that is probably unneeded.

An upcoming DRM update will include even fatter firmware, and we'd
like to minimize the impact of it.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.77 2020/12/23 10:35:18 rin Exp $
d315 1
a315 1
		${DISKLABEL} -R -F ${image} ${tmp}/label
d319 1
a319 1
		${DISKLABEL} -R -F ${image} ${tmp}/label
@


1.78.2.1
log
@Pull up following revision(s) (requested by jmcneill in ticket #561):

	etc/etc.evbppc/Makefile.inc: revision 1.15
	sys/arch/evbppc/wii/dev/wiifb.c: revision 1.1
	sys/arch/evbppc/wii/dev/wiifb.c: revision 1.2
	sys/arch/evbppc/wii/dev/bwdsp.c: revision 1.1
	sys/arch/evbppc/wii/dev/wiifb.c: revision 1.3
	sys/arch/evbppc/wii/dev/bwdsp.c: revision 1.2
	distrib/utils/embedded/files/evbppc_wii_icon.png: revision 1.1
	usr.sbin/sysinst/arch/evbppc/md.h: revision 1.4
	sys/arch/evbppc/wii/dev/wiifb.c: revision 1.4
	sys/arch/evbppc/wii/dev/viio.h: revision 1.1
	sys/arch/evbppc/wii/dev/wiifb.c: revision 1.5
	sys/arch/evbppc/wii/dev/mainbus.h: revision 1.1
	distrib/utils/embedded/conf/wii.conf: revision 1.1
	distrib/utils/embedded/conf/wii.conf: revision 1.2
	distrib/utils/embedded/conf/wii.conf: revision 1.3
	sys/dev/sdmmc/sdhcvar.h: revision 1.34
	sys/dev/sdmmc/sdhc.c: revision 1.118
	sys/arch/evbppc/wii/dev/resetbtn.c: revision 1.1
	distrib/utils/embedded/conf/evbppc.conf: revision 1.1
	sys/dev/wsfb/genfb.c: revision 1.91
	sys/arch/evbppc/wii/dev/resetbtn.c: revision 1.2
	sys/dev/wscons/wsconsio.h: revision 1.127
	sys/arch/powerpc/oea/oea_machdep.c: revision 1.85
	sys/arch/evbppc/wii/dev/hollywood.h: revision 1.1
	sys/arch/evbppc/conf/std.wii: revision 1.1
	sys/arch/evbppc/wii/dev/hollywood.h: revision 1.2
	sys/arch/evbppc/wii/dev/hollywood.c: revision 1.1
	sys/arch/evbppc/conf/std.wii: revision 1.2
	sys/arch/evbppc/wii/dev/hollywood.c: revision 1.2
	sys/arch/evbppc/conf/std.wii: revision 1.3
	sys/arch/powerpc/oea/cpu_subr.c: revision 1.109
	sys/arch/evbppc/wii/wii_mmuinit.S: revision 1.1
	sys/dev/usb/usb.h: revision 1.124
	sys/arch/evbppc/wii/machdep.c: revision 1.1
	sys/arch/evbppc/wii/dev/rtcsram.c: revision 1.1
	sys/arch/powerpc/include/oea/hid.h: revision 1.14
	sys/arch/evbppc/wii/mainbus.c: revision 1.1
	sys/arch/evbppc/wii/machdep.c: revision 1.2
	sys/arch/evbppc/wii/dev/ehci_hollywood.c: revision 1.1
	sys/arch/evbppc/wii/mainbus.c: revision 1.2
	sys/arch/evbppc/wii/machdep.c: revision 1.3
	sys/arch/evbppc/wii/dev/ehci_hollywood.c: revision 1.2
	sys/arch/evbppc/wii/mainbus.c: revision 1.3
	sys/arch/evbppc/wii/machdep.c: revision 1.4
	sys/arch/evbppc/wii/dev/hwgpio.c: revision 1.1
	sys/arch/evbppc/wii/dev/sdhc_hollywood.c: revision 1.1
	sys/arch/evbppc/wii/dev/sdhc_hollywood.c: revision 1.2
	sys/arch/evbppc/wii/wii_locore.S: revision 1.1
	sys/arch/evbppc/conf/files.wii: revision 1.1
	sys/arch/evbppc/wii/wii_locore.S: revision 1.2
	sys/arch/evbppc/include/wii.h: revision 1.1
	sys/arch/evbppc/conf/files.wii: revision 1.2
	sys/arch/evbppc/wii/dev/exi.c: revision 1.1
	sys/arch/evbppc/include/wii.h: revision 1.2
	sys/arch/evbppc/conf/files.wii: revision 1.3
	sys/arch/powerpc/powerpc/clock.c: revision 1.18
	sys/arch/evbppc/include/wii.h: revision 1.3
	sys/arch/evbppc/conf/files.wii: revision 1.4
	sys/arch/evbppc/include/wii.h: revision 1.4
	sys/arch/evbppc/wii/dev/exi.h: revision 1.1
	sys/arch/evbppc/wii/dev/avenc.c: revision 1.1
	sys/arch/evbppc/include/wii.h: revision 1.5
	sys/arch/evbppc/include/wii.h: revision 1.6
	sys/arch/evbppc/include/wii.h: revision 1.7
	sys/arch/evbppc/wii/dev/avenc.h: revision 1.1
	distrib/utils/embedded/mkimage: revision 1.79
	sys/arch/evbppc/conf/WII: revision 1.1
	sys/arch/evbppc/conf/INSTALL_WII: revision 1.1
	distrib/utils/embedded/files/evbppc_wii_meta.xml: revision 1.1
	sys/arch/evbppc/wii/dev/vireg.h: revision 1.1
	sys/arch/evbppc/conf/WII: revision 1.2
	distrib/utils/embedded/files/evbppc_wii_meta.xml: revision 1.2
	sys/arch/evbppc/wii/dev/vireg.h: revision 1.2
	sys/arch/evbppc/conf/WII: revision 1.3
	sys/arch/evbppc/conf/WII: revision 1.4
	usr.sbin/sysinst/arch/evbppc/md.c: revision 1.11
	sys/arch/evbppc/wii/dev/ohci_hollywood.c: revision 1.1
	sys/dev/usb/ehcivar.h: revision 1.52
	sys/arch/evbppc/wii/pic_pi.c: revision 1.1
	sys/arch/evbppc/wii/dev/ohci_hollywood.c: revision 1.2
	etc/etc.evbppc/ttys: revision 1.8
	sys/arch/evbppc/wii/dev/bwai.c: revision 1.1
	sys/arch/evbppc/wii/dev/bwai.c: revision 1.2
	sys/arch/evbppc/wii/dev/bwai.c: revision 1.3
	sys/arch/evbppc/wii/autoconf.c: revision 1.1
	sys/arch/evbppc/conf/Makefile.wii.inc: revision 1.1
	sys/arch/evbppc/wii/dev/bwai.h: revision 1.1
	sys/arch/evbppc/wii/autoconf.c: revision 1.2
	sys/arch/evbppc/conf/Makefile.wii.inc: revision 1.2

powerpc: oea: Fix prefetchable mappings
Prefetchable mappings need PMAP_NOCACHE to get write-combine semantics.
powerpc: oea: Decode IBM750CL L2 cache information.
sdmmc: add support for optional delay after register write
wscons: Add HOLLYWOOD display and YUY2 pixel format types
wsfb: add support for optional "devcmap" property
A hardware driver can supply a pointer to a 16x 32-bit array to override
the default rasops device colour map in the "devcmap" property.
ehci: add EHCIF_32BIT_ACCESS flag to force 32-bit MMIO
fix comments: HID0 ICFI/DCFI are "flash invalidate", not "flush invalidate"
powerpc: fix delay for large (> ~5sec) values
When calculating the target timebase, promote '1000' on the RHS to ULL
to force 64-bit calculation, otherwise 'n * 1000' will overflow.
usb: increase USB_PORT_RESET_RECOVERY from 10ms to 20ms
I changed this from 250ms to 10ms back in 2021 based on a similar FreeBSD
change, but it seems to be a bit too aggressive for some platforms.
evbppc: Add initial support for the Nintendo Wii
wii: support RB_POWERDOWN
build fix: use dd with count=1 for compat with NetBSD dd(1)
wii: Add NTSC 480p support.
In addition to this, add VIIO_{GET,SET}REGS ioctl support to allow for
poking at video interface registers from userland. This is helpful for
debugging display issues.
wii: Add 128x48 icon to SD card image
wii: Fix a comment
wii: Add drivers for Broadway DSP and Audio interface.
0: [*] audio0 @@ bwdsp0: Broadway DSP
       playback: 16, 2ch, 48000Hz
       record:   unavailable
       (P-) slinear_be 16/16, 2ch, { 48000 }
wii: Add screenblank support.
wii: Use screen dimming register for screen blanking.
wii: Add GPIO, I2C, and basic A/V encoder driver.
wii: Use A/V encoder volume controls instead of using a software filter.
wii: Simply DSP driver - no interrupt handler required.
wii: provide device names to intr_establish
wii$ intrctl list
interrupt id      CPU0  device name(s)
pi irq 14        64769* hollywood0
hollywood irq 36  5872* ehci0
hollywood irq 39 58907* sdhc0
hollywood irq 40     4* sdhc1
hollywood irq 49     0* resetbtn0
pi irq 5             0* bwai0
wii: Add support for passing boot options to the kernel.
wii: Add External interface bus and RTC support
wii: Remove objcopy after kernel build.
HBC will do the right thing.
Add wsvt25 entries (off by default) for ttyE0-ttyE3.
Add support for "PAL" (576i) mode on Wii.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.78 2021/09/25 08:54:30 maya Exp $
d315 1
a315 1
		${DISKLABEL} -m -R -F ${image} ${tmp}/label
d319 1
a319 1
		${DISKLABEL} -m -R -F ${image} ${tmp}/label
@


1.77
log
@Fix fallout from mkimage rev 1.76.

For mkimage:

- Update "size" if auto-calculated.
- Use "dd bs=1" instead of non-portable "head -c".
- Some style nits.

For MD make_label() functions:

- Stop using "newsize" as image size in MB, use "size" instead.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.76 2020/12/21 16:38:02 riastradh Exp $
d65 1
a65 1
sets="base comp etc games man misc modules rescue tests text"
@


1.76
log
@embedded/mkimage: Pad image with zeros to multiple of 4 MB plus 1 MB.

Otherwise, there may not be enough space after the ffs partition for a
gpt, leading to very confusing results.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.75 2020/07/17 15:16:34 jmcneill Exp $
a261 1
cursize="$(getsize "${image}")"
d263 1
a263 1
	size="${cursize}"
d266 1
a266 1
	alignsize=$((alignunit*((cursize + alignunit - 1)/alignunit)))
d268 4
a271 2
	if [ $cursize -lt $alignsize ]; then
		head -c "$((alignsize - cursize))" < /dev/zero >> "${image}"
@


1.75
log
@Create an "octeon.img.gz" bootable image for evbmips64-eb release builds.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.74 2020/05/24 18:43:39 jmcneill Exp $
d262 1
d264 8
a271 1
	size="$(getsize "${image}")"
a272 8
newsize=$((${size} / 2 / 1024))
compare=$((${newsize} * 2 * 1024))
while [ "${compare}" != "${size}" ]
do    
	size="$((size + size - compare))"  
	newsize="$((${size} / 2 / 1024))"
	compare="$((${newsize} * 2 * 1024))"
done                      
@


1.74
log
@Add support for hybrid MBR/GPT images.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.73 2020/05/24 14:45:49 jmcneill Exp $
d287 1
a287 1
	${GPT} ${gpt_flags} ${image} add -b ${initsecs} -s ${bootsecs} -l ${gpt_label_efi:-EFI} -t efi
@


1.73
log
@Add GPT support to mkimage.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.72 2020/05/18 21:19:34 jmcneill Exp $
d152 1
d275 3
d283 1
a283 1
	${GPT} ${image} destroy || true
d286 11
a296 5
	${GPT} ${image} create ${gpt_create_flags}
	${GPT} ${image} add -b ${initsecs} -s ${bootsecs} -l ${gpt_label_efi:-EFI} -t efi
	${GPT} ${image} set -a required -i 1
	${GPT} ${image} add -a 4m -b ${ffsstart} -l ${gpt_label_ffs:-netbsd-root} -t ffs
	${GPT} ${image} show
@


1.72
log
@Separate devicetree .dts -> .dtb building from kernel builds. They are now
part of a separate set, "dtb.tgz", and only built when MKDTB=yes. This
defaults to yes for earmv[67]* and aarch64, and no everywhere else.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.71 2019/10/30 14:16:15 martin Exp $
d57 1
d151 1
d273 1
a273 2
if [ -n "${msdosid}" ]; then
	echo ${bar} Running fdisk ${bar}
d276 38
a313 8
	${FDISK} -f -i ${image}
	${FDISK} -f -a -u -0 -s ${msdosid}/${initsecs}/${bootsecs} -F ${image}
	if [ -z "${bootonly}" ]; then
		ffsstart="$(getsectors ${ffsoffset})"
		imagesize="$(getsize "${image}")"
		imagesecs="$(getsectors ${imagesize})"
		ffssize="$(expr ${imagesecs} - ${ffsstart})"
		${FDISK} -f -u -1 -s 169/${ffsstart}/${ffssize} -F ${image}
a314 13

	echo ${bar} Adding label ${bar}
	make_label > ${tmp}/label
	${DISKLABEL} -R -F ${image} ${tmp}/label
elif [ -n "${netbsdid}" ]; then
	echo ${bar} Adding label ${bar}
	make_label > ${tmp}/label
	${DISKLABEL} -R -F ${image} ${tmp}/label

	echo ${bar} Running fdisk ${bar}
	${FDISK} -f -i ${image}
	${FDISK} -f -a -u -0 -s 169/${init} ${image}
	${INSTALLBOOT} -f -v ${image} ${release}/usr/mdec/bootxx_ffsv1
@


1.71
log
@Derive the FAT type from the MBR partition type and pass it on to makefs
when crating a msdos file system.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.70 2019/10/02 11:16:00 maya Exp $
d218 18
d238 1
@


1.70
log
@Split out /rescue to its own set and adapt installers/images to add it.

This is meant to make updates safer: if something goes wrong with updating
base, we still have the old, standalone /rescue to recover from.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.69 2017/11/28 02:56:44 kre Exp $
d220 8
a227 1
	${MAKEFS} -N ${release}/etc -t msdos -o volume_label=NETBSD \
@


1.69
log
@
Be more precise about exactly what fails when something does.

Relying upon set -e to abort things is sort of OK (it is not
a recommended option to use in general - too many odd special cases),
but only if user can work out from the "build failed" what actually
went wrong.

Tested only on amd64 build (for this, i386 is the same) - if anyone
has problems on builds for other systems, please let me know.  However
the changes affect only failure paths, the most likely problem would
be for a build to fail to halt on an error, and I hope I have avoided
that.  There should be no difference at all to error-free builds.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.68 2017/11/28 00:24:08 kre Exp $
d64 1
a64 1
sets="base comp etc games man misc modules tests text"
@


1.69.4.1
log
@Mostly merge changes from HEAD upto 20200411
@
text
@d2 1
a2 1
# $NetBSD$
d64 1
a64 1
sets="base comp etc games man misc modules rescue tests text"
d220 1
a220 8
	case $(( ${msdosid} )) in
	1)	fat_opt=",fat_type=12";;
	4|6|14)	fat_opt=",fat_type=16";;
	11|12)	fat_opt=",fat_type=32";;
	*)	fat_opt=;;
	esac
	${MAKEFS} -N ${release}/etc -t msdos \
	    -o "volume_label=NETBSD${fat_opt}" \
@


1.69.6.1
log
@Pull up following revision(s) (requested by maya in ticket #435):

	distrib/sets/maketars: revision 1.90
	usr.sbin/sysinst/arch/playstation2/md.h: revision 1.2
	usr.sbin/sysinst/arch/sandpoint/md.h: revision 1.3
	usr.sbin/sysinst/arch/evbppc/md.h: revision 1.3
	usr.sbin/sysinst/arch/hpcarm/md.h: revision 1.3
	usr.sbin/sysinst/arch/mvme68k/md.h: revision 1.3
	distrib/sun3/MakeInstTape: revision 1.3
	usr.sbin/sysinst/util.c: revision 1.33
	distrib/sets/lists/rescue/mi: revision 1.1
	distrib/sets/lists/base/rescue.sun2: file removal
	usr.sbin/sysinst/arch/zaurus/md.h: revision 1.3
	distrib/sets/lists/base/rescue.ad.m68k.shl: file removal
	distrib/sets/regpkgset: revision 1.13
	usr.sbin/sysinst/arch/i386/md.h: revision 1.7
	distrib/sets/lists/base/rescue.sparc: file removal
	distrib/notes/mvme68k/xfer: revision 1.19
	distrib/sets/sets.subr: revision 1.187
	distrib/common/bootimage/Makefile.bootimage: revision 1.22
	usr.sbin/sysinst/msg.mi.de: revision 1.16
	usr.sbin/sysinst/arch/atari/md.h: revision 1.3
	rescue/Makefile: revision 1.38
	distrib/sets/lists/base/rescue.macppc: file removal
	usr.sbin/sysinst/arch/arc/md.h: revision 1.4
	distrib/miniroot/install.sub: revision 1.49
	usr.sbin/sysinst/arch/acorn32/md.h: revision 1.3
	usr.sbin/sysinst/arch/x68k/md.h: revision 1.3
	usr.sbin/sysinst/arch/hpcmips/md.h: revision 1.3
	usr.sbin/sysinst/arch/bebox/md.h: revision 1.3
	usr.sbin/sysinst/arch/hpcsh/md.h: revision 1.2
	distrib/sets/lists/base/rescue.shark: file removal
	usr.sbin/sysinst/arch/emips/md.h: revision 1.5
	distrib/utils/embedded/mkimage: revision 1.70
	usr.sbin/sysinst/arch/shark/md.h: revision 1.3
	usr.sbin/sysinst/arch/pmax/md.h: revision 1.4
	usr.sbin/sysinst/arch/amiga/md.h: revision 1.4
	usr.sbin/sysinst/arch/hp300/md.h: revision 1.5
	rescue/list.ldconfig: file removal
	distrib/sets/lists/base/rescue.ad.m68k: file removal
	usr.sbin/sysinst/arch/prep/md.h: revision 1.4
	usr.sbin/sysinst/arch/cats/md.h: revision 1.4
	usr.sbin/sysinst/arch/amd64/md.h: revision 1.7
	usr.sbin/sysinst/msg.mi.es: revision 1.17
	usr.sbin/sysinst/msg.mi.fr: revision 1.20
	usr.sbin/sysinst/msg.mi.pl: revision 1.23
	distrib/sets/lists/base/rescue.i386: file removal
	usr.sbin/sysinst/arch/evbarm/md.h: revision 1.3
	distrib/sets/lists/base/rescue.vax: file removal
	distrib/amd64/uefi-installimage/Makefile.bootimage: revision 1.12
	usr.sbin/sysinst/arch/evbmips/md.h: revision 1.3
	distrib/sets/lists/base/rescue.mi: file removal
	distrib/sets/README: revision 1.14
	usr.sbin/sysinst/arch/sgimips/md.h: revision 1.4
	distrib/sets/lists/base/rescue.sparc64: file removal
	distrib/sets/lists/base/rescue.mi: revision 1.45
	distrib/sets/lists/base/rescue.mi: revision 1.46
	usr.sbin/sysinst/arch/ofppc/md.h: revision 1.4
	usr.sbin/sysinst/arch/cobalt/md.h: revision 1.4
	distrib/sets/lists/base/rescue.ad.arm: file removal
	distrib/sets/lists/base/rescue.mac68k: file removal
	usr.sbin/sysinst/defs.h: revision 1.45
	usr.sbin/sysinst/arch/landisk/md.h: revision 1.2
	distrib/notes/atari/xfer: revision 1.17
	etc/Makefile: revision 1.441
	usr.sbin/sysinst/msg.mi.en: revision 1.22
	distrib/sun2/MakeInstTape: revision 1.2

Remove ldconfig from /rescue, and mark it MI obsolete.
- ldconfig in netbsd refers to a.out binaries only. We've been ELF-only
  since NetBSD 2.0 or so, and having it in /rescue served little purpose
  even before that, as /rescue is standalone.
- Using MI obsolete to avoid the need for MD set lists where ldconfig
  is the sole entry

Mark /rescue/edlabel as MI-obsolete, so we can remove all remaining MD
rescue set list files.

Split out /rescue to its own set and adapt installers/images to add it.

This is meant to make updates safer: if something goes wrong with updating
base, we still have the old, standalone /rescue to recover from.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.69 2017/11/28 02:56:44 kre Exp $
d64 1
a64 1
sets="base comp etc games man misc modules rescue tests text"
@


1.68
log
@
Handle use of TMPDIR in cleanup as well.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.67 2017/11/28 00:14:30 kre Exp $
d81 6
@


1.67
log
@
Honour ${TMPDIR} if set for location of image, rather than always
simply using /tmp
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.66 2017/07/06 00:17:04 jmcneill Exp $
d77 1
a77 1
	/tmp/$PROG.*)	rm -fr "$tmp";;
@


1.66
log
@Replace HUMMINGBIRD_A31 with SUNXI kernel on armv7.img and include .dtb
files for SUNXI and TEGRA kernels on the MSDOS partition.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.65 2017/06/10 23:26:32 christos Exp $
d69 1
a69 1
tmp="$(mktemp -d "/tmp/$PROG.XXXXXX")"
@


1.65
log
@add the tests set.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.64 2017/04/11 21:06:30 jmcneill Exp $
d54 1
@


1.64
log
@Now that FAT+FFS images include the BSD partition in the MBR partition
table, install the disklabel after setting up MBR partitions. This moves
the disklabel to the BSD partition from the start of the disk, avoiding
a conflict with the ODROID-C1 bootloader.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.63 2017/04/11 18:04:08 jmcneill Exp $
d63 1
a63 1
sets="base comp etc games man misc modules text"
@


1.64.4.1
log
@Pull up following revision(s) (requested by jmcneill in ticket #114):
	sys/arch/arm/samsung/exynos_intr.h: revision 1.3
	sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.1
	sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.2
	sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.3
	sys/arch/arm/sunxi/sunxi_gates.c: revision 1.1
	distrib/utils/embedded/mkimage: revision 1.66
	sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.4
	sys/arch/arm/sunxi/sunxi_rsb.c: revision 1.1
	sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.5
	sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.6
	sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.7
	sys/dev/gpio/gpio.c: revision 1.59
	sys/arch/arm/sunxi/sunxi_ccu_prediv.c: revision 1.1
	sys/conf/Makefile.kern.inc: revision 1.257
	sys/arch/evbarm/conf/ODROID-XU_INSTALL: file removal
	sys/arch/arm/sunxi/sunxi_ccu_prediv.c: revision 1.2
	sys/conf/Makefile.kern.inc: revision 1.258
	sys/arch/arm/fdt/psci_fdt.h: revision 1.1
	sys/arch/arm/sunxi/sunxi_resets.c: revision 1.1
	sys/arch/evbarm/conf/files.sunxi: revision 1.1
	sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.8
	sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.9
	sys/arch/arm/samsung/files.exynos: revision 1.22
	distrib/utils/embedded/conf/armv7.conf: revision 1.13
	sys/arch/arm/samsung/files.exynos: revision 1.23
	sys/arch/evbarm/conf/std.tegra: revision 1.15
	distrib/utils/embedded/conf/armv7.conf: revision 1.14
	sys/arch/arm/samsung/files.exynos: revision 1.24
	distrib/utils/embedded/conf/armv7.conf: revision 1.15
	sys/arch/evbarm/sunxi/genassym.cf: revision 1.1
	sys/arch/arm/samsung/exynos_fdt.c: file removal
	sys/dev/fdt/fdt_pinctrl.c: revision 1.4
	sys/arch/arm/samsung/exynos_sysmmu.c: revision 1.2
	sys/arch/arm/sunxi/sun8i_h3_gpio.c: revision 1.1
	sys/arch/arm/sunxi/sunxi_twi.c: revision 1.1
	sys/dev/usb/ehci.c: revision 1.255
	sys/arch/arm/sunxi/sunxi_twi.c: revision 1.2
	sys/arch/arm/sunxi/sun8i_a83t_ccu.h: revision 1.1
	sys/dev/ic/dwc_mmc.c: revision 1.11
	sys/arch/arm/cortex/gic.c: revision 1.24
	distrib/evbarm/instkernel/ramdisk/Makefile: revision 1.17
	etc/etc.evbarm/Makefile.inc: revision 1.87
	etc/etc.evbarm/Makefile.inc: revision 1.88
	sys/arch/arm/fdt/gic_fdt.c: revision 1.5
	etc/Makefile: revision 1.429
	sys/arch/arm/fdt/gic_fdt.c: revision 1.6
	sys/arch/arm/fdt/gic_fdt.c: revision 1.7
	sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.1
	sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.2
	sys/arch/evbarm/conf/std.sunxi: revision 1.1
	sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.3
	sys/arch/evbarm/conf/std.sunxi: revision 1.2
	sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.4
	sys/arch/evbarm/conf/std.sunxi: revision 1.3
	sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.5
	sys/arch/arm/sunxi/sunxi_ccu_div.c: revision 1.1
	sys/dev/gpio/gpiovar.h: revision 1.17
	sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.6
	sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.7
	sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.8
	sys/arch/arm/sunxi/sunxi_rsb.h: revision 1.1
	sys/arch/arm/samsung/exynos_i2c.c: revision 1.12
	sys/dev/fdt/fdtvar.h: revision 1.21
	sys/arch/evbarm/sunxi/sunxi_start.S: revision 1.1
	sys/arch/arm/samsung/exynos_i2c.c: revision 1.13
	sys/dev/fdt/fdtvar.h: revision 1.22
	sys/arch/evbarm/conf/SUNXI: revision 1.10
	sys/dev/fdt/fdtvar.h: revision 1.23
	sys/arch/evbarm/conf/SUNXI: revision 1.11
	sys/dev/fdt/gpioleds.c: revision 1.1
	sys/dev/fdt/fdtvar.h: revision 1.24
	sys/arch/evbarm/conf/SUNXI: revision 1.12
	sys/arch/evbarm/conf/SUNXI: revision 1.13
	sys/arch/arm/cortex/gic.c: revision 1.30
	sys/arch/evbarm/conf/SUNXI: revision 1.14
	sys/arch/evbarm/conf/SUNXI: revision 1.15
	sys/arch/evbarm/conf/SUNXI: revision 1.16
	sys/arch/arm/sunxi/sunxi_emac.c: revision 1.1
	etc/Makefile: revision 1.430
	sys/arch/arm/sunxi/sunxi_emac.c: revision 1.2
	etc/Makefile: revision 1.431
	sys/arch/evbarm/conf/VEXPRESS_A15: revision 1.17
	sys/arch/arm/sunxi/sunxi_emac.c: revision 1.3
	sys/arch/arm/sunxi/sunxi_emac.c: revision 1.4
	sys/arch/arm/samsung/exynos5422_clock.c: revision 1.6
	sys/arch/arm/samsung/exynos_platform.c: revision 1.1
	sys/dev/ofw/ofw_subr.c: revision 1.29
	sys/arch/arm/samsung/exynos_platform.c: revision 1.2
	sys/arch/evbarm/conf/mk.vexpress: revision 1.3
	sys/arch/arm/samsung/exynos_platform.c: revision 1.3
	sys/arch/evbarm/conf/mk.vexpress: revision 1.4
	sys/arch/arm/samsung/exynos_platform.c: revision 1.4
	sys/arch/arm/arm/psci.h: revision 1.1
	sys/arch/arm/samsung/exynos_platform.c: revision 1.5
	sys/arch/arm/samsung/exynos_platform.c: revision 1.6
	sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.10
	external/bsd/mdocml/bin/mandoc/Makefile: revision 1.12
	sys/dev/fdt/files.fdt: revision 1.17
	sys/dev/fdt/files.fdt: revision 1.18
	sys/dev/fdt/files.fdt: revision 1.19
	sys/arch/arm/samsung/exynos_sscom.c: revision 1.8
	sys/arch/arm/sunxi/sun8i_a83t_ccu.c: revision 1.1
	sys/arch/arm/sunxi/sunxi_mmc.c: revision 1.1
	sys/arch/arm/samsung/exynos_sscom.c: revision 1.9
	sys/arch/arm/conf/files.arm: revision 1.133
	sys/arch/arm/samsung/mct_var.h: revision 1.5
	sys/arch/arm/sunxi/sunxi_platform.c: revision 1.1
	sys/arch/arm/sunxi/sunxi_platform.c: revision 1.2
	sys/arch/evbarm/conf/std.vexpress: revision 1.6
	sys/arch/arm/sunxi/sunxi_platform.c: revision 1.3
	sys/arch/arm/sunxi/sun6i_a31_gpio.c: revision 1.1
	sys/arch/arm/sunxi/sunxi_platform.c: revision 1.4
	sys/arch/arm/sunxi/sun6i_a31_gpio.c: revision 1.2
	sys/arch/arm/sunxi/files.sunxi: revision 1.1
	sys/dev/ofw/ofw_subr.c: revision 1.30
	sys/arch/arm/sunxi/files.sunxi: revision 1.2
	sys/dev/ofw/openfirm.h: revision 1.35
	sys/arch/arm/sunxi/files.sunxi: revision 1.3
	sys/dev/ofw/openfirm.h: revision 1.36
	sys/arch/arm/sunxi/files.sunxi: revision 1.4
	sys/arch/arm/sunxi/files.sunxi: revision 1.5
	sys/arch/evbarm/exynos/exynos_machdep.c: file removal
	sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.1
	sys/arch/arm/samsung/sscom.c: revision 1.9
	sys/arch/arm/sunxi/files.sunxi: revision 1.6
	sys/dev/fdt/ohci_fdt.c: revision 1.1
	sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.1
	sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.2
	sys/arch/arm/sunxi/files.sunxi: revision 1.7
	sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.2
	sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.3
	sys/arch/arm/sunxi/files.sunxi: revision 1.8
	sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.3
	sys/arch/arm/sunxi/files.sunxi: revision 1.9
	sys/arch/arm/samsung/exynos_sscom.c: revision 1.10
	sys/arch/evbarm/conf/mk.tegra: revision 1.5
	sys/arch/arm/samsung/exynos_dwcmmc.c: revision 1.4
	sys/arch/evbarm/conf/mk.tegra: revision 1.6
	sys/arch/evbarm/conf/EXYNOS: revision 1.15
	sys/arch/evbarm/conf/EXYNOS: revision 1.16
	sys/arch/evbarm/conf/EXYNOS: revision 1.17
	sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.1
	sys/arch/evbarm/conf/EXYNOS: revision 1.19
	sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.2
	sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.3
	sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.4
	sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.5
	sys/arch/arm/sunxi/sunxi_emac.h: revision 1.1
	sys/arch/evbarm/conf/mk.sunxi: revision 1.1
	sys/arch/evbarm/include/bootconfig.h: revision 1.7
	sys/arch/evbarm/conf/TEGRA: revision 1.24
	sys/arch/arm/arm/psci.c: revision 1.1
	sys/dev/led.c: revision 1.1
	sys/dev/led.c: revision 1.2
	sys/arch/arm/arm/psci_arm.S: revision 1.1
	sys/arch/arm/sunxi/sunxi_ccu_gate.c: revision 1.1
	sys/arch/arm/sunxi/sunxi_ccu_gate.c: revision 1.2
	sys/dev/fdt/ehci_fdt.c: revision 1.1
	sys/dev/fdt/ehci_fdt.c: revision 1.2
	sys/arch/arm/sunxi/sun6i_a31_ccu.h: revision 1.1
	sys/arch/evbarm/conf/EXYNOS: revision 1.21
	sys/arch/arm/sunxi/files.sunxi: revision 1.10
	sys/arch/arm/sunxi/files.sunxi: revision 1.11
	sys/dev/fdt/fdtbus.c: revision 1.14
	sys/arch/arm/sunxi/sunxi_mmc.h: revision 1.1
	sys/arch/arm/samsung/exynos5422_dma.c: file removal
	usr.bin/config/mkmakefile.c: revision 1.69
	sys/conf/files: revision 1.1178
	sys/arch/arm/sunxi/sunxi_platform.h: revision 1.1
	sys/arch/evbarm/exynos/exynos_start.S: revision 1.4
	sys/arch/arm/samsung/exynos_pinctrl.c: revision 1.11
	sys/arch/arm/samsung/exynos_pinctrl.c: revision 1.12
	sys/arch/arm/sunxi/sunxi_rtc.c: revision 1.1
	sys/arch/arm/sunxi/sun8i_h3_ccu.h: revision 1.1
	sys/arch/arm/samsung/exynos5410_clock.c: revision 1.1
	sys/arch/arm/samsung/exynos5410_clock.c: revision 1.2
	sys/arch/evbarm/conf/SUNXI: revision 1.1
	external/bsd/elftosb/usr.sbin/elftosb/Makefile: revision 1.5
	sys/arch/evbarm/conf/SUNXI: revision 1.2
	sys/arch/arm/fdt/psci_fdt.c: revision 1.1
	sys/arch/evbarm/conf/SUNXI: revision 1.3
	sys/arch/evbarm/conf/SUNXI: revision 1.4
	sys/arch/evbarm/conf/files.exynos: revision 1.3
	sys/arch/evbarm/conf/SUNXI: revision 1.5
	sys/arch/evbarm/conf/SUNXI: revision 1.6
	sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.1
	sys/dev/fdt/fixedfactorclock.c: revision 1.1
	sys/dev/fdt/fdt_subr.c: revision 1.14
	sys/arch/evbarm/conf/SUNXI: revision 1.7
	sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.2
	sys/arch/arm/sunxi/sun8i_a83t_gpio.c: revision 1.1
	sys/dev/fdt/fdt_subr.c: revision 1.15
	sys/arch/evbarm/conf/SUNXI: revision 1.8
	sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.3
	sys/dev/ic/dwc_mmc_reg.h: revision 1.6
	sys/dev/fdt/fdt_subr.c: revision 1.16
	sys/arch/evbarm/conf/SUNXI: revision 1.9
	usr.bin/config/mkmakefile.c: revision 1.70
	sys/dev/fdt/fdt_phy.c: revision 1.1
	sys/arch/evbarm/conf/ODROID-XU: file removal
	sys/arch/arm/fdt/arm_fdt.c: revision 1.4
	sys/arch/arm/samsung/exynos_reg.h: revision 1.14
	sys/conf/files: revision 1.1180
	sys/arch/arm/samsung/exynos_reg.h: revision 1.15
	sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.1
	sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.2
	sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.3
	sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.4
	sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.5
	sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.6
	sys/dev/ic/dwc_mmc_var.h: revision 1.6
	sys/arch/arm/samsung/exynos_combiner.c: revision 1.7
	sys/arch/evbarm/exynos/platform.h: revision 1.2
	sys/arch/arm/fdt/files.fdt: revision 1.12
	sys/arch/evbarm/conf/std.exynos: revision 1.2
	sys/arch/evbarm/conf/std.exynos: revision 1.3
	sys/arch/arm/rockchip/rockchip_dwcmmc.c: revision 1.6
	sys/arch/arm/sunxi/sunxi_com.c: revision 1.1
	sys/dev/led.h: revision 1.1
	sys/arch/evbarm/conf/std.exynos: revision 1.5
	sys/arch/arm/sunxi/sunxi_com.c: revision 1.2
	sys/arch/evbarm/conf/files.evbarm: revision 1.26
	usr.bin/config/defs.h: revision 1.99
	sys/arch/arm/fdt/arm_fdtvar.h: revision 1.6
	sys/arch/arm/samsung/exynos_soc.c: revision 1.32
	sys/arch/arm/sunxi/sun6i_a31_ccu.c: revision 1.1
	sys/arch/arm/sunxi/sun6i_a31_ccu.c: revision 1.2
	sys/arch/arm/samsung/mct.c: revision 1.11
	sys/arch/evbarm/conf/ODROID-U: file removal
	sys/arch/arm/samsung/mct.c: revision 1.12
	sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.1
	sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.2
	sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.3
	sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.4
Get the EXYNOS kernel building again with recent FDT changes. Untested.
Use arm_fdt_cpu_hatch and add mmu entry for DTB
Fix exynos5 devmap, bootstrap, and implement early_putchar.
Calculate UART frequency based on bootloader config.
Fix KERNEL_BASE_PHYS (how did this ever work?)
Avoid divide-by-zero for unconfigured PLLs
Correctly initialize i2cbus attach args.
Add delay and enable mct timecounter.
Fix build w/o VERBOSE_INIT_ARM
Remove ODROID-U and ODROID-XU kernel configs as they no longer work.
- Replace CONSADDR with SSCOM2CONSOLE in example
- Remove gtmr (Exynos5422 uses mct)
- cinclude EXYNOS.local instead of TEGRA.local
Use fdtbus_intr_establish to hook in block interrupts instead of
intr_establish.
Simplify MCT; just enable it and then attach an ARMv7 generic timer.
Add support for building DTB files during kernel build, from christos.
build vexpress-v2p-ca15-tc1.dtb with the kernel
build tegra124-apalis-eval.dtb, tegra124-jetson-tk1.dtb, tegra124-nyan-big.dtb, tegra124-nyan-blaze.dtb, and tegra124-venice2.dtb with the kernel
Allow multiline makeoptions to work by quoting the newline..
Bump for quoting makeoptions with multiple lines.
un-c99
bump required config version for multiline makeoptions feature
Set DTS makeoption in kernel config
Assign DTB files to a variable so we can make -V DTB
put the dtb files with their kernels.
no need for debug printing.
Don't assume that CPU index = GIC CPU interface number. We can determine
the current CPU interface number by reading from the read-only
GICD_ITARGETSR0 through GICD_ITARGETSR7 registers.
This gets interrupts working on Exynos 5422, where the boot processor has
GIC CPU interface #4.
use -v to get the expanded variable.
Use -v to get the expanded variables.
Get baud rate from sclk_uartN instead of uartN. Print IRQ number at attach.
Fix PLL con0 register locations and add uart clocks
Disable exyortc for now, it doesn't work.
More or less a rewrite of dwc_mmc, based on awin_mmc, adding DMA support.
Update for new dwc_mmc driver
Fix dmesg
Add Exynos 5410 clock controller driver.
Fix a few typos in clock parent names for mmc clocks.
From jmcneill@@
Update for new dwc_mmc driver
Implement platform reset for exynos5
Attach fdtbus to a /clocks node with no compatible string.
Add support for ARM Power State Coordination Interface (PSCI).
Support interrupt sharing.
Add initial support for Allwinner H3 SoC.
ARM Trusted Firmware reserves SGIs 8-15 for secure use. Even without ATF,
U-Boot on some platforms may use SGIs in this range for the PSCI
implementation.
Change ARMGIC_IPI_BASE to 0 from (16 - NIPI) and add a compile-time assert
to ensure that we don't end up with a conflict.
Add H3 MMC support
SD/MMC clock fixes
Add FDT PHY interface.
Add glue for generic ehci/ohci bindings.
Rename a variable, NFC.
Support parents in different clock domains.
Add USB stuff. Doesn't quite work yet.
Synopsys DesignWare APB UART needs "options COM_AWIN" for now.
Add i2c glue.
Add RTC driver.
PHY registers start at index 1. Now USB works.
Don't allow sharing edge and level triggered interrupts.
Add arm_fdt_memory_dump helper for dumping physical addresses from ddb
Print clocks with aprint_debug
Remove unused defines
Add fdtbus_get_string helper
Add of_search_compatible, which searches an array of compat_data structures
for a matching "compatible" entry matching the supplied OFW node. This
allows us to associate data with compatible strings.
Add driver for Allwinner Gigabit Ethernet (EMAC) as found in sun8i and
later family SoCs.
This is a port of my FreeBSD driver which has been confirmed to work on
Allwinner H3, A83T, and A64 SoCs.
Fix dmesg
Add basic support for Allwinner A31.
Add basic FDT GPIO support.
Fix the pinctrl api to match the spec. A pinctrl config can have more
than one xref, and an xref may have specifier data associated with it.
Enable sunxi pinctrl support
Adjust to new pinctrl API
Add P2WI/RSB driver, based on awin_p2wi.c.
Fix typo in a compat string.
Configure pin defaults at attach
No need to explicitly set pinctrl config 0 now
Fix some register definitions.
Disallow sharing between MPSAFE and non-MPSAFE handlers.
Add of_match_compat_data.
This routine searches an array of compat_data structures for a
matching "compatible" entry matching the supplied OFW node.
Add options __HAVE_CPU_UAREA_ALLOC_IDLELWP
Add support for reserved memory and MEMORY_DISK_DYNAMIC for FDT-based
kernels.
the extent code cannot use the full range of u_long,
so ignore the last page before 4GB too.  ok jmcneill@@
Copy install ramdisk to releasedir. Provide both a raw ffs and
Legacy U-Boot version of it.
Replace HUMMINGBIRD_A31 with SUNXI kernel on armv7.img and include .dtb
files for SUNXI and TEGRA kernels on the MSDOS partition.
Let the controller provide a default name for pins. This makes pins easier
to locate when we have multiple banks and a variable number of pins per
bank.
Attach gpio(4) to sunxigpio
Test for kernel build directory before reading DTB list
Add support for Allwinner A83T SoC.
Add A83T files
Fixup busdma sync and locking in the RX path. Disable batch RX/TX ints.
Fix AHB2 register definition and explicitly set AHB2 parent to PLL_PERIPH0/2 -- this gives us 50% more bus bandwidth for emac
Restore TX_INTERVAL_DEFAULT to 64
Drop the sunxi_emac_rx_batch feature. It was originally designed to
reduce the amount of mutex unlock/lock cycles during the RX path on
FreeBSD and if_input, but it is not required to drop the lock before
calling if_percpuq_enqueue on NetBSD.
Write back the data value instead of mask in sunxi_gpio_write
Add a helper for exposing LED controls via sysctl.
Add GPIO LED driver.
add gpioleds
Add misc. gates and resets driver, and explicitly enable PIO clocks
at attach.
Add fdtbus_get_string_index helper.
Add driver for fixed-factor clocks.
Add ffclock
Remove the requirement for ehci to attach after companion devices.
"go for it" - skrll@@
Remove the hack to find companion devices and just assume 1 companion if
ETTF flag is not set.
Remove pass numbers for ehci/ohci now that the attach order no longer matters
Use unsigned char for ctype functions, suggested by christos
Add : to body of populate_sunxi to appease bash.
port-evbarm/52388: Fix number of args to a debug printf.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.64 2017/04/11 21:06:30 jmcneill Exp $
a53 1
MAKE=${TOOL_MAKE:-make}
@


1.63
log
@Improvements and fixes for FAT+FFS images:
 - Add a "NETBSD" volume label to the MSDOS file-system.
 - Explicitly initialize boot sector.
 - Correct an issue where the MSDOS file-system was larger than the
   partition table entry.
 - Add NetBSD partition to the MBR partition table.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.62 2017/03/14 06:37:39 skrll Exp $
a237 3
echo ${bar} Adding label ${bar}
make_label > ${tmp}/label
${DISKLABEL} -R -F ${image} ${tmp}/label
d251 4
d256 4
@


1.62
log
@Mark the msdos parition active for boards like the BeagleBone Black
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.61 2015/08/01 10:05:51 jmcneill Exp $
d85 22
d213 2
a214 2
	${MAKEFS} -N ${release}/etc -t msdos \
	    -O $((${init} / 2))m -s $((${boot} / 2 + ${init} / 2))m \
d245 1
d247 7
@


1.61
log
@use a larger (64KB) block size, this helps SD card performance
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.60 2015/07/15 11:27:13 martin Exp $
d223 1
a223 1
	${FDISK} -f -u -0 -s ${msdosid}/${initsecs}/${bootsecs} -F ${image}
@


1.61.4.1
log
@Sync with HEAD
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.64 2017/04/11 21:06:30 jmcneill Exp $
a84 22
getsectors() {
	case "$1" in
	*g)
		m=1073741824
		v=${1%g}
		;;
	*m)
		m=1048576
		v=${1%m}
		;;
	*k)
		m=1024
		v=${1%k}
		;;
	*[0-9b])
		m=1
		v=${1%b}
		;;
	esac
	echo $((m * v / 512))
}

d191 2
a192 2
	${MAKEFS} -N ${release}/etc -t msdos -o volume_label=NETBSD \
	    -O $((${init} / 2))m -s $((${boot} / 2))m \
d216 3
d223 1
a223 13
	${FDISK} -f -i ${image}
	${FDISK} -f -a -u -0 -s ${msdosid}/${initsecs}/${bootsecs} -F ${image}
	if [ -z "${bootonly}" ]; then
		ffsstart="$(getsectors ${ffsoffset})"
		imagesize="$(getsize "${image}")"
		imagesecs="$(getsectors ${imagesize})"
		ffssize="$(expr ${imagesecs} - ${ffsstart})"
		${FDISK} -f -u -1 -s 169/${ffsstart}/${ffssize} -F ${image}
	fi

	echo ${bar} Adding label ${bar}
	make_label > ${tmp}/label
	${DISKLABEL} -R -F ${image} ${tmp}/label
a224 4
	echo ${bar} Adding label ${bar}
	make_label > ${tmp}/label
	${DISKLABEL} -R -F ${image} ${tmp}/label

@


1.61.2.1
log
@Sync with HEAD
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.62 2017/03/14 06:37:39 skrll Exp $
d223 1
a223 1
	${FDISK} -f -a -u -0 -s ${msdosid}/${initsecs}/${bootsecs} -F ${image}
@


1.61.2.2
log
@Sync with HEAD
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.64 2017/04/11 21:06:30 jmcneill Exp $
a84 22
getsectors() {
	case "$1" in
	*g)
		m=1073741824
		v=${1%g}
		;;
	*m)
		m=1048576
		v=${1%m}
		;;
	*k)
		m=1024
		v=${1%k}
		;;
	*[0-9b])
		m=1
		v=${1%b}
		;;
	esac
	echo $((m * v / 512))
}

d191 2
a192 2
	${MAKEFS} -N ${release}/etc -t msdos -o volume_label=NETBSD \
	    -O $((${init} / 2))m -s $((${boot} / 2))m \
d216 3
a222 1
	${FDISK} -f -i ${image}
a223 11
	if [ -z "${bootonly}" ]; then
		ffsstart="$(getsectors ${ffsoffset})"
		imagesize="$(getsize "${image}")"
		imagesecs="$(getsectors ${imagesize})"
		ffssize="$(expr ${imagesecs} - ${ffsstart})"
		${FDISK} -f -u -1 -s 169/${ffsstart}/${ffssize} -F ${image}
	fi

	echo ${bar} Adding label ${bar}
	make_label > ${tmp}/label
	${DISKLABEL} -R -F ${image} ${tmp}/label
a224 4
	echo ${bar} Adding label ${bar}
	make_label > ${tmp}/label
	${DISKLABEL} -R -F ${image} ${tmp}/label

@


1.60
log
@Add a new endianes flag to mkimage and pass it on big endian arm builds.
From Rin Okuyama.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.59 2015/05/24 17:08:21 christos Exp $
d200 1
a200 1
	    -o d=4096,f=2048,b=16384 -b $((${extra}))m \
@


1.59
log
@fix mkubootimage
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.58 2015/04/19 17:56:57 hubertf Exp $
d87 1
a87 1
Usage: $PROG -h <host-arch> [-bdmx] [-K <kerneldir>] [-S <srcdir>] [-D <destdir>] [-c <custom-files-dir>] [-s <Mb size>] [<image>]
d99 1
a99 1
OPTS="K:D:S:bc:dh:mr:s:x"
d130 1
d136 1
d198 1
a198 1
	${MAKEFS} -r -N ${release}/etc -t ffs -rx \
@


1.58
log
@Add some documentation:
Tell what this does, and what it expects from conf files
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.57 2015/04/18 22:06:48 hubertf Exp $
d59 1
@


1.57
log
@Properly spell X' name. From X(7):

       The  X.Org  Foundation  requests  that the following names be used when
       referring to this software:

                                          X
                                   X Window System
                                    X Version 11
                             X Window System, Version 11
                                         X11
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.56 2015/04/06 22:20:52 jmcneill Exp $
d35 14
@


1.56
log
@initialize resize before pulling in board config
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.55 2015/04/06 20:19:28 jmcneill Exp $
d78 1
a78 1
-x	Load the x sets too, not just the base ones
@


1.55
log
@Add support for auto-growing the root partition. Enable it for rpi.img.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.54 2015/04/06 17:59:36 jmcneill Exp $
d105 2
a113 1
resize=false
@


1.54
log
@resizing of ffsv2 still doesn't work well, so revert previous, and instead
explicitly set fsize=2048/bsize=16384, which gives a pretty decent boost
to resize_ffs performance on its own
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.53 2015/04/05 17:05:45 jmcneill Exp $
d112 1
@


1.53
log
@Use FFSv2 instead of FFSv1 for the root file-system. This should fix the
"resize_ffs takes forever" issues with evbarm images -- growing a v2
file-system is much faster than v1.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.52 2015/01/29 14:54:06 skrll Exp $
d181 1
a181 1
	    -o v=2,d=4096 -b $((${extra}))m \
@


1.52
log
@Fix previous so that the new generated rc.conf is picked up and that
any new new mount points (e.g. /proc and /kern) are generated.

While here increate the fs size so that postfix can actually build
/etc/mail/aliases.db
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.51 2015/01/23 15:17:58 skrll Exp $
d181 1
a181 1
	    -o d=4096 -b $((${extra}))m \
@


1.51
log
@PR/49596: mkimage: incorrect permissions on evbarm images

Use NetBSD.dist in our mtree specification to populate the top level
directories, etc.

For each generated file hand craft an mtree entry.

Remove specialdirs as NetBSD.dist creates /proc and /kern.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.50 2015/01/18 17:37:54 skrll Exp $
d179 1
a179 1
	${MAKEFS} -N ${release}/etc -t ffs -rx \
@


1.50
log
@Use [dx]sets_p as flag for debug/X sets inclusion. xsets is the list of
sets.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.49 2014/12/14 00:28:46 christos Exp $
d157 1
a157 1
	(echo '/set type=dir uname=root gname=wheel mode=0755'
a169 4
if [ -z "${bootonly}" ]; then
	(cd ${mnt}; ${MTREE} -N ${release}/etc -c -k all | 
	    ${MTREE} -N ${release}/etc -C -k all) >> "$tmp/selected_sets"
fi
@


1.49
log
@fix image building:
	- round up the total size of the disk image
	- fix fdisk offset for netbsd ffs images
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.48 2014/04/03 22:51:38 christos Exp $
d109 2
a110 2
dsets=false
xsets=false
d122 1
a122 1
	d)	dsets=true
d124 1
a124 1
		if $xsets; then
d133 1
a133 1
	x)	xsets=true
d135 1
a135 1
		if $dsets; then
@


1.48
log
@now that fdisk has optional arguments, don't pass -1
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.47 2014/03/31 18:18:29 christos Exp $
d193 7
d212 1
a212 1
	${FDISK} -f -a -u -0 -s 169 ${image}
@


1.48.4.1
log
@Pull up following revision(s) (requested by skrll in ticket #437):
	distrib/utils/embedded/mkimage: revision 1.50
Use [dx]sets_p as flag for debug/X sets inclusion. xsets is the list of
sets.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.48 2014/04/03 22:51:38 christos Exp $
d109 2
a110 2
dsets_p=false
xsets_p=false
d122 1
a122 1
	d)	dsets_p=true
d124 1
a124 1
		if $xsets_p; then
d133 1
a133 1
	x)	xsets_p=true
d135 1
a135 1
		if $dsets_p; then
@


1.48.4.2
log
@Pull up following revision(s) (requested by skrll in ticket #465):
	distrib/utils/embedded/conf/rpi_inst.conf: revision 1.6
	distrib/utils/embedded/conf/usermode.conf: revision 1.4
	distrib/utils/embedded/mkimage: revision 1.51
	distrib/utils/embedded/conf/x86.conf: revision 1.6
	distrib/utils/embedded/conf/evbarm.conf: revision 1.18
PR/49596: mkimage: incorrect permissions on evbarm images
Use NetBSD.dist in our mtree specification to populate the top level
directories, etc.
For each generated file hand craft an mtree entry.
Remove specialdirs as NetBSD.dist creates /proc and /kern.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.48.4.1 2015/01/20 09:50:46 martin Exp $
d157 1
a157 1
	(cat "${release}/etc/mtree/NetBSD.dist"
d170 4
@


1.48.4.3
log
@Pull up following revision(s) (requested by skrll in ticket #470):
	distrib/utils/embedded/mkimage: revision 1.52
	distrib/utils/embedded/conf/x86.conf: revision 1.7
	distrib/utils/embedded/conf/evbarm.conf: revision 1.20
Fix previous so that the new generated rc.conf is picked up and that
any new new mount points (e.g. /proc and /kern) are generated.
While here increate the fs size so that postfix can actually build
/etc/mail/aliases.db
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.48.4.2 2015/01/28 11:27:03 martin Exp $
d179 1
a179 1
	${MAKEFS} -r -N ${release}/etc -t ffs -rx \
@


1.48.4.4
log
@Pull up following revision(s) (requested by jmcneill in ticket #664):
	distrib/utils/embedded/mkimage: revision 1.53
Use FFSv2 instead of FFSv1 for the root file-system. This should fix the
"resize_ffs takes forever" issues with evbarm images -- growing a v2
file-system is much faster than v1.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.48.4.3 2015/01/29 15:12:48 martin Exp $
d181 1
a181 1
	    -o v=2,d=4096 -b $((${extra}))m \
@


1.48.4.5
log
@Pull up following revision(s) (requested by jmcneill in ticket #667):
	distrib/utils/embedded/mkimage: revision 1.54
resizing of ffsv2 still doesn't work well, so revert previous, and instead
explicitly set fsize=2048/bsize=16384, which gives a pretty decent boost
to resize_ffs performance on its own
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.48.4.4 2015/04/06 01:59:36 snj Exp $
d181 1
a181 1
	    -o d=4096,f=2048,b=16384 -b $((${extra}))m \
@


1.48.4.6
log
@Pull up following revision(s) (requested by skrll in ticket #909):
	distrib/sets/lists/etc/mi: revision 1.237
	distrib/sets/lists/tests/mi: revision 1.613
	distrib/utils/embedded/conf/armv7.conf: revisions 1.1, 1.2
	distrib/utils/embedded/conf/beagleboard.conf: delete
	distrib/utils/embedded/conf/evbarm.conf: revisions 1.21, 1.22
	distrib/utils/embedded/conf/rpi.conf: revisions 1.28, 1.29
	distrib/utils/embedded/conf/rpi_inst.conf: revisions 1.7, 1.8
	distrib/utils/embedded/conf/usermode.conf: revision 1.5
	distrib/utils/embedded/conf/x86.conf: revision 1.5
	distrib/utils/embedded/files/resize_disklabel: revision 1.1
	distrib/utils/embedded/mkimage: revisions 1.49, 1.55-1.59
	etc/defaults/rc.conf: revision 1.133
	etc/etc.evbarm/Makefile.inc: revisions 1.72, 1.76
	etc/rc.d/Makefile: revision 1.93 via patch
	etc/rc.d/resize_root: revisions 1.1-1.3
	etc/rc.d/root: revision 1.5
	sbin/resize_ffs/Makefile: revision 1.5
	sbin/resize_ffs/resize_ffs.8: revisions 1.14-1.16
	sbin/resize_ffs/resize_ffs.c: revisions 1.39-1.44
	share/man/man5/rc.conf.5: revision 1.158, 1.159
	tests/sbin/resize_ffs/Makefile: revision 1.4
	tests/sbin/resize_ffs/common.sh: revision 1.14
	tests/sbin/resize_ffs/t_check.sh: revision 1.1
	tests/sbin/resize_ffs/t_grow.sh: revision 1.9
	tests/sbin/resize_ffs/t_grow_swapped.sh: revision 1.3
	tests/sbin/resize_ffs/t_shrink.sh: revision 1.8
	tests/sbin/resize_ffs/t_shrink_swapped.sh: revision 1.2
fix image building:
         - round up the total size of the disk image
         - fix fdisk offset for netbsd ffs images
--
Make get_dev_size work on regular files too.
--
Use `!= -1' instead of `== 0' out of paranoia.
--
- Add -c to check to see if grow/shrink is required
- Divide by DEV_BSIZE when returning size of file.
- Update manpage
--
New sentence, new line. Sort option descriptions.
--
Add resize_root boot operation. If resize_root=YES in rc.conf then
the system attempts to resize the root file system to fill it's
partition prior to mounting read-write. Useful for things like AMI
file system images. May eventually be used by arm images after
coming up with similar solution for increasing the parition size.
--
- Add new tests for -c check flag in resize_ffs
--
Bump date for previous.
it's -> its
--
Handle case in grow() where last cylinder group is too small for ufs2.
Align with code in shrink().
--
factor out geometry calculation and use this also in CheckOnly mode.
be a bit more verbose in Verbose mode.
--
Add support for auto-growing the root partition. Enable it for rpi.img.
--
initialize resize before pulling in board config
--
add KEYWORD: interactive, honour resize_root_flags and
resize_root_postcmd rc vars
--
if the -p flag is specified, display a progress bar while growing the
file-system
--
show resize_ffs progress bar when resizing root partition
--
fix typo in previous; pass -y unconditionally to resize_ffs, not -p
--
Rename beagleboard.img to armv7.img. The new image includes the same
kernels as beagleboard.img plus support for Raspberry Pi 2, ODROID-C1,
Cubieboard2, Cubietruck, Hummingbird A31, and Banana Pi.
--
Properly spell X' name. From X(7):
        The  X.Org  Foundation  requests  that the following names be
used when
        referring to this software:
                                           X
                                    X Window System
                                     X Version 11
                              X Window System, Version 11
                                          X11
--
Add some documentation:
Tell what this does, and what it expects from conf files
--
Cleanup: make_filesystems is not used any longer, purge remains
--
More cleanup:
Instead of first overwriting the *_evbarm functions with own code,
and then calling them from the regular functions, directly put the
code into the regular functions.
No more functions from evbarm.conf are used now.
Some variables are still used!
--
define TOOL_MKUBOOTIMAGE for mkimage
--
fix mkubootimage
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.48.4.5 2015/04/06 18:47:54 snj Exp $
a34 14
#
# Makes a bootable image for the host architecture given.
# The host specific functions are pulled in from a /bin/sh script in the
# "conf" directory, and is expected to provide the following shell
# functions, which are called in the following order:
#
#  - make_fstab: Creates the host's /etc/fstab with / on ${rootdev}.
#    If -m is given, a number of directories are put on a tmpfs RAM disk
#  - customize: After unpacking the sets, this gets the system to
#    a working state, e. g. by setting up /etc/rc.conf and /dev
#  - populate: Add common goods like kernel and bootloader
#  - make_label: Prints disklabel to stdout
#

a44 1
MKUBOOTIMAGE=${TOOL_MKUBOOTIMAGE:-mkubootimage}
d78 1
a78 1
-x	Load the X sets too, not just the base ones
a104 2
resize=false

a188 7
compare=$((${newsize} * 2 * 1024))
while [ "${compare}" != "${size}" ]
do    
	size="$((size + size - compare))"  
	newsize="$((${size} / 2 / 1024))"
	compare="$((${newsize} * 2 * 1024))"
done                      
d201 1
a201 1
	${FDISK} -f -a -u -0 -s 169/${init} ${image}
@


1.48.4.7
log
@Pull up following revision(s) (requested by sevan in ticket #1386):
	distrib/utils/embedded/mkimage: revision 1.62
Mark the msdos parition active for boards like the BeagleBone Black
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.48.4.6 2015/08/06 21:13:43 snj Exp $
d221 1
a221 1
	${FDISK} -f -a -u -0 -s ${msdosid}/${initsecs}/${bootsecs} -F ${image}
@


1.47
log
@provide a -r rootdev option to handle the wd/sd/ld lossage.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.46 2014/03/31 17:05:03 christos Exp $
d205 1
a205 1
	${FDISK} -f -a -u -0 -s 169/-1/-1/ ${image}
@


1.46
log
@these changes produce a bootable system under qemu, but its root is trashed.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.45 2014/03/31 16:20:48 christos Exp $
d75 1
d84 1
a84 1
OPTS="K:D:S:bc:dh:ms:x"
d112 1
d131 1
@


1.45
log
@Add preliminary support for creating x86 usb sticks with mkimage.
This is untested, and just a checkpoint of the work. Image looks
ok, but I have not tried if it boots.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.44 2013/09/14 12:51:27 ast Exp $
d55 1
a55 1
mkdir -p "${mnt}/etc" "${mnt}/dev" "${mnt}/boot"
d181 1
a181 1
	    -O $(((${init} + ${boot} + ${swap}) / 2))m \
@


1.44
log
@Fix build release of evbarm which had been failing in mkimage
beagleboard_smp with the elusive message:

    "gzip: can't stat: gzip: No such file or directory"

This was due to GZIP=gzip being defined in mkimage; we now use:

    GZIP_CMD=${TOOL_GZIP:-gzip} # ${GZIP} is special to gzip(1)

as distrib/sets/sets.subr already does in these files as well:

    distrib/utils/embedded/mkimage
    distrib/utils/embedded/conf/beagleboard.conf
    distrib/utils/embedded/conf/rpi.conf
    distrib/utils/embedded/conf/rpi_inst.conf
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.43 2013/06/27 14:51:30 christos Exp $
d4 1
a4 1
# Copyright (c) 2013 The NetBSD Foundation, Inc.
d44 1
a47 1
release="/usr/obj/evbarm/release"
d105 1
d152 1
a152 1
if [ -z "$bootonly" ]; then
d167 1
a167 1
if [ -z "$bootonly" ]; then
d171 1
a171 1
if [ -n ${msdosid} ]; then
d178 1
a178 1
if [ -z "$bootonly" ]; then
d194 1
a194 1
if [ -n ${msdosid} ]; then
d199 5
@


1.43
log
@SSD cards is stupid.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.42 2013/06/27 03:03:16 christos Exp $
a41 1
GZIP=${TOOL_GZIP:-gzip}
d44 1
d203 1
a203 1
	${GZIP} -9 ${image}
@


1.42
log
@explain -m better
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.41 2013/06/27 03:00:53 christos Exp $
d76 1
a76 1
-m	Optimize the OS installation to mimimize disk writes for SSD cards
@


1.41
log
@tidy up, fix usage
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.40 2013/06/16 13:47:42 jakllsch Exp $
d76 1
a76 1
-m	Mimimize disk writes for sd cards
@


1.40
log
@Use TOOL_GZIP in mkimage, and pass the TOOL_GZIP into it.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.39 2013/05/20 19:27:17 christos Exp $
d72 1
a72 1
Usage: $PROG -h <host-arch> [-bmx] [-K <kerneldir>] [-S <srcdir>] [-D <destdir>] [-c <custom-files-dir>] [-s <Mb size>] [<image>]
d118 1
a118 1
	b)	bootonly="true";;
d173 2
a174 1
	    -O $((${init} / 2))m -s $((${boot} / 2 + ${init} / 2))m ${image} ${mnt}/boot
d181 1
a181 2
		-o d=4096 \
	    -b $((${extra}))m \
@


1.39
log
@- explanations for single letter flags
- flag to add debug sets
- flag to minimize writes to sd's
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.38 2013/04/03 19:37:43 htodd Exp $
d42 1
d203 1
a203 1
	gzip -9 ${image}
@


1.38
log
@Double extra to fix image size to fix build.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.37 2013/03/28 00:20:02 jmcneill Exp $
d71 6
a76 1
Usage: $PROG -h <host-arch> [-b] [-K <kerneldir>] [-S <srcdir>] [-D <destdir>] [-c <custom-files-dir>] [-s <Mb size>] [<image>]
d82 1
a82 1
OPTS="K:D:S:bc:h:s:x"
d106 3
d118 6
d126 1
d128 6
a133 1
	x)	selected_sets="$sets $xsets";;
@


1.37
log
@For ffs, set bytes per inode to 4K. Otherwise we get a density based on
the contents of the image, which aren't very useful after the file-system
has been resized -- for rpi.img, this was 22K per inode!
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.36 2013/03/19 22:16:53 garbled Exp $
d159 2
a160 2
	    -b $((${extra} / 2))m \
	    -o d=4096 \
@


1.36
log
@Add a new installer image for Raspberry PI to evbarm

Includes the following major changes:

1) Add new configmenu item to sysinst to allow creation of users at
post-install time.
2) Add an sshramdisk type to evbarm, which is a ramdisk with sshd
enabled, allowing users to install on a headless PI by sshing to the
device with the account "sysinst" password "netbsd" to begin the
installation. (Note, neither the account, nor the ssh setup are copied to
the finalized installation image)
3) Change mkimage to build a boot-only image, without the root filesystems.

Much of the sshramdisk code could be reused on other ports easily.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.35 2013/02/15 00:13:06 christos Exp $
d160 1
@


1.35
log
@don't use [ -f $i ] && cat $i, since we are using -e
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.34 2013/02/12 12:45:12 jmcneill Exp $
d71 1
a71 1
Usage: $PROG -h <host-arch> [-K <kerneldir>] [-S <srcdir>] [-D <destdir>] [-c <custom-files-dir>] [-s <Mb size>] [<image>]
d77 1
a77 1
OPTS="K:D:S:c:h:s:x"
d109 1
d130 10
a139 8
echo ${bar} configuring sets ${bar}
(echo '/set type=dir uname=root gname=wheel mode=0755'
for i in $selected_sets; do
	s="${release}/etc/mtree/set.$i"
	if [ -f "$s" ]; then
		cat "$s"
	fi
done) > "$tmp/selected_sets"
d145 4
a148 2
(cd ${mnt}; ${MTREE} -N ${release}/etc -c -k all | 
    ${MTREE} -N ${release}/etc -C -k all) >> "$tmp/selected_sets"
d152 1
a152 1
	    -O $((${init} / 2))m -s $((${boot} / 2))m ${image} ${mnt}/boot
d155 7
a161 5
echo ${bar} Populating ffs filesystem ${bar}
${MAKEFS} -N ${release}/etc -t ffs -rx \
    -O $(((${init} + ${boot} + ${swap}) / 2))m \
    -b $((${extra} / 2))m \
    -F "$tmp/selected_sets" ${image} "${release}" "${mnt}"
@


1.34
log
@add extra space to root partition
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.33 2013/02/11 18:11:20 jmcneill Exp $
d133 3
a135 1
	[ -f "$s" ] && cat "$s"
@


1.33
log
@set -e
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.32 2013/02/10 21:51:05 jmcneill Exp $
d151 1
@


1.32
log
@set src= before pulling in host config
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.31 2013/02/10 16:56:38 jmcneill Exp $
d35 2
@


1.31
log
@no sh -x
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.30 2013/02/10 16:56:01 jmcneill Exp $
d74 1
a74 1
# First pass for options to get the host
d80 1
d106 1
a106 1
	S)	src="$OPTARG";;
@


1.30
log
@fix msdos mbr partition size calculation
@
text
@d1 2
a2 2
#!/bin/sh -x
# $NetBSD: mkimage,v 1.29 2013/02/10 16:13:23 christos Exp $
@


1.29
log
@don't dup -F
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.28 2013/02/10 16:12:37 christos Exp $
d160 3
a162 1
	${FDISK} -f -u -0 -s ${msdosid}/${init}/${boot} -F ${image}
@


1.28
log
@add -F to fdisk
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.27 2013/02/10 15:51:59 christos Exp $
d160 1
a160 1
	${FDISK} -F -f -u -0 -s ${msdosid}/${init}/${boot} -F ${image}
@


1.27
log
@mass -N db to makefs too
@
text
@d1 2
a2 2
#!/bin/sh
# $NetBSD: mkimage,v 1.26 2013/02/10 15:45:33 christos Exp $
d160 1
a160 1
	${FDISK} -f -u -0 -s ${msdosid}/${init}/${boot} -F ${image}
@


1.26
log
@specify a database for mtree.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.25 2013/02/10 15:35:34 jmcneill Exp $
d141 2
a142 2
	${MAKEFS} -t msdos -O $((${init} / 2))m -s $((${boot} / 2))m \
	    ${image} ${mnt}/boot
d146 2
a147 1
${MAKEFS} -t ffs -rx -O $(((${init} + ${boot} + ${swap}) / 2))m \
@


1.25
log
@dont call mtree directly
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.24 2013/02/10 03:09:07 christos Exp $
d137 2
a138 1
(cd ${mnt}; ${MTREE} -c -k all | ${MTREE} -C -k all) >> "$tmp/selected_sets"
@


1.24
log
@really calling disklabel with the arguments of fdisk does not work.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.23 2013/02/10 02:09:47 christos Exp $
d41 1
d137 1
a137 1
(cd ${mnt}; mtree -c -k all | mtree -C -k all) >> "$tmp/selected_sets"
@


1.23
log
@- remove dup trap
- compare size to 0 for autosizing
- remove .gz file before compressing.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.22 2013/02/10 01:28:42 christos Exp $
d39 1
a39 1
FDISK=${TOOL_DISKLABEL:-fdisk}
@


1.22
log
@add compression support.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.21 2013/02/09 18:50:11 christos Exp $
d52 1
a112 2
trap cleanup 0 1 2 3 15

d147 2
a148 2
if [ -z "$size" ]; then
	size=$(getsize ${image})
d150 1
a150 1
newsize=$((size / 2 / 1024))
d162 1
@


1.21
log
@add tool hooks.
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.20 2013/02/09 11:20:56 jmcneill Exp $
d121 5
d160 7
@


1.20
log
@fix usage again -- -D specifies destdir not releasedir
include conf/${h}.conf not conf/rpi.conf
fix ./mkimage: line 110: "7" - 1 : syntax error: operand expected (error token is ""7" - 1 ")
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.19 2013/02/09 11:15:14 jmcneill Exp $
d38 4
a120 2
. "${DIR}/conf/${h}.conf"

d135 1
a135 1
	makefs -t msdos -O $((${init} / 2))m -s $((${boot} / 2))m \
d140 1
a140 1
makefs -t ffs -rx -O $(((${init} + ${boot} + ${swap}) / 2))m \
d150 1
a150 1
disklabel -R -F ${image} ${tmp}/label
d153 1
a153 1
	fdisk -f -u -0 -s ${msdosid}/${init}/${boot} -F ${image}
@


1.19
log
@fix usage
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.18 2013/02/08 19:14:14 christos Exp $
d63 1
a63 1
Usage: $PROG -h <host-arch> [-K <kerneldir>] [-S <srcdir>] [-D <releasedir>] [-c <custom-files-dir>] [-s <Mb size>] [<image>]
d110 1
a110 1
shift $(( "$OPTIND" - 1 ))
d117 1
a117 1
. "$DIR/conf/rpi.conf"
@


1.18
log
@fix options
@
text
@d2 1
a2 1
# $NetBSD: mkimage,v 1.17 2013/02/03 09:16:24 christos Exp $
d63 1
a63 1
Usage: $PROG -h <host-arch> [-K <kerneldir>] [-S <srcdir>] [-R <releasedir>] [-c <custom-files-dir>] [-s <Mb size>] [<image>]
@


1.17
log
@switch to makefs
@
text
@d2 1
a2 1
# $NetBSD$
d69 1
a69 1
OPTS="K:R:S:c:h:s:x"
d97 2
a98 2
	K)	release="$OPTARG";;
	R)	kerneldir="$OPTARG";;
@


1.16
log
@Add the tests sets by default. Tweak the usage output.
@
text
@d1 2
a2 3
#! /bin/sh

# $NetBSD: mkimage,v 1.15 2013/01/21 16:49:49 skrll Exp $
d4 1
a4 1
# Copyright (c) 2012 Alistair Crooks <agc@@NetBSD.org>
d7 3
d18 15
a32 11
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
d35 20
a54 38
# find next available vnd, from kre
next_avail ()
{
	local dev="$1"
	local N=$(( ${#dev} + 1 ))
	local unit units

	units=$(
		sysctl -n hw.disknames		|
			tr ' ' '\012'		|
			grep '^'"${dev}"'[0-9]'	|
			sort -n -k 1.$N			)

	test -z "${units}" && {
		test -e "/dev/${dev}0a" || {
			echo >&2 "No ${dev}s available!"
			return 1
		}
		echo "${dev}0"
		return
	}

	N=0
	for unit in ${units}
	do
		if [ "${unit}" = "${dev}${N}" ]
		then
			N=$(( N + 1 ))
		else
			echo "${dev}${N}"
			return
		fi
	done

	test -e /dev/"${dev}${N}a" || {
		echo >&2 "All ${dev}s in use"
		return 1
	}
d56 3
a58 1
	echo "${dev}${N}"
d63 1
a63 1
Usage: $PROG -h <host-arch> [-S <setsdir>] [-c <custom-files-dir>] [-s <Mb size>] [<image>]
a67 122
# Return the filesystem size for an ls -l or tar -xvf list
# Directories and symlinks in tar are 0 size, we assume one block
# (which is too much), we round up by the fragment size the rest.
getfssize() {
	local bsize="$1"
	local fsize="$2"

	awk -v fsize=${fsize} -v bsize=${bsize} '
	NF >= 9 && $1 != "tar:" {
		if ($5 == 0)
			tot += bsize;
		else
			tot += ((int)(($5 + fsize - 1) / fsize)) * fsize;
	}
	END {
		printf("%d\n", tot);
	}'
}

# find the size of the gzipped files in a .tgz archive
# Directories appear as 0, so count them as one block
# and round up files to a fragment.
sizeone() {
	if [ ! -f "$1" ]
	then
		echo "$PROG: Missing set $1" 1>&2
		echo 0
		return;
	fi

        case "$1" in 
        *.tgz|*.tar.gz|*.tbz|*.tar.bz2|*.txz|*.tar.xz)
                tar tvzf "$1" | getfssize ${bsize} ${fsize}
                ;;
        *)
                echo 0
                ;; 
        esac
}


# Return the usable filesystem size in bytes, given the total size in bytes,
# and optionally block and fragment sizes
getffssize() {
	local bytes="$1"
	local barg
	local farg
	local overhead

	if [ -n "$2" ]
	then
		barg="-b $2"
		if [ -n "$3" ]
		then
			farg="-f $3"
		fi
	fi

	overhead=$(newfs -N ${farg} ${barg} -s "${bytes}b" -F /dev/null |
	    awk '/using/ {
		printf("%d\n", substr($6, 1, length($6) - 3) * 1024 * 1024);
	    }'
	)
	echo $(( ${bytes} - ${overhead} ))
}

# Compute the size of an ffs filesystem that can fit x bytes.
# Instead of duplicating the newfs calculations here we let
# it do the job, using binary search.
makeffssize() {
	local bytes=$1
	local bsize=$2
	local fsize=$3
	local max=$(( 2 * ${bytes} ))
	local min="${bytes}"
	local cur
	local res
	while true; do
		cur="$(( ( ${max} + ${min} ) / 2 ))"
		res="$(getffssize "${cur}" ${bsize} ${fsize})"
#		echo ${min} ${cur} ${max} ${res} ${bytes} 1>&2
		if [ "${res}" -eq "${bytes}" ]
		then
		    break
		elif [ "$(( ${min} + 1 ))" -ge "${max}" ]
		then
		    break
		elif [ "${res}" -lt "${bytes}" ]
		then
		    min="${cur}"
		elif [ "${res}" -gt "${bytes}" ]
		then
		    max="${cur}"
		fi
	done
	echo "${cur}"
}

finish() {
	cleanup
	${sudo} umount ${mnt}
	${sudo} vnconfig -u ${vnddev}
	rm -fr ${mnt}
}


DIR="$(dirname "$0")"
PROG="$(basename "$0")"
bar="==="
sudo=
mnt="${TMPDIR:-/tmp}/image.$$"
src="/usr/src"
obj="/usr/obj"

sets="base comp etc games man misc modules tests text"
xsets="xbase xcomp xetc xfont xserver"

# Presumable block and fragment size.
bsize=16384
fsize=2048
mtob=$(( 1024 * 1024 ))

d69 1
a69 1
OPTS="S:c:h:s:x"
d91 2
d97 3
a99 1
	S)	setsdir="$OPTARG";;
d103 1
a103 1
	x)	sets="$sets $xsets";;
d108 1
a108 1
trap finish 0 1 2 3 15
d117 1
a117 11
# calculate the set bytes
setbytes=0
echo -n "${bar} computing set sizes ("
b=
for s in ${sets}; do
	one="$(sizeone ${setsdir}/${s}.tgz)"
	echo -n "$b$s=$(( ${one} / ${mtob} ))MB"
	setbytes=$(( ${setbytes} +  ${one} ))
	b=" "
done
echo "): $(( ${setbytes} / ${mtob} ))MB ${bar}"
d119 6
a124 54
# calculate size of custom files
custbytes=0
if [ -d "${custom}" ]; then
	custbytes=$(ls -lR "${custom}" | getfssize ${bsize} ${fsize})
fi
echo "${bar} computing custom sizes: $(( ${custbytes} / ${mtob} ))MB ${bar}"

# how many bytes
rawbytes="$(( ${setbytes} + ${custbytes} ))"
echo -n "${bar} computing ffs filesystem size for $(( ${rawbytes} / ${mtob} ))MB: "
ffsbytes="$(makeffssize "${rawbytes}")"
ffsmb=$(( ${ffsbytes} / ${mtob} ))
echo " ${ffsmb}MB ${bar}"

# total in MB
total=$(( ${ffsmb} + ${overhead} ))
echo "${bar} overhead: ${overhead}MB ${bar}"

if [ $size -eq 0 ]; then
        # auto-size the pkgs fs
        newsize=${total}
else
        # check that we've been given enough space
        if [ ${total} -gt ${size} ]; then
                echo "$PROG: Given size is ${size} MB, but we need ${total} MB" >&2
                exit 1
        fi
	newsize=${size}
fi

echo "${bar} making a new ${newsize} MB image in ${image} ${bar}"
dd if=/dev/zero of=${image} bs=1m count=${newsize} conv=sparse

vnddev=$(next_avail vnd)
echo "${bar} mounting image via vnd ${vnddev} ${bar}"
${sudo} vnconfig ${vnddev} ${image}
${sudo} mkdir -p ${mnt}
make_filesystems

${sudo} mkdir -p ${mnt}/etc ${mnt}/dev

echo -n "${bar} installing sets:"
(cd ${mnt} &&
	for s in ${sets}; do
		ss="${setsdir}/${s}.tgz"
		if [ -f "${ss}" ]; then
			echo -n " ${s}"
			${sudo} tar xpzf "${ss}"
		fi
	done
)
echo " ${bar}"

echo "${bar} performing customisations ${bar}"
d127 2
d130 5
a134 13
${sudo} cat > ${mnt}/etc/rc.conf << EOF
#
# see rc.conf(5) for more information.
#
# Use program=YES to enable program, NO to disable it. program_flags are
# passed to the program on the command line.
#

# Load the defaults in from /etc/defaults/rc.conf (if it's readable).
# These can be overridden below.
#
if [ -r /etc/defaults/rc.conf ]; then
        . /etc/defaults/rc.conf
d137 3
a139 3
# If this is not set to YES, the system will drop into single-user mode.
#
rc_configured=YES
d141 4
a144 5
hostname=${h}

EOF

customize
d146 6
a151 7
for d in ${specialdirs}; do
	${sudo} mkdir -p ${mnt}/${d}
done

if [ \( -n "${custom}" \) -a \( -d "${custom}" \) ]; then
	echo "${bar} user customisations from files in ${custom} ${bar}"
	(cd ${custom} && ${sudo} pax -rwpe . ${mnt})
d153 1
a153 2

exit 0
@


1.15
log
@More usage updates
@
text
@d3 1
a3 1
# $NetBSD: mkimage,v 1.14 2013/01/21 16:47:23 skrll Exp $
d73 1
a73 1
Usage: $PROG -h <host-arch> [-S <setsdir>] [-c <custom-files-dir>] [-s <size>] [<image>]
d192 1
a192 1
sets="base comp etc games man misc modules text"
@


1.14
log
@Update usage output a little
@
text
@d3 1
a3 1
# $NetBSD: mkimage,v 1.13 2013/01/16 23:27:34 christos Exp $
d73 1
a73 1
Usage: $PROG -h <host-arch> [-S <setsdir>] [-c <custom-files-dir>] [-s <size>]
@


1.13
log
@- Add support for xsets
- Factor out common evbarm code
@
text
@d3 1
a3 1
# $NetBSD: mkimage,v 1.12 2013/01/16 15:58:19 christos Exp $
d73 1
a73 1
Usage: $PROG [-S <setsdir>] [-c <custom-files-dir>] [-h <host-arch>] [-s <size>]
@


1.12
log
@tidy up some more by factoring out the sizing code.
@
text
@d3 2
a4 2
# $NetBSD: mkimage,v 1.11 2013/01/15 21:04:41 christos Exp $

d75 1
a75 1
exit 1
d177 4
a180 3
    cleanup
    ${sudo} umount ${mnt}
    ${sudo} vnconfig -u ${vnddev}
d192 2
d231 1
a231 1
	x)	set -x;;
d248 1
d251 1
a251 1
	echo -n " $s=$(( ${one} / ${mtob} ))MB"
d253 1
@


1.11
log
@Make autosizing really work:
    - Use newfs to compute the actual filesystem required size.
    - Fix the computation of set sizes to account for blocks and fragments.
This results into a 95% full filesystem for my test (Total 566MB, 24MB free)
from which 8MB is my requested overhead. Not perfect, but good enough.
@
text
@d3 1
a3 1
# $NetBSD: mkimage,v 1.10 2013/01/15 03:26:27 christos Exp $
d71 26
d107 1
d110 1
a110 11
                tar tvzf "$1" |
		awk -v fsize=${fsize} -v bsize=${bsize} '
		{
			if ($5 == 0)
				tot += bsize;
			else
				tot += ((int)(($5 + fsize - 1) / fsize)) * fsize;
		}
		END {
			printf("%d\n", tot);
		}'
a117 6
usage() {
	cat << EOF 1>&2
Usage: $PROG [-S <setsdir>] [-c <custom-files-dir>] [-h <host-arch>] [-s <size>]
EOF
exit 1
}
d195 1
d247 1
a247 1
	echo -n " $s=$(( ${one} / 1024 / 1024 ))MB"
d250 1
a250 1
echo "): $(( ${setbytes} / 1024 / 1024 ))MB ${bar}"
d255 1
a255 2
	custbytes=$(ls -lR "${custom}" | 
	    awk 'NF == 9 { tot += $5 } END { print tot }')
d257 1
a257 1
echo "${bar} computing custom sizes: $(( ${custbytes} / 1024 / 1024 ))MB ${bar}"
d261 1
a261 1
echo -n "${bar} computing ffs filesystem size for $(( ${rawbytes} / 1024 / 1024 ))MB: "
d263 1
a263 1
ffsmb=$(( ${ffsbytes} / 1024 / 1024 ))
@


1.10
log
@first step at autosizing, still does not work.
@
text
@d3 1
a3 1
# $NetBSD: mkimage,v 1.9 2013/01/15 02:50:08 jmcneill Exp $
d72 2
d82 12
a93 5
        *.tgz|*.tar.gz)
                tar tvzf "$1" | awk '{ tot += $5 } END { print tot }'
                ;;
        *.tbz|*.tar.bz2)
                tar tvjf "$1" | awk '{ tot += $5 } END { print tot }' 
d108 57
d171 1
d180 5
d230 3
a232 1
total=0
d235 2
a236 1
	total=$(( ${total} +  ${one} ))
d238 2
d241 1
a241 1
custsize=0
d243 2
a244 1
	custsize=$(ls -lR "${custom}" | awk 'NF == 9 { tot += $5 } END { print tot }')
d246 13
a258 1
total=$(( ( ( ${total} + ${custsize} ) / 1000000 ) + ${overhead} ))
@


1.9
log
@expand set name to path when checking to see if the tgz exists
@
text
@d3 1
a3 1
# $NetBSD: mkimage,v 1.8 2013/01/14 12:12:19 jmcneill Exp $
d171 1
a171 1
        size=${total}
d178 1
d181 2
a182 2
echo "${bar} making a new ${size} MB image in ${image} ${bar}"
dd if=/dev/zero of=${image} bs=1m count=${size} conv=sparse
d192 1
a192 1
echo "${bar} installing sets ${bar}"
d195 4
a198 3
		if [ -f "${setsdir}/${s}.tgz" ]; then
			echo ${s}
			${sudo} tar xpzf ${setsdir}/${s}.tgz
d202 1
@


1.8
log
@move 'trap' after command args are parsed
@
text
@d3 1
a3 1
# $NetBSD: mkimage,v 1.7 2013/01/13 21:51:47 christos Exp $
d194 1
a194 1
		if [ -f "${s}" ]; then
@


1.7
log
@honor ${TMPDIR}
@
text
@d3 1
a3 1
# $NetBSD: mkimage,v 1.6 2013/01/13 20:59:22 christos Exp $
a104 1
trap finish 0 1 2 3 15
d149 2
@


1.6
log
@complain on unknown options
@
text
@d3 1
a3 1
# $NetBSD: mkimage,v 1.5 2013/01/13 20:58:38 christos Exp $
d110 1
a110 1
mnt="/tmp/image.$$"
@


1.5
log
@move configuration to new place.
@
text
@d3 1
a3 1
# $NetBSD: mkimage,v 1.4 2013/01/13 20:57:18 christos Exp $
d146 1
a146 1
	*)	;;
@


1.4
log
@Adjust mkimage to handle RPI. From skrll@@
@
text
@d3 1
a3 1
# $NetBSD: mkimage,v 1.3 2012/02/29 04:49:50 agc Exp $
d129 1
a129 1
if [ ! -f "${DIR}/${h}.conf" ]
d131 1
a131 1
	echo $PROG: ${DIR}/${h}.conf is not present 1>&2
d135 1
a135 1
. "${DIR}/${h}.conf"
@


1.3
log
@consolidate all of the volatile /var.* directories which are mounted as tmpfs
into a single one for /var - same as /root, /etc
@
text
@d3 1
a3 1
# $NetBSD: mkimage,v 1.2 2012/01/20 02:19:47 agc Exp $
d73 6
d92 16
d109 38
a146 19
custom=custom
h=usermode1.$(uname -n)
image=usermode.img
overhead=8 # in MB
sets="base etc modules"
setsdir=/usr/build/release/$(uname -m)/binary/sets
size=0	# in MB
specialdirs="/kern /proc"
usermodedirs="/var.cow /etc.cow /root.cow /pkgs"
sudo="sudo"

while [ $# -gt 0 ]; do
	case "$1" in
	-S)	setsdir=$2; shift ;;
	-c)	custom=$2; shift ;;
	-h)	h=$2; shift ;;
	-s)	size=$2; shift ;;
	-x)	set -x ;;
	*)	break ;;
a147 1
	shift
d150 2
a151 1
if [ $# -gt 0 ]; then
d159 2
a160 1
	total=$(expr ${total} + $(sizeone ${setsdir}/${s}.tgz))
d167 1
a167 1
total=$(expr \( \( ${total} + ${custsize} \) / 1000000 \) + ${overhead})
d174 1
a174 1
                echo "File system size given as ${size} MB, but it needs ${total} MB" >&2
d180 1
a180 1
dd if=/dev/zero of=${image} bs=1m count=${size}
d185 4
a188 2
${sudo} newfs /dev/r${vnddev}a
${sudo} mount /dev/${vnddev}a /mnt
d191 1
a191 1
(cd /mnt &&
d193 4
a196 2
		echo ${s}
		${sudo} tar xpzf ${setsdir}/${s}.tgz
a200 1
${sudo} rm -f /mnt/etc/motd
d202 1
a202 21
tmp=/tmp/usermode.$$
cat > ${tmp} << EOF
# NetBSD/usermode /etc/fstab
/dev/ld0a       /               ffs     ro              1 1
/dev/ld1a	/pkgs		ffs	ro		1 2
kernfs          /kern           kernfs  rw
ptyfs           /dev/pts        ptyfs   rw
procfs          /proc           procfs  rw
# mount /root as tmpfs on top of existing dir
tmpfs           /root.cow       tmpfs   rw,-s2M         0 0
/root.cow       /root           union   rw,hidden       0 0
# mount /etc as tmpfs on top of existing dir
tmpfs           /etc.cow        tmpfs   rw,-s12M        0 0
/etc.cow        /etc            union   rw,hidden       0 0
# mount /var as tmpfs on top of existing dir
tmpfs           /var.cow        tmpfs   rw,-s32M         0 0
/var.cow        /var            union   rw,hidden       - -
tmpfs           /tmp            tmpfs   rw,-s32M        0 0
/dev/cd0a       /cdrom          cd9660  ro,noauto
EOF
${sudo} mv ${tmp} /mnt/etc/fstab
d204 1
a204 2
cat > ${tmp} << EOF
#       $NetBSD: mkimage,v 1.2 2012/01/20 02:19:47 agc Exp $
d223 1
a223 2
# make sure we have the right rw filesystem at boot
critical_filesystems_local="/var.cow /var /etc.cow /etc /root.cow /root"
d225 1
a225 4
# Add local overrides below
#
dhcpcd=YES
sshd=YES
d227 1
a227 3
hostname=${h}
EOF
${sudo} mv ${tmp} /mnt/etc/rc.conf
a228 4
echo "${bar} making extra directories ${bar}"
for d in ${usermodedirs}; do
	${sudo} mkdir -p /mnt/${d}
done
d230 1
a230 1
	${sudo} mkdir -p /mnt/${d}
d233 1
a233 15
echo "${bar} customising /var/tmp ${bar}"
${sudo} rm -rf /mnt/var/tmp
(cd /mnt/var && ${sudo} ln -s /tmp tmp)

# package-related stuff
(cat /mnt/etc/csh.cshrc;echo "setenv PKG_DBDIR /usr/pkg/.dbdir") > ${tmp}
${sudo} mv ${tmp} /mnt/etc/csh.cshrc
(cat /mnt/etc/profile;echo "export PKG_DBDIR=/usr/pkg/.dbdir") > ${tmp}
${sudo} mv ${tmp} /mnt/etc/profile
(echo "PKG_DBDIR=/usr/pkg/.dbdir") > ${tmp}
${sudo} mv ${tmp} /mnt/etc/mk.conf
(cd /mnt/usr && ${sudo} ln -s /pkgs/usr/pkg pkg)

# last, customisation stage
if [ -d ${custom} ]; then
d235 1
a235 1
	(cd ${custom} && ${sudo} pax -rwpe . /mnt)
a237 5
df /mnt

${sudo} umount /mnt
${sudo} vnconfig -u ${vnddev}

@


1.3.4.1
log
@resync with head
@
text
@d1 5
a5 4
#!/bin/sh
# $NetBSD$
#
# Copyright (c) 2013 The NetBSD Foundation, Inc.
a7 3
# This code is derived from software contributed to The NetBSD Foundation
# by Christos Zoulas.
#
d16 12
a27 33
# 3. Neither the name of The NetBSD Foundation nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

set -e

DIR="$(cd "$(dirname "$0")" && pwd)"
PROG="$(basename "$0")"

DISKLABEL=${TOOL_DISKLABEL:-disklabel}
FDISK=${TOOL_FDISK:-fdisk}
MAKEFS=${TOOL_MAKEFS:-makefs}
MTREE=${TOOL_MTREE:-mtree}

src="/usr/src"
release="/usr/obj/evbarm/release"
sets="base comp etc games man misc modules text"
xsets="xbase xcomp xetc xfont xserver" 
minfree="10%"
bar="==="
d29 38
a66 11
tmp="$(mktemp -d "/tmp/$PROG.XXXXXX")"
mnt="${tmp}/mnt"
mkdir -p "${mnt}/etc" "${mnt}/dev" "${mnt}/boot"

trap "cleanup" 0 1 2 3 15

cleanup() {
	case "$tmp" in
	/tmp/$PROG.*)	rm -fr "$tmp";;
	esac
}
d68 1
a68 3
getsize() {
	set -- $(ls -l $1)
	echo $5
d71 13
a83 5
usage() {
	cat << EOF 1>&2
Usage: $PROG -h <host-arch> [-K <kerneldir>] [-S <srcdir>] [-D <destdir>] [-c <custom-files-dir>] [-s <Mb size>] [<image>]
EOF
	exit 1
d86 20
a105 8
# First pass for options to get the host and src directories
OPTS="K:D:S:c:h:s:x"
while getopts "$OPTS" f
do
	case $f in
	h)	h="$OPTARG";;
	S)	src="$OPTARG";;
	*)	;;
d107 1
d110 4
a113 3
if [ -z "$h" ]
then
	usage
d116 77
a192 4
if [ ! -f "${DIR}/conf/${h}.conf" ]
then
	echo $PROG: ${DIR}/conf/${h}.conf is not present 1>&2
	exit 1
d195 3
a197 1
. "${DIR}/conf/${h}.conf"
d199 2
a200 1
selected_sets="$sets"
d202 4
a205 14
OPTIND=1
while getopts "$OPTS" f
do
	case $f in
	D)	release="$OPTARG";;
	K)	kernel="$OPTARG";;
	S)	;;
	c)	custom="$OPTARG";;
	h)	;;
	s)	size="$OPTARG";;
	x)	selected_sets="$sets $xsets";;
	*)	usage;;
	esac
done
d207 3
a209 6
shift $(( $OPTIND - 1 ))
if [ -n "$1" ]; then
	# take the next argument as being the image name
	image="$1"
	shift
fi
d211 7
a217 31
case "$image" in
*.gz)	compress=true; image="${image%.gz}";;
*)	compress=false;;
esac

echo ${bar} configuring sets ${bar}
(echo '/set type=dir uname=root gname=wheel mode=0755'
for i in $selected_sets; do
	s="${release}/etc/mtree/set.$i"
	if [ -f "$s" ]; then
		cat "$s"
	fi
done) > "$tmp/selected_sets"

make_fstab
customize
populate

(cd ${mnt}; ${MTREE} -N ${release}/etc -c -k all | 
    ${MTREE} -N ${release}/etc -C -k all) >> "$tmp/selected_sets"
if [ -n ${msdosid} ]; then
	echo ${bar} Populating msdos filesystem ${bar}
	${MAKEFS} -N ${release}/etc -t msdos \
	    -O $((${init} / 2))m -s $((${boot} / 2))m ${image} ${mnt}/boot
fi

echo ${bar} Populating ffs filesystem ${bar}
${MAKEFS} -N ${release}/etc -t ffs -rx \
    -O $(((${init} + ${boot} + ${swap}) / 2))m \
    -b $((${extra} / 2))m \
    -F "$tmp/selected_sets" ${image} "${release}" "${mnt}"
d219 17
a235 2
if [ "${size}" = 0 ]; then
	size="$(getsize "${image}")"
a236 1
newsize=$((${size} / 2 / 1024))
d238 1
a238 9
echo ${bar} Adding label ${bar}
make_label > ${tmp}/label
${DISKLABEL} -R -F ${image} ${tmp}/label
if [ -n ${msdosid} ]; then
	echo ${bar} Running fdisk ${bar}
	initsecs=$((${init} * 1024))
	bootsecs=$((${boot} * 1024))
	${FDISK} -f -u -0 -s ${msdosid}/${initsecs}/${bootsecs} -F ${image}
fi
d240 2
a241 6
if $compress; then
	echo ${bar} Compressing image ${bar}
	rm -f "${image}.gz"
	gzip -9 ${image}
	image="${image}.gz"
fi
d243 1
a243 1
echo ${bar} Image is ${image} ${bar}
@


1.3.4.2
log
@resync from head
@
text
@a41 1
GZIP=${TOOL_GZIP:-gzip}
d71 1
a71 6
Usage: $PROG -h <host-arch> [-bmx] [-K <kerneldir>] [-S <srcdir>] [-D <destdir>] [-c <custom-files-dir>] [-s <Mb size>] [<image>]

-b	Boot only, no sets loaded
-d	Add the debug sets
-m	Mimimize disk writes for sd cards
-x	Load the x sets too, not just the base ones
d77 1
a77 1
OPTS="K:D:S:bc:dh:ms:x"
a100 3
dsets=false
xsets=false
minwrites=false
a108 7
	b)	bootonly="true";;
	d)	dsets=true
		selected_sets="$selected_sets debug"
		if $xsets; then
			selected_sets="$selected_sets xdebug"
		fi
		;;
a110 1
	m)	minwrites=true;;
d112 1
a112 6
	x)	xsets=true
		selected_sets="$selected_sets $xsets"
		if $dsets; then
		    selected_sets="$selected_sets xdebug"
		fi
		;;
d129 8
a136 10
if [ -z "$bootonly" ]; then
	echo ${bar} configuring sets ${bar}
	(echo '/set type=dir uname=root gname=wheel mode=0755'
	for i in $selected_sets; do
		s="${release}/etc/mtree/set.$i"
		if [ -f "$s" ]; then
			cat "$s"
		fi
	done) > "$tmp/selected_sets"
fi
d142 2
a143 4
if [ -z "$bootonly" ]; then
	(cd ${mnt}; ${MTREE} -N ${release}/etc -c -k all | 
	    ${MTREE} -N ${release}/etc -C -k all) >> "$tmp/selected_sets"
fi
d147 1
a147 1
	    -O $((${init} / 2))m -s $((${boot} / 2 + ${init} / 2))m ${image} ${mnt}/boot
d150 5
a154 8
if [ -z "$bootonly" ]; then
	echo ${bar} Populating ffs filesystem ${bar}
	${MAKEFS} -N ${release}/etc -t ffs -rx \
	    -O $(((${init} + ${boot} + ${swap}) / 2))m \
		-o d=4096 \
	    -b $((${extra}))m \
	    -F "$tmp/selected_sets" ${image} "${release}" "${mnt}"
fi
d174 1
a174 1
	${GZIP} -9 ${image}
@


1.3.4.3
log
@Rebase to HEAD as of a few days ago.
@
text
@d4 1
a4 1
# Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
d42 1
a44 2
INSTALLBOOT=${TOOL_INSTALLBOOT:-installboot}
GZIP_CMD=${TOOL_GZIP:-gzip} # ${GZIP} is special to gzip(1)
d47 1
d55 1
a55 1
mkdir -p "${mnt}/etc" "${mnt}/dev"
d72 1
a72 1
Usage: $PROG -h <host-arch> [-bdmx] [-K <kerneldir>] [-S <srcdir>] [-D <destdir>] [-c <custom-files-dir>] [-s <Mb size>] [<image>]
a74 1
-r	root device kind (sd, wd, ld)
d76 1
a76 1
-m	Optimize the OS installation to mimimize disk writes for SSDs
d83 1
a83 1
OPTS="K:D:S:bc:dh:mr:s:x"
a104 1
release="/usr/obj/${MACHINE}/release"
a109 1
rootdev=ld
d118 1
a118 1
	b)	bootonly=true;;
a127 1
	r)	rootdev="$OPTARG";;
d151 1
a151 1
if [ -z "${bootonly}" ]; then
d166 1
a166 1
if [ -z "${bootonly}" ]; then
d170 1
a170 1
if [ -n "${msdosid}" ]; then
d173 1
a173 2
	    -O $((${init} / 2))m -s $((${boot} / 2 + ${init} / 2))m \
	    ${image} ${mnt}/boot
d176 1
a176 1
if [ -z "${bootonly}" ]; then
d179 3
a181 2
	    -O ${ffsoffset} \
	    -o d=4096 -b $((${extra}))m \
d193 1
a193 1
if [ -n "${msdosid}" ]; then
a197 5
elif [ -n "${netbsdid}" ]; then
	echo ${bar} Running fdisk ${bar}
	${FDISK} -f -i ${image}
	${FDISK} -f -a -u -0 -s 169 ${image}
	${INSTALLBOOT} -f -v ${image} ${release}/usr/mdec/bootxx_ffsv1
d203 1
a203 1
	${GZIP_CMD} -9 ${image}
@


1.3.2.1
log
@file mkimage was added on branch yamt-pagecache on 2012-04-17 00:02:49 +0000
@
text
@d1 243
@


1.3.2.2
log
@sync with head
@
text
@a0 243
#! /bin/sh

# $NetBSD$

# Copyright (c) 2012 Alistair Crooks <agc@@NetBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

# find next available vnd, from kre
next_avail ()
{
	local dev="$1"
	local N=$(( ${#dev} + 1 ))
	local unit units

	units=$(
		sysctl -n hw.disknames		|
			tr ' ' '\012'		|
			grep '^'"${dev}"'[0-9]'	|
			sort -n -k 1.$N			)

	test -z "${units}" && {
		test -e "/dev/${dev}0a" || {
			echo >&2 "No ${dev}s available!"
			return 1
		}
		echo "${dev}0"
		return
	}

	N=0
	for unit in ${units}
	do
		if [ "${unit}" = "${dev}${N}" ]
		then
			N=$(( N + 1 ))
		else
			echo "${dev}${N}"
			return
		fi
	done

	test -e /dev/"${dev}${N}a" || {
		echo >&2 "All ${dev}s in use"
		return 1
	}

	echo "${dev}${N}"
}

# find the size of the gzipped files in a .tgz archive
sizeone() {
        case "$1" in 
        *.tgz|*.tar.gz)
                tar tvzf "$1" | awk '{ tot += $5 } END { print tot }'
                ;;
        *.tbz|*.tar.bz2)
                tar tvjf "$1" | awk '{ tot += $5 } END { print tot }' 
                ;;
        *)
                echo 0
                ;; 
        esac
}

bar="==="
custom=custom
h=usermode1.$(uname -n)
image=usermode.img
overhead=8 # in MB
sets="base etc modules"
setsdir=/usr/build/release/$(uname -m)/binary/sets
size=0	# in MB
specialdirs="/kern /proc"
usermodedirs="/var.cow /etc.cow /root.cow /pkgs"
sudo="sudo"

while [ $# -gt 0 ]; do
	case "$1" in
	-S)	setsdir=$2; shift ;;
	-c)	custom=$2; shift ;;
	-h)	h=$2; shift ;;
	-s)	size=$2; shift ;;
	-x)	set -x ;;
	*)	break ;;
	esac
	shift
done

if [ $# -gt 0 ]; then
	# take the next argument as being the image name
	image="$1"
	shift
fi

total=0
for s in ${sets}; do
	total=$(expr ${total} + $(sizeone ${setsdir}/${s}.tgz))
done
# calculate size of custom files
custsize=0
if [ -d "${custom}" ]; then
	custsize=$(ls -lR "${custom}" | awk 'NF == 9 { tot += $5 } END { print tot }')
fi
total=$(expr \( \( ${total} + ${custsize} \) / 1000000 \) + ${overhead})
if [ $size -eq 0 ]; then
        # auto-size the pkgs fs
        size=${total}
else
        # check that we've been given enough space
        if [ ${total} -gt ${size} ]; then
                echo "File system size given as ${size} MB, but it needs ${total} MB" >&2
                exit 1
        fi
fi

echo "${bar} making a new ${size} MB image in ${image} ${bar}"
dd if=/dev/zero of=${image} bs=1m count=${size}

vnddev=$(next_avail vnd)
echo "${bar} mounting image via vnd ${vnddev} ${bar}"
${sudo} vnconfig ${vnddev} ${image}
${sudo} newfs /dev/r${vnddev}a
${sudo} mount /dev/${vnddev}a /mnt

echo "${bar} installing sets ${bar}"
(cd /mnt &&
	for s in ${sets}; do
		echo ${s}
		${sudo} tar xpzf ${setsdir}/${s}.tgz
	done
)

echo "${bar} performing customisations ${bar}"
${sudo} rm -f /mnt/etc/motd

tmp=/tmp/usermode.$$
cat > ${tmp} << EOF
# NetBSD/usermode /etc/fstab
/dev/ld0a       /               ffs     ro              1 1
/dev/ld1a	/pkgs		ffs	ro		1 2
kernfs          /kern           kernfs  rw
ptyfs           /dev/pts        ptyfs   rw
procfs          /proc           procfs  rw
# mount /root as tmpfs on top of existing dir
tmpfs           /root.cow       tmpfs   rw,-s2M         0 0
/root.cow       /root           union   rw,hidden       0 0
# mount /etc as tmpfs on top of existing dir
tmpfs           /etc.cow        tmpfs   rw,-s12M        0 0
/etc.cow        /etc            union   rw,hidden       0 0
# mount /var as tmpfs on top of existing dir
tmpfs           /var.cow        tmpfs   rw,-s32M         0 0
/var.cow        /var            union   rw,hidden       - -
tmpfs           /tmp            tmpfs   rw,-s32M        0 0
/dev/cd0a       /cdrom          cd9660  ro,noauto
EOF
${sudo} mv ${tmp} /mnt/etc/fstab

cat > ${tmp} << EOF
#       $NetBSD$
#
# see rc.conf(5) for more information.
#
# Use program=YES to enable program, NO to disable it. program_flags are
# passed to the program on the command line.
#

# Load the defaults in from /etc/defaults/rc.conf (if it's readable).
# These can be overridden below.
#
if [ -r /etc/defaults/rc.conf ]; then
        . /etc/defaults/rc.conf
fi

# If this is not set to YES, the system will drop into single-user mode.
#
rc_configured=YES

# make sure we have the right rw filesystem at boot
critical_filesystems_local="/var.cow /var /etc.cow /etc /root.cow /root"

# Add local overrides below
#
dhcpcd=YES
sshd=YES

hostname=${h}
EOF
${sudo} mv ${tmp} /mnt/etc/rc.conf

echo "${bar} making extra directories ${bar}"
for d in ${usermodedirs}; do
	${sudo} mkdir -p /mnt/${d}
done
for d in ${specialdirs}; do
	${sudo} mkdir -p /mnt/${d}
done

echo "${bar} customising /var/tmp ${bar}"
${sudo} rm -rf /mnt/var/tmp
(cd /mnt/var && ${sudo} ln -s /tmp tmp)

# package-related stuff
(cat /mnt/etc/csh.cshrc;echo "setenv PKG_DBDIR /usr/pkg/.dbdir") > ${tmp}
${sudo} mv ${tmp} /mnt/etc/csh.cshrc
(cat /mnt/etc/profile;echo "export PKG_DBDIR=/usr/pkg/.dbdir") > ${tmp}
${sudo} mv ${tmp} /mnt/etc/profile
(echo "PKG_DBDIR=/usr/pkg/.dbdir") > ${tmp}
${sudo} mv ${tmp} /mnt/etc/mk.conf
(cd /mnt/usr && ${sudo} ln -s /pkgs/usr/pkg pkg)

# last, customisation stage
if [ -d ${custom} ]; then
	echo "${bar} user customisations from files in ${custom} ${bar}"
	(cd ${custom} && ${sudo} pax -rwpe . /mnt)
fi

df /mnt

${sudo} umount /mnt
${sudo} vnconfig -u ${vnddev}

exit 0
@


1.3.2.3
log
@sync with head
@
text
@d4 1
a4 1
#
a70 26
usage() {
	cat << EOF 1>&2
Usage: $PROG -h <host-arch> [-S <setsdir>] [-c <custom-files-dir>] [-s <size>] [<image>]
EOF
	exit 1
}

# Return the filesystem size for an ls -l or tar -xvf list
# Directories and symlinks in tar are 0 size, we assume one block
# (which is too much), we round up by the fragment size the rest.
getfssize() {
	local bsize="$1"
	local fsize="$2"

	awk -v fsize=${fsize} -v bsize=${bsize} '
	NF >= 9 && $1 != "tar:" {
		if ($5 == 0)
			tot += bsize;
		else
			tot += ((int)(($5 + fsize - 1) / fsize)) * fsize;
	}
	END {
		printf("%d\n", tot);
	}'
}

a71 2
# Directories appear as 0, so count them as one block
# and round up files to a fragment.
a72 7
	if [ ! -f "$1" ]
	then
		echo "$PROG: Missing set $1" 1>&2
		echo 0
		return;
	fi

d74 5
a78 2
        *.tgz|*.tar.gz|*.tbz|*.tar.bz2|*.txz|*.tar.xz)
                tar tvzf "$1" | getfssize ${bsize} ${fsize}
a85 68

# Return the usable filesystem size in bytes, given the total size in bytes,
# and optionally block and fragment sizes
getffssize() {
	local bytes="$1"
	local barg
	local farg
	local overhead

	if [ -n "$2" ]
	then
		barg="-b $2"
		if [ -n "$3" ]
		then
			farg="-f $3"
		fi
	fi

	overhead=$(newfs -N ${farg} ${barg} -s "${bytes}b" -F /dev/null |
	    awk '/using/ {
		printf("%d\n", substr($6, 1, length($6) - 3) * 1024 * 1024);
	    }'
	)
	echo $(( ${bytes} - ${overhead} ))
}

# Compute the size of an ffs filesystem that can fit x bytes.
# Instead of duplicating the newfs calculations here we let
# it do the job, using binary search.
makeffssize() {
	local bytes=$1
	local bsize=$2
	local fsize=$3
	local max=$(( 2 * ${bytes} ))
	local min="${bytes}"
	local cur
	local res
	while true; do
		cur="$(( ( ${max} + ${min} ) / 2 ))"
		res="$(getffssize "${cur}" ${bsize} ${fsize})"
#		echo ${min} ${cur} ${max} ${res} ${bytes} 1>&2
		if [ "${res}" -eq "${bytes}" ]
		then
		    break
		elif [ "$(( ${min} + 1 ))" -ge "${max}" ]
		then
		    break
		elif [ "${res}" -lt "${bytes}" ]
		then
		    min="${cur}"
		elif [ "${res}" -gt "${bytes}" ]
		then
		    max="${cur}"
		fi
	done
	echo "${cur}"
}

finish() {
	cleanup
	${sudo} umount ${mnt}
	${sudo} vnconfig -u ${vnddev}
	rm -fr ${mnt}
}


DIR="$(dirname "$0")"
PROG="$(basename "$0")"
d87 19
a105 20
sudo=
mnt="${TMPDIR:-/tmp}/image.$$"
src="/usr/src"
obj="/usr/obj"

sets="base comp etc games man misc modules text"
xsets="xbase xcomp xetc xfont xserver"

# Presumable block and fragment size.
bsize=16384
fsize=2048
mtob=$(( 1024 * 1024 ))

# First pass for options to get the host
OPTS="S:c:h:s:x"
while getopts "$OPTS" f
do
	case $f in
	h)	h="$OPTARG";;
	*)	;;
d107 1
d110 1
a110 30
if [ -z "$h" ]
then
	usage
fi

if [ ! -f "${DIR}/conf/${h}.conf" ]
then
	echo $PROG: ${DIR}/conf/${h}.conf is not present 1>&2
	exit 1
fi

. "${DIR}/conf/${h}.conf"

OPTIND=1
while getopts "$OPTS" f
do
	case $f in
	S)	setsdir="$OPTARG";;
	c)	custom="$OPTARG";;
	h)	;;
	s)	size="$OPTARG";;
	x)	sets="$sets $xsets";;
	*)	usage;;
	esac
done

trap finish 0 1 2 3 15

shift $(( "$OPTIND" - 1 ))
if [ -n "$1" ]; then
d116 1
a116 4
# calculate the set bytes
setbytes=0
echo -n "${bar} computing set sizes ("
b=
d118 1
a118 4
	one="$(sizeone ${setsdir}/${s}.tgz)"
	echo -n "$b$s=$(( ${one} / ${mtob} ))MB"
	setbytes=$(( ${setbytes} +  ${one} ))
	b=" "
a119 2
echo "): $(( ${setbytes} / ${mtob} ))MB ${bar}"

d121 1
a121 1
custbytes=0
d123 1
a123 1
	custbytes=$(ls -lR "${custom}" | getfssize ${bsize} ${fsize})
d125 1
a125 13
echo "${bar} computing custom sizes: $(( ${custbytes} / ${mtob} ))MB ${bar}"

# how many bytes
rawbytes="$(( ${setbytes} + ${custbytes} ))"
echo -n "${bar} computing ffs filesystem size for $(( ${rawbytes} / ${mtob} ))MB: "
ffsbytes="$(makeffssize "${rawbytes}")"
ffsmb=$(( ${ffsbytes} / ${mtob} ))
echo " ${ffsmb}MB ${bar}"

# total in MB
total=$(( ${ffsmb} + ${overhead} ))
echo "${bar} overhead: ${overhead}MB ${bar}"

d128 1
a128 1
        newsize=${total}
d132 1
a132 1
                echo "$PROG: Given size is ${size} MB, but we need ${total} MB" >&2
a134 1
	newsize=${size}
d137 2
a138 2
echo "${bar} making a new ${newsize} MB image in ${image} ${bar}"
dd if=/dev/zero of=${image} bs=1m count=${newsize} conv=sparse
d143 2
a144 4
${sudo} mkdir -p ${mnt}
make_filesystems

${sudo} mkdir -p ${mnt}/etc ${mnt}/dev
d146 2
a147 2
echo -n "${bar} installing sets:"
(cd ${mnt} &&
d149 2
a150 5
		ss="${setsdir}/${s}.tgz"
		if [ -f "${ss}" ]; then
			echo -n " ${s}"
			${sudo} tar xpzf "${ss}"
		fi
a152 1
echo " ${bar}"
d155 1
d157 21
a177 1
make_fstab
d179 2
a180 1
${sudo} cat > ${mnt}/etc/rc.conf << EOF
d199 8
a207 1

d209 1
d211 4
a214 2
customize

d216 1
a216 1
	${sudo} mkdir -p ${mnt}/${d}
d219 15
a233 1
if [ \( -n "${custom}" \) -a \( -d "${custom}" \) ]; then
d235 1
a235 1
	(cd ${custom} && ${sudo} pax -rwpe . ${mnt})
d238 5
@


1.3.2.4
log
@sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs.  ("Protocol error: too many arguments")
@
text
@d1 2
a2 1
#!/bin/sh
d5 1
a5 1
# Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
a7 3
# This code is derived from software contributed to The NetBSD Foundation
# by Christos Zoulas.
#
a15 15
# 3. Neither the name of The NetBSD Foundation nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
d17 45
d63 4
a66 1
set -e
d68 2
a69 2
DIR="$(cd "$(dirname "$0")" && pwd)"
PROG="$(basename "$0")"
d71 6
a76 6
DISKLABEL=${TOOL_DISKLABEL:-disklabel}
FDISK=${TOOL_FDISK:-fdisk}
MAKEFS=${TOOL_MAKEFS:-makefs}
MTREE=${TOOL_MTREE:-mtree}
INSTALLBOOT=${TOOL_INSTALLBOOT:-installboot}
GZIP_CMD=${TOOL_GZIP:-gzip} # ${GZIP} is special to gzip(1)
d78 18
a95 5
src="/usr/src"
sets="base comp etc games man misc modules text"
xsets="xbase xcomp xetc xfont xserver" 
minfree="10%"
bar="==="
d97 19
a115 10
tmp="$(mktemp -d "/tmp/$PROG.XXXXXX")"
mnt="${tmp}/mnt"
mkdir -p "${mnt}/etc" "${mnt}/dev"

trap "cleanup" 0 1 2 3 15

cleanup() {
	case "$tmp" in
	/tmp/$PROG.*)	rm -fr "$tmp";;
	esac
d118 24
a141 3
getsize() {
	set -- $(ls -l $1)
	echo $5
d144 31
a174 3
usage() {
	cat << EOF 1>&2
Usage: $PROG -h <host-arch> [-bdmx] [-K <kerneldir>] [-S <srcdir>] [-D <destdir>] [-c <custom-files-dir>] [-s <Mb size>] [<image>]
d176 5
a180 7
-b	Boot only, no sets loaded
-r	root device kind (sd, wd, ld)
-d	Add the debug sets
-m	Optimize the OS installation to mimimize disk writes for SSDs
-x	Load the x sets too, not just the base ones
EOF
	exit 1
d183 19
a201 2
# First pass for options to get the host and src directories
OPTS="K:D:S:bc:dh:mr:s:x"
a205 1
	S)	src="$OPTARG";;
a221 7
release="/usr/obj/${MACHINE}/release"

selected_sets="$sets"
dsets=false
xsets=false
minwrites=false
rootdev=ld
d227 1
a227 10
	D)	release="$OPTARG";;
	K)	kernel="$OPTARG";;
	S)	;;
	b)	bootonly=true;;
	d)	dsets=true
		selected_sets="$selected_sets debug"
		if $xsets; then
			selected_sets="$selected_sets xdebug"
		fi
		;;
a229 2
	m)	minwrites=true;;
	r)	rootdev="$OPTARG";;
d231 1
a231 6
	x)	xsets=true
		selected_sets="$selected_sets $xsets"
		if $dsets; then
		    selected_sets="$selected_sets xdebug"
		fi
		;;
d236 3
a238 1
shift $(( $OPTIND - 1 ))
d245 60
a304 12
case "$image" in
*.gz)	compress=true; image="${image%.gz}";;
*)	compress=false;;
esac

if [ -z "${bootonly}" ]; then
	echo ${bar} configuring sets ${bar}
	(echo '/set type=dir uname=root gname=wheel mode=0755'
	for i in $selected_sets; do
		s="${release}/etc/mtree/set.$i"
		if [ -f "$s" ]; then
			cat "$s"
d306 21
a326 1
	done) > "$tmp/selected_sets"
d329 8
a336 1
make_fstab
a337 1
populate
d339 7
a345 44
if [ -z "${bootonly}" ]; then
	(cd ${mnt}; ${MTREE} -N ${release}/etc -c -k all | 
	    ${MTREE} -N ${release}/etc -C -k all) >> "$tmp/selected_sets"
fi
if [ -n "${msdosid}" ]; then
	echo ${bar} Populating msdos filesystem ${bar}
	${MAKEFS} -N ${release}/etc -t msdos \
	    -O $((${init} / 2))m -s $((${boot} / 2 + ${init} / 2))m \
	    ${image} ${mnt}/boot
fi

if [ -z "${bootonly}" ]; then
	echo ${bar} Populating ffs filesystem ${bar}
	${MAKEFS} -N ${release}/etc -t ffs -rx \
	    -O ${ffsoffset} \
	    -o d=4096 -b $((${extra}))m \
	    -F "$tmp/selected_sets" ${image} "${release}" "${mnt}"
fi

if [ "${size}" = 0 ]; then
	size="$(getsize "${image}")"
fi
newsize=$((${size} / 2 / 1024))

echo ${bar} Adding label ${bar}
make_label > ${tmp}/label
${DISKLABEL} -R -F ${image} ${tmp}/label
if [ -n "${msdosid}" ]; then
	echo ${bar} Running fdisk ${bar}
	initsecs=$((${init} * 1024))
	bootsecs=$((${boot} * 1024))
	${FDISK} -f -u -0 -s ${msdosid}/${initsecs}/${bootsecs} -F ${image}
elif [ -n "${netbsdid}" ]; then
	echo ${bar} Running fdisk ${bar}
	${FDISK} -f -i ${image}
	${FDISK} -f -a -u -0 -s 169 ${image}
	${INSTALLBOOT} -f -v ${image} ${release}/usr/mdec/bootxx_ffsv1
fi

if $compress; then
	echo ${bar} Compressing image ${bar}
	rm -f "${image}.gz"
	${GZIP_CMD} -9 ${image}
	image="${image}.gz"
d348 1
a348 1
echo ${bar} Image is ${image} ${bar}
@


1.2
log
@While the resulting image from mkimage can always be mounted with vnd,
and then modified, it is much easier to let this late, user-oriented
customisation be done automatically.  These mods let mkimage change
information based on files in a "custom" directory, which can be set
in mkimage using -c customdir.

After all other configuration, the files under custom/ will be copied
into the main image.  The files under custom/ are taken into account
when performing autosizing.

Also, generalise the sets directory to point to the current machine
architecture, although this can be overwritten from the command line
by anyone making cross-images.

An example to make a user image with an embedded read-only 100 MB
iSCSI target:

% ./mkimage -c custom
=== making a new 272 MB image in usermode.img ===
272+0 records in
272+0 records out
285212672 bytes transferred in 7.616 secs (37449142 bytes/sec)
=== mounting image via vnd vnd0 ===
/dev/rvnd0a: 272.0MB (557056 sectors) block size 8192, fragment size 1024
        using 6 cylinder groups of 45.34MB, 5803 blks, 11264 inodes.
super-block backups (for fsck_ffs -b #) at:
32, 92880, 185728, 278576, 371424, 464272,
=== installing sets ===
base
etc
modules
=== performing customisations ===
=== making extra directories ===
=== customising /var/tmp ===
=== user customisations from files in custom ===
Filesystem    1K-blocks       Used      Avail %Cap Mounted on
/dev/vnd0a       269967     263958      -7489 102% /mnt
% ls -l -R custom
total 8
drwxr-xr-x  3 agc  agc  512 Jan 18 03:58 etc
drwxr-xr-x  2 agc  agc  512 Jan 18 04:00 iscsi

custom/etc:
total 8
drwxr-xr-x  2 agc  agc  512 Jan 18 03:58 iscsi
-rw-r--r--  1 agc  agc  564 Jan 18 03:58 rc.conf

custom/etc/iscsi:
total 6
-r--r--r--  1 agc  agc  799 Jan 18 04:27 targets

custom/iscsi:
total 102484
-rw-r--r--  1 agc  agc  104857600 Jan 18 04:00 iscsi-target0
% sudo vnconfig vnd0 usermode.img
% sudo mount /dev/vnd0a /mnt
% cat /mnt/etc/iscsi/targets
# $NetBSD: targets,v 1.2 2006/02/16 19:30:57 agc Exp $
#
# Structure of this file:
#
# + an extent is a straight (offset, length) pair of a file or device
#   it's the lowest common storage denominator
#   at least one is needed
# + a device is made up of one or more extents or other devices
#   devices can be added in a hierachical manner, to enhance resilience
# + in this example, no device definitions are necessary, as the target
#   will just use a simple extent for persistent storage
# + a target is made up of 1 or more devices
# The code does not support RAID1 recovery at present

# Simple file showing 1 extent, mapped straight into 1 target

# extent        file or device          start           length
extent0         /iscsi/iscsi-target0    0               100MB

# target        flags   storage         netmask
target0         ro      extent0         0.0.0.0/0
% ls -l /mnt/iscsi/iscsi-target0
-rw-r--r--  1 agc  agc  104857600 Jan 18 04:00 /mnt/iscsi/iscsi-target0
% diff custom/etc/iscsi/targets /mnt/etc/iscsi/targets
%
@
text
@d3 1
a3 1
# $NetBSD: mkimage,v 1.1 2012/01/15 02:01:02 agc Exp $
d95 1
a95 1
usermodedirs="/var.run /var.log /etc.cow /root.cow /pkgs"
d171 3
a173 7
# mount /var/run as tmpfs on top of existing dir
tmpfs           /var.run        tmpfs   rw,-s1M         0 0
/var.run        /var/run        union   rw,hidden       - -
# mount /var/log as tmpfs on top of existing dir
tmpfs           /var.log        tmpfs   rw,-s10M        0 0
/var.log        /var/log        union   rw,hidden       - -
tmpfs           /var/db         tmpfs   rw,-s8M         0 0
d180 1
a180 1
#       $NetBSD: mkimage,v 1.1 2012/01/15 02:01:02 agc Exp $
d200 1
a200 1
critical_filesystems_local="/var/db /var.run /var/run /var.log /var/log /etc.cow /etc /root.cow /root"
@


1.1
log
@Add 3 scripts which are useful for making images for usermode, or any
embedded platform in particular.

+ mkimage will make an autosized image in a file (using vnd) from sets
the resulting image can be mounted read-only, with tmpfs used for volatile
files on top of read-only bases

+ mkpkgs will make an autosized image in a file (using vnd) from binary
packages

+ usermode is an easy way to invoke usermode, making sure that bridging
is set up properly, and that the host syscallemu module is loaded. This
script then runs usermode with two file images (as produced by mkimage
and mkpkgs)
@
text
@d3 1
a3 1
# $NetBSD: genraidconf.sh,v 1.5 2011/05/19 00:24:22 agc Exp $
d86 4
a89 2
setsdir=/usr/build/release/i386/binary/sets
size=0	# in MB
a90 2
image=usermode.img
h=usermode1.$(uname -n)
d92 3
d96 1
a96 2
specialdirs="/kern /proc"
bar="==="
d101 1
d120 6
a125 1
total=$(expr \( ${total} / 1000000 \) + ${overhead})
d142 3
a144 3
sudo vnconfig ${vnddev} ${image}
sudo newfs /dev/r${vnddev}a
sudo mount /dev/${vnddev}a /mnt
d150 1
a150 1
		sudo tar xpzf ${setsdir}/${s}.tgz
d155 1
a155 1
sudo rm -f /mnt/etc/motd
d181 1
a181 1
sudo mv ${tmp} /mnt/etc/fstab
d184 1
a184 1
#       $NetBSD: rc.conf,v 1.96 2000/10/14 17:01:29 wiz Exp $
d213 1
a213 1
sudo mv ${tmp} /mnt/etc/rc.conf
d217 1
a217 1
	sudo mkdir -p /mnt/${d}
d220 1
a220 1
	sudo mkdir -p /mnt/${d}
d224 2
a225 2
sudo rm -rf /mnt/var/tmp
(cd /mnt/var && sudo ln -s /tmp tmp)
d229 1
a229 1
sudo mv ${tmp} /mnt/etc/csh.cshrc
d231 1
a231 1
sudo mv ${tmp} /mnt/etc/profile
d233 8
a240 2
sudo mv ${tmp} /mnt/etc/mk.conf
(cd /mnt/usr && sudo ln -s /pkgs/usr/pkg pkg)
d244 2
a245 2
sudo umount /mnt
sudo vnconfig -u ${vnddev}
@

