0015-procd-remove-procd-nand-package.patch 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Fri, 21 Apr 2017 20:37:58 +0200
  3. Subject: procd: remove procd-nand package
  4. We always want to support staged upgrades now, so it's better to include
  5. upgraded into the main package. /lib/upgrade/nand.sh is moved to
  6. base-files.
  7. The procd-nand-firstboot package is removed for now, it may return later
  8. as a separate package.
  9. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
  10. diff --git a/package/base-files/Makefile b/package/base-files/Makefile
  11. index fdeda95a17cd463f0348bf0606ad40dde717d21f..54f752c802ae2125bf65415807e5b55b45d16190 100644
  12. --- a/package/base-files/Makefile
  13. +++ b/package/base-files/Makefile
  14. @@ -19,7 +19,9 @@ PKG_BUILD_DEPENDS:=usign/host
  15. PKG_LICENSE:=GPL-2.0
  16. # Extend depends from version.mk
  17. -PKG_CONFIG_DEPENDS += CONFIG_SIGNED_PACKAGES CONFIG_TARGET_INIT_PATH CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE
  18. +PKG_CONFIG_DEPENDS += \
  19. + CONFIG_SIGNED_PACKAGES CONFIG_TARGET_INIT_PATH CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE \
  20. + CONFIG_NAND_SUPPORT
  21. include $(INCLUDE_DIR)/package.mk
  22. @@ -31,7 +33,7 @@ endif
  23. define Package/base-files
  24. SECTION:=base
  25. CATEGORY:=Base system
  26. - DEPENDS:=+netifd +libc +procd +jsonfilter +SIGNED_PACKAGES:usign +SIGNED_PACKAGES:lede-keyring +fstools +fwtool
  27. + DEPENDS:=+netifd +libc +procd +jsonfilter +SIGNED_PACKAGES:usign +SIGNED_PACKAGES:lede-keyring +NAND_SUPPORT:ubi-utils +fstools +fwtool
  28. TITLE:=Base filesystem for Lede
  29. URL:=http://openwrt.org/
  30. VERSION:=$(PKG_RELEASE)-$(REVISION)
  31. @@ -106,9 +108,16 @@ ifdef CONFIG_SIGNED_PACKAGES
  32. endef
  33. endif
  34. +ifeq ($(CONFIG_NAND_SUPPORT),)
  35. + define Package/base-files/nand-support
  36. + rm -f $(1)/lib/upgrade/nand.sh
  37. + endef
  38. +endif
  39. +
  40. define Package/base-files/install
  41. $(CP) ./files/* $(1)/
  42. $(Package/base-files/install-key)
  43. + $(Package/base-files/nand-support)
  44. if [ -d $(GENERIC_PLATFORM_DIR)/base-files/. ]; then \
  45. $(CP) $(GENERIC_PLATFORM_DIR)/base-files/* $(1)/; \
  46. fi
  47. diff --git a/package/base-files/files/lib/upgrade/nand.sh b/package/base-files/files/lib/upgrade/nand.sh
  48. new file mode 100644
  49. index 0000000000000000000000000000000000000000..6bd2005344c081df20e5a330a69e49e37225c39f
  50. --- /dev/null
  51. +++ b/package/base-files/files/lib/upgrade/nand.sh
  52. @@ -0,0 +1,376 @@
  53. +#!/bin/sh
  54. +# Copyright (C) 2014 OpenWrt.org
  55. +#
  56. +
  57. +. /lib/functions.sh
  58. +
  59. +# 'kernel' partition on NAND contains the kernel
  60. +CI_KERNPART="kernel"
  61. +
  62. +# 'ubi' partition on NAND contains UBI
  63. +CI_UBIPART="ubi"
  64. +
  65. +ubi_mknod() {
  66. + local dir="$1"
  67. + local dev="/dev/$(basename $dir)"
  68. +
  69. + [ -e "$dev" ] && return 0
  70. +
  71. + local devid="$(cat $dir/dev)"
  72. + local major="${devid%%:*}"
  73. + local minor="${devid##*:}"
  74. + mknod "$dev" c $major $minor
  75. +}
  76. +
  77. +nand_find_volume() {
  78. + local ubidevdir ubivoldir
  79. + ubidevdir="/sys/devices/virtual/ubi/$1"
  80. + [ ! -d "$ubidevdir" ] && return 1
  81. + for ubivoldir in $ubidevdir/${1}_*; do
  82. + [ ! -d "$ubivoldir" ] && continue
  83. + if [ "$( cat $ubivoldir/name )" = "$2" ]; then
  84. + basename $ubivoldir
  85. + ubi_mknod "$ubivoldir"
  86. + return 0
  87. + fi
  88. + done
  89. +}
  90. +
  91. +nand_find_ubi() {
  92. + local ubidevdir ubidev mtdnum
  93. + mtdnum="$( find_mtd_index $1 )"
  94. + [ ! "$mtdnum" ] && return 1
  95. + for ubidevdir in /sys/devices/virtual/ubi/ubi*; do
  96. + [ ! -d "$ubidevdir" ] && continue
  97. + cmtdnum="$( cat $ubidevdir/mtd_num )"
  98. + [ ! "$mtdnum" ] && continue
  99. + if [ "$mtdnum" = "$cmtdnum" ]; then
  100. + ubidev=$( basename $ubidevdir )
  101. + ubi_mknod "$ubidevdir"
  102. + echo $ubidev
  103. + return 0
  104. + fi
  105. + done
  106. +}
  107. +
  108. +nand_get_magic_long() {
  109. + dd if="$1" skip=$2 bs=4 count=1 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
  110. +}
  111. +
  112. +get_magic_long_tar() {
  113. + ( tar xf $1 $2 -O | dd bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2> /dev/null
  114. +}
  115. +
  116. +identify_magic() {
  117. + local magic=$1
  118. + case "$magic" in
  119. + "55424923")
  120. + echo "ubi"
  121. + ;;
  122. + "31181006")
  123. + echo "ubifs"
  124. + ;;
  125. + "68737173")
  126. + echo "squashfs"
  127. + ;;
  128. + "d00dfeed")
  129. + echo "fit"
  130. + ;;
  131. + "4349"*)
  132. + echo "combined"
  133. + ;;
  134. + *)
  135. + echo "unknown $magic"
  136. + ;;
  137. + esac
  138. +}
  139. +
  140. +
  141. +identify() {
  142. + identify_magic $(nand_get_magic_long "$1" "${2:-0}")
  143. +}
  144. +
  145. +identify_tar() {
  146. + identify_magic $(get_magic_long_tar "$1" "$2")
  147. +}
  148. +
  149. +nand_restore_config() {
  150. + sync
  151. + local ubidev=$( nand_find_ubi $CI_UBIPART )
  152. + local ubivol="$( nand_find_volume $ubidev rootfs_data )"
  153. + [ ! "$ubivol" ] &&
  154. + ubivol="$( nand_find_volume $ubidev rootfs )"
  155. + mkdir /tmp/new_root
  156. + if ! mount -t ubifs /dev/$ubivol /tmp/new_root; then
  157. + echo "mounting ubifs $ubivol failed"
  158. + rmdir /tmp/new_root
  159. + return 1
  160. + fi
  161. + mv "$1" "/tmp/new_root/sysupgrade.tgz"
  162. + umount /tmp/new_root
  163. + sync
  164. + rmdir /tmp/new_root
  165. +}
  166. +
  167. +nand_upgrade_prepare_ubi() {
  168. + local rootfs_length="$1"
  169. + local rootfs_type="$2"
  170. + local has_kernel="${3:-0}"
  171. + local has_env="${4:-0}"
  172. +
  173. + local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
  174. + if [ ! "$mtdnum" ]; then
  175. + echo "cannot find ubi mtd partition $CI_UBIPART"
  176. + return 1
  177. + fi
  178. +
  179. + local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  180. + if [ ! "$ubidev" ]; then
  181. + ubiattach -m "$mtdnum"
  182. + sync
  183. + ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  184. + fi
  185. +
  186. + if [ ! "$ubidev" ]; then
  187. + ubiformat /dev/mtd$mtdnum -y
  188. + ubiattach -m "$mtdnum"
  189. + sync
  190. + ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  191. + [ "$has_env" -gt 0 ] && {
  192. + ubimkvol /dev/$ubidev -n 0 -N ubootenv -s 1MiB
  193. + ubimkvol /dev/$ubidev -n 1 -N ubootenv2 -s 1MiB
  194. + }
  195. + fi
  196. +
  197. + local kern_ubivol="$( nand_find_volume $ubidev kernel )"
  198. + local root_ubivol="$( nand_find_volume $ubidev rootfs )"
  199. + local data_ubivol="$( nand_find_volume $ubidev rootfs_data )"
  200. +
  201. + # remove ubiblock device of rootfs
  202. + local root_ubiblk="ubiblock${root_ubivol:3}"
  203. + if [ "$root_ubivol" -a -e "/dev/$root_ubiblk" ]; then
  204. + echo "removing $root_ubiblk"
  205. + if ! ubiblock -r /dev/$root_ubivol; then
  206. + echo "cannot remove $root_ubiblk"
  207. + return 1;
  208. + fi
  209. + fi
  210. +
  211. + # kill volumes
  212. + [ "$kern_ubivol" ] && ubirmvol /dev/$ubidev -N kernel || true
  213. + [ "$root_ubivol" ] && ubirmvol /dev/$ubidev -N rootfs || true
  214. + [ "$data_ubivol" ] && ubirmvol /dev/$ubidev -N rootfs_data || true
  215. +
  216. + # update kernel
  217. + if [ "$has_kernel" = "1" ]; then
  218. + if ! ubimkvol /dev/$ubidev -N kernel -s $kernel_length; then
  219. + echo "cannot create kernel volume"
  220. + return 1;
  221. + fi
  222. + fi
  223. +
  224. + # update rootfs
  225. + local root_size_param
  226. + if [ "$rootfs_type" = "ubifs" ]; then
  227. + root_size_param="-m"
  228. + else
  229. + root_size_param="-s $rootfs_length"
  230. + fi
  231. + if ! ubimkvol /dev/$ubidev -N rootfs $root_size_param; then
  232. + echo "cannot create rootfs volume"
  233. + return 1;
  234. + fi
  235. +
  236. + # create rootfs_data for non-ubifs rootfs
  237. + if [ "$rootfs_type" != "ubifs" ]; then
  238. + if ! ubimkvol /dev/$ubidev -N rootfs_data -m; then
  239. + echo "cannot initialize rootfs_data volume"
  240. + return 1
  241. + fi
  242. + fi
  243. + sync
  244. + return 0
  245. +}
  246. +
  247. +nand_do_upgrade_success() {
  248. + local conf_tar="/tmp/sysupgrade.tgz"
  249. +
  250. + sync
  251. + [ -f "$conf_tar" ] && nand_restore_config "$conf_tar"
  252. + echo "sysupgrade successful"
  253. + umount -a
  254. + reboot -f
  255. +}
  256. +
  257. +# Flash the UBI image to MTD partition
  258. +nand_upgrade_ubinized() {
  259. + local ubi_file="$1"
  260. + local mtdnum="$(find_mtd_index "$CI_UBIPART")"
  261. +
  262. + [ ! "$mtdnum" ] && {
  263. + CI_UBIPART="rootfs"
  264. + mtdnum="$(find_mtd_index "$CI_UBIPART")"
  265. + }
  266. +
  267. + if [ ! "$mtdnum" ]; then
  268. + echo "cannot find mtd device $CI_UBIPART"
  269. + umount -a
  270. + reboot -f
  271. + fi
  272. +
  273. + local mtddev="/dev/mtd${mtdnum}"
  274. + ubidetach -p "${mtddev}" || true
  275. + sync
  276. + ubiformat "${mtddev}" -y -f "${ubi_file}"
  277. + ubiattach -p "${mtddev}"
  278. + nand_do_upgrade_success
  279. +}
  280. +
  281. +# Write the UBIFS image to UBI volume
  282. +nand_upgrade_ubifs() {
  283. + local rootfs_length=`(cat $1 | wc -c) 2> /dev/null`
  284. +
  285. + nand_upgrade_prepare_ubi "$rootfs_length" "ubifs" "0" "0"
  286. +
  287. + local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  288. + local root_ubivol="$(nand_find_volume $ubidev rootfs)"
  289. + ubiupdatevol /dev/$root_ubivol -s $rootfs_length $1
  290. +
  291. + nand_do_upgrade_success
  292. +}
  293. +
  294. +nand_board_name() {
  295. + if type 'platform_nand_board_name' >/dev/null 2>/dev/null; then
  296. + platform_nand_board_name
  297. + return
  298. + fi
  299. +
  300. + cat /tmp/sysinfo/board_name
  301. +}
  302. +
  303. +nand_upgrade_tar() {
  304. + local tar_file="$1"
  305. + local board_name="$(nand_board_name)"
  306. + local kernel_mtd="$(find_mtd_index $CI_KERNPART)"
  307. +
  308. + local kernel_length=`(tar xf $tar_file sysupgrade-$board_name/kernel -O | wc -c) 2> /dev/null`
  309. + local rootfs_length=`(tar xf $tar_file sysupgrade-$board_name/root -O | wc -c) 2> /dev/null`
  310. +
  311. + local rootfs_type="$(identify_tar "$tar_file" sysupgrade-$board_name/root)"
  312. +
  313. + local has_kernel=1
  314. + local has_env=0
  315. +
  316. + [ "$kernel_length" != 0 -a -n "$kernel_mtd" ] && {
  317. + tar xf $tar_file sysupgrade-$board_name/kernel -O | mtd write - $CI_KERNPART
  318. + }
  319. + [ "$kernel_length" = 0 -o ! -z "$kernel_mtd" ] && has_kernel=0
  320. +
  321. + nand_upgrade_prepare_ubi "$rootfs_length" "$rootfs_type" "$has_kernel" "$has_env"
  322. +
  323. + local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  324. + [ "$has_kernel" = "1" ] && {
  325. + local kern_ubivol="$(nand_find_volume $ubidev kernel)"
  326. + tar xf $tar_file sysupgrade-$board_name/kernel -O | \
  327. + ubiupdatevol /dev/$kern_ubivol -s $kernel_length -
  328. + }
  329. +
  330. + local root_ubivol="$(nand_find_volume $ubidev rootfs)"
  331. + tar xf $tar_file sysupgrade-$board_name/root -O | \
  332. + ubiupdatevol /dev/$root_ubivol -s $rootfs_length -
  333. +
  334. + nand_do_upgrade_success
  335. +}
  336. +
  337. +# Recognize type of passed file and start the upgrade process
  338. +nand_do_upgrade_stage2() {
  339. + local file_type=$(identify $1)
  340. +
  341. + if type 'platform_nand_pre_upgrade' >/dev/null 2>/dev/null; then
  342. + platform_nand_pre_upgrade "$1"
  343. + fi
  344. +
  345. + [ ! "$(find_mtd_index "$CI_UBIPART")" ] && CI_UBIPART="rootfs"
  346. +
  347. + case "$file_type" in
  348. + "ubi") nand_upgrade_ubinized $1;;
  349. + "ubifs") nand_upgrade_ubifs $1;;
  350. + *) nand_upgrade_tar $1;;
  351. + esac
  352. +}
  353. +
  354. +nand_upgrade_stage2() {
  355. + [ $1 = "nand" ] && {
  356. + [ -f "$2" ] && {
  357. + touch /tmp/sysupgrade
  358. +
  359. + killall -9 telnetd
  360. + killall -9 dropbear
  361. + killall -9 ash
  362. +
  363. + kill_remaining TERM
  364. + sleep 3
  365. + kill_remaining KILL
  366. +
  367. + sleep 1
  368. +
  369. + if [ -n "$(rootfs_type)" ]; then
  370. + v "Switching to ramdisk..."
  371. + run_ramfs ". /lib/functions.sh; include /lib/upgrade; nand_do_upgrade_stage2 $2"
  372. + else
  373. + nand_do_upgrade_stage2 $2
  374. + fi
  375. + return 0
  376. + }
  377. + echo "Nand upgrade failed"
  378. + exit 1
  379. + }
  380. +}
  381. +
  382. +nand_upgrade_stage1() {
  383. + [ -f /tmp/sysupgrade-nand-path ] && {
  384. + path="$(cat /tmp/sysupgrade-nand-path)"
  385. + [ "$SAVE_CONFIG" != 1 -a -f "$CONF_TAR" ] &&
  386. + rm $CONF_TAR
  387. +
  388. + ubus call system nandupgrade "{\"prefix\": \"$RAM_ROOT\", \"path\": \"$path\" }"
  389. + exit 0
  390. + }
  391. +}
  392. +
  393. +# Check if passed file is a valid one for NAND sysupgrade. Currently it accepts
  394. +# 3 types of files:
  395. +# 1) UBI - should contain an ubinized image, header is checked for the proper
  396. +# MAGIC
  397. +# 2) UBIFS - should contain UBIFS partition that will replace "rootfs" volume,
  398. +# header is checked for the proper MAGIC
  399. +# 3) TAR - archive has to include "sysupgrade-BOARD" directory with a non-empty
  400. +# "CONTROL" file (at this point its content isn't verified)
  401. +#
  402. +# You usually want to call this function in platform_check_image.
  403. +#
  404. +# $(1): board name, used in case of passing TAR file
  405. +# $(2): file to be checked
  406. +nand_do_platform_check() {
  407. + local board_name="$1"
  408. + local tar_file="$2"
  409. + local control_length=`(tar xf $tar_file sysupgrade-$board_name/CONTROL -O | wc -c) 2> /dev/null`
  410. + local file_type="$(identify $2)"
  411. +
  412. + [ "$control_length" = 0 -a "$file_type" != "ubi" -a "$file_type" != "ubifs" ] && {
  413. + echo "Invalid sysupgrade file."
  414. + return 1
  415. + }
  416. +
  417. + return 0
  418. +}
  419. +
  420. +# Start NAND upgrade process
  421. +#
  422. +# $(1): file to be used for upgrade
  423. +nand_do_upgrade() {
  424. + echo -n $1 > /tmp/sysupgrade-nand-path
  425. + install_bin /sbin/upgraded
  426. + ln -s "$RAM_ROOT"/sbin/upgraded /tmp/upgraded
  427. + nand_upgrade_stage1
  428. +}
  429. diff --git a/package/system/procd/Makefile b/package/system/procd/Makefile
  430. index ea014b5b3461e1ed55fb272592a1c2be6535c2c8..64a78cc24ee9caf58ea140d161cad2b5742c2ebd 100644
  431. --- a/package/system/procd/Makefile
  432. +++ b/package/system/procd/Makefile
  433. @@ -22,11 +22,9 @@ PKG_LICENSE_FILES:=
  434. PKG_MAINTAINER:=John Crispin <john@phrozen.org>
  435. -PKG_FLAGS:=nonshared
  436. -
  437. PKG_CONFIG_DEPENDS:= \
  438. CONFIG_TARGET_INIT_PATH CONFIG_KERNEL_SECCOMP \
  439. - CONFIG_NAND_SUPPORT CONFIG_PROCD_SHOW_BOOT CONFIG_PROCD_ZRAM_TMPFS \
  440. + CONFIG_PROCD_SHOW_BOOT CONFIG_PROCD_ZRAM_TMPFS \
  441. CONFIG_KERNEL_NAMESPACES CONFIG_PACKAGE_procd-ujail CONFIG_PACKAGE_procd-seccomp
  442. include $(INCLUDE_DIR)/package.mk
  443. @@ -42,7 +40,7 @@ TARGET_LDFLAGS += $(if $(CONFIG_USE_GLIBC),-lrt)
  444. define Package/procd
  445. SECTION:=base
  446. CATEGORY:=Base system
  447. - DEPENDS:=+ubusd +ubus +libjson-script +ubox +USE_GLIBC:librt +libubox +libubus +NAND_SUPPORT:procd-nand
  448. + DEPENDS:=+ubusd +ubus +libjson-script +ubox +USE_GLIBC:librt +libubox +libubus
  449. TITLE:=OpenWrt system process manager
  450. endef
  451. @@ -60,20 +58,6 @@ define Package/procd-seccomp
  452. TITLE:=OpenWrt process seccomp helper + utrace
  453. endef
  454. -define Package/procd-nand
  455. - SECTION:=utils
  456. - CATEGORY:=Utilities
  457. - DEPENDS:=@NAND_SUPPORT +ubi-utils
  458. - TITLE:=OpenWrt sysupgrade nand helper
  459. -endef
  460. -
  461. -define Package/procd-nand-firstboot
  462. - SECTION:=utils
  463. - CATEGORY:=Utilities
  464. - DEPENDS:=procd-nand
  465. - TITLE:=OpenWrt firstboot nand helper
  466. -endef
  467. -
  468. define Package/procd/config
  469. menu "Configuration"
  470. depends on PACKAGE_procd
  471. @@ -91,10 +75,6 @@ endmenu
  472. endef
  473. -ifeq ($(CONFIG_NAND_SUPPORT),y)
  474. - CMAKE_OPTIONS += -DBUILD_UPGRADED=1
  475. -endif
  476. -
  477. ifeq ($(CONFIG_PROCD_SHOW_BOOT),y)
  478. CMAKE_OPTIONS += -DSHOW_BOOT_ON_CONSOLE=1
  479. endif
  480. @@ -114,7 +94,7 @@ endif
  481. define Package/procd/install
  482. $(INSTALL_DIR) $(1)/sbin $(1)/etc $(1)/lib/functions
  483. - $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/{init,procd,askfirst,udevtrigger} $(1)/sbin/
  484. + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/{init,procd,askfirst,udevtrigger,upgraded} $(1)/sbin/
  485. $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libsetlbf.so $(1)/lib
  486. $(INSTALL_BIN) ./files/reload_config $(1)/sbin/
  487. $(INSTALL_DATA) ./files/hotplug*.json $(1)/etc/
  488. @@ -133,21 +113,6 @@ define Package/procd-seccomp/install
  489. $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libpreload-trace.so $(1)/lib
  490. endef
  491. -define Package/procd-nand/install
  492. - $(INSTALL_DIR) $(1)/sbin $(1)/lib/upgrade
  493. -
  494. - $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upgraded $(1)/sbin/
  495. - $(INSTALL_DATA) ./files/nand.sh $(1)/lib/upgrade/
  496. -endef
  497. -
  498. -define Package/procd-nand-firstboot/install
  499. - $(INSTALL_DIR) $(1)/lib/preinit
  500. -
  501. - $(INSTALL_DATA) ./files/nand-preinit.sh $(1)/lib/preinit/60-nand-firstboot.sh
  502. -endef
  503. -
  504. $(eval $(call BuildPackage,procd))
  505. $(eval $(call BuildPackage,procd-ujail))
  506. $(eval $(call BuildPackage,procd-seccomp))
  507. -$(eval $(call BuildPackage,procd-nand))
  508. -$(eval $(call BuildPackage,procd-nand-firstboot))
  509. diff --git a/package/system/procd/files/nand-preinit.sh b/package/system/procd/files/nand-preinit.sh
  510. deleted file mode 100644
  511. index cf596246d1f2891cbeb7b5c7cac4bb6e002b13fb..0000000000000000000000000000000000000000
  512. --- a/package/system/procd/files/nand-preinit.sh
  513. +++ /dev/null
  514. @@ -1,21 +0,0 @@
  515. -#!/bin/sh
  516. -# Copyright (C) 2014 OpenWrt.org
  517. -
  518. -nand_takeover() {
  519. - . /lib/upgrade/nand.sh
  520. - mtd=$(find_mtd_index "$CI_UBIPART")
  521. - esize=$(cat /proc/mtd | grep mtd$mtd |cut -d" " -f 3)
  522. - [ -z "$esize" ] && return 1
  523. - esize=$(printf "%d" 0x$esize)
  524. - for a in `seq 0 64`; do
  525. - mtd -o $((a * esize)) -l 400 dump /dev/mtd$mtd > /tmp/takeover.hdr
  526. - MAGIC=$(dd if=/tmp/takeover.hdr bs=1 skip=261 count=5 2> /dev/null)
  527. - SIZE=$(printf "%d" 0x$(dd if=/tmp/takeover.hdr bs=4 count=1 2> /dev/null | hexdump -v -n 4 -e '1/1 "%02x"'))
  528. - [ "$MAGIC" = "ustar" ] && {
  529. - mtd -o $((a * esize)) -l $((SIZE + 4)) dump /dev/mtd$mtd | dd bs=1 skip=4 of=/tmp/sysupgrade.tar
  530. - nand_do_upgrade_stage2 /tmp/sysupgrade.tar
  531. - }
  532. - done
  533. -}
  534. -
  535. -boot_hook_add initramfs nand_takeover
  536. diff --git a/package/system/procd/files/nand.sh b/package/system/procd/files/nand.sh
  537. deleted file mode 100644
  538. index 6bd2005344c081df20e5a330a69e49e37225c39f..0000000000000000000000000000000000000000
  539. --- a/package/system/procd/files/nand.sh
  540. +++ /dev/null
  541. @@ -1,376 +0,0 @@
  542. -#!/bin/sh
  543. -# Copyright (C) 2014 OpenWrt.org
  544. -#
  545. -
  546. -. /lib/functions.sh
  547. -
  548. -# 'kernel' partition on NAND contains the kernel
  549. -CI_KERNPART="kernel"
  550. -
  551. -# 'ubi' partition on NAND contains UBI
  552. -CI_UBIPART="ubi"
  553. -
  554. -ubi_mknod() {
  555. - local dir="$1"
  556. - local dev="/dev/$(basename $dir)"
  557. -
  558. - [ -e "$dev" ] && return 0
  559. -
  560. - local devid="$(cat $dir/dev)"
  561. - local major="${devid%%:*}"
  562. - local minor="${devid##*:}"
  563. - mknod "$dev" c $major $minor
  564. -}
  565. -
  566. -nand_find_volume() {
  567. - local ubidevdir ubivoldir
  568. - ubidevdir="/sys/devices/virtual/ubi/$1"
  569. - [ ! -d "$ubidevdir" ] && return 1
  570. - for ubivoldir in $ubidevdir/${1}_*; do
  571. - [ ! -d "$ubivoldir" ] && continue
  572. - if [ "$( cat $ubivoldir/name )" = "$2" ]; then
  573. - basename $ubivoldir
  574. - ubi_mknod "$ubivoldir"
  575. - return 0
  576. - fi
  577. - done
  578. -}
  579. -
  580. -nand_find_ubi() {
  581. - local ubidevdir ubidev mtdnum
  582. - mtdnum="$( find_mtd_index $1 )"
  583. - [ ! "$mtdnum" ] && return 1
  584. - for ubidevdir in /sys/devices/virtual/ubi/ubi*; do
  585. - [ ! -d "$ubidevdir" ] && continue
  586. - cmtdnum="$( cat $ubidevdir/mtd_num )"
  587. - [ ! "$mtdnum" ] && continue
  588. - if [ "$mtdnum" = "$cmtdnum" ]; then
  589. - ubidev=$( basename $ubidevdir )
  590. - ubi_mknod "$ubidevdir"
  591. - echo $ubidev
  592. - return 0
  593. - fi
  594. - done
  595. -}
  596. -
  597. -nand_get_magic_long() {
  598. - dd if="$1" skip=$2 bs=4 count=1 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
  599. -}
  600. -
  601. -get_magic_long_tar() {
  602. - ( tar xf $1 $2 -O | dd bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2> /dev/null
  603. -}
  604. -
  605. -identify_magic() {
  606. - local magic=$1
  607. - case "$magic" in
  608. - "55424923")
  609. - echo "ubi"
  610. - ;;
  611. - "31181006")
  612. - echo "ubifs"
  613. - ;;
  614. - "68737173")
  615. - echo "squashfs"
  616. - ;;
  617. - "d00dfeed")
  618. - echo "fit"
  619. - ;;
  620. - "4349"*)
  621. - echo "combined"
  622. - ;;
  623. - *)
  624. - echo "unknown $magic"
  625. - ;;
  626. - esac
  627. -}
  628. -
  629. -
  630. -identify() {
  631. - identify_magic $(nand_get_magic_long "$1" "${2:-0}")
  632. -}
  633. -
  634. -identify_tar() {
  635. - identify_magic $(get_magic_long_tar "$1" "$2")
  636. -}
  637. -
  638. -nand_restore_config() {
  639. - sync
  640. - local ubidev=$( nand_find_ubi $CI_UBIPART )
  641. - local ubivol="$( nand_find_volume $ubidev rootfs_data )"
  642. - [ ! "$ubivol" ] &&
  643. - ubivol="$( nand_find_volume $ubidev rootfs )"
  644. - mkdir /tmp/new_root
  645. - if ! mount -t ubifs /dev/$ubivol /tmp/new_root; then
  646. - echo "mounting ubifs $ubivol failed"
  647. - rmdir /tmp/new_root
  648. - return 1
  649. - fi
  650. - mv "$1" "/tmp/new_root/sysupgrade.tgz"
  651. - umount /tmp/new_root
  652. - sync
  653. - rmdir /tmp/new_root
  654. -}
  655. -
  656. -nand_upgrade_prepare_ubi() {
  657. - local rootfs_length="$1"
  658. - local rootfs_type="$2"
  659. - local has_kernel="${3:-0}"
  660. - local has_env="${4:-0}"
  661. -
  662. - local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
  663. - if [ ! "$mtdnum" ]; then
  664. - echo "cannot find ubi mtd partition $CI_UBIPART"
  665. - return 1
  666. - fi
  667. -
  668. - local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  669. - if [ ! "$ubidev" ]; then
  670. - ubiattach -m "$mtdnum"
  671. - sync
  672. - ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  673. - fi
  674. -
  675. - if [ ! "$ubidev" ]; then
  676. - ubiformat /dev/mtd$mtdnum -y
  677. - ubiattach -m "$mtdnum"
  678. - sync
  679. - ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  680. - [ "$has_env" -gt 0 ] && {
  681. - ubimkvol /dev/$ubidev -n 0 -N ubootenv -s 1MiB
  682. - ubimkvol /dev/$ubidev -n 1 -N ubootenv2 -s 1MiB
  683. - }
  684. - fi
  685. -
  686. - local kern_ubivol="$( nand_find_volume $ubidev kernel )"
  687. - local root_ubivol="$( nand_find_volume $ubidev rootfs )"
  688. - local data_ubivol="$( nand_find_volume $ubidev rootfs_data )"
  689. -
  690. - # remove ubiblock device of rootfs
  691. - local root_ubiblk="ubiblock${root_ubivol:3}"
  692. - if [ "$root_ubivol" -a -e "/dev/$root_ubiblk" ]; then
  693. - echo "removing $root_ubiblk"
  694. - if ! ubiblock -r /dev/$root_ubivol; then
  695. - echo "cannot remove $root_ubiblk"
  696. - return 1;
  697. - fi
  698. - fi
  699. -
  700. - # kill volumes
  701. - [ "$kern_ubivol" ] && ubirmvol /dev/$ubidev -N kernel || true
  702. - [ "$root_ubivol" ] && ubirmvol /dev/$ubidev -N rootfs || true
  703. - [ "$data_ubivol" ] && ubirmvol /dev/$ubidev -N rootfs_data || true
  704. -
  705. - # update kernel
  706. - if [ "$has_kernel" = "1" ]; then
  707. - if ! ubimkvol /dev/$ubidev -N kernel -s $kernel_length; then
  708. - echo "cannot create kernel volume"
  709. - return 1;
  710. - fi
  711. - fi
  712. -
  713. - # update rootfs
  714. - local root_size_param
  715. - if [ "$rootfs_type" = "ubifs" ]; then
  716. - root_size_param="-m"
  717. - else
  718. - root_size_param="-s $rootfs_length"
  719. - fi
  720. - if ! ubimkvol /dev/$ubidev -N rootfs $root_size_param; then
  721. - echo "cannot create rootfs volume"
  722. - return 1;
  723. - fi
  724. -
  725. - # create rootfs_data for non-ubifs rootfs
  726. - if [ "$rootfs_type" != "ubifs" ]; then
  727. - if ! ubimkvol /dev/$ubidev -N rootfs_data -m; then
  728. - echo "cannot initialize rootfs_data volume"
  729. - return 1
  730. - fi
  731. - fi
  732. - sync
  733. - return 0
  734. -}
  735. -
  736. -nand_do_upgrade_success() {
  737. - local conf_tar="/tmp/sysupgrade.tgz"
  738. -
  739. - sync
  740. - [ -f "$conf_tar" ] && nand_restore_config "$conf_tar"
  741. - echo "sysupgrade successful"
  742. - umount -a
  743. - reboot -f
  744. -}
  745. -
  746. -# Flash the UBI image to MTD partition
  747. -nand_upgrade_ubinized() {
  748. - local ubi_file="$1"
  749. - local mtdnum="$(find_mtd_index "$CI_UBIPART")"
  750. -
  751. - [ ! "$mtdnum" ] && {
  752. - CI_UBIPART="rootfs"
  753. - mtdnum="$(find_mtd_index "$CI_UBIPART")"
  754. - }
  755. -
  756. - if [ ! "$mtdnum" ]; then
  757. - echo "cannot find mtd device $CI_UBIPART"
  758. - umount -a
  759. - reboot -f
  760. - fi
  761. -
  762. - local mtddev="/dev/mtd${mtdnum}"
  763. - ubidetach -p "${mtddev}" || true
  764. - sync
  765. - ubiformat "${mtddev}" -y -f "${ubi_file}"
  766. - ubiattach -p "${mtddev}"
  767. - nand_do_upgrade_success
  768. -}
  769. -
  770. -# Write the UBIFS image to UBI volume
  771. -nand_upgrade_ubifs() {
  772. - local rootfs_length=`(cat $1 | wc -c) 2> /dev/null`
  773. -
  774. - nand_upgrade_prepare_ubi "$rootfs_length" "ubifs" "0" "0"
  775. -
  776. - local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  777. - local root_ubivol="$(nand_find_volume $ubidev rootfs)"
  778. - ubiupdatevol /dev/$root_ubivol -s $rootfs_length $1
  779. -
  780. - nand_do_upgrade_success
  781. -}
  782. -
  783. -nand_board_name() {
  784. - if type 'platform_nand_board_name' >/dev/null 2>/dev/null; then
  785. - platform_nand_board_name
  786. - return
  787. - fi
  788. -
  789. - cat /tmp/sysinfo/board_name
  790. -}
  791. -
  792. -nand_upgrade_tar() {
  793. - local tar_file="$1"
  794. - local board_name="$(nand_board_name)"
  795. - local kernel_mtd="$(find_mtd_index $CI_KERNPART)"
  796. -
  797. - local kernel_length=`(tar xf $tar_file sysupgrade-$board_name/kernel -O | wc -c) 2> /dev/null`
  798. - local rootfs_length=`(tar xf $tar_file sysupgrade-$board_name/root -O | wc -c) 2> /dev/null`
  799. -
  800. - local rootfs_type="$(identify_tar "$tar_file" sysupgrade-$board_name/root)"
  801. -
  802. - local has_kernel=1
  803. - local has_env=0
  804. -
  805. - [ "$kernel_length" != 0 -a -n "$kernel_mtd" ] && {
  806. - tar xf $tar_file sysupgrade-$board_name/kernel -O | mtd write - $CI_KERNPART
  807. - }
  808. - [ "$kernel_length" = 0 -o ! -z "$kernel_mtd" ] && has_kernel=0
  809. -
  810. - nand_upgrade_prepare_ubi "$rootfs_length" "$rootfs_type" "$has_kernel" "$has_env"
  811. -
  812. - local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
  813. - [ "$has_kernel" = "1" ] && {
  814. - local kern_ubivol="$(nand_find_volume $ubidev kernel)"
  815. - tar xf $tar_file sysupgrade-$board_name/kernel -O | \
  816. - ubiupdatevol /dev/$kern_ubivol -s $kernel_length -
  817. - }
  818. -
  819. - local root_ubivol="$(nand_find_volume $ubidev rootfs)"
  820. - tar xf $tar_file sysupgrade-$board_name/root -O | \
  821. - ubiupdatevol /dev/$root_ubivol -s $rootfs_length -
  822. -
  823. - nand_do_upgrade_success
  824. -}
  825. -
  826. -# Recognize type of passed file and start the upgrade process
  827. -nand_do_upgrade_stage2() {
  828. - local file_type=$(identify $1)
  829. -
  830. - if type 'platform_nand_pre_upgrade' >/dev/null 2>/dev/null; then
  831. - platform_nand_pre_upgrade "$1"
  832. - fi
  833. -
  834. - [ ! "$(find_mtd_index "$CI_UBIPART")" ] && CI_UBIPART="rootfs"
  835. -
  836. - case "$file_type" in
  837. - "ubi") nand_upgrade_ubinized $1;;
  838. - "ubifs") nand_upgrade_ubifs $1;;
  839. - *) nand_upgrade_tar $1;;
  840. - esac
  841. -}
  842. -
  843. -nand_upgrade_stage2() {
  844. - [ $1 = "nand" ] && {
  845. - [ -f "$2" ] && {
  846. - touch /tmp/sysupgrade
  847. -
  848. - killall -9 telnetd
  849. - killall -9 dropbear
  850. - killall -9 ash
  851. -
  852. - kill_remaining TERM
  853. - sleep 3
  854. - kill_remaining KILL
  855. -
  856. - sleep 1
  857. -
  858. - if [ -n "$(rootfs_type)" ]; then
  859. - v "Switching to ramdisk..."
  860. - run_ramfs ". /lib/functions.sh; include /lib/upgrade; nand_do_upgrade_stage2 $2"
  861. - else
  862. - nand_do_upgrade_stage2 $2
  863. - fi
  864. - return 0
  865. - }
  866. - echo "Nand upgrade failed"
  867. - exit 1
  868. - }
  869. -}
  870. -
  871. -nand_upgrade_stage1() {
  872. - [ -f /tmp/sysupgrade-nand-path ] && {
  873. - path="$(cat /tmp/sysupgrade-nand-path)"
  874. - [ "$SAVE_CONFIG" != 1 -a -f "$CONF_TAR" ] &&
  875. - rm $CONF_TAR
  876. -
  877. - ubus call system nandupgrade "{\"prefix\": \"$RAM_ROOT\", \"path\": \"$path\" }"
  878. - exit 0
  879. - }
  880. -}
  881. -
  882. -# Check if passed file is a valid one for NAND sysupgrade. Currently it accepts
  883. -# 3 types of files:
  884. -# 1) UBI - should contain an ubinized image, header is checked for the proper
  885. -# MAGIC
  886. -# 2) UBIFS - should contain UBIFS partition that will replace "rootfs" volume,
  887. -# header is checked for the proper MAGIC
  888. -# 3) TAR - archive has to include "sysupgrade-BOARD" directory with a non-empty
  889. -# "CONTROL" file (at this point its content isn't verified)
  890. -#
  891. -# You usually want to call this function in platform_check_image.
  892. -#
  893. -# $(1): board name, used in case of passing TAR file
  894. -# $(2): file to be checked
  895. -nand_do_platform_check() {
  896. - local board_name="$1"
  897. - local tar_file="$2"
  898. - local control_length=`(tar xf $tar_file sysupgrade-$board_name/CONTROL -O | wc -c) 2> /dev/null`
  899. - local file_type="$(identify $2)"
  900. -
  901. - [ "$control_length" = 0 -a "$file_type" != "ubi" -a "$file_type" != "ubifs" ] && {
  902. - echo "Invalid sysupgrade file."
  903. - return 1
  904. - }
  905. -
  906. - return 0
  907. -}
  908. -
  909. -# Start NAND upgrade process
  910. -#
  911. -# $(1): file to be used for upgrade
  912. -nand_do_upgrade() {
  913. - echo -n $1 > /tmp/sysupgrade-nand-path
  914. - install_bin /sbin/upgraded
  915. - ln -s "$RAM_ROOT"/sbin/upgraded /tmp/upgraded
  916. - nand_upgrade_stage1
  917. -}